Skip to content

fix(code-mode): serialize catalog handles nested in final values - #130276

Merged
VACInc merged 2 commits into
openclaw:mainfrom
VACInc:fix/code-mode-nested-handle-serialization
Aug 26, 2026
Merged

VACInc merged 2 commits into
openclaw:mainfrom
VACInc:fix/code-mode-nested-handle-serialization

Conversation

@VACInc

@VACInc VACInc commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

In OpenClaw code mode, catalog.search() results are callable handles that serialize to {callableName, toolName, ...} metadata when returned as the program's final value. That only worked for a bare handle or a flat array of handles. Any nesting — Promise.all([catalog.search(a), catalog.search(b)]), or { tools: [...] } — dumped each handle as null, so the model saw [[null,null,...]] and concluded no matching tool existed.

Observed in a live Telegram session on 2026-08-26: three parallel searches returned 24 nulls; the model then declared its tool surface read-only and stopped, although the shell exec global it was searching for was present.

Why This Change Was Made

serializeCatalogHandles in src/agents/code-mode-controller-source.ts now walks arrays and plain objects recursively (cycle-guarded, prototype-checked so class instances and toJSON hooks are untouched). The cycle guard tracks the active recursion path, so shared non-cyclic containers are projected at every returned alias instead of being mistaken for cycles. Metadata projection stays the single serialization path; no new bridge surface.

The previously failing MCP CI assertion now uses the test file's existing frozen-clock helper. That assertion is not testing the catalog deadline, and a concurrent identical shard passed while this PR's shard exhausted its 50 ms wall-clock deadline under CI contention.

User Impact

Nested catalog handles in a code-mode return value now surface their tool names/schemas instead of null, including when the containing object is shared across multiple return paths. Tool discovery through catalog.search therefore composes with Promise.all, keyed results, and shared containers.

Evidence

  • Regression test serializes catalog handles nested inside arrays and plain objects covers a shared container through three paths; it fails before the active-path fix and passes afterward.
  • node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts: 22 passed.
  • node scripts/run-vitest.mjs src/node-host/mcp.test.ts: 18 passed.
  • Affected core-test typecheck graphs (agents-root, other) pass.
  • Production LOC: +17 / -3; tests +36 / -2.

@clawsweeper

clawsweeper Bot commented Aug 26, 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 the agents Agent runtime and tooling label Aug 26, 2026
@VACInc
VACInc marked this pull request as ready for review August 26, 2026 18:05
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 26, 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 4:48 PM ET / 20:48 UTC.

ClawSweeper review

What this changes

This PR recursively converts nested code-mode catalog tool handles into plain metadata and freezes time for one non-timeout MCP lifecycle test.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still serializes only a bare handle or flat array, while this exact-head patch repairs nested and shared return values at the sole pre-dump boundary. No blocking patch defect was found.

Priority: P2
Reviewed head: 3c70cfb4ed53c60f8b452c1819110e2d332a1c4a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary fix with meaningful regression coverage addresses the previous shared-alias blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository context identifies this as maintainer-associated work; the focused guest regression and exact-head CI are supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository context identifies this as maintainer-associated work; the focused guest regression and exact-head CI are supplemental validation.
Evidence reviewed 7 items Current-main gap: Current main only maps direct array entries through callable metadata, leaving nested objects and arrays unprojected.
Exact-head repair: The PR recursively projects handles in arrays and plain/null-prototype objects, while retaining an active-path cycle guard so shared aliases are serialized each time.
Owner boundary: Completed guest values are passed through the injected serializer immediately before QuickJS dumps them to host data, so this is the narrow canonical repair location.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts"

[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130276-My06H3/target

 ✓  agents-core  src/agents/code-mode.guest.test.ts (22 tests) 11920ms
     ✓ runs JavaScript through QuickJS-WASI and resumes nested tool calls with wait  704ms
     ✓ serializes 'catalog.search' handles as safe public metadata  424ms
     ✓ serializes catalog handles nested inside arrays and plain objects  421ms
     ✓ exposes catalog tools as bare globals and removes the legacy guest surface  623ms
     ✓ keeps normalized, reserved, and colliding prompt names aligned with runtime  1671ms
     ✓ keeps private lifecycle hooks intact while invoking colliding catalog globals  636ms
     ✓ uses the client tool as the single winner for a shadowed exact name  624ms
     ✓ returns structured values from globals and callable catalog handles  1072ms
     ✓ wraps network-controlled 'bare global' output without changing structured values  416ms
     ✓ wraps network-controlled 'catalog handle' output without changing structured values  636ms
     ✓ wraps caught errors thrown by an invoked network tool  462ms
     ✓ wraps uncaught network tool errors while preserving the failed guest result  425ms
     ✓ returns no catalog handles for a missing tool without exposing ids  472ms
     ✓ isolates and cleans up 12 concurrent real guest workers  1417ms
     ✓ clamps omitted code-mode catalog search limits to maxSearchLimit  425ms

 Test Files  1 passed (1)
      Tests  22 passed (22)
   Start at  20:49:27
   Duration  28.34s (transform 13.24s, setup 940ms, import 15.13s, tests 11.92s, environment 0ms)

[test] passed 1 Vitest shard in 34.52s

Assertions:

  • FAIL expect_output: serializes catalog handles nested inside arrays and plain objects

How this fits together

Code mode runs guest JavaScript in QuickJS and returns its completed value to the agent. Catalog search produces callable tool handles that must be converted to plain metadata before the QuickJS result dump reaches the model.

flowchart LR
  A[Guest code] --> B[Catalog search]
  B --> C[Callable tool handles]
  C --> D[Final value serialization]
  D --> E[QuickJS result dump]
  E --> F[Agent and model output]
Loading

Before merge

  • Resolve merge risk (P1) - The bug fix adds 14 net production lines, but recursive projection is necessary at the only boundary before QuickJS dumps the guest result; no upgrade or configuration risk was found.
  • Complete next step (P2) - The existing branch is the focused repair; no separate automated repair lane is needed.
Agent review details

Security

None.

PR surface

Source +14, Tests +34. Total +48 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 3 +14
Tests 2 36 2 +34
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 53 5 +48

Review metrics

Metric Value Why it matters
Production vs test LOC production +17/-3 (net +14); tests +36/-2 (net +34) The production growth is confined to the sole pre-dump serialization owner and the regression covers nested and shared aliases.

Stored data model

Persistent data-model change detected: serialized state: src/agents/code-mode.guest.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the guest-side recursive projection after normal exact-head merge checks; do not add a second host-side serialization path.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge the guest-side recursive projection after normal exact-head merge checks; do not add a second host-side serialization path.

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

Yes. Current main's flat-array serializer and the completed-result call chain establish the defect, while the focused guest regression exercises nested arrays, objects, and shared aliases.

Is this the best way to solve the issue?

Yes. The guest-side serializer is the last controllable transformation before QuickJS dumps the value, making this narrower than a parallel host-side serializer; the separately discussed null-prototype __proto__ behavior is pre-existing dump behavior, not introduced here.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository context identifies this as maintainer-associated work; the focused guest regression and exact-head CI are supplemental validation.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This fixes missing tool metadata in a bounded code-mode result path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository context identifies this as maintainer-associated work; the focused guest regression and exact-head CI are supplemental validation.

Evidence

What I checked:

Likely related people:

  • roboclaw-bot: Current blame attributes the active serializer and the shared-alias repair to this exact head. (role: exact-head follow-up author; confidence: high; commits: 3c70cfb4ed53; files: src/agents/code-mode-controller-source.ts, src/agents/code-mode.guest.test.ts, src/node-host/mcp.test.ts)
  • Peter Steinberger: History identifies the earlier code-mode global-tools change as related feature work, though the sparse checkout could not load its historical source blobs. (role: earlier code-mode feature contributor; confidence: medium; commits: 4249df34b42a; files: src/agents/code-mode-controller-source.ts, src/agents/code-mode.worker.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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-26T18:12:22.125Z sha 574b3de :: found issues before merge. :: [P2] Traverse shared nested values instead of treating them as cycles
  • reviewed 2026-08-26T18:54:56.553Z sha 574b3de :: found issues before merge. :: [P2] Traverse shared nested values instead of treating them as cycles
  • reviewed 2026-08-26T20:19:06.946Z sha 3c70cfb :: found issues before merge. :: [P2] Preserve __proto__ as an own returned field

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Aug 26, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Maintainer disposition and verification for exact head 3c70cfb4ed53c60f8b452c1819110e2d332a1c4a:

  • The original shared-alias P2 is fixed: seen now tracks only the active recursion path, and the boundary regression returns one shared container through three paths. node scripts/run-vitest.mjs src/agents/code-mode.guest.test.ts passes 22/22.
  • The later __proto__ report is not introduced or exposed by this PR. I implemented the recommended guest-side own-data-property behavior with Object.fromEntries and added the exact null-prototype regression locally; it still returned special: {}. [email protected] drops the key later in vm.dump: its host-object dump creates {} and assigns obj[key] = ... (node_modules/quickjs-wasi/dist/index.js:1647-1665). On the PR base, the untouched guest object reaches this same dump path, so the behavior is unchanged by this patch. Correcting that general runtime limitation requires an upstream dependency or worker-boundary change, not a special case at the flagged serializer lines.
  • The separate Codex runtime was checked at codex-rs/code-mode-runtime/src/runtime/value.rs:16-42,286-304 and codex-rs/core/src/tools/code_mode/response_adapter.rs:10-49; it uses a different V8 JSON path and does not share this QuickJS-WASI boundary.
  • The unrelated MCP CI failure was a 50 ms wall-clock flake; the test now uses the existing frozen-clock helper and passes 18/18.
  • Required exact-head check openclaw/ci-gate is green: https://github.com/openclaw/openclaw/actions/runs/33009191830/job/98316259445

No known in-scope proof gaps remain.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 26, 2026
@VACInc
VACInc enabled auto-merge (squash) August 26, 2026 23:45
@VACInc
VACInc merged commit ea248cd into openclaw:main Aug 26, 2026
204 checks passed
vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (26 commits)
  fix(plugins): preserve registry epoch on activation rollback (#129232)
  refactor(plugins): make discovery invocation-owned (#130486)
  feat(ui): save appearance preferences per user profile (#130340)
  fix: Buzz bots recover relay stalls and reject revoked senders (#130467)
  fix(code-mode): serialize catalog handles nested in final values (#130276)
  fix(webchat): CLI skill and harness-injected turns render as operator-sent messages (#130427)
  fix(agents): read the published model catalog owner from session_status (#130277)
  fix(channels): preserve long presentation text (#130368)
  fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
  refactor(plugins): unify setup registration and artifact selection (#130474)
  fix(memory): prevent forgotten session content from returning (#130451)
  refactor(outbound): consolidate transport completion (#130460)
  fix(workers): protect in-flight workspace manifests from concurrent retention (#130449)
  fix(portals): keep worker previews reachable and owned by the active environment (#130434)
  fix(config): keep core channels keys in the generated config schema (#120736)
  chore(deps): refresh dependencies after seven-day cooldown (#130296)
  fix(agents): remind exec models to quote shell metacharacters (#125485)
  fix(auth): honor shared-store ownership in temp-state exec and agent deletion (#130437)
  fix(openshell): preserve file writes during concurrent mirror commands (#130447)
  fix(workers): report full nodes as at capacity, not offline (#130445)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…nclaw#130276)

* fix(code-mode): serialize catalog handles nested in final values

* fix(code-mode): serialize shared catalog aliases

---------

Co-authored-by: VACInc <[email protected]>
Co-authored-by: roboclaw-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

2 participants