Skip to content

fix(native-chat): sample a Codex next-prompt suggestion when a hidden chat is shown again - #52380

Merged
nwparker merged 1 commit into
stablyai:mainfrom
bbingz:fix/52366-hidden-chat-suggestion
Nov 29, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
bbingz:fix/52366-hidden-chat-suggestion

Conversation

@bbingz

@bbingz bbingz commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

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

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

[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]
Loading

Reviews (4) · Last reviewed commit: "fix(native-chat): sample a Codex suggest..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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: Passed 4

Check name Status Explanation
Linked Issues check Passed 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 Passed 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 Passed 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 Passed 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.

Share

@bbingz

bbingz commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Fork unit full for the previous head 08d7986b8c310c6d7d7fe428ff71ecb930adc91a succeeded: https://github.com/bbingz/orca/actions/runs/46241871325

PR description, PR test LoC, and Headless Node server on that same head also succeeded. Closed the fork verification PR bbingz#121

Follow-up cd6249c155b85b4b810dc118ab35d2ae1269951c locks the one-shot and in-flight cancellation cases from the Greptile note. New fork verification PR: bbingz#122. Its unit full run is queued: https://github.com/bbingz/orca/actions/runs/46243197967. Not watched in this tick.

@bbingz

bbingz commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Fork verification for cd6249c finished. Unit full concluded success, with no failed jobs: https://github.com/bbingz/orca/actions/runs/46243197967. Closing bbingz#122.

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.

Fixes stablyai#52366

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/52366-hidden-chat-suggestion branch from cd6249c to 5865cf5 Compare November 29, 2026 09:39
@nwparker 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

@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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8039d233-8032-4735-bc37-25d9c8232e85
Commits

Reviewing files that changed from the base of the PR and between cd6249c and 5865cf5.

Files selected for processing: 2

  • src/main/codex/structured/turns/codex-composer-predictions.test.ts
  • src/main/codex/structured/turns/codex-composer-predictions.ts

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

Comment on lines +71 to +72
if (session && state?.unreadTurnId && isIdle(session)) {
this.sampleForReader(sessionId, session, state, state.unreadTurnId)

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.

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.

@nwparker
nwparker merged commit a296625 into stablyai:main Nov 29, 2026
56 of 57 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.

[Bug]: Codex gray-text suggestion is missing after returning to a chat that finished in the background

2 participants