Skip to content

A running agent's resume note is not a sleep, so switch-on builds report it connected (dark, layout-owner build only) - #31485

Merged
Jinwoo-H merged 4 commits into
mainfrom
fd/l254-live-resume-not-sleep
Oct 21, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
fd/l254-live-resume-not-sleep

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​362 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​344
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​42 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46

ELI5

In test builds where the main process owns the layout (the "layout-owner" switch, still off for users), Orca saves a note for every running coding agent that says how to resume it after a crash. The layout code stored that note in the same place as "this pane is asleep". So every running agent looked asleep, and Orca reported its terminal as disconnected and not writable. Now a resume note for a running agent is kept separately, and only a real sleep counts as asleep.

What Changed

Before (switch-on builds only):

  • A running agent with a provider session read connected: false and writable: false with verdict unverifiable in terminal.list.
  • The renderer keeps a resume record with origin 'live' for every running agent (and 'quit' for one captured at quit, which may still be running after a warm reattach).
  • The shared layout load put every record into leaf.sleeping. Main's terminal index (terminal-surface-index.ts, main-terminal-surfaces.ts) turned that into status 'sleeping', and the terminal summary forced the pane disconnected.
  • live-background-terminal-mount-authority.spec.ts:521 fails for this reason. It has failed on main since Layout-owner build: main answers terminal questions from its own layout (A1, dark) #31187.

After:

  • leaf.sleeping means only a real sleep: origin 'worktree-sleep' or no origin. That is the desktop's existing rule (isHibernationDoneRecord, and the origin doc in agent-session-resume.ts). It is now one shared predicate, isPaneSleepRecord.
  • A running agent's 'live' or 'quit' record goes to a new optional LayoutLeaf.resume. It moves and closes with its pane exactly as sleeping does.
  • Save writes sleeping ?? resume back to the same sleepingAgentSessionsByPaneKey entry, so the file on disk is byte-identical.
  • The commands follow the same rule:
    • sleep: a record-only live or quit capture is routed by the predicate.
    • startPane: an unbound pane with either record is still refused, as today, so a plain start never loses how its agent resumes.
    • A record-only wake drops either record. A waking start wakes only slept panes, never a running agent's pane.
  • Second switch-on bug, same cause, fixed: main's shutdown reconnect facts (shutdown-reconnect-facts.ts) counted a live record as a sleep. That left an agent's SSH relay session, and its workspace, out of what the next startup reconnects. It now uses the same predicate.
  • Census-shape extension (no weaker):
    • Each field of the sleeping disk table can now name one alternate source (orFrom): "leaf.sleeping.X or leaf.resume.X".
    • The fact-locations mutation test still mutates every source separately, and each must change the disk output.
    • A new check fails if a pane's record lands in both fields or in neither, for all four origins.
    • A model rule (leaf_sleeping_and_resume) is checked after every command in the command tests.
    • No existing check was removed or loosened.

The terminal index readers are unchanged: once leaf.sleeping means only sleep, they are correct.

Why

The lead ruled that the fix goes at the save/load boundary, so leaf.sleeping has one meaning everywhere, rather than every reader learning to skip live records. We considered keeping live and quit records as "carried" records outside the leaf. That needs no census change, but the record would not follow its pane when main moves or re-keys it, so resume after a crash would lose it. A leaf field moves with the pane for free.

Linked Issue

Resolves ledger L254.

Visual Proof

N/A: dark change, switch-on builds only. No UI or copy change. It changes what terminal.list reports for running agents in layout-owner builds.

Testing

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

These tests fail without the fix:

  • In a switch-on build, a pane bound to a live terminal with a 'live' or 'quit' record reads connected, writable and live.
  • Each of the four sleep-command transitions.
  • The startPane refusal for an unbound pane with a resume record.
  • A resume record moves with a pane dragged to a new tab, and goes on closePane and closeTabs.
  • Published layout frames never carry either record.
  • Shutdown reconnect facts reconnect the relay of an SSH pane with a live or quit record.

These pass at both base and head, as they should:

  • A real slept pane still reads sleeping.
  • A load then save round-trip keeps sleepingAgentSessionsByPaneKey byte-identical for all four origins.
  • The save-format golden tests, with no regeneration.

A waking start leaves a running agent alone.

Gates:

  • pnpm tc and the CI static-analysis gate pass.
  • The changed-file unit tests pass.
  • vitest over src/main/runtime, src/main/persistence, src/renderer/src/runtime, src/renderer/src/components/terminal-pane and src/shared/workspace-layout was compared at base and head, switch-on and switch-off. No file fails only at head; the only head-only failures were flaky under load:
    • structured-agent-shell-environment hit a temp-directory cleanup error (ENOTEMPTY) and passes alone;
    • workspace-layout-paired-desktop hits a 30 s timeout at base and at head;
    • terminal-tail-redraw-wall-time passes alone.

Server specs (switch-on, fresh build at base 505d671 and at head):

Spec Base Head
live-background-terminal-mount-authority fail (:660, the agent reads connected:false) pass
headless-serve-focused-terminal-create pass pass
paired-mobile-desktop-tab-composition pass pass
paired-desktop-server-layout-frames pass pass

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

  • Mixed versions: the disk format is unchanged, and nothing new goes over the wire. Layout frames copy only a pane's terminal binding and title.
  • SSH: fixes the reconnect of an agent's relay session in switch-on builds.
  • Switch-off: the renderer still reads the same session map, and the load and save round-trip is identical.
  • Cross-platform: no platform logic changed.

Resolves ledger L254

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)

…-on builds

The shared layout load put every pane resume record into leaf.sleeping, so main's
terminal index read a live or quit capture as a slept pane and terminal.list
reported running agents as disconnected and unverifiable. Records of slept panes
(isPaneSleepRecord) now load to leaf.sleeping and running agents' records to
leaf.resume; both save to the same sleepingAgentSessionsByPaneKey entry, so the
disk format is unchanged. The disk-field census names both holders, and a model
rule refuses a pane holding both.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2a8d3f8b-8568-4253-a313-5df65ff736ce
📥 Commits

Reviewing files that changed from the base of the PR and between 29a1446 and e2bee4f.

📒 Files selected for processing: 20
  • src/main/persistence/window-save-divergence-values.ts
  • src/main/persistence/window-save-divergence.ts
  • src/main/persistence/window-save-reconnect-facts.test.ts
  • src/main/runtime/terminal/recovery/shutdown-reconnect-facts.ts
  • src/main/runtime/terminal/surface/terminal-surface-verdict-main.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/empty-reattach-retire-evidence.ts
  • src/shared/agent-session-resume.ts
  • src/shared/workspace-layout/workspace-layout-command-persistence.test.ts
  • src/shared/workspace-layout/workspace-layout-commands.test.ts
  • src/shared/workspace-layout/workspace-layout-disk-fields.ts
  • src/shared/workspace-layout/workspace-layout-fact-locations.test.ts
  • src/shared/workspace-layout/workspace-layout-load-bindings.ts
  • src/shared/workspace-layout/workspace-layout-model-rules.test.ts
  • src/shared/workspace-layout/workspace-layout-model-rules.ts
  • src/shared/workspace-layout/workspace-layout-model.ts
  • src/shared/workspace-layout/workspace-layout-process-commands.ts
  • src/shared/workspace-layout/workspace-layout-resume-record.test.ts
  • src/shared/workspace-layout/workspace-layout-round-trip.test.ts
  • src/shared/workspace-layout/workspace-layout-rule-types.ts
  • src/shared/workspace-layout/workspace-layout-save.ts

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

📝 Walkthrough

Workspace layouts now distinguish sleeping pane records from running-agent resume records by origin. Loading, saving, and layout commands handle both record types, and validation reports leaves containing both. Terminal recovery uses the same classification when assigning sleeping state. Window-save divergence handling treats resume data as opaque and as a main-owned binding field.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 1e59a

Merge Risk: ⚪ Minimal · up to 1e59a

No merge-blocking issue was identified; the record-handling change is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 61.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the primary change: running-agent resume records are no longer treated as sleeping in layout-owner builds.
Description check Passed The description is detailed and covers the change, rationale, linked ledger reference, testing, compatibility considerations, and checklist. It is mostly complete despite omitting the formal AI Disclo…
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.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, linked ledger reference, testing, compatibility considerations, and checklist. It is mostly complete despite omitting the formal AI Disclosure and Review sections.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H
Jinwoo-H merged commit bbc8303 into main Oct 21, 2026
54 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