Skip to content

fix(codex): keep the stale-pane prompt when two accounts share a label - #11228

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/stale-pane-prompt-compares-account-ids
Jul 28, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/stale-pane-prompt-compares-account-ids

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

The bug

A Codex pane that outlives the app is re-prompted at startup by the stale-pane sweep. Main decides staleness authoritatively and by account id (codex-stale-pane-accounts.ts: record.accountId !== activeAccountId). The renderer then discarded that answer: markRestoredStaleCodexSessionsForRestart resolved both ids to display labels, and the store's A → B → A collapse deleted the notice whenever previousAccountLabel === nextAccountLabel.

Two accounts can share a label:

  • doAddAccount has no duplicate-email check, and the label is the bare email — so one OpenAI login added under two ChatGPT workspaces produces two accounts that read identically.
  • Any roster read failure, or an id missing from the roster, collapses every account to the fallback string Codex account.

Worse, notifiedPtyIds was built unconditionally from stalePanes, so a pane whose notice had just been deleted still reported notified: true. The bind sweep adds those to a module-level set that notifyCodexPaneBoundForStaleSweep early-returns on for the rest of the session. The set resets on relaunch, but the deletion recurs — so the prompt never comes back.

Consequence: the pane keeps running under the other account's auth.json and quota, with no prompt, on this and every subsequent launch.

The fix

Both halves — either one alone leaves the bug reachable:

  1. Compare account ids, not labels. CodexRestartNotice now carries previousAccountId / nextAccountId, and markCodexRestartNotices decides the A → B → A collapse (and the dismissal carry-forward) on ids when both sides know them, falling back to labels only for callers that carry none. The restored-stale path passes main's ids straight through; both live-switch call sites already had the ids on hand.
  2. Only suppress panes that actually kept a notice. markCodexRestartNotices returns the ptyIds left holding a notice, and the sweep marks notified from that rather than from the stale list.

Secondary, and only because the prompt text would otherwise read "switch from x@y to x@y": the prompt label appends the ChatGPT workspace when that is what distinguishes two same-email accounts. StatusBar.tsx and AccountsPane.tsx held byte-identical private copies of getCodexAccountLabel, used for nothing but these notices; both now call the one shared resolver.

Tests

src/renderer/src/lib/codex-stale-pane-account-identity.test.ts is fail-first. On the parent commit, 4 of its 5 cases fail and the regression guard passes:

× keeps the prompt when the two accounts resolve to the same label
× keeps the prompt when the roster read fails and every label collapses
× disambiguates shared emails by ChatGPT workspace
× does not report notified for a pane whose notice the store dropped
✓ raises no notice and reports nothing notified for a pane on the selected account
Tests  4 failed | 1 passed (5)

Also added: id-vs-label collapse and dismissal cases in codex-restart-notice-lifecycle.test.ts, and a sweep-level guard that a pane whose notice the store dropped is still swept on its next bind.

Verification

  • pnpm typecheck (all three projects, after clearing tsbuildinfo) — clean
  • pnpm lint (oxlint, both code-quality gates, reliability gates, max-lines ratchet, both localization gates) — clean
  • 7345 tests across src/renderer/src/lib, src/renderer/src/store/slices, src/renderer/src/components, src/main/codex, src/main/codex-accounts — pass, except 41 pre-existing localStorage is undefined failures in 7 unrelated files (Node 26 vs. the repo's Node 24; none reference the notice code)

The startup sweep asks main which panes are stale, and main answers by
account id. The renderer then threw that away: it resolved both ids to
labels and let the store's A -> B -> A collapse compare the strings. Two
accounts can share a label — doAddAccount has no duplicate-email check, so
one OpenAI login used in two ChatGPT workspaces gives both the same email,
and a failed roster read collapses every account to 'Codex account'. Either
way the notice was deleted for a pane that really is running under the
account the user switched away from.

The sweep then made it permanent: it marked every stale pane notified,
including the ones whose notice had just been dropped, and a notified pane
is suppressed for the rest of the session. Relaunching cleared the set but
the deletion recurred, so the prompt never came back and the pane kept
running on the other account's auth.json and quota, silently.

Carry the account ids into the notice and decide on them, falling back to
labels only for callers that have none; report which panes were left holding
a notice so a dropped one cannot claim suppression. The prompt also names
the ChatGPT workspace when that is what tells two same-email accounts apart,
which is what the two duplicated getCodexAccountLabel copies now share.
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a compound bug where two Codex accounts sharing the same email label (or a failed roster read collapsing every account to 'Codex account') would cause the stale-pane sweep to suppress the restart prompt permanently. The fix has two orthogonal parts: account comparison is now id-based (with a label fallback for legacy callers), and markCodexRestartNotices now returns only the ptyIds that kept a notice so the sweep can distinguish a raised prompt from one the A→B→A collapse silently dropped.

  • CodexRestartNotice gains optional previousAccountId/nextAccountId fields, and markCodexRestartNotices returns string[] instead of void; the A→B→A collapse and dismissal carry-forward both route through the new isSameCodexRestartNoticeAccount helper that prefers ids over labels.
  • The two private getCodexAccountLabel copies in AccountsPane.tsx and StatusBar.tsx are replaced by the shared resolveCodexRestartPromptAccountLabel, which also appends the ChatGPT workspace label when two accounts share an email to avoid "switch from x@y to x@y" prompt text.
  • Five new integration-level tests exercise the exact failure modes described in the bug report (shared labels, roster-read failure, suppression after a dropped notice), plus lifecycle tests for id-vs-label collapse and dismissal carry-forward.

Confidence Score: 4/5

Safe to merge. The fix is scoped, well-tested at multiple levels, and the two changed invariants (id-based comparison, return-value-gated suppression) are both explicitly exercised by fail-first tests.

When two accounts sharing an email both lack a workspaceLabel, resolveCodexRestartPromptAccountLabel returns the bare email for both, so the prompt reads 'switch from x@y to x@y'. The fix is that the prompt now reliably appears — the id comparison sees through the label collision — but the text still can't distinguish the two accounts in this edge case. This is an acknowledged limitation rather than a regression, and the id-based identity logic is correct throughout.

Files Needing Attention: No files require special attention. The sweep-level test added to codex-stale-pane-sweep.test.ts is a good regression guard for the suppression logic.

Important Files Changed

Filename Overview
src/renderer/src/store/slices/terminals.ts markCodexRestartNotices now returns ptyIds that kept a notice; collapse and dismissal carry-forward use id-aware comparison. The noticedPtyIds side-effect inside set() matches the existing wasQueued pattern immediately above it.
src/renderer/src/store/slices/codex-restart-notice-account-identity.ts New utility type and isSameCodexRestartNoticeAccount helper; correctly falls back to label comparison only when neither side carries an id.
src/renderer/src/lib/codex-session-restart.ts markRestoredStaleCodexSessionsForRestart now builds notifiedPtyIds from the store's return value rather than the raw stale list; resolveCodexRestartPromptAccountLabel extracted and exported, consolidating the duplicate label logic.
src/renderer/src/components/settings/AccountsPane.tsx Private getCodexAccountLabel removed; previousAccountId/nextAccountId now passed to markLiveCodexSessionsForRestart so the store can compare by id.
src/renderer/src/components/status-bar/StatusBar.tsx Same refactor as AccountsPane; private getCodexAccountLabel dropped, ids forwarded to markLiveCodexSessionsForRestart.
src/renderer/src/lib/codex-stale-pane-account-identity.test.ts New fail-first test file covering the exact regression scenarios: shared email, roster failure, workspace disambiguation, and dropped-notice suppression prevention.
src/renderer/src/store/slices/codex-restart-notice-lifecycle.test.ts Extended with id-vs-label collapse, system-default collapse, dismissal carry-forward, and re-ask-on-third-account cases.
src/renderer/src/lib/codex-stale-pane-sweep.test.ts Existing expectations updated to include new id fields; new case verifies a pane whose notice the store dropped is not suppressed from future sweeps.

Reviews (1): Last reviewed commit: "fix(codex): keep the stale-pane prompt w..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 85248b16-638e-4990-a57b-73e6655015b7

📥 Commits

Reviewing files that changed from the base of the PR and between 930ff96 and f0f755c.

📒 Files selected for processing (10)
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/lib/codex-session-restart-shell-flap.test.ts
  • src/renderer/src/lib/codex-session-restart.test.ts
  • src/renderer/src/lib/codex-session-restart.ts
  • src/renderer/src/lib/codex-stale-pane-account-identity.test.ts
  • src/renderer/src/lib/codex-stale-pane-sweep.test.ts
  • src/renderer/src/store/slices/codex-restart-notice-account-identity.ts
  • src/renderer/src/store/slices/codex-restart-notice-lifecycle.test.ts
  • src/renderer/src/store/slices/terminals.ts

📝 Walkthrough

Walkthrough

Codex restart notices now carry previous and next account IDs alongside labels. Notice lifecycle logic compares IDs when available, handles colliding labels, tracks retained PTYs, and updates dismissal and collapse behavior. Restart-session helpers resolve disambiguated labels and forward account IDs from account switching and stale-pane recovery. Tests cover identity collisions, roster failures, stale-pane retries, dropped notices, and restored-session prompts.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and fix, but it does not follow the required template sections like Summary, Screenshots, Testing, AI Review Report, Security Audit, or Notes. Rewrite the PR description using the required template headings and add screenshots or No visual change, testing, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: preserving stale-pane prompts when labels collide.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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.

@brennanb2025
brennanb2025 merged commit 77ac0bd into main Jul 28, 2026
27 checks passed
zpyoung pushed a commit to zpyoung/orca that referenced this pull request Jul 29, 2026
stablyai#11228)

The startup sweep asks main which panes are stale, and main answers by
account id. The renderer then threw that away: it resolved both ids to
labels and let the store's A -> B -> A collapse compare the strings. Two
accounts can share a label — doAddAccount has no duplicate-email check, so
one OpenAI login used in two ChatGPT workspaces gives both the same email,
and a failed roster read collapses every account to 'Codex account'. Either
way the notice was deleted for a pane that really is running under the
account the user switched away from.

The sweep then made it permanent: it marked every stale pane notified,
including the ones whose notice had just been dropped, and a notified pane
is suppressed for the rest of the session. Relaunching cleared the set but
the deletion recurred, so the prompt never came back and the pane kept
running on the other account's auth.json and quota, silently.

Carry the account ids into the notice and decide on them, falling back to
labels only for callers that have none; report which panes were left holding
a notice so a dropped one cannot claim suppression. The prompt also names
the ChatGPT workspace when that is what tells two same-email accounts apart,
which is what the two duplicated getCodexAccountLabel copies now share.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#11228)

The startup sweep asks main which panes are stale, and main answers by
account id. The renderer then threw that away: it resolved both ids to
labels and let the store's A -> B -> A collapse compare the strings. Two
accounts can share a label — doAddAccount has no duplicate-email check, so
one OpenAI login used in two ChatGPT workspaces gives both the same email,
and a failed roster read collapses every account to 'Codex account'. Either
way the notice was deleted for a pane that really is running under the
account the user switched away from.

The sweep then made it permanent: it marked every stale pane notified,
including the ones whose notice had just been dropped, and a notified pane
is suppressed for the rest of the session. Relaunching cleared the set but
the deletion recurred, so the prompt never came back and the pane kept
running on the other account's auth.json and quota, silently.

Carry the account ids into the notice and decide on them, falling back to
labels only for callers that have none; report which panes were left holding
a notice so a dropped one cannot claim suppression. The prompt also names
the ChatGPT workspace when that is what tells two same-email accounts apart,
which is what the two duplicated getCodexAccountLabel copies now share.
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