You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(native-chat): sample a Codex next-prompt suggestion when a hidden chat is shown again - #52380
If Codex finishes a reply while you are looking at a different chat, the gray "next prompt" suggestion never showed up when you came back. Now Orca asks for it once when you return to that chat.
What Changed
Before: at turn/completed, CodexComposerPredictions only called thread/sample if a composer was reading that chat right then. If the chat was hidden, the request was skipped and nothing retried it. Showing the chat again only registered the reader, so the empty composer stayed blank.
After:
A turn that finishes with no reader is remembered as unreadTurnId on the per-session prediction state.
When a reader returns (interestChanged(sessionId, true)), Orca sends one thread/sample for that turn, but only if suggestions are still enabled, the session is idle (not ended, no pending dispatch, no active turn) and no newer turn has started. turn/started clears the remembered turn.
Turn end and reader return go through the same gate (sampleForReader), so the setting and the unsupported check apply the same way on both paths.
If the reader leaves again while the sample is in flight, the reply is still published. Delivery already keeps the latest suggestion and restates it when a reader opens, so dropping it would just lose it. A send, a new turn or a relaunch still discards a stale reply.
A chat that was visible when the turn finished still samples right away, as before. Claude is unchanged, because it does not use thread/sample.
Why
The sampler required a live reader at turn/completed, and the return path never retried. Retrying on return reuses the existing request rather than inventing a suggestion locally. Hiding and showing the chat again repeatedly does not resend the request, because the remembered turn is cleared once it is sampled.
N/A. The composer's rendering does not change. This fix makes the main process send the existing thread/sample request for a hidden Codex chat when it is shown again. No before/after capture was recorded, and the behavior is covered by the unit tests below.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
New src/main/codex/structured/turns/codex-composer-predictions.test.ts (macOS, vitest):
A turn that finished while hidden is sampled once when the chat is shown, and hiding and showing it again does not send a second thread/sample.
A reply that arrives after the reader left is still published.
A hidden turn is not sampled once a newer turn has started.
Run against main's codex-composer-predictions.ts, the first two tests fail (2 failed, 1 passed). With this change, all 9 tests in src/main/codex/structured/turns/ pass. oxlint, oxfmt, the anti-slop and native code-quality oxlint configs, ast-grep and check-changed-code-quality all pass on the touched files.
Not run: Electron UI, Linux and Windows. The change is platform-independent main-process logic.
Performance
None, because the added work is one map lookup and an idle check on each reader change, plus clearing a field on turn/started. Micro-benchmark against main with N=10 and N=200 sessions: interestChanged takes about 21-37 ns per call (main: 14-18 ns), and observe is unchanged at about 610-670 ns per call. The cost does not grow with N. Across 400k hide and show toggles, thread/sample was sent exactly once per unread turn (5 at N=10, 100 at N=200), which is the one request a visible chat would already have sent. No new polling, I/O or subprocess work.
Risk
Level: Low
If a newer turn somehow started without sending turn/started, returning to the chat could request a suggestion for the previous reply. The user would see a gray suggestion they can ignore. A plain revert removes the retry, and sent messages and saved transcripts are unaffected.
Review
Reviewed in the maintainer bug bash. Follow-ups on top of the original fix: one shared gate for turn end and reader return, and keeping a reply whose reader left mid-sample.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
This is main-process logic in the shared Codex session adapter. It does not change IPC shapes, SSH, mobile or saved transcripts.
Original fix by @bbingz in #52380, landed on this PR with authorship preserved.
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)
I stated the risk: what could break, for whom, and how to back it out
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)
[Low impact] The PR appears safe to merge; no new blocking issue was found.
Summary
Remembers a completed Codex turn while its chat has no reader, then requests the existing suggestion when a reader returns.
Hidden Codex chats now ask for a next-prompt suggestion when reopened.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Codex turn completes] --> B{Reader present?}
B -- Yes --> C[Request suggestion]
B -- No --> D[Remember turn]
D --> E{What happens next?}
E -- Reader returns while idle --> C
E -- New turn starts --> F[Forget remembered turn]
C --> G{Same session and turn still idle?}
G -- Yes --> H[Retain and publish suggestion]
G -- No --> I[Discard reply]
When a turn completes without an active reader, the prediction module records its ID. When interest returns, it checks sampling eligibility and queues the turn if eligible. Tests verify the sampling request, suggestion update, single-sampling behavior, and handling of a pending result after the reader leaves or a newer turn starts.
Severity of issue fixed: Medium
Merge Risk: Low · up to 5865c
Gray-text suggestions may still be missing in a narrow case where the chat is reopened while a send is still in flight. The fix for the main hidden-chat case is sound, so this is mergeable with this follow-up noted.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Issue #52366 has one coding requirement group: when a hidden native Codex chat is shown again after its turn finished, make one thread/sample request for the latest completed turn if still eligible, a…
Out of Scope Changes check
The PR changes two files per the summary evidence: codex-composer-predictions.ts (implementation, about +41/-17) and codex-composer-predictions.test.ts (tests, +76/-0). Both files serve the sampling-o…
Title check
The title names the main change: Codex next-prompt suggestions are now sampled when a hidden chat is shown again. The raw summary, objectives, and linked issue #52366 all describe this fix. The title …
Description check
The description follows the template and covers ELI5, What Changed, Why, Linked Issue (Fixes #52366), Visual Proof (N/A with reason), Testing, Performance, Risk (Low, with revert path), and Checklist.…
Full details: Linked Issues check
Explanation
Issue #52366 has one coding requirement group: when a hidden native Codex chat is shown again after its turn finished, make one thread/sample request for the latest completed turn if still eligible, and show a returned suggestion as gray text. The current PR summary for codex-composer-predictions.ts states that PredictionState retains a completed turn that was not sampled because no reader was present. It also states that a reader arrival samples that turn when the session is idle, and that a newer turn clears the retained turn. The test file summary at the current head lists three cases: a completed hidden turn is sampled once when the chat becomes visible; a pending suggestion is still applied if the chat becomes hidden; and a newer turn prevents sampling the older completed turn. These cases cover the requirement. Gray-text rendering and Tab behavior are existing code that the issue does not ask this PR to change. Limits: the text diff could not be read at the current head because changed blobs are missing from the checkout. The verdict rests on the AI-generated summaries and the PR description. The author-reported test runs were not re-run. The earlier assessment's test list (in-flight cancellation on turn/started) differs from the current summary, so that detail is not re-verified here.
Full details: Out of Scope Changes check
Explanation
The PR changes two files per the summary evidence: codex-composer-predictions.ts (implementation, about +41/-17) and codex-composer-predictions.test.ts (tests, +76/-0). Both files serve the sampling-on-return behavior required by #52366. The PR description states that composer rendering, SSH, mobile, saved transcripts, and Claude behavior are unchanged, and no other changed file appears in the supplied evidence. The behavior change that delivers a pending sample result after the reader leaves is described in the PR and is tied to the same sampling path. Limit: the implementation diff could not be read at the current head, so line-level confirmation is not available.
Full details: Title check
Explanation
The title names the main change: Codex next-prompt suggestions are now sampled when a hidden chat is shown again. The raw summary, objectives, and linked issue #52366 all describe this fix. The title is specific and matches the changeset, though it is long at 89 characters.
Full details: Description check
Explanation
The description follows the template and covers ELI5, What Changed, Why, Linked Issue (Fixes #52366), Visual Proof (N/A with reason), Testing, Performance, Risk (Low, with revert path), and Checklist. The Performance section gives measured numbers. The AI Disclosure section is empty, but the author may be a team member, so the template allows that. The final lint/typecheck/test/build checklist item is unchecked, which the template permits when CI covers it.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A Codex turn that finished while nobody was reading its chat skipped
thread/sample and never retried, so returning to the empty composer showed
no gray next-prompt suggestion. Remember that unread turn and sample it once
when a reader returns, if suggestions are still enabled and no newer turn has
started. A reply that lands after the reader left is still kept, since
delivery restates the latest suggestion when a reader opens.
Fixesstablyai#52366
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(native-chat): sample a Codex suggestion when a hidden chat returns
fix(native-chat): sample a Codex next-prompt suggestion when a hidden chat is shown again
Nov 29, 2026
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Retry the retained turn when a pending dispatch settles.
When a turn completes while dispatch is still awaiting, observe retains that turn in unreadTurnId and skips sampling. If the reader returns before dispatch clears dispatchPending, interestChanged skips sampling because isIdle is false. The finally block that clears dispatchPending does not notify the predictions module. The retained turn then stays unsampled until another interest change or a new turn.
Settling a dispatch that leaves the session idle must also re-run the deferred sample for a retained turn. That retry must use the same eligibility checks as interestChanged. The mechanism that triggers the retry is an open design choice; the evidence does not require one specific approach.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
If Codex finishes a reply while you are looking at a different chat, the gray "next prompt" suggestion never showed up when you came back. Now Orca asks for it once when you return to that chat.
What Changed
Before: at
turn/completed,CodexComposerPredictionsonly calledthread/sampleif a composer was reading that chat right then. If the chat was hidden, the request was skipped and nothing retried it. Showing the chat again only registered the reader, so the empty composer stayed blank.After:
unreadTurnIdon the per-session prediction state.interestChanged(sessionId, true)), Orca sends onethread/samplefor that turn, but only if suggestions are still enabled, the session is idle (not ended, no pending dispatch, no active turn) and no newer turn has started.turn/startedclears the remembered turn.sampleForReader), so the setting and the unsupported check apply the same way on both paths.A chat that was visible when the turn finished still samples right away, as before. Claude is unchanged, because it does not use
thread/sample.Why
The sampler required a live reader at
turn/completed, and the return path never retried. Retrying on return reuses the existing request rather than inventing a suggestion locally. Hiding and showing the chat again repeatedly does not resend the request, because the remembered turn is cleared once it is sampled.Linked Issue
Fixes #52366
Visual Proof
N/A. The composer's rendering does not change. This fix makes the main process send the existing
thread/samplerequest for a hidden Codex chat when it is shown again. No before/after capture was recorded, and the behavior is covered by the unit tests below.Testing
New
src/main/codex/structured/turns/codex-composer-predictions.test.ts(macOS, vitest):thread/sample.Run against
main'scodex-composer-predictions.ts, the first two tests fail (2 failed, 1 passed). With this change, all 9 tests insrc/main/codex/structured/turns/pass. oxlint, oxfmt, the anti-slop and native code-quality oxlint configs, ast-grep andcheck-changed-code-qualityall pass on the touched files.Not run: Electron UI, Linux and Windows. The change is platform-independent main-process logic.
Performance
None, because the added work is one map lookup and an idle check on each reader change, plus clearing a field on
turn/started. Micro-benchmark againstmainwith N=10 and N=200 sessions:interestChangedtakes about 21-37 ns per call (main: 14-18 ns), andobserveis unchanged at about 610-670 ns per call. The cost does not grow with N. Across 400k hide and show toggles,thread/samplewas sent exactly once per unread turn (5 at N=10, 100 at N=200), which is the one request a visible chat would already have sent. No new polling, I/O or subprocess work.Risk
Level: Low
If a newer turn somehow started without sending
turn/started, returning to the chat could request a suggestion for the previous reply. The user would see a gray suggestion they can ignore. A plain revert removes the retry, and sent messages and saved transcripts are unaffected.Review
Reviewed in the maintainer bug bash. Follow-ups on top of the original fix: one shared gate for turn end and reader return, and keeping a reply whose reader left mid-sample.
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
This is main-process logic in the shared Codex session adapter. It does not change IPC shapes, SSH, mobile or saved transcripts.
Original fix by @bbingz in #52380, landed on this PR with authorship preserved.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)