Repository navigation
improve: reduce CPU and memory for large tool catalogs - #207900
Conversation
Carry the bound hook, caller, and abort closures into Code Mode and Tool Search when compaction has no new execution context. Preserve the rebuild path for actual overrides and availability projections.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. |
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: passed. What this changesThis PR reuses prepared tool executors during catalog compaction when their hook context already matches. Example: Code Mode prepares a synthetic catalog containing 64 native tools and 32 bundle MCP tools.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses measured catalog overhead, and the reviewed changes introduce no actionable correctness or security findings. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTool assembly binds execution hooks, caller identity, and cancellation; catalog compaction consumes those tools and produces model-facing declarations plus run-local executable entries. flowchart TD
A[Tool definitions] --> B[Tool assembly]
B --> C[Bound executors]
C --> D[Catalog compaction]
D --> E[Model declarations]
D --> F[Run local catalog]
F --> G[Tool execution]
Technical reviewBest possible solution: Keep executor ownership in tool assembly and reuse its bindings when equivalent, retaining independent catalog projections where availability or context differs. Do we have a high-confidence way to reproduce the issue? Current-main source exposes unconditional catalog rewrapping, and the PR supplies a repeatable synthetic benchmark and reported parent-red regression; this review executed no target code. Is this the best way to solve the issue? The approach removes redundant construction at the existing owner without adding a cache, public option, or parallel execution path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a3fb66462294. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +100, Other +241. Total +354 across 7 files. Added test files: 0. 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 Reviewed November 28, 2026, 9:43 PM ET / November 29, 2026, 02:43 UTC. |
|
Merged via squash.
|
…line * commit 'c876514dc21154a07f3755320495d2a93584b46b': (538 commits) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) fix: verify chat Stop recovery after dashboard pairing (#207888) test(activity): check midnight refresh against the elapsed window (#207859) test(ui): use one persisted message ID in queued-image handoff (#207861) test(agents): release configured MCP fixture resources (#207716) fix(workboard): clear CI failures in the session filter editor (#207858) perf(ai): reduce allocation in OpenAI Responses streams (#207889) chore: stop the Workboard resident-owner CLI test from failing on main (#207898) test(agents): isolate endpoint-based overflow classification (#207688) chore(doctor): record why the root defaultModel migration stays (#207890) refactor(infra): simplify audit recovery write progress (#157141) fix: show restart blockers in service logs (#207879) test(infra): exercise group identity in session roundtrip (#207671) test(infra): exercise live owner expiry policy (#207672) feat: let Knowledge learn from your Gmail through Composio (#207266) test: stop the history-worker overload test from failing CI on slow runners (#207862) test(auth): assert SecretRef plaintext is absent from storage (#207698) chore(doctor): hold expired doctor migrations as removal-pending (#207865) fix: show ended one-time automations in History (#201280) ...
* commit '2194d14488091e2047d2f87ebbb093212f30840e': (540 commits) fix: stop reporting a child worker as finished when the Gateway loses contact (#207713) fix: keep the Activity visibility test stable at midnight (#207847) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) fix: verify chat Stop recovery after dashboard pairing (#207888) test(activity): check midnight refresh against the elapsed window (#207859) test(ui): use one persisted message ID in queued-image handoff (#207861) test(agents): release configured MCP fixture resources (#207716) fix(workboard): clear CI failures in the session filter editor (#207858) perf(ai): reduce allocation in OpenAI Responses streams (#207889) chore: stop the Workboard resident-owner CLI test from failing on main (#207898) test(agents): isolate endpoint-based overflow classification (#207688) chore(doctor): record why the root defaultModel migration stays (#207890) refactor(infra): simplify audit recovery write progress (#157141) fix: show restart blockers in service logs (#207879) test(infra): exercise group identity in session roundtrip (#207671) test(infra): exercise live owner expiry policy (#207672) feat: let Knowledge learn from your Gmail through Composio (#207266) test: stop the history-worker overload test from failing CI on slow runners (#207862) test(auth): assert SecretRef plaintext is absent from storage (#207698) ...
…seline * commit '32403124cae2ccbcfc556e844b218682b133956e': (547 commits) perf(gateway): skip session display preparation for transcript recall (#207916) test(agents): verify complete bracketed paste payload (#207733) test: stop timing out the cron recovery settlement test on slow runners (#207920) fix: show when worktree cleanup stopped or will retry (#207883) fix: show approval destinations only when the forwarding mode uses them (#207885) fix: keep inherited tools when changing agent settings (#207884) feat: let Knowledge add someone's email or other alias to a page without rewriting it (#207881) fix: stop reporting a child worker as finished when the Gateway loses contact (#207713) fix: keep the Activity visibility test stable at midnight (#207847) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) fix: verify chat Stop recovery after dashboard pairing (#207888) test(activity): check midnight refresh against the elapsed window (#207859) test(ui): use one persisted message ID in queued-image handoff (#207861) test(agents): release configured MCP fixture resources (#207716) fix(workboard): clear CI failures in the session filter editor (#207858) perf(ai): reduce allocation in OpenAI Responses streams (#207889) chore: stop the Workboard resident-owner CLI test from failing on main (#207898) test(agents): isolate endpoint-based overflow classification (#207688) chore(doctor): record why the root defaultModel migration stays (#207890) ...
…eline * commit 'eee1e0553d29456424ac367008c3cf080f9866ec': (550 commits) fix(acp): deliver bound channel replies to the pending question (#207035) fix(cron): keep required reports from going silent when nothing changes (#207044) test(sessions): assert participant queue rollback state (#207891) perf(gateway): skip session display preparation for transcript recall (#207916) test(agents): verify complete bracketed paste payload (#207733) test: stop timing out the cron recovery settlement test on slow runners (#207920) fix: show when worktree cleanup stopped or will retry (#207883) fix: show approval destinations only when the forwarding mode uses them (#207885) fix: keep inherited tools when changing agent settings (#207884) feat: let Knowledge add someone's email or other alias to a page without rewriting it (#207881) fix: stop reporting a child worker as finished when the Gateway loses contact (#207713) fix: keep the Activity visibility test stable at midnight (#207847) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) fix: verify chat Stop recovery after dashboard pairing (#207888) test(activity): check midnight refresh against the elapsed window (#207859) test(ui): use one persisted message ID in queued-image handoff (#207861) test(agents): release configured MCP fixture resources (#207716) fix(workboard): clear CI failures in the session filter editor (#207858) perf(ai): reduce allocation in OpenAI Responses streams (#207889) ...
…ions suite * commit '60e80f1c5fd439f7aa4ce33f54985c7efdc30884': (555 commits) refactor: remove the bundled GBrain adapter (#207924) improve(ui): show optional run limits beside the automation schedule (#201283) test(onboarding): inspect recorded output for credential leaks (#207872) perf(exec): reduce host memory sampler allocations (#207927) test(mcp-relay): isolate the Connected apps fallback locale (#207923) fix(acp): deliver bound channel replies to the pending question (#207035) fix(cron): keep required reports from going silent when nothing changes (#207044) test(sessions): assert participant queue rollback state (#207891) perf(gateway): skip session display preparation for transcript recall (#207916) test(agents): verify complete bracketed paste payload (#207733) test: stop timing out the cron recovery settlement test on slow runners (#207920) fix: show when worktree cleanup stopped or will retry (#207883) fix: show approval destinations only when the forwarding mode uses them (#207885) fix: keep inherited tools when changing agent settings (#207884) feat: let Knowledge add someone's email or other alias to a page without rewriting it (#207881) fix: stop reporting a child worker as finished when the Gateway loses contact (#207713) fix: keep the Activity visibility test stable at midnight (#207847) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) fix: verify chat Stop recovery after dashboard pairing (#207888) ...
* commit 'ba0a7a5fac3e2f1b642d05502273b98dc75adf4f': (556 commits) test(agents): fix provider header filtering coverage (#207732) refactor: remove the bundled GBrain adapter (#207924) improve(ui): show optional run limits beside the automation schedule (#201283) test(onboarding): inspect recorded output for credential leaks (#207872) perf(exec): reduce host memory sampler allocations (#207927) test(mcp-relay): isolate the Connected apps fallback locale (#207923) fix(acp): deliver bound channel replies to the pending question (#207035) fix(cron): keep required reports from going silent when nothing changes (#207044) test(sessions): assert participant queue rollback state (#207891) perf(gateway): skip session display preparation for transcript recall (#207916) test(agents): verify complete bracketed paste payload (#207733) test: stop timing out the cron recovery settlement test on slow runners (#207920) fix: show when worktree cleanup stopped or will retry (#207883) fix: show approval destinations only when the forwarding mode uses them (#207885) fix: keep inherited tools when changing agent settings (#207884) feat: let Knowledge add someone's email or other alias to a page without rewriting it (#207881) fix: stop reporting a child worker as finished when the Gateway loses contact (#207713) fix: keep the Activity visibility test stable at midnight (#207847) perf(agents): reuse prepared tool catalog executors (#207900) fix: show the Gateway command default beside host rules in Devices (#207887) ...
Carry the bound hook, caller, and abort closures into Code Mode and Tool Search when compaction has no new execution context. Preserve the rebuild path for actual overrides and availability projections. Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Code Mode and Tool Search rebuild the execution wrappers for deferred tools while preparing each run's catalog. A run can keep both sets of wrappers live, and the extra work grows with the number of tools.
User Impact
Large tool catalogs use less CPU during preparation and hold less heap while runs are live. Tool calls keep their hook order, admitted caller and cancellation behavior. The synthetic provider requests stayed byte-identical.
Why This Change Was Made
Tool assembly already owns the hook, caller identity and cancellation bindings. Compaction carries the prepared executor forward when its hook context meets the catalog's requirements. It rebuilds tools when a real context override or independently prepared availability view requires one. The embedded attempt supplies one deadline reader to both paths. Catalog registration builds one initial row per executable tool and continues to use the prepared descriptors for the model-facing view.
Production runtime LOC +50/−37 (+13). The added lines preserve the distinct binding and availability cases. Tests +101/−1, benchmark +240, Knip entry +1.
Evidence
A retained-only production sample on
90ab1fadfrom 17:03 to 17:13 PST on November 28, 2026 recorded 374 MB allocated during the window and still live at the end. About 42 MB was attributed to this catalog build across before-tool-call (15.4 MB), caller context (14.5 MB) and abort (12.5 MB). Individual rebuild sites accounted for 8.0 MB in caller context, 6.9 MB in abort and 6.3 MB in the before-tool-call wrapper. The same sample attributed 6.4 MB and 5.3 MB to schema publication under MCP catalog and provider normalization and 5.7 MB to MCP header rendering. This change reuses the existing prepared schema and prompt paths on eligible catalog hits. The sample measures live allocations within the window.The synthetic workload compiled 96 tools (64 native and 32 bundle MCP) through the production catalog and provider serializer. It warmed 100 attempts per process and held 600 live attempts for the heap checkpoint. A uses the parent catalog on the same prepared inputs. Five A/A and five A/B pairs ran in independent processes with alternating arm order. These are per-run median / sample p95 values.
All samples produced provider request SHA-256
39c0285896b0bc00ff5efd1dc7d690765ce320e27c070088496bb3e2e2d0b80e. This proof exercises the catalog boundary with synthetic executors and no live provider or MCP traffic.The focused regression fails on the parent at executor reuse. It passes with the fix and verifies that the two plugin hooks each run once in priority order under the bound caller identity, the tool receives the bound abort signal, a subsequent aborted call is refused, and the catalog declarations and prompt stay byte-identical. 167 focused tests passed across eight files, including prompt-prefix stability and the Code Mode agent loop.
Codex autoreview of the final staged change against
9f63c3c17e48e5completed with no actionable P0–P2 findings. The benchmark script typecheck passed after correcting the synthetic MCP capability summary. Core lint and the core and test typechecks passed. The Knip production and full-tree scans reproduced the same unused exports on the exact parent. #202209 introduced the now-unusedAgentCommandPluginIngressOptsandclearNativeRepositorySourceModulesForTestexports. #207581 removed the last external use ofresolveUpdateInstallSurfaceMock.The auxiliary CI Planner Benchmark
validatejob failed on an unused upgrade fixture.pnpm deadcode:unused-fileson the exact parent reproduced the same failure forscripts/e2e/lib/upgrade-survivor/system-event-account.mjs, added by #207275 (b9ddb611c5dce9). This job is outside the required CI gate. Failed check