Skip to content

fix: release Codex prompt claims after turn completion - #21138

Merged
OrcaWin merged 1 commit into
mainfrom
np-oom-scan-codex-prompt-claims
Sep 18, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
np-oom-scan-codex-prompt-claims

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3044 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3043

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

  • Actual request delivery, cancellation and delayed completion proof: 32 expired prompts retained before, zero after on Node 26 and Electron 43.7 / Node 24. Session cleanup, wrong-thread/turn, refused completion and replacement ownership controls pass.
  • 71 tests across six suites, including four new lifetime regressions; reversed source fails the three targeted regressions.
  • Node, CLI and Web typechecks, focused normal/type-aware lint and changed-code quality pass. Independent review and root Node/Electron reruns pass.

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.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change updates CodexPromptRegistry.clearTurn to clear claimed prompts that match the specified thread and turn. It adds regression tests for evicted claims, replacement prompts, long turn identifiers, and session clearing. It also adds reproducible Node and Electron audit fixtures, source-hash metadata, comparison results, and validation reports.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 86bb5

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… 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 upstrea…
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: releasing Codex prompt claims after turn completion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/audits/codex-prompt-claim-retention/before.config.mjs (1)

6-8: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Resolve sources.cjs relative to the config file, not the process cwd.

resolve('docs/audits/...') resolves against process.cwd(). If vitest starts from any directory other than the worktree root, the require fails with MODULE_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')

resolve is 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

📥 Commits

Reviewing files that changed from the base of the PR and between f36a7ce and 86bb589.

📒 Files selected for processing (12)
  • docs/audits/codex-prompt-claim-retention/README.md
  • docs/audits/codex-prompt-claim-retention/before.config.mjs
  • docs/audits/codex-prompt-claim-retention/electron-results.json
  • docs/audits/codex-prompt-claim-retention/fix.patch
  • docs/audits/codex-prompt-claim-retention/node-results.json
  • docs/audits/codex-prompt-claim-retention/reproduce.cjs
  • docs/audits/codex-prompt-claim-retention/scenario.cjs
  • docs/audits/codex-prompt-claim-retention/source-versions.json
  • docs/audits/codex-prompt-claim-retention/sources.cjs
  • docs/audits/codex-prompt-claim-retention/validation.json
  • src/main/codex/codex-prompt-registry-retention.test.ts
  • src/main/codex/codex-prompt-registry.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 whose byAddress/boundPrompts entries 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.ts adds 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, reversed fix.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-ignored docs/** and has no allow-list entry, so these evidence files are tracked only via force-add — a clean git add docs/audits/... silently skips them. Adding !docs/audits/ and !docs/audits/** (mirroring the docs/site pattern) would make the bundle reproducible from a clean checkout.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit fbfe3a2 into main Sep 18, 2026
53 of 55 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant