Skip to content

fix(cli): harden phala docs grep pattern passing and MCP request timeout - #487

Open
Leechael wants to merge 3 commits into
mainfrom
fix/cli-docs-mcp-hardening
Open

fix(cli): harden phala docs grep pattern passing and MCP request timeout#487
Leechael wants to merge 3 commits into
mainfrom
fix/cli-docs-mcp-hardening

Conversation

@Leechael

Copy link
Copy Markdown
Collaborator

Summary

Review follow-ups from #485 (which merged before these could land):

  • docs grep: pass the pattern via -e. A pattern starting with - would otherwise be parsed by rg as flags (e.g. -foo becomes -f oo and fails with a confusing "No such file or directory" error). -- was considered first, but the docs virtual filesystem shell does not support it (verified live: rg ... -- returns "unrecognized option '--'"), while -e works for both regular and dash-leading patterns.
  • docs MCP calls now have a request timeout. Every call previously used a bare fetch with no timeout, so a hung docs server would block the CLI indefinitely -- especially painful for agent-driven usage. callDocsTool applies AbortSignal.timeout (default 60s, matching the CLI-wide default, overridable per call), and a new resolveDocsToolOptions helper wires the global --timeout flag into all five docs subcommands. Timeout failures get a distinct, actionable error message instead of the generic network-error one.
  • test fix: the errorTests loop in error-messages.test.ts allows cases up to 10s via the execa timeout, but bun:test kills any test at its default 5s. Cases with a real API round trip (e.g. cvms get invalid-id-format) exceed 5s on slower networks and fail locally / in the pre-commit hook despite correct behavior. Each case now gets a bun timeout 5s above its execa timeout. CI was unaffected because its API latency is lower.

Testing

  • bun run fmt / lint / type-check / test all clean (469 tests, 0 fail)
  • pre-commit hooks pass locally (previously blocked by the 5s bun test timeout described above)
  • Live smoke tests against docs.phala.com:
    • phala docs grep --files PHALA_CLOUD_API_KEY works unchanged
    • server-side rg -Sn -e '-foo' / returns exit 1 (no matches) instead of the flag-parsing error
    • PHALA_DOCS_MCP_URL=http://10.255.255.1/mcp phala docs search test --timeout 2 aborts in ~2.3s with: "Phala docs server at ... did not respond within 2s. Try again shortly, or browse https://docs.phala.com directly."

A pattern starting with `-` would otherwise be parsed by rg as flags
(e.g. `-foo` becomes `-f oo` and fails with a confusing "No such file
or directory" error). The `--` separator was considered first but the
docs virtual filesystem shell does not support it (verified live:
`rg ... --` returns "unrecognized option '--'"), while `-e` works for
both regular and dash-leading patterns.
The errorTests loop allows individual cases up to 10s via the execa
timeout, but bun:test kills any test at its default 5s timeout. Cases
that make a real API round trip (e.g. "cvms get invalid-id-format")
exceed 5s on slower networks and fail locally and in the pre-commit
hook even though the command behaved correctly. Give each case a bun
timeout 5s above its execa timeout so the execa deadline always wins.
CI was unaffected because its API latency is lower.
Every "phala docs" call previously used a bare fetch with no timeout,
so a hung docs server would block the CLI indefinitely -- especially
painful for agent-driven usage.

- callDocsTool now applies AbortSignal.timeout, defaulting to 60s
  (matching the CLI-wide default) with a per-call timeoutMs override
- new resolveDocsToolOptions helper wires the global --timeout flag
  (resolveTimeoutSeconds) into all five docs subcommands, so docs
  commands behave like every other command
- timeout failures get a distinct, actionable error message instead of
  the generic network-error one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant