Skip to content

fix(agents): retain model context through tool inventory projection - #142896

Merged
steipete merged 1 commit into
mainfrom
codex/tool-inventory-model-lease
Sep 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/tool-inventory-model-lease

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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.

@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 9, 2026
@steipete
steipete marked this pull request as ready for review September 9, 2026 06:46
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 2:52 AM ET / 06:52 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: d050608fba764b8a2b5ada1412a1c42c6a51a53d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with relevant regression coverage and reported built-runtime validation; no blocking correctness concern was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor gate does not apply. The captured body reports built Gateway/CLI inventory calls exercising the dynamic normalizer; inspected regressions cover lease lifetime and MCP workspace scoping. No material authorization change triggers additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor gate does not apply. The captured body reports built Gateway/CLI inventory calls exercising the dynamic normalizer; inspected regressions cover lease lifetime and MCP workspace scoping. No material authorization change triggers additional final-effect proof.
Evidence reviewed 9 items Current main still has the defect: The dynamic resolver returns model context from its try block and releases the lease in finally, before callers perform inventory projection.
Latest release comparison: The supplied latest release, v2026.9.3, contains the same early-release implementation; this repair is not already present there.
Ownership and generation scope: The acquired context retains the original lease, runs projection inside its prepared generation, rejects use after release, and releases failed or unresolved acquisitions. All production callers migrate to this internal acquisition.
Findings None None.
Security None None.

How this fits together

Tool 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +39, Tests +216. Total +255 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 4 169 130 +39
Tests 6 352 136 +216
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 521 266 +255

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +39 lines; tests/support net +216 lines Production growth implements explicit acquisition and cleanup; most growth covers ownership, workspace scoping, and failure regressions.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs a bounded model-resource lifetime defect in tool inventory projection without evidence of a widespread outage.
  • 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: The supplied repository state identifies a maintainer-authored PR, so the external-contributor gate does not apply. The captured body reports built Gateway/CLI inventory calls exercising the dynamic normalizer; inspected regressions cover lease lifetime and MCP workspace scoping. No material authorization change triggers additional final-effect proof.

Label justifications:

  • P2: This repairs a bounded model-resource lifetime defect in tool inventory projection without evidence of a widespread outage.
  • 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: The supplied repository state identifies a maintainer-authored PR, so the external-contributor gate does not apply. The captured body reports built Gateway/CLI inventory calls exercising the dynamic normalizer; inspected regressions cover lease lifetime and MCP workspace scoping. No material authorization change triggers additional final-effect proof.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 34e0e5d into main Sep 9, 2026
248 checks passed
@steipete
steipete deleted the codex/tool-inventory-model-lease branch September 9, 2026 08:58
@steipete

steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime 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: L 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.

1 participant