Repository navigation
fix(code-mode): nested tool errors lose their message when details only flag the error - #159359
Conversation
…e error
Code Mode projects a nested native tool result to its `details` value. A
plugin tool that reports failure as `isError: true` with details such as
`{ error: true }` carries its reason only in text content, so the guest and
the model saw `{"error":true}` and could not explain the failure (observed
with visitor-access `visitor_list` when the plugin runtime was not started).
ToolSearchRuntime now owns the guest-value projection for both `callValue`
and a new `callExactValue`; the bridge's inline duplicate is removed. For an
explicit `isError: true` result whose details carry no string `message` or
`error`, the projection adds the text content as `message` (or returns
`{ message }` when details are absent). Other results, including core tool
failures reported through details status, are unchanged.
Output-schema validation must check what the tool returned, so the plain details unwrap stays for assertCatalogOutputMatchesSchema while only the guest projection adds error text.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. Reviewed September 27, 2026, 12:38 AM ET / 04:38 UTC (Revision 2). ClawSweeper reviewWhat this changesCode Mode adds a native tool's error text to the value returned to agent JavaScript when structured details lack an explanation, with regression coverage and updated guest API documentation. Merge readiness⛔ Needs changes before merge - 1 item remains The fix is still needed on current main, and the prior blank-message finding is addressed. The captured GitHub author association is CONTRIBUTOR, so after-fix behavior on a real Gateway remains a merge proof gate. Priority: P2 Review scores
Verification
How this fits togetherCode Mode runs agent-written JavaScript and sends nested calls through the bridge to Tool Search and native tools. Tool Search returns a guest value that the code can use and the agent can report. flowchart LR
A[Agent JavaScript] --> B[Code Mode bridge]
B --> C[Tool Search runtime]
C --> D[Native tool]
D --> E[Error result projection]
E --> F[Guest value]
F --> G[Agent response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +31, Tests +30, Docs +3. Total +64 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one Tool Search guest-value projection while validating tool output against raw details, and confirm the explanatory value in a redacted real Gateway Code Mode run. Do we have a high-confidence way to reproduce the issue? Yes. Current main drops text content from the visitor-access error shape, and the PR reports a matching live Gateway trace; this read-only review did not execute a Gateway. Is this the best way to solve the issue? Yes. The shared guest-value projection repairs both native call paths while output-schema validation continues to inspect raw tool details. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against aad795bf312a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Once details carry no non-empty string message or error, an explicit isError result takes its message from the text content, including when details.message is blank or not a string.
|
Landing without the requested after-fix live Gateway transcript, with this rationale:
After the next regular deployment includes this change, the same |
|
Merged via squash.
|
…ly flag the error (openclaw#159359) * fix(code-mode): keep nested tool error text when details only flag the error Code Mode projects a nested native tool result to its `details` value. A plugin tool that reports failure as `isError: true` with details such as `{ error: true }` carries its reason only in text content, so the guest and the model saw `{"error":true}` and could not explain the failure (observed with visitor-access `visitor_list` when the plugin runtime was not started). ToolSearchRuntime now owns the guest-value projection for both `callValue` and a new `callExactValue`; the bridge's inline duplicate is removed. For an explicit `isError: true` result whose details carry no string `message` or `error`, the projection adds the text content as `message` (or returns `{ message }` when details are absent). Other results, including core tool failures reported through details status, are unchanged. * fix(code-mode): validate output contracts against raw tool details Output-schema validation must check what the tool returned, so the plain details unwrap stays for assertCatalogOutputMatchesSchema while only the guest projection adds error text. * fix(code-mode): replace blank error messages with tool error text Once details carry no non-empty string message or error, an explicit isError result takes its message from the text content, including when details.message is blank or not a string.
What Problem This Solves
Fixes: in Code Mode, a nested tool failure shows up to the model as a bare
{"error":true}when the tool reportsisError: truebut keeps its explanation only in text content.Observed on a live Gateway: the visitor-access
visitor_listtool returned{ content: [{ type: "text", text: "Start the Gateway with visitor-access enabled before managing visitors." }], details: { error: true }, isError: true }. The nested-tool transcript event recorded the full result, but theexecresult the model received contained only"value":{"error":true}. Across five calls the model could only report{"error":true}and never saw why.User Impact
User impact: when a plugin tool fails inside a Code Mode cell, guest code and the model now see the tool's own error text (as
message) and can explain or recover from the failure. Tools whose error details already carry a non-emptymessageorerrorstring, and all non-error results, return exactly what they did before.Why This Change Was Made
Code Mode projects a nested native tool result to its
detailsvalue (the documented guest contract). That projection lived in two places,ToolSearchRuntime.callValueand an inline copy in the bridge'scallValuecase, and both droppedcontentunconditionally.ToolSearchRuntimenow owns the guest-value projection for bothcallValueand a newcallExactValue, and the bridge's duplicate is gone. For an explicitisError: trueresult whose details carry no non-emptymessageorerrorstring, the projection setsmessagefrom the joined text content, replacing a blank or non-stringmessage(or returns{ message }when details are absent). Output-schema validation still checks the rawdetails, so declared output contracts keep describing what the tool actually returned.The trigger is deliberately the explicit
isError: truemarker, not the broaderisToolResultErrorclassification: core tools such as shellexecreport failures throughdetails.status/exitCodewith potentially large output text, and duplicating that text into the guest value would inflate replies toward the program-data budget. Results still resolve rather than throw, matching how MCPisErrorresults already reach guest code.Docs:
docs/tools/code-mode/guest-api.mddocuments the addedmessage.Release-note context: Code Mode now surfaces a failing tool's error text (as
message) instead of a bare{"error":true}when the tool's details only flag the error.Evidence
keeps an explicit tool error's text when its details carry no messageinsrc/agents/code-mode.contracts.test.tsdrives the realexec→ bridge → catalog path with a visitor-shaped error result, a no-details error, a blankmessage, and a structured error whose details already carryerror. On the original code it fails with[{ error: true }, null, …]; with the fix it returns[{ error: true, message: reason }, { message }, { error: true, message: text }, <structured details unchanged>]. The blank-message case (from ClawSweeper's review) failed on the previous head withmessage: " ".pnpm test src/agents/code-mode.contracts.test.ts --maxWorkers=1warm wall is 12.9 s for the whole file, dominated by shared transform/import (tests 3%). CI seconds to follow once the run exists.tbx_01m3gbeghyqprpmz5ga7x9bky3(run):CI=1 node scripts/check-changed.mjson the changed paths passed (core typecheck, all core-test typecheck graphs, lint, dead-export scan, ratchets, format, docs baseline), thennode scripts/run-vitest.mjsovercode-mode.contracts,code-mode.bridge,code-mode-nodes,code-mode,tool-search-runtime, andtool-searchtests: 6 files, 271 tests passed.Follow-up (separate change): the visitor-access tools return successful output only as text with
details: {}, so Code Mode callers get{}on success too; those tools should return structured details.