Repository navigation
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 SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9acde3ef6e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!params.sessionKey) { | ||
| return undefined; | ||
| } | ||
| const existing = codeModeCatalogDescriptionStamps.get(params.sessionKey); |
There was a problem hiding this comment.
Rotate the stamp when a session lifecycle rolls over
Because this lookup is keyed only by sessionKey, /new, /reset, and idle/daily rollover for the same conversation all reuse the old value. initSessionStateAttemptLocked creates a new lifecycle at src/auto-reply/reply/session.ts:568-577 and :653-654, but keeps the same key (and usually the same durable session id), so the first prompt of the fresh transcript still advertises the prior tools and Code Mode configuration until the Gateway process restarts. Include the lifecycle revision in this identity or delete the stamp on rollover so next-session refresh actually occurs.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| // the whole prompt cache. The first catalog application of a session stamps | ||
| // the description; later catalog changes keep runtime discovery through | ||
| // catalog.search/API.list without rewriting the model-visible text. | ||
| const codeModeCatalogDescriptionStamps = new Map<string, CodeModeCatalogDescriptionStamp>(); |
There was a problem hiding this comment.
Bound the process-wide catalog-stamp cache
In a long-lived Gateway that encounters many conversation or subagent session keys, each entry retains the entire exec description (an up-to-8 KB catalog index plus static guidance) forever. A repo-wide search shows the only clear path is resetCodeModeCatalogDescriptionStamps, called from test support; catalog disposal and session cleanup never remove a key, so normal session churn grows the heap without bound. Add lifecycle-owned eviction or a bounded retention policy.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. What this changesThis PR replaces catalog-dependent Code Mode tool descriptions with fixed guidance directing models to runtime discovery. Example: A session's catalog grows from stable_alpha to stable_alpha plus stable_beta.
Review scores
ProductKind: Performance · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 5 items remain Current main solves the central cache-instability problem, but the same author's paired issue remains open, preventing automatic closure; the PR's additional discovery-only direction needs an owner decision. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherCode Mode compacts enabled tools behind exec and wait controls; models discover callable contracts, and guest execution dispatches through the current policy-filtered catalog. flowchart TD
A[Enabled tools] --> B[Current tool catalog]
B --> C[Runtime discovery]
D[Fixed control descriptions] --> E[Provider request]
E --> F[Guest execution]
C --> F
F --> B
Technical reviewBest possible solution: Retain current main's stable controls and current catalog guidance, then resolve the paired report and this alternative PR together. Do we have a high-confidence way to reproduce the issue? Current-main source removes the catalog-description rewrite and its regression asserts identical serialized control schemas across different catalogs; no target code was executed during this review. Is this the best way to solve the issue? Current main solves the reported problem while preserving current signatures; removing those signatures requires a separate product justification rather than another cache fix. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4e8011872afe; fix evidence: commit 0de636660ab3, main fix timestamp 2026-10-12T22:31:04Z. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -132, Tests +245, Docs +9. Total +122 across 20 files. Added test files: 1. 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: No label 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 HistoryReview history (3 earlier review cycles)
Reviewed October 13, 2026, 12:41 AM ET / 04:41 UTC (Revision 4). |
Fixes: long sessions lose their reusable prompt prefix whenever the tool catalog drifts between runs of one session. The Code Mode exec description embedded the tool catalog index (callable names, input/output hints, MCP server lists), and applyCodeModeCatalog rewrote it on every catalog change via catalogRef.onChange. The tools array precedes system and messages in provider prompts, so any description change invalidates the cached prefix for the whole session; on long-running agents this showed up as a full cache rewrite of a 170k-950k token prompt on every catalog change (late MCP connects, plugin loads, client tool shadows). Make the exec description stable, catalog-independent discovery guidance per review: it never embeds catalog-dependent names, schemas, or the catalog index, so the provider-visible tools array stays byte-identical as the catalog drifts, across /new and /reset, and across sessions. Current tool contracts (names, schemas, owners) are obtained at execution time through catalog.search, handle describe(), and the API.list/API.read declaration files, so a mid-session name collision can never leave a stale owner contract advertised in the prompt. Swarm guidance is config-conditioned and hedged by run permissions; skills, nodes, and MCP guidance is hedged by availability, keeping the text stable without advertising contracts a run cannot resolve. Execution restrictions remain bridge-enforced and no longer touch the prompt; shell guidance points at discovery instead of a frozen callable name, so a client shadow can strand no stale name behind the shell global. Removes the session description stamp, its process-wide map, and resetCodeModeCatalogDescriptionStamps entirely, retiring that approach's lifecycle, retention, and callable-ownership defects. Tests: new code-mode.catalog-description-stability.test.ts (byte-identity across growth/shrink/owner change/reset, post-collision discovery and execution to the current owner, first-turn collision); code-mode.catalog-index.test.ts rewritten to byte-stability across catalog overflow/reorder plus runtime discovery signatures; collision, observer, registry-copy, retention, swarm, skill-authority, integrated, host-contract, and node-plugin suites updated to the stable contract. Proof: redacted shipped-gateway trace (real gateway process, loopback mock provider) showing the provider-visible tools array byte-identical across turns, a mid-session /new, and a fresh session, with guest discovery returning current contracts each turn.
9acde3e to
48386d8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48386d8b82
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // `catalog.search` / `API.list`, so the prompt never advertises a contract | ||
| // that a mid-session collision may already have moved to another owner. | ||
| const CODE_MODE_SHELL_DISCOVERY_GUIDANCE = | ||
| " For heavier computation, discover the shell tool with `catalog.search` or `API.list` and call the returned callable; its name and schema come from discovery, not from this prompt."; |
There was a problem hiding this comment.
Stop treating API.list results as callables
When a model chooses the newly advertised API.list route for shell discovery, API.list returns { files: [...] } file descriptors in createCodeModeControllerSource (lines 343–357), not a callable, so the next instruction to “call the returned callable” leads to a non-function call. Only catalog.search returns callable handles; direct this sentence to search, or explain the list/read/global-name sequence.
Useful? React with 👍 / 👎.
| session: it never embeds callable names, input/output hints, or the catalog | ||
| index, so catalog drift (late MCP connects, plugin loads, client shadows, |
There was a problem hiding this comment.
Remove the remaining quick-index instructions
After this removes the catalog index, the same page still says providers receive a bounded native-tool index at lines 108–110, while docs/tools/code-mode/quickstart.md:157 and CODE_MODE_SHELL_SOURCE_ERROR still teach quick-index/-> ? syntax that can no longer appear. This leaves both public docs and model-visible recovery instructions pointing at a retired contract; update the remaining references to runtime handle metadata, describe(), and API discovery as part of the cutover.
AGENTS.md reference: AGENTS.md:L52-L52
Useful? React with 👍 / 👎.
| const swarmGuidance = resolveSwarmConfig(ctx.runtimeConfig ?? ctx.config, ctx.agentId).enabled | ||
| ? " Swarm globals `agents.run`, `phase`, and `log` support orchestration when this run permits spawning; read `agents.d.ts` for types and orchestration idioms." |
There was a problem hiding this comment.
Update the documented Swarm prompt condition
When Swarm is configured on but sessions_spawn is absent, an MCP lookalike, or execution-denied, this code now includes the hedged Swarm guidance (the new cases in code-mode-swarm.test.ts:588-613 explicitly expect that), but docs/tools/code-mode/quickstart.md:300-303 still says the prompt hints appear only when the native tool is present and permitted. Operators inspecting the payload can therefore mistake hint presence for capability availability; document the new config-conditioned hint separately from actual guest installation.
AGENTS.md reference: AGENTS.md:L52-L52
Useful? React with 👍 / 👎.
|
Closing as superseded: main fixed the Code Mode catalog-description churn in 0de6366, which keeps the control descriptions stable while preserving the bounded signatures. Thanks to the reviewers for the detailed findings. |
Closes #170233
Related: #170050, #169091
What Problem This Solves
Fixes: long Code Mode sessions lose their reusable prompt prefix whenever the
tool catalog drifts between runs of one session (late MCP connects, plugin
loads, client tool shadows), so every later turn pays full input cost again
instead of reusing the cached prefix.
User Impact
User impact: long-running agents on providers with prompt caching keep their
cached prefix across mid-session catalog changes, restoring cache hit rates
for the rest of the session; tool discovery and execution behavior are
unchanged.
Why This Change Was Made
The
exectool description embeds the tool catalog index, andapplyCodeModeCatalogrewrote it on every catalog change viacatalogRef.onChange. The tools array precedes system and messages inprovider prompts, so any description change invalidates the cached prefix for
the whole session; on long sessions this showed up as a full cache rewrite of
a 170k-950k token prompt on every catalog change.
This change stamps the catalog into the description on the first catalog
application of a session (keyed by
sessionKey, which the tool-surface planalready threads through the bridge) and makes
onChangea no-op afterwards.Runtime discovery is unchanged:
catalog.search/API.listexpose new toolsat runtime, and a new session gets the current catalog. Runs without a
session key keep the previous per-run behavior, so headless and
schema-projection surfaces are untouched.
Alternative considered: keying the stamp by
catalogRefidentity instead ofadding a
sessionKeyparam. Rejected because the same session can rebuild itstool surface (and catalog ref) across runs — exactly the paths where late
connects land — so ref-keying would still rewrite the prefix per rebuild.
Moving the catalog index out of the tools array entirely (discovery-only via
catalog.search) was also considered and rejected as a larger behavioralchange: the index is what lets the model plan around available tools, and a
moving system-prompt block invalidates the cache the same way.
Related: #170050 stabilized message-tool and replay prefix content; #169091
removed execution-allowlist dependence from this same description. This PR
covers the remaining rewrite trigger: catalog drift between runs of one
session.
Evidence
Focused tests (synthetic, provider-free), repo's own runner:
src/agents/code-mode.catalog-description-stamp.test.ts(new, 3 tests):exec description byte-identical across two runs of one session when the
catalog grows;
catalog.searchstill finds and calls the mid-session toolat runtime while the description stays stamped; a new session gets a fresh
description with the current catalog.
code-mode.test.ts,code-mode.bridge.lifecycle.test.ts,node-plugin-tools.test.ts,code-mode-retention.test.ts— 49 tests.embedded-agent-runner/run/attempt-client-tools.test.ts— 15 tests.embedded-agent-runner.prompt-cache.test.ts,tool-surface-bridge.test.ts,tool-surface-plan*.test.ts) — 4 shards passed (290 tests).oxfmt --checkclean on the 9 touched files;oxlintclean;pnpm tsgo:core(core typecheck) clean.Existing suites that asserted the old rewrite-on-drift contract
(
code-modeclient-shadow, bridge-lifecycle client tool, descriptionretention restriction, embedded runner observer/registry) now assert the
stamped contract with equivalent rigor, including that the live catalog still
narrows/grows while descriptions stay pinned.
Release-note context: keep Code Mode tool declarations stable across
mid-session catalog changes so long sessions keep their prompt-cache prefix.