Skip to content

perf(agents): wave-1 tool output contracts for code mode - #110215

Merged
steipete merged 8 commits into
mainfrom
claude/tool-output-contracts-wave1
Jul 18, 2026
Merged

steipete merged 8 commits into
mainfrom
claude/tool-output-contracts-wave1

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Code Mode's quick index shows -> ? for most built-in tools, forcing the model to spend a raw-inspection exec (a full model round trip) before it can filter or map a result. Only the conversation tools and agents_list declared output contracts — and the agents_list hint silently never rendered because its eight-literal agentRuntime.source union exceeded the six-value literal cap.

Two compactor semantics also blocked adoption: an explicitly opaque leaf (Type.Unknown) demoted an otherwise-exact contract, and there was no per-tool measurement to rank which contracts pay for themselves.

Why This Change Was Made

  • src/agents/tool-schema-hints.ts: an empty schema is JSON Schema's top type, so it now renders as a complete unknown leaf instead of demoting the whole contract; literal-union cap raised 6 -> 8 (combined 96-char bound unchanged) which repairs the dead agents_list hint; union scans are bounded in O(1) before any per-variant work.
  • Wave-1 contracts, all describing current output exactly (zero behavior change): screen (byte-exact ui.command passthrough, reuses UiCommandResultSchema), spawn_task, sessions_search, openclaw delegate, and terminal (four result families) with tool-local schemas at the owner boundary.
  • scripts/repro/tool-surface-live-bench.ts: counts raw-first inspection execs per tool (exec result deep-equal to one recorded tool result), so future contract PRs are ranked by measured avoided turns.
  • scripts/repro/tool-schema-hint-bench.ts: hot-path micro-benchmark for hint compaction, catalog assembly, and declared-output validation.

User Impact

Code Mode agents see trusted declared output hints for six more built-in tools and compose them in one exec instead of paying an inspection turn. No tool result fields changed; untrusted MCP/client schemas remain excluded and fail-closed validation is unchanged.

Evidence

  • Focused: node scripts/run-vitest.mjs src/agents/tool-schema-hints.test.ts src/agents/tools/ src/agents/tool-search.test.ts src/agents/code-mode.test.ts — 66 files, 1521 tests green post-rebase.
  • Contract tests per tool: schema identity, Value.Check against executed results, exact compact-hint snapshots (or explicit absence).
  • Hot path: scripts/repro/tool-schema-hint-bench.ts — full applyCodeModeCatalog 745 us per run attempt at 72 tools; typical hints 1.4-5.9 us/op; adversarial 5k-property schema bounded at ~465 us.
  • Autoreview (Codex gpt-5.6-sol, branch mode vs origin/main): clean, "patch is correct (0.87)"; one earlier P2 (unbounded union pre-scan) fixed in fix(agents): bound union scans before literal-union analysis.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4a183bc7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
const envelope = parsed as { status?: unknown; value?: unknown };
// Scalars deep-equal too easily; only structured raw returns count.
const value = envelope.status === "completed" ? envelope.value : undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle tool_search_code's ok envelope

When the live bench runs the tool-search-code surface, tool_search_code results are wrapped by runCodeMode() as { ok: true, value, logs, telemetry } (src/agents/tool-search.ts:2240), but this detector only unwraps values when status === "completed". Because CODE_EXEC_TOOL_NAMES includes tool_search_code, raw-result inspection turns for that surface are never counted, so the new per-tool rawInspectionExecs metric is biased to zero for one of the surfaces this benchmark compares.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 17, 2026, 7:28 PM ET / 23:28 UTC.

Summary
The branch adds compact Code Mode output contracts for five built-in tool surfaces, broadens safe schema-hint rendering, documents the declared contracts, and adds contract-performance benchmark instrumentation.

PR surface: Source +99, Tests +113, Docs +3, Other +288. Total +503 across 17 files.

Reproducibility: yes. The source path is clear: run the live bench with a tool_search_code invocation whose result is wrapped as { ok: true, value, logs, telemetry }; the detector’s completed-status-only unwrapping misses the recorded value.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/tools/sessions-search-tool.test.ts, serialized state: src/agents/tools/sessions-search-tool.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🐚 platinum hermit
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Normalize the tool_search_code { ok, value } envelope in the raw-inspection detector.
  • Rerun the tool-surface benchmark and include the corrected per-tool count in the PR evidence.

Next step before merge

  • [P2] A single mechanical benchmark normalization repair can address the remaining P2 finding without changing the output-contract design.

Security
Cleared: The diff adds local schemas, tests, docs, and benchmark instrumentation without new dependencies, workflow permissions, artifact downloads, or secret-handling paths.

Review findings

  • [P2] Unwrap Code Mode results before counting raw inspections — scripts/repro/tool-surface-live-bench.ts:738
Review details

Best possible solution:

Normalize the Code Mode { ok, value } result before comparing it with recorded tool results, then rerun the per-tool live bench so the wave-ranking metric covers every advertised code-execution surface.

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

Yes. The source path is clear: run the live bench with a tool_search_code invocation whose result is wrapped as { ok: true, value, logs, telemetry }; the detector’s completed-status-only unwrapping misses the recorded value.

Is this the best way to solve the issue?

No. Owner-local output schemas are the right boundary, but the benchmark must account for the existing Code Mode envelope before it is used to rank avoided inspection turns.

Full review comments:

  • [P2] Unwrap Code Mode results before counting raw inspections — scripts/repro/tool-surface-live-bench.ts:738
    tool_search_code returns Code Mode’s { ok: true, value, logs, telemetry } envelope, but this detector only unwraps status === "completed". Because the tool is included in the compared code-execution set, an exec that merely prints its result cannot match the recorded value and rawInspectionExecs is always reported as zero for that surface. This re-raises the prior P2 blocker; normalize the { ok, value } envelope before the deep-equality comparison.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: The incorrect benchmark can mis-rank future Code Mode contract work, but it does not change user tool results or persisted behavior.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes post-change live benchmark output and focused execution evidence for the affected Code Mode/tool path; rerun that benchmark after fixing the retained metric defect, redacting any private runtime details if posted.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes post-change live benchmark output and focused execution evidence for the affected Code Mode/tool path; rerun that benchmark after fixing the retained metric defect, redacting any private runtime details if posted.

Label justifications:

  • P2: The incorrect benchmark can mis-rank future Code Mode contract work, but it does not change user tool results or persisted behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes post-change live benchmark output and focused execution evidence for the affected Code Mode/tool path; rerun that benchmark after fixing the retained metric defect, redacting any private runtime details if posted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes post-change live benchmark output and focused execution evidence for the affected Code Mode/tool path; rerun that benchmark after fixing the retained metric defect, redacting any private runtime details if posted.
Evidence reviewed

PR surface:

Source +99, Tests +113, Docs +3, Other +288. Total +503 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 6 102 3 +99
Tests 7 113 0 +113
Docs 1 8 5 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 3 296 8 +288
Total 17 519 16 +503

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/tool-search.test.ts src/agents/code-mode.test.ts.
  • [P1] node --import tsx scripts/repro/tool-surface-live-bench.ts.

What I checked:

  • Retained benchmark defect: The existing review identifies that tool_search_code returns Code Mode's { ok: true, value, logs, telemetry } envelope, while the new raw-inspection detector unwraps only status === "completed"; its rawInspectionExecs metric is therefore biased to zero for that compared surface. (scripts/repro/tool-surface-live-bench.ts:738, e4a183bc7fc9)
  • Code Mode result contract: The reviewed comment traces the envelope to runCodeMode() in the current tool-search implementation, so the defect is in the benchmark’s normalization rather than in the underlying tool’s returned value. (src/agents/tool-search.ts:2240, e4a183bc7fc9)
  • Focused validation supplied by contributor: The PR body reports focused agent/tool tests and a post-change live benchmark run; this supports the contract work but does not validate the per-tool metric for the wrapped code-mode result. (src/agents/tool-schema-hints.test.ts:52, f64fcca5738a)
  • Protected review route: The supplied GitHub context marks this PR maintainer, so automated cleanup should not close it and a maintainer should review the final corrected benchmark result. (f64fcca5738a)

Likely related people:

  • steipete: The supplied branch history attributes all eight focused agent-tool/schema commits, including the latest type-exactness follow-up, to this contributor; a local current-main blame pass was unavailable in this read-only environment. (role: recent area contributor; confidence: low; commits: e36e56062e22, 1ec3e3707849, e4a183bc7fc9; files: src/agents/tool-schema-hints.ts, src/agents/tools/terminal-tool.ts, scripts/repro/tool-surface-live-bench.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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 d371ea1 into main Jul 18, 2026
147 of 151 checks passed
@steipete
steipete deleted the claude/tool-output-contracts-wave1 branch July 18, 2026 00:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…0215)

* feat(agents): keep output contracts complete across opaque schema leaves

* test(agents): add code mode schema-hint hot-path micro-benchmark

* test(agents): count raw-first inspection execs per tool in live bench

* feat(agents): expand compact output contract hints

* feat(agents): declare wave one tool output contracts

* docs(tools): list built-in output contracts

* fix(agents): bound union scans before literal-union analysis

* fix(agents): keep wave-1 contract schemas module-local and type-exact
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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant