Repository navigation
fix: reuse compacted tool catalogs between agent runs - #199804
Conversation
Share bounded immutable catalog metadata by finalized descriptors and schema fingerprints while retaining current-run executors and cleanup. Preserve identical prompt bytes and full MCP output validation. Add cross-session bridge regressions and synthetic allocation, retention and Gateway workloads.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review the final catalog ownership, canonical key, cache bounds, prompt byte stability, MCP validation, and current-run executor lifetime at |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR shares detached tool-catalog metadata and rendered prompts across runs with equivalent finalized tool definitions. Example: Two agent sessions use the same 109 tool definitions.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a useful, bounded performance improvement that current main lacks; no actionable correctness or security defect was found in the reviewed head. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherAgent preparation supplies policy-filtered tool definitions to the catalog owner, which produces discovery prompts and Code Mode metadata while retaining executable bindings in the current run. flowchart TD
A[Finalized tool definitions] --> B[Run catalog]
B --> C[Bounded descriptor cache]
C --> D[Discovery prompts]
C --> E[Code Mode projections]
E --> F[Current run bridge]
B --> F
F --> G[Current tool executor]
Technical reviewBest possible solution: Keep one bounded owner for detached catalog projections while preserving current-run execution, policy, and cleanup. Do we have a high-confidence way to reproduce the issue? Current-main source shows fresh run catalog identities bypassing the existing preparation caches; the PR supplies comparative synthetic measurements, but this read-only review executed no target code. Is this the best way to solve the issue? The change addresses the repeated projection work at its owner, removes superseded preparation paths, and justifies the bounded cache with measured reuse rather than claiming to fix the unproven heap-growth cause. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7de99f0419bb. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +167, Tests +158, Docs +15, Other +746. Total +1086 across 18 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 15, 2026, 6:25 PM ET / 23:25 UTC (Revision 3). |
Keep policy-driven run lifetime replacement independent of detached metadata reuse. Establish ready middleware replies before the immediate-reply parity assertion; the previous cold fixture fails on the exact base after #199434. Select the populated synthetic workspace and require successful cron completion in the Gateway measurement.
|
@clawsweeper re-review The previous review had no open items. The follow-up separates metadata reuse from execution-lifetime identity, initializes middleware before testing immediately ready replies, and selects the populated synthetic workspace with a successful-cron assertion. Production code is unchanged. The two affected test files now pass all 36 tests, with type/lint/format checks and fresh Codex autoreview clean. Please review final head |
|
🦞👀 Re-review progress:
|
Scope loopback model commands to one sample so resumed child-completion messages from a reused fixture cannot replay an earlier synthetic spawn.
|
@clawsweeper re-review Final head is |
|
🦞👀 Re-review progress:
|
|
Merged via squash auto-merge.
|
Shared compacted tool catalogs (#199804) keyed MCP metadata with stableStringify, which keeps undefined members, then JSON.parsed those key bytes for the frozen snapshot. An MCP descriptor with an undefined optional field (mode) threw SyntaxError and failed subagent runs about 2 s after spawn on Team ea8bbbb. Snapshot through JSON.stringify instead; the cache key is unchanged. Regression test fails on the parent with the production SyntaxError and passes with the fix. Focused tool-search tests 5/5, Codex autoreview scoped-clean. Admin-merged at the pinned head with no failed checks (15 pending) to restore subagents on Team.
* fix: reuse compacted tool catalogs between agent runs Share bounded immutable catalog metadata by finalized descriptors and schema fingerprints while retaining current-run executors and cleanup. Preserve identical prompt bytes and full MCP output validation. Add cross-session bridge regressions and synthetic allocation, retention and Gateway workloads. * test: distinguish catalog reuse from execution lifetimes Keep policy-driven run lifetime replacement independent of detached metadata reuse. Establish ready middleware replies before the immediate-reply parity assertion; the previous cold fixture fails on the exact base after openclaw#199434. Select the populated synthetic workspace and require successful cron completion in the Gateway measurement. * test: isolate catalog measurement samples from recovered messages Scope loopback model commands to one sample so resumed child-completion messages from a reused fixture cannot replay an earlier synthetic spawn.
…w#199909) Shared compacted tool catalogs (openclaw#199804) keyed MCP metadata with stableStringify, which keeps undefined members, then JSON.parsed those key bytes for the frozen snapshot. An MCP descriptor with an undefined optional field (mode) threw SyntaxError and failed subagent runs about 2 s after spawn on Team 9482c95. Snapshot through JSON.stringify instead; the cache key is unchanged. Regression test fails on the parent with the production SyntaxError and passes with the fix. Focused tool-search tests 5/5, Codex autoreview scoped-clean. Admin-merged at the pinned head with no failed checks (15 pending) to restore subagents on Team.
What Problem This Solves
Fixes repeated tool-catalog compaction when Code Mode starts another run, session, subagent, or retry with the same effective tool definitions.
User Impact
Agent runs reuse identical catalog text and immutable metadata while keeping tool execution bound to the current run. No configuration or schema migration is required. This reduces catalog preparation CPU and allocation; it does not establish that catalog builds caused the reported production heap growth.
Why This Change Was Made
The old reuse boundary was a run-local catalog reference, and execution/prompt preparation followed fresh entries-array identities. The new owner keys detached metadata by ordered, finalized descriptors and schema fingerprints, sharing bindings, prompts and worker metadata across runs. Executable tools and lifecycle state remain run-local. Raw and published copies of the same native schema have the same key; opaque client schemas stay with the live describe/call path. MCP publication preserves schemas that cannot be published losslessly.
The shared owner is bounded to 32 catalogs, 1 Mi-character input per catalog and 4 Mi-character aggregate inputs, with bounded prompt variants. It replaces duplicate per-run preparation; the net +167 production lines supply the previously missing cross-run lifetime and bounds (282 added, 115 removed). Related: #199346 separately makes MCP output-validator compilation lazy; this change preserves its validation boundary.
Evidence
Production motivation supplied by the TS peer: Team r336, 2026-11-15, 19:57–21:30Z recorded 176 builtin Code Mode catalog reuse misses against 77 webchat turns (~2.3×). The turn denominator excludes subagents, cron and recovery/retry attempts, so this is an upper bound per run. Windows with 27–29 builds coincided with +73–91 MB after-GC floor steps; quiet windows with 5–9 builds ranged from −36 to +7 MB. This is correlation, not a demonstrated leak. No Team data was copied and no Team runtime was changed.
a4d4aa4417a8964a62754143ac1b90ea4bfd29b00b7cc1fa95027d86de99d32d). Prefix and affected consumer tests pass. Native/MCP/client regressions execute through the real headless bridge with current-run results. The original three cross-run regressions fail the intended reuse assertion on exact parent913e6ea294413887fc9bb71a70a5e24a53936fbf.pnpm check:changedfound unrelated unused exports, reproduced on the exact parent and introduced byef930ebbad771ae219e033f8c5b59a12b5445ffb(state copy/swap upgrade) andcec47fd13f23df46069da1beb65ceaec6e66d04f/ feat(openclaw-id): name invited members from their email and ask who they are on first visit #198491 (member welcome). These are existing main regressions, not ignored noise. Exact-head CI remains required.CI on the first head exposed an old metadata test equating shared preparation with execution-session identity; the updated test preserves policy-driven lifetime replacement independently. It also exposed an inherited immediate-reply fixture regression from #199434 (
37d977fd28b0): the exact parent fails, and substituting that owner’s preceding version passes all 20 parity tests. The fixture now completes asynchronous first-call middleware discovery before asserting immediate replies, retaining the existing single-execution, memory, call-count and cleanup assertions. Both affected files pass locally (36 tests), with type/lint/format checks and fresh Codex review. ClawSweeper reviewed final head9244bf780b745318caef052e9685227e80f02e72with zero findings and zero open checklist items. Exact-head CI remains required before landing.The measurement model now scopes markers to each sample so pending completion notifications from a reused synthetic fixture cannot replay old spawn commands. This final follow-up affects only the measurement script; it passed script type/lint/format checks and Codex autoreview. Earlier diagnostic-heavy profiles and replay-contaminated samples are excluded from the final timing comparison.