Skip to content

fix(codex): say a full Stop wait can overrun quit's eviction budget, and unref its timer - #23859

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/codex-stop-wait-budget
Sep 30, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/codex-stop-wait-budget

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3

ELI5

A code comment claimed that a Codex Stop's short wait always fits inside the time Orca allows for shutting Codex down when the app quits. It does not always fit, so the comment now says what really happens. The wait's timer also no longer counts as something that keeps the app running.

What Changed

Before

  • A Stop that lands before Codex has opened the turn waits up to 5 seconds for it (added in fix(native-chat): Stop is there from the moment a message is sent #23026). The comment on that 5-second limit said it stayed under the quit path's eviction budget.
  • That budget is 8 seconds: 1 second to drain, up to 6 seconds for a supervised Codex close, and 1 second of margin. A close or quit queued behind a waiting Stop spends the wait out of it. So a full 5-second wait plus a slow Codex close can run past it, and the next launch's recovery then settles the leftover lease. The comment said otherwise.
  • The wait's timer was a plain timer, so it counted as pending work that keeps the Node process alive.

After

  • The comment states the real bound and what happens when it is exceeded.
  • The timer is unref'd, as the repo's other Codex timers are, so a Stop's wait is never the thing that keeps the process alive at quit.

No behaviour a user sees changes: the 5-second limit and the order of close and quit are the same.

Why

The comment is the only record of why 5 seconds was safe, and it overstated that. The accurate version matters for whoever next changes the eviction budget or the wait. Unref'ing matches codex-structured-notification-retry.ts and codex-structured-journal-generic-frames.ts. Shortening the wait or releasing it at quit was not needed: overrunning needs a full wait and a slow close at the same moment, and recovery already handles it.

Linked Issue

No issue. Follow-up from #23026's final review.

Visual Proof

N/A: a code comment and a timer flag; nothing a user sees changes.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • No new test: whether a timer is unref'd is not observable to a behaviour test, and the comment has no runtime effect. The Stop wait's existing tests pass (codex-structured-turn-open-wait.test.ts, 10/10).

  • pnpm tc:node, oxlint, check:code-quality:changed and the anti-slop audit pass.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

N/A for SSH, mobile and mixed versions: a comment and a timer flag inside the local Codex adapter.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author: @BrennanKB5

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cd4e8d64-cce1-4025-bb08-c111c5a051ff

📥 Commits

Reviewing files that changed from the base of the PR and between ff98f8d and 3aad0f1.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The wait timeout now calls unref when the runtime supports it. The Stop wait documentation now states that a queued close or quit consumes part of the eviction budget, and that recovery on the next launch settles the lease if the wait and provider close exceed that budget.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to ff98f

When owner status remains unresolved, restarting may leave the lease in place and report execution_owner_reconciling; qualify the new recovery description so it does not promise guaranteed settlement.

Architecture Summary

Architecture risk: 🔵 Low · up to ff98f

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/main/codex/codex-structured-prompt-ownership.ts: Updated the Stop wait documentation: a queued close or quit spends the eviction budget, so a full wait plus a slow provider close can overrun it, with the next launch’s recovery settling the lease. The old comment described the budget relationship but not this overrun and recovery outcome.
  • observed — Modified behavior in src/main/codex/codex-structured-turn-open-wait.ts: The wait timeout now calls unref when available; its existing timeout behavior is unchanged.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the changes, rationale, scope, testing, and compatibility impact. The formal linked-issue entry is missing, and the full lint, typecheck, test, and build checklist rem…
Title check ✅ Passed The title is concise, specific, and accurately summarizes both changes: the eviction-budget documentation correction and the timer unref update.
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adjusts timeout behavior and clarifies budget semantics in Codex wait logic.

The PR appears safe to merge; no actionable issue was established in its two changed files.

Summary

The PR corrects the Codex Stop-wait comment to acknowledge that a full wait plus a slow close can exceed the quit eviction budget, and unrefs the wait timer so it does not keep the process alive.

Reviews (3) · Last reviewed commit: "Merge origin/main (main CI fix #23923)"

@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 new issues found.

Reviewed changes

  • CODEX_STOP_TURN_OPEN_WAIT_MS comment corrected — the JSDoc now records the real bound: a Stop queued ahead of a close/quit spends its 5s wait from the quit path's eviction budget, so a full wait plus a slow provider close can overrun it and next launch's recovery settles the lease.
  • Wait timer unref'd — bound.unref?.() in createCodexTurnOpenWaits so a pending Stop wait is never what keeps the Node process alive at quit, matching codex-structured-notification-retry.ts:73 and codex-structured-journal-generic-frames.ts:41.

Verified the arithmetic against structured-agent-session-host-teardown.ts:39 (1000 drain + 6000 supervised close + 1000 margin = 8000) and confirmed a Stop holds the session serialize across the wait while quit's eviction phase queued behind it is wrapped in withPhaseTimeout(..., CHILD_EVICTION_TIMEOUT_MS) — so a 5000 + 6000 sequence does exceed the budget. pnpm test on codex-structured-turn-open-wait.test.ts and structured-agent-session-codex-turn-end-settlement.test.ts passes 18/18.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status

Ready. Head 7a55d542a77, based on main. CI green.

The comment on the Codex Stop's 5-second wait now says what really happens: a close or quit queued behind a waiting Stop spends the wait out of the 8-second eviction budget, so a full wait plus a slow close can overrun it, and the next launch's recovery settles the lease. The wait's timer is unref'd like the other Codex timers. No user-visible change. No new test, since neither is observable to one; the wait's tests pass, and tc:node, oxlint, the changed-lines gate and the anti-slop audit pass.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e3bbcded-cdf9-49ff-9068-020b52f5e5ed

📥 Commits

Reviewing files that changed from the base of the PR and between c2517a4 and ff98f8d.

📒 Files selected for processing (2)
  • src/main/codex/codex-structured-prompt-ownership.ts
  • src/main/codex/codex-structured-turn-open-wait.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Comment on lines +24 to +26
/** How long a Stop waits for Codex to open the turn it answered a send into. A close or quit queued
* behind the Stop spends this out of the eviction budget, so a full wait plus a slow provider
* close can overrun it; the next launch's recovery then settles the lease. */

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Qualify the next-launch recovery outcome.

When restart recovery lacks sufficient owner-death evidence, it can retain the unresolved lease and report execution_owner_reconciling. The comment currently states that recovery settles the lease unconditionally.

Suggested fix
- * close can overrun it; the next launch's recovery then settles the lease. */
+ * close can overrun it; the next launch's recovery attempts to settle the lease, but may
+ * retain it as unresolved and report `execution_owner_reconciling`. */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** How long a Stop waits for Codex to open the turn it answered a send into. A close or quit queued
* behind the Stop spends this out of the eviction budget, so a full wait plus a slow provider
* close can overrun it; the next launch's recovery then settles the lease. */
/** How long a Stop waits for Codex to open the turn it answered a send into. A close or quit queued
* behind the Stop spends this out of the eviction budget, so a full wait plus a slow provider
* close can overrun it; the next launch's recovery attempts to settle the lease, but may
* retain it as unresolved and report `execution_owner_reconciling`. */

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status update: merged current main in (head 3aad0f15db9), CI green (19 passed). The only conflict was the comment beside main's new provider-turn helper; both kept. Not merged.

@brennanb2025
brennanb2025 merged commit 69b1e40 into main Sep 30, 2026
33 checks passed
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