Skip to content

fix(code-mode): nested tool errors lose their message when details only flag the error - #159359

Merged
steipete merged 3 commits into
mainfrom
steipete/clever-cerf-25c2cd
Sep 27, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/clever-cerf-25c2cd

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 reports isError: true but keeps its explanation only in text content.

Observed on a live Gateway: the visitor-access visitor_list tool 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 the exec result 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-empty message or error string, 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 details value (the documented guest contract). That projection lived in two places, ToolSearchRuntime.callValue and an inline copy in the bridge's callValue case, and both dropped content unconditionally.

ToolSearchRuntime now owns the guest-value projection for both callValue and a new callExactValue, and the bridge's duplicate is gone. For an explicit isError: true result whose details carry no non-empty message or error string, the projection sets message from the joined text content, replacing a blank or non-string message (or returns { message } when details are absent). Output-schema validation still checks the raw details, so declared output contracts keep describing what the tool actually returned.

The trigger is deliberately the explicit isError: true marker, not the broader isToolResultError classification: core tools such as shell exec report failures through details.status/exitCode with 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 MCP isError results already reach guest code.

Docs: docs/tools/code-mode/guest-api.md documents the added message.

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

  • Regression keeps an explicit tool error's text when its details carry no message in src/agents/code-mode.contracts.test.ts drives the real exec → bridge → catalog path with a visitor-shaped error result, a no-details error, a blank message, and a structured error whose details already carry error. 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 with message: " ".
  • Cost: the new test runs in 52 ms; pnpm test src/agents/code-mode.contracts.test.ts --maxWorkers=1 warm wall is 12.9 s for the whole file, dominated by shared transform/import (tests 3%). CI seconds to follow once the run exists.
  • Blacksmith Testbox tbx_01m3gbeghyqprpmz5ga7x9bky3 (run): CI=1 node scripts/check-changed.mjs on the changed paths passed (core typecheck, all core-test typecheck graphs, lint, dead-export scan, ratchets, format, docs baseline), then node scripts/run-vitest.mjs over code-mode.contracts, code-mode.bridge, code-mode-nodes, code-mode, tool-search-runtime, and tool-search tests: 6 files, 271 tests passed.
  • Codex autoreview of the combined candidate, and of the blank-message follow-up, found no remaining P0/P1 issues. An earlier gate run caught that the rename orphaned the output-schema validation callers; the second commit restores the raw-details unwrap for them.

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.

…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.
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 27, 2026, 12:38 AM ET / 04:38 UTC (Revision 2).

ClawSweeper review

What this changes

Code 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
Reviewed head: 60439b2f25c323f12311e55b905d7b83c4c38ac7

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch addresses the prior finding, while after-fix evidence is limited to the synthetic-tool harness.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 7 items Current main still drops the explanation: At the fetched main revision, both the Tool Search value path and the Code Mode bridge return details without the text content.
Concrete failing tool shape: The visitor-access tool returns text content alongside details containing only an error flag and an explicit isError marker.
Introduced projection: The patch projects text into a missing or blank error message only for explicit isError results; output-schema validation still unwraps raw details.
Findings None None.
Security None None.

How this fits together

Code 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]
Loading

Before merge

  • Complete next step (P2) - Add a redacted after-fix real Gateway Code Mode transcript showing the visitor-access error returned with its explanatory message. Redact IP addresses, keys, phone numbers, and private endpoints; update the PR body to trigger re-review, or ask a maintainer to comment @clawsweeper re-review if it does not.
Agent review details

Security

None.

PR surface

Source +31, Tests +30, Docs +3. Total +64 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 45 14 +31
Tests 1 30 0 +30
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 81 17 +64

Review metrics

Metric Value Why it matters
Production and test delta production +31 net lines, tests +30 net lines The production growth centralizes the two guest-value paths and adds the error projection; the test exercises the bridge boundary.

Technical review

Best 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.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Missing nested-tool error explanations impair Code Mode recovery, with a limited affected path.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

  • Current main still drops the explanation: At the fetched main revision, both the Tool Search value path and the Code Mode bridge return details without the text content. (src/agents/code-mode-bridge.ts:342, aad795bf312a)
  • Concrete failing tool shape: The visitor-access tool returns text content alongside details containing only an error flag and an explicit isError marker. (extensions/visitor-access/src/tools.ts:85, 60439b2f25c3)
  • Introduced projection: The patch projects text into a missing or blank error message only for explicit isError results; output-schema validation still unwraps raw details. (src/agents/tool-search-runtime.ts:709, 60439b2f25c3)
  • Prior finding addressed at current head: The new projection replaces whitespace-only messages, and the bridge regression expects the tool text for that case. This addresses the prior review's blank-message finding. (src/agents/code-mode.contracts.test.ts:139, 60439b2f25c3)
  • Proof coverage: The captured PR body describes a live Gateway observation before the fix and an after-fix Code Mode harness with synthetic plugin results and passing tests. It does not provide an after-fix real Gateway observation of the changed return value. (60439b2f25c3)
  • Current author association: The live GitHub REST response reports CONTRIBUTOR. The supplied Repository State instead says MEMBER; this proof assessment uses the current API response and does not use the discrepancy to propose closure. (60439b2f25c3)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Donnie Fiander: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add redacted after-fix Gateway output showing a Code Mode call receiving the visitor-access explanation as message.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-27T03:06:37.447Z sha 5b1490e :: needs changes before merge. :: [P2] Replace blank detail messages with the tool's 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.
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landing without the requested after-fix live Gateway transcript, with this rationale:

  • The review for 60439b2f25c3 lists no actionable code findings, and notes that maintainer-authored PRs are exempt from the live after-fix gate. The earlier blank-message finding is fixed in this head and covered by the regression.
  • The only observed reproduction is on a production deployment, and deploying an unmerged head there requires a separate per-deployment approval. Rebuilding the exact failure state (visitor-access tools registered while its runtime is absent) on a local Gateway would be a contrived setup rather than the observed path.
  • The regression drives the real exec tool through the Code Mode bridge and ToolSearchRuntime into a tool returning the observed result shape. The one layer it does not execute, the Gateway's nested-tool executor, hands the raw tool result to the same acceptResultBeforeProjection snapshot; the live nested-tool transcript event already recorded isError: true on that result, so the field reaches the projection point.

After the next regular deployment includes this change, the same visitor_list failure should show its explanation in the exec result; I'll confirm there.

@steipete
steipete merged commit f7df40b into main Sep 27, 2026
196 of 198 checks passed
@steipete
steipete deleted the steipete/clever-cerf-25c2cd branch September 27, 2026 05:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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