Repository navigation
fix: release Codex prompt claims after turn completion - #21138
Conversation
📝 WalkthroughWalkthroughThe change updates Priority: ⬇️ Low Merge Risk: 🔵 Low · up to This PR ships a small, well-tested production fix that releases stale prompt claims when a Codex turn completes, backed by extensive before/after audit evidence on Node and Electron. The one remaining issue is a narrow robustness gap in the audit-only Vitest config that could make the audit script fail to locate its source-loading helper if run from a non-root working directory; it does not affect application behavior and is safe to merge with a follow-up fix. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the defect, fix, scope, and validation, but it omits most required template sections. It does not provide a Linked Issue, Visual Proof or N/A statement, Testing checkboxes and platform details, AI Disclosure, Review, boundary confirmation, Notes, or the Checklist. Resolution Complete the required template sections. Add the issue link after "Fixes #", state "N/A" with a reason for Visual Proof if applicable, document manual and automated testing with platforms, complete AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist items. Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (6 skipped: 6 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/audits/codex-prompt-claim-retention/before.config.mjs (1)
6-8: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winResolve
sources.cjsrelative to the config file, not the process cwd.
resolve('docs/audits/...')resolves againstprocess.cwd(). If vitest starts from any directory other than the worktree root, the require fails withMODULE_NOT_FOUND.createRequire(import.meta.url)already accepts a relative specifier, so the path can be anchored to this file.♻️ Proposed change
-import { resolve } from 'node:path' import { createRequire } from 'node:module' import { defineConfig, mergeConfig } from 'vitest/config' import baseConfig from '../../../config/vitest.config.ts' -const loadSources = createRequire(import.meta.url)( - resolve('docs/audits/codex-prompt-claim-retention/sources.cjs') -) +const loadSources = createRequire(import.meta.url)('./sources.cjs')
resolveis still needed on line 18, so keep the import if you prefer a smaller diff.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 35491dd8-9c4e-428d-bd56-c4c562132b32
📒 Files selected for processing (12)
docs/audits/codex-prompt-claim-retention/README.mddocs/audits/codex-prompt-claim-retention/before.config.mjsdocs/audits/codex-prompt-claim-retention/electron-results.jsondocs/audits/codex-prompt-claim-retention/fix.patchdocs/audits/codex-prompt-claim-retention/node-results.jsondocs/audits/codex-prompt-claim-retention/reproduce.cjsdocs/audits/codex-prompt-claim-retention/scenario.cjsdocs/audits/codex-prompt-claim-retention/source-versions.jsondocs/audits/codex-prompt-claim-retention/sources.cjsdocs/audits/codex-prompt-claim-retention/validation.jsonsrc/main/codex/codex-prompt-registry-retention.test.tssrc/main/codex/codex-prompt-registry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one scope note and a nitpick below.
Reviewed changes — initial review of 86bb589.
- Claim release on turn completion —
clearTurn()now also enumerates...this.claims.keys()in its prompt set, so a confirmed-cancellation claim whosebyAddress/boundPromptsentries were evicted or replaced is released when its exact thread/turn completes.forget()object-identity checks keep a replacement prompt and its live claim. - Retention regressions —
codex-prompt-registry-retention.test.tsadds four tests: 32 evicted claims released on exact-turn completion, wrong-thread/wrong-turn and refused settlement preserved, replacement authority preserved, oversized-turn digest match, plus a session-clear control. - Audit evidence —
docs/audits/codex-prompt-claim-retention/bundles the reproduction (in-memory original/candidate bundles, reversedfix.patch, hash-checked baseline), Node/Electron results, and validation records.
I re-ran the new suite (18 passed), then reverted the one-line fix locally: exactly the three targeted regressions fail and the session-clear control passes, confirming the tests pin the bug rather than passing regardless. Source was restored; tree is clean.
ℹ️ Claims are released on turn completion but remain outside the registry byte budget
retainedPromptBytes() (src/main/codex/codex-prompt-registry.ts:253) sums only byAddress and boundPrompts, so a claim that has been evicted from both maps is retained — and uncounted, with no size cap on claims — until an exact-turn turn/completed or session clear arrives. This fix closes the normal completion path (verified: 32 retained → 0), and the PR's Limits section already scopes out #19831 attribution; flagging only so the residual no-completion window is tracked if a hard bound on claimed prompts is intended later.
Technical details
# Claimed prompts bypass the registry byte/entry caps
## Affected sites
- `src/main/codex/codex-prompt-registry.ts:253-256` — `retainedPromptBytes()` uses `byAddress` + `boundPrompts` only; `claims` never contributes to `MAX_CODEX_PROMPT_REGISTRY_BYTES`.
- `src/main/codex/codex-prompt-registry.ts:112-124` / `258-274` — trim/registration evict only from `byAddress`/`journalItemIds` + `boundPrompts`, never `claims`.
## Required outcome
- Confirm whether the intended bound is "session clear" only. If not, claimed prompts need either byte accounting or a cap so a long-lived session with many confirmed cancellations that never receive a matching `turn/completed` cannot grow `claims` without limit.
## Open questions for the human
- Is a follow-up planned to bound `claims` independently of turn-completion delivery, or is per-session lifetime considered sufficient?ℹ️ Nitpicks
docs/audits/**lives under the wholesale-ignoreddocs/**and has no allow-list entry, so these evidence files are tracked only via force-add — a cleangit add docs/audits/...silently skips them. Adding!docs/audits/and!docs/audits/**(mirroring thedocs/sitepattern) would make the bundle reproducible from a clean checkout.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…21138) Co-authored-by: m4air <[email protected]>

Confirmed Codex cancellation keeps a prompt claim until its turn completes. If lookup entries are evicted or replaced first, turn cleanup cannot find that claim, so the session retains the prompt after completion.
Include claimed prompts in the existing exact-thread/turn cleanup. Existing object-identity checks preserve replacement prompts and their live claims. This changes no registry limits, cancellation timing, process ownership or wire data.
Validation
Portable, source-hash-checked evidence is in
docs/audits/codex-prompt-claim-retention/. The ordering is injected and uses ordinary small prompts; it establishes a lifetime defect, without attributing #19831 or measuring incident-scale growth.