Skip to content

fix(gateway): omit JavaScript class names from proven RPC failures - #124563

Merged
steipete merged 3 commits into
mainfrom
steipete/gateway-errorshape-contract
Aug 16, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/gateway-errorshape-contract

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators could receive JavaScript error class names in Gateway RPC failures when a handler passed a diagnostic formatter or raw String(error) into ErrorShape.message.

The concrete live reproduction was fs.listDir on a missing workspace descendant. The CLI rendered Gateway call failed: Error: ENOENT: ..., even though ErrorShape.message is the user-facing wire contract shared by the CLI, Control UI, plugins, and ACP.

Why This Change Was Made

Adds one Gateway-owned errorShapeFromError constructor that uses the canonical redacting formatErrorMessageWithCode renderer, then adopts it at eight producers with proven handler/client reachability:

Producer Reachability and observed behavior
src/gateway/server-methods/fs.ts:119 A schema-valid absolute path reaches fs.readdir; ENOENT previously became Error: ENOENT.... Live CLI proof is below.
src/gateway/agent-turn/agent-delivery-phase.ts:142 Strict delivery without an unambiguous configured channel reaches resolveMessageChannelSelection, whose ordinary Error previously leaked Error:.
src/gateway/agent-turn/agent-delivery-phase.ts:153 A strict explicit target can carry a plugin target-resolution Error; the new owner-boundary test proves the message omits the class and retains INVALID_TARGET.
src/gateway/agent-turn/agent-delivery-phase.ts:177 Strict fallback target resolution returns the same typed Error family; an existing handler test reproduced Error: Delivering to Telegram requires target.
src/gateway/agent-turn/agent-turn-service.ts:414 A session deleted between persistence and lifecycle admission produced Error: Session ... was deleted...; the existing handler test already asserted the old prefix exactly.
src/gateway/agent-turn/agent-session-persist.ts:373 A session deleted before its initial authoritative store touch produced the same prefixed wire error; existing handler coverage reproduced it.
src/gateway/agent-turn/agent-session-persist.ts:431 A newly touched session deleted before admission revalidation produced the same prefixed wire error; existing handler coverage reproduced it.
src/gateway/agent-turn/agent-run-admission-phase.ts:353 Plugin-subagent registry persistence can throw SQLite errors. The handler test now proves `disk full

This deliberately does not change formatForLog; diagnostic logs keep error names and diagnostic formatting.

Inventory and guard decision

The task's 55-site grep count was incomplete on current main: a balanced AST inventory found 67 message expressions across 34 files because 12 multiline calls were missed. Of those, 60 can receive an Error, six are already behavior-neutral because their Error branch uses .message, and one stringifies a schema-validated identifier rather than an error.

This PR changes 8 proven sites and deliberately leaves 59:

  • 52 reachable candidates in web, health, TTS, send, talk, pairing, auth status, nodes, attachments, board/worktrees, and remaining agent/WS fallback paths. Each needs its own handler-level wire proof before behavior changes.
  • 6 already class-safe expressions in portals, conversations, and schema-validated channel formatting.
  • 1 non-error secrets.resolve target identifier coercion.

I did not add the proposed AST guard. Making it pass now would require either 52 additional untested behavior changes or roughly 59 allow comments that normalize known debt. The single canonical constructor makes the correct new path obvious without institutionalizing that baseline; a future guard is worthwhile once the remaining handlers have focused wire tests.

User Impact

For the repaired RPC paths, clients now render the actionable operator message and structured error code without a JavaScript class prefix. Structured primary and cause-chain codes still survive, and sensitive text still goes through the canonical redactor.

No protocol shape, ErrorShape, outer Gateway error codes, or diagnostic log formatting changed. No changelog entry was added, per task instructions.

Production LOC: +33/-22 (net +11). Tests/test support: +89/-13 (net +76).

Evidence

Live isolated scratch Gateway on port 19789 with channels skipped:

before: Gateway call failed: Error: ENOENT: no such file or directory, scandir '<scratch>/workspace-dev/does-not-exist'
after:  Gateway call failed: ENOENT: no such file or directory, scandir '<scratch>/workspace-dev/does-not-exist' | ENOENT

The JSON response retained outer code: INVALID_REQUEST; only the wire message changed, and it now retains the filesystem's structured ENOENT.

Validation:

  • Regression-first proof: 7 existing handler tests failed against the old producers for the expected class-prefix/code-loss reason, then passed after the repair.
  • The new strict target-resolution test was also run with the old String(Error) producer restored temporarily; it failed with Error: Reserved target... and missing INVALID_TARGET, then passed with the canonical helper.
  • node scripts/run-vitest.mjs src/gateway/server-methods/fs.test.ts src/gateway/server-methods/agent.test.ts src/gateway/server.agent.gateway-server-agent-a.test.ts src/gateway/server.agent.gateway-server-agent-b.test.ts — 335 passed.
  • node scripts/run-vitest.mjs src/gateway/agent-turn/agent-delivery-phase.test.ts — 1 passed.
  • pnpm build — passed.
  • node scripts/check-changed.mjs — passed on Blacksmith Testbox tbx_01m057vte4va102gpfnt62v78r; exact successful run: https://github.com/openclaw/openclaw/actions/runs/31946483691
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output — clean, no accepted/actionable findings. Follow-up test-only reviews were also clean.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 12:25
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 8:31 AM ET / 12:31 UTC.

ClawSweeper review

What this changes

This PR adds a Gateway-local ErrorShape constructor and uses it at eight proven RPC failure producers so clients receive redacted messages without JavaScript error class names while retaining structured codes.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking findings: current main still emits diagnostic error formatting on the targeted RPC paths, while this PR uses the existing redacting message formatter at the Gateway wire boundary. The protected maintainer label means it should remain open for normal maintainer handling.

Priority: P2
Reviewed head: fe29bbcb46abde10c1bf44e93e0e49599a2e327e

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with direct terminal evidence, regression coverage, and no supported correctness or security finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.
Evidence reviewed 7 items Current failure path: Current main sends String(error) from fs.listDir into ErrorShape, which includes an Error class name for ordinary filesystem errors.
Diagnostic versus wire boundary: formatForLog is explicitly for Gateway logs and includes Error.name and code diagnostics; it is unsuitable as client-facing wire text.
Canonical formatter contract: The existing formatter delegates to normalization-core with secret redaction and code inclusion; its implementation uses Error.message rather than Error.toString and preserves cause-chain codes.
Findings None None.
Security None None.

How this fits together

Gateway handlers turn filesystem, delivery, session, and agent-run failures into ErrorShape responses consumed by CLI and other RPC clients. The change separates client-facing error text from Gateway diagnostic log rendering.

flowchart LR
  A[RPC request] --> B[Gateway handler]
  B --> C[Filesystem or agent-run failure]
  C --> D[Wire error formatter]
  D --> E[ErrorShape response]
  E --> F[CLI and RPC clients]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by 11 lines; the growth is justified by the Gateway-local bridge because the protocol package cannot depend on src/infra's redacting formatter.
Agent review details

Security

None.

PR surface

Source +22, Tests +65. Total +87 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 9 53 31 +22
Tests 4 69 4 +65
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 122 35 +87

Review metrics

Metric Value Why it matters
Production versus test LOC production +33/-22 (net +11); tests/test support +89/-13 (net +76) The small production increase centralizes eight wire-error conversions at the Gateway boundary; test growth covers observable response payloads.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the ErrorShape protocol unchanged and land the Gateway-local redacting bridge after exact-head CI completes successfully.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the ErrorShape protocol unchanged and land the Gateway-local redacting bridge after exact-head CI completes successfully.

Do we have a high-confidence way to reproduce the issue?

Yes, with high confidence: current main directly stringifies or log-formats the implicated errors, and the PR body includes an isolated Gateway CLI before/after transcript for the fs.listDir path.

Is this the best way to solve the issue?

Yes. A Gateway-owned bridge is the narrowest maintainable location because the protocol-level ErrorShape constructor cannot import Gateway redaction policy, while the existing formatter already defines the desired message and code behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 66db70133b2c.

Labels

Label changes:

  • add P2: This repairs operator-facing Gateway error text on several bounded RPC failure paths without evidence of an availability or security emergency.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.

Label justifications:

  • P2: This repairs operator-facing Gateway error text on several bounded RPC failure paths without evidence of an availability or security emergency.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a direct isolated-Gateway CLI before/after transcript for the repaired filesystem RPC path, supplemented by focused handler regressions.

Evidence

What I checked:

Likely related people:

  • steipete: Current producer lines, ErrorShape construction, and the canonical formatter are attributed to the same recent Gateway commit; steipete also authored the focused follow-up repair. (role: recent Gateway and canonical error-formatting contributor; confidence: high; commits: 0c7b560b2346, 3f4dd7119f71, 03c188754ce2; files: src/gateway/server-methods/fs.ts, src/gateway/agent-turn/agent-delivery-phase.ts, src/infra/errors.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 7511601 into main Aug 16, 2026
251 checks passed
@steipete
steipete deleted the steipete/gateway-errorshape-contract branch August 16, 2026 12:40
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
…penclaw#124563)

* fix(gateway): keep diagnostic formatting out of wire errors

* test(gateway): cover strict delivery wire errors

* test(gateway): complete strict delivery request fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant