Skip to content

Keep a woken Codex terminal's saved session when its workspace sleeps again - #42864

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sleep-exit-on-wake
Nov 16, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/sleep-exit-on-wake

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

A finished Codex terminal loses its saved conversation when its workspace sleeps, wakes with the Codex tab resumed, and sleeps again before another prompt. The tab then reopens as a bare shell.

Sleep records the old process's exit while preserving the finished pane.
Wake retires the sleeping pane, but its provider-session-only launch row cannot supersede that exit without a hook.
The next Sleep reads the retained exit and deletes the saved session.

Forget the old exit through the server's existing alias-aware path only when spawn retires a sleeping pane. Ordinary exits remain authoritative; the presence check and sleep capture probe are unchanged.

Test: extend the existing server-pane-sleep fixture through the real presence, capture, and apply paths for idle Codex resume, Claude's new-process hook, failed resume into a bare shell, and an ordinary exit. On main, the idle Codex and failed-resume cases delete the saved record.

Validation: git diff --check passed. No dependencies installed, builds, typechecks, tests, or pnpm check:changed run locally, per this task's machine restriction. The normal commit and push completed without bypassing hooks.

Regression from #41793

Plan: CI and an admitted QA machine run the targeted test, typechecks, required checks, and the Sleep → wake idle Codex → Sleep repro before review.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready for review

Fix: a finished Codex terminal agent whose workspace is slept, woken (the tab resumes and is left idle) and slept again no longer loses its saved session. Before, its tab reopened as a bare shell and the conversation was gone. Regression from #41793.

Cause: the "agent exited" note recorded at the first sleep survived the wake. A resumed Codex sends nothing until its next turn, so the second sleep read the old note as a real exit and deleted the saved session. The fix forgets that note when the sleeping pane's process restarts (server-pane-sleep.ts:30), only for panes that were sleeping.

Review: fresh Claude Opus and Codex reviewers both approve with no findings (every wake route, pane-key aliases, restart persistence, SSH and mobile wake traced). The #41793 owner agreed the fix.

CI: green, 28 checks, CLEAN.

QA (M4Air, real Codex v0.169.0 + Claude Opus 5.5):

  • The new test passes on this head; with the fix line reverted, the idle-Codex and failed-resume cases fail.
  • Sleep → wake (Codex idle) → Sleep → wake, two full cycles: both agents resume their conversations with their replies; no bare shell.
  • Codex tab never opened during the wake: resumes. Graceful quit and relaunch while asleep: both resume.

Codex resumed after the second wake
Codex resumed after a wake-idle-sleep cycle

Older bugs QA saw, the same with and without this PR (not fixed here):

  • A Codex that was resumed by a wake and then really quit (/quit) comes back resumed at the next wake.
  • Done statuses disappear from the sidebar while a workspace sleeps.
  • After a relaunch, a workspace that was asleep at quit opens awake (not checked on main).

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