Repository navigation
fix(agents): retain model context through tool inventory projection - #142896
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 2:52 AM ET / 06:52 UTC. ClawSweeper reviewWhat this changesThe PR retains dynamic model resources while building tool inventories, scopes provider normalization to the selected generation, and caches only inventory data. Merge readiness✅ Ready for maintainer review This focused fix remains necessary: current main and v2026.9.3 still release the model lease before inventory projection. No blocking introduced defect was found, and the related aggregate draft is not a replacement landing path. Priority: P2 Review scores
Verification
How this fits togetherTool inventory combines session configuration, model capabilities, tool policies, and discovered MCP tools into the lists shown by informational commands and the Gateway. Provider normalization determines which tool schemas can appear in those lists. flowchart TD
A[Session and model settings] --> B[Acquire model context]
B --> C[Project base tool inventory]
C --> D[Cache inventory data]
E[Discovered MCP tools] --> F[Filter and normalize in workspace]
B --> F
D --> G[Return available tools]
F --> G
C --> H[Release model resources]
F --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +39, Tests +216. Total +255 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep model resources owned through synchronous projection, retain only inert inventory results in caches, and preserve workspace-specific MCP normalization. Do we have a high-confidence way to reproduce the issue? Yes, from source: a dynamic-model inventory request releases its prepared lease before provider normalization on current main. The PR supplies a regression observing owner count during that callback; this review did not execute it. Is this the best way to solve the issue? Yes. Extending the existing lease through projection and removing executable context from the cache repairs the lifetime boundary without adding another public API or configuration path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 338a53fbde2c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Related: #140674
What Problem This Solves
Dynamic tool inventory released its prepared model lease before provider callbacks projected the tool schemas. The Gateway then cached that executable model after release. MCP projection could also miss the selected provider's normalizer because it ran outside that prepared generation.
Why This Change Was Made
An internal acquisition now keeps the original model lease and runs projection inside its exact generation. The informational command, session-reset check, and Gateway consumers release it after projection. The Gateway cache stores inventory data; a nonempty MCP projection acquires its workspace-specific model context when needed.
Static resolution, stale/background refresh, coalescing, and read-only MCP behavior remain unchanged. The handle rejects use after its own release without introducing a new snapshot-publication freshness policy. No public SDK, configuration, schema, dependency, or version changes.
User Impact
Tool inventories use the intended provider's schema normalization while its resources are owned, including sandbox MCP workspaces. Unrelated ambient providers cannot substitute for the selected generation. Empty or filtered MCP catalogs preserve the base inventory without additional acquisition.
Evidence
A native failing-before test observed zero prepared owners inside the actual provider normalization hook. The repaired path observes one, then releases it after projection. All 87 focused tests pass, covering native same/sandbox MCP scopes, competing ambient providers, errors, cache behavior, and command/reset callers. The canonical changed gate, 207.2-second ordinary build, and fresh full-scope independent Codex review pass. A callback config-narrowing error found by the first gate was repaired by capturing the existing config value, and the final reset cases were rerun.
A real built Gateway and two built CLI tools.effective calls returned identical inventories containing the synthetic plugin tool; the dynamic provider normalizer ran. Readiness took 4.56 seconds and the CLI calls 0.80 / 0.61 seconds, including process startup and connection. The owned Gateway drained and exited zero. The initial fixture was missing its required tools manifest contract; only that synthetic fixture was corrected.
Paired in-process handler measurements on the same base used 25 alternating samples after five warmups. With Node 24.20, uncached base+MCP took 6.35 → 6.62 ms, warm inventory without MCP 0.118 → 0.118 ms, and warm MCP 0.25 → 1.44 ms. The latter pays for one real acquisition and the previously missed selected normalizer. Node 26 showed a similar approximately 1.3 ms warm-MCP cost. These are bounded synthetic measurements, not a general speedup claim.
All runtime proof used isolated synthetic state and no external provider requests. General prepared/cache physical disposal remains separate work.