Repository navigation
Conversation
A reply turn recorded the prepared model-runtime generation at dispatch but only acquired its run lease later. A hosted model catalog adoption committed in between published a new generation, and the lease rejected the recorded one as superseded before any model call, failing the user's turn. Dispatch now admits the published record and holds its generation in the same synchronous step. The hold keeps the generation's registries open (custody, not plugin work, so plugin reload drains are not blocked) and lends the configured snapshot to the turn's run lease through the existing borrow contract. The turn finishes on the generation it was admitted with; later turns use the new one. A stale generation without a live hold still fails closed.
|
🦞👀 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. What this changesThe branch retains a reply’s admitted model runtime through dispatch preparation so a hosted catalog replacement does not invalidate its later run lease. Example: A user sends hello while catalog 300 replaces catalog 200
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Current main still exposes the reported race, and this PR offers a useful focused repair. No actionable introduced defect was found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway prepares model choices, credentials, and plugin registrations before running a reply. Dispatch captures those facts, and the run lease keeps the selected runtime available through execution. flowchart TD
A[Incoming message] --> B[Published model runtime]
B --> C[Dispatch retains admitted generation]
D[Hosted catalog replacement] --> B
C --> E[Prepare reply]
E --> F{Snapshot matches selected runtime}
F -->|Yes| G[Run reply on admitted generation]
F -->|No| H[Reject unsupported borrowing]
G --> I[Release dispatch custody]
Technical reviewBest possible solution: Keep dispatch custody and guarded borrowing in the existing runtime owners, consolidate overlapping repair work, and retain tracking for catalog-adoption cases outside this patch’s supported snapshot. Do we have a high-confidence way to reproduce the issue? Yes: capture dispatch on catalog 200, publish catalog 300, then acquire the run lease with the captured generation. Current-main source establishes the rejection, and the contributor reports matching built-Gateway failures; this review did not execute code. Is this the best way to solve the issue? Yes for the supported reply-dispatch case: atomic custody repairs the ownership gap without rebinding the turn or weakening stale-generation checks. It does not satisfy the linked issue’s broader acceptance for different workspaces or previously unloaded runtime plugins. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 98eb5759c934. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +91, Tests +99. Total +190 across 14 files. Added test files: 0. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 October 8, 2026, 11:23 PM ET / October 9, 2026, 03:23 UTC. |
|
Superseded by #167492, which landed on main first and fixes the same race (a turn keeps its admitted model-runtime generation across a hosted catalog adoption), with broader coverage of cron and Gateway preparation. Closing this one. |
Fixes #167573
What Problem This Solves
Fixes: a chat turn fails with
prepared model runtime plugin generation was supersededbefore any model call when the Gateway adopts a newer hosted model catalog between accepting the message and starting the turn. Any Gateway whose build is older than the hosted catalog adopts it at startup and on each refresh, so the first turn after an adoption can fail.User Impact
User impact: messages accepted before a hosted catalog adoption now complete on the model runtime they were admitted with; later messages use the adopted catalog. No configuration change or user action is needed.
Why This Change Was Made
A reply turn records the published model-runtime generation at dispatch but acquires its run lease later. If a publication commits in between, the old generation is no longer the configured owner's, and the lease fails closed by design (#128138): a stale generation must not republish over newer state.
The fix makes recording the generation and holding it one step. The published-record owner now offers
acquire, which reads the dispatch record and, in the same synchronous step, takes custody of its generation and keeps the configured snapshot borrowable. Dispatch disposes that lease when the attempt settles.runPreparedReplyacquires its run lease inside that generation's scope, so the existing borrow contract (the same one the Gatewayagentpath and nested turns use) lends the admitted snapshot when a newer generation was published.Invariants kept:
I chose this over rebinding the turn to the newest generation when the lease finds it superseded. A rebind would mix generations within one turn: dispatch hooks ran on the old inbound plugin registry. It would also contradict the tested fail-closed contract for unheld stale generations.
This change is independent of #165957.
Evidence
src/agents/prepared-model-runtime.remote-publication.test.tsruns the realdispatchLowLevelChannelReplyFromConfig, the real prepared runtime, and the realrunPreparedReply(turn internals mocked after admission). Inside the reply resolver it adopts a hosted catalog throughapplyRemoteModelCatalogUpdate, then starts the turn.608134ea54c(production code reverted, test kept), it fails with the production error:prepared model runtime plugin generation was superseded for …/agents/default/agent.node scripts/run-vitest.mjs src/agents/prepared-model-runtime.remote-publication.test.ts --maxWorkers=1: 11/11 pass, wall time 25.8s. The new test takes about 1.6s of CI time.allowGatewaySubagentBinding: true, which matches Gateway startup.src/gateway/gateway-active-memory.test.tsagainst a freshpnpm build, withdist/build-info.jsonbuiltAtbackdated so the hosted catalog is newer. I also made a local, uncommitted edit that turns hosted catalog refresh back on in that test.608134ea54c: 0/3 pass. Each run fails withgeneration was superseded.remote model catalog appliedis logged afterchat.send.pnpm tsgo:core,pnpm tsgo:core:test, oxlint, oxfmt, andgit diff --checkare clean.get-reply-run.ts. Tests are +139/−40, mostly the regression test and moving dispatch test mocks to the new lease shape.Gaps
agentmethod and isolated cron keeploadfollowed immediately by their own run lease. Those paths do not have the dispatch-to-lease window this issue covers.