Repository navigation
improve(code-mode): call tools as global functions - #126262
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 3:01 PM ET / 19:01 UTC. ClawSweeper reviewWhat this changesThis PR replaces Code Mode’s hidden tool-routing object with direct async tool globals and callable catalog handles, while aligning MCP guest results and migrating one documented persisted Cron trigger pattern. Merge readinessThe exact head addresses the prior MCP result-shape blocker and no new concrete correctness defect was found. This maintainer-owned PR remains necessary because current main still exposes the legacy Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherCode Mode executes model-authored JavaScript in an isolated worker and routes authorized calls through a run-scoped tool catalog. MCP tools, resources, and prompts enter through provider runtimes and are projected back to guest code and transcript output. flowchart LR
Model[Model-authored program] --> Worker[Isolated Code Mode worker]
Worker --> Catalog[Run-scoped callable catalog]
Catalog --> Bridge[Policy-checked execution bridge]
Bridge --> MCP[MCP tool and utility runtimes]
MCP --> Projection[Guest-result projection]
Projection --> Output[Guest value and transcript output]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +712, Tests +1278, Docs +39, Other +29. Total +2058 across 75 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase or verify the clean merge result, rerun the documented Code Mode/MCP and Doctor migration proof on that exact head, then land the single canonical direct-global API with its bounded Doctor migration. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a new Code Mode contract. The PR body supplies after-fix Gateway/MCP and OpenAI execution evidence, while source and focused tests cover the resulting boundary. Is this the best way to solve the issue? Yes. A single run-scoped projection supplies prompt names, guest globals, catalog handles, bridge routing, and replay checks; the Doctor-owned migration is the correct place to repair the documented persisted trigger shape. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 231405930acc. 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 (6 earlier review cycles)
|
99a9578 to
453d0fd
Compare
|
Blocking contract finding before landing this rewrite: the generated The existing MCP integration fixture does not cross the raw MCP materializer boundary, so its green result misses this mismatch. A production-boundary reproduction returns only The clean owner is the Code Mode MCP guest projection, not the shared MCP materializer or Tool Search. Project the final value to Required proof before merge: real-materializer success and |
334c94b to
7bd4b2d
Compare
|
@clawsweeper re-review Addressed both findings on behavior head
Proof is refreshed in the PR body: 312 focused boundary tests, final changed-file gates, final build, clean autoreview/secret scan, and a real OpenAI Code Mode matrix passing 7/7 scenarios with no legacy API, exact IDs, tool failures, detached schema calls, or |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
cf0c895 to
10eb392
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready maintainer proof for exact reviewed head The canonical run-scoped callable projection now owns direct async tool globals, collision resolution, callable catalog discovery, hidden exact IDs, and policy-checked host dispatch. MCP remains in its namespace with native Validation:
ClawSweeper: the durable review initially lagged on an older head, but the exact-head re-review has now published with no actionable findings; the prior private-global, stable-upgrade, and MCP-projection findings were all fixed and independently reproduced. Its display harness marked a partial failure because an expected terminal string was not observed, although its captured Vitest run explicitly reports 10/10 passing. The optional request to rebase is intentionally skipped: current main drift is advisory, GitHub reports |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* feat(code-mode): expose tools as global functions * fix(code-mode): harden callable tool composition * fix(code-mode): reserve private guest globals * fix(cron): migrate legacy code-mode triggers * fix(code-mode): align final tool result contracts
….call API The browser-automation skill's Code Mode Loop still taught the guest `tools.call(browserTool, input)` API that openclaw#126262 removed, together with the `.result.details`/`.result.content` envelope reads. Rewrite the loop for the current contract: call the `browser(...)` async global directly, receive the tool's structured details (targetId, url, newElements, stats, blockedByDialog), and diff url/new-element counts between cells instead of filtering snapshot text, since rendered page text is no longer guest-visible in code mode.
… removed tools.call API (#128456) * docs(browser): teach the code-mode global call, not the removed tools.call API The browser-automation skill's Code Mode Loop still taught the guest `tools.call(browserTool, input)` API that #126262 removed, together with the `.result.details`/`.result.content` envelope reads. Rewrite the loop for the current contract: call the `browser(...)` async global directly, receive the tool's structured details (targetId, url, newElements, stats, blockedByDialog), and diff url/new-element counts between cells instead of filtering snapshot text, since rendered page text is no longer guest-visible in code mode. * docs(browser): resolve callable from quick index and read via targeted evaluate * docs(browser): call the search-resolved handle and carry cell state explicitly
… removed tools.call API (openclaw#128456) * docs(browser): teach the code-mode global call, not the removed tools.call API The browser-automation skill's Code Mode Loop still taught the guest `tools.call(browserTool, input)` API that openclaw#126262 removed, together with the `.result.details`/`.result.content` envelope reads. Rewrite the loop for the current contract: call the `browser(...)` async global directly, receive the tool's structured details (targetId, url, newElements, stats, blockedByDialog), and diff url/new-element counts between cells instead of filtering snapshot text, since rendered page text is no longer guest-visible in code mode. * docs(browser): resolve callable from quick index and read via targeted evaluate * docs(browser): call the search-resolved handle and carry cell state explicitly
What Problem This Solves
Code Mode taught models to invoke hidden tools through verbose internal routing syntax such as
tools.callValue("openclaw:core:sessions_spawn", {...}). That spent prompt and output tokens on implementation details, exposed source-qualified catalog IDs, and gave Code Mode duplicate-name behavior that differed from the normal direct tool surface.Why This Change Was Made
This hard-cuts the guest API to one simpler contract: authorized non-MCP tools are async global functions such as
sessions_spawn({...})andweb_search({...}). One run-scoped catalog owns the effective winner, final callable name, provider-visible quick index, search view, bridge routing, snapshots, and replay checks—even after client tools append or prompt policy restricts the surface. Hidden exact identities remain host-only.The old guest
toolsobject,ALL_TOOLS, raw call envelopes, and exact-ID examples are removed rather than retained as runtime compatibility aliases. Callable discovery results serialize to bounded public metadata instead ofnull, without detached schema calls or arbitrary usertoJSONexecution. Every__openclaw*tool name is projected outside the worker-private namespace.MCP remains under its namespace, but its generated contract now matches execution. Tool calls expose JSON-safe native
content,structuredContent, andisError; resource and prompt operations expose their native result shapes. Top-level private_metanever enters guest or transcript output, nested content-block metadata is preserved, resolved MCP failures remain recoverable guest values while staying failed in lifecycle accounting, and every executable network MCP surface participates in external-content wrapping and turn tainting. Requester OAuth connect tools and MCP-annotated custom node commands follow the same guest contract without changing their direct result semantics.The model guidance explicitly encourages same-program composition for declared outputs, raw-first handling for unknown outputs, and reserves
restartSafefor explicit gateway-restart recovery. The concretereadtool supports explicitoptional: true; missing canonical daily notes retain their shipped implicit not-found behavior, while arbitrary missing paths and real filesystem errors still reject. The existing five-variantsessions_sendoutput schema is rendered as a complete quick-index hint instead of a false-> ?.The runtime remains hard-cut to the new API, but stable-upgrade compatibility is handled at the storage owner.
openclaw doctor --fixAST-migrates the documentedv2026.7.1persisted Cron trigger idiom from literaltools.call("exec", {...})plus.result.detailsto canonical direct calls. Custom, dynamic, shadowed, or ambiguous legacy scripts remain byte-for-byte unchanged and are reported per job for manual remediation. Beta-onlytools.callValueand standalone script payloads receive no compatibility path.User Impact
Models can write shorter, ordinary JavaScript:
Dependent calls remain sequential, independent calls remain composable with
Promise.all, and nested calls use the same policy, approval, hooks, telemetry, network-content, and replay-safety boundaries. Optional reads can branch without exceptions:Output-hint audit: 141 statically known tools can enter the hidden catalog. This change brings complete hints from 19 to 20 by promoting the already-valid
sessions_sendschema. The remaining 121-> ?tools consist of 120 tools without an owner-declaredoutputSchemaplus the intentionally partial/openbrowserschema. Additional hints belong at each owning tool boundary; runtime inference from TypeScript or remote payloads remains intentionally absent.AI-assisted implementation; adversarially reviewed and verified by the maintainer.
Evidence
267ffc4754a08181f1a15ff7cfbd0f4d817ca25a; the four original commits remained patch-identicaldoctor --fix, preserves unsupported/beta-only rows, and is idempotentexec, 6 MCP namespace calls, structured success, resolved failure, block metadata retention, top-level metadata stripping, all four resource/prompt operations, zero Tool Search pollutionPromise.all, callable search+invoke, metadata serialization, unknown-output raw-first, and optional-read recovery; zero legacy APIs, exact IDs, tool failures, detached schema calls, orrestartSafe: truenode scripts/check-changed.mjs -- <30 changed files>passed all core/tests/extensions/scripts typechecks, format/lint, dead-export, security, database, schema-version, boundary, and import-cycle gatespnpm buildpassed; only existing third-party dependencyevalwarningsgit diff --checkpassedProduction LOC: +1046/-334 (net +712) | Tooling/test support: +36/-7 | Tests: +2085/-807 | Docs: +155/-116
The positive production delta owns concrete capabilities rather than runtime fallbacks: deterministic catalog projection, MCP guest/transcript separation and network provenance, shipped Cron AST migration with SQLite repair/reporting, and extracted read contracts. The runtime has one canonical Code Mode API.