Skip to content

fix(terminal): keep a deliberately slept workspace from respawning its PTY - #13343

Closed
mmarabel wants to merge 3 commits into
stablyai:mainfrom
mmarabel:gatsby74/sleeping-resume-bug
Closed

mmarabel wants to merge 3 commits into
stablyai:mainfrom
mmarabel:gatsby74/sleeping-resume-bug

Conversation

@mmarabel

@mmarabel mmarabel commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Putting a workspace to sleep could briefly stop its terminals and then silently restart them during unrelated background work. Sleeping now sticks until the workspace is explicitly opened or woken, and explicit wakes reliably bring plain-shell workspaces back.

What Changed

  • Keep an in-memory sleep-intent marker after successful workspace teardown; clear it on failed sleep or explicit activation/wake.
  • Keep hidden panes in inactive, deliberately slept workspaces cold instead of fresh-spawning a PTY.
  • Preserve visible panes and queued startup commands, including agent resume and background launches.
  • On a mobile/background wake with no sleeping-agent record, remount only the selected plain-shell tab and request its targeted background mount.
  • Recheck sleep intent immediately before spawn. If sleep wins an in-flight spawn race, retire the late local/direct-SSH PTY through its owning transport; paired-runtime PTYs use exact host-owned shutdown with the raw runtime handle.

Why

A slept workspace leaves mounted panes behind. Their deferred connect path could later run because another workspace changed, find no PTY to attach, and create a new one. The same race could complete a spawn after sleep teardown had begun. Both paths recreated terminals without an explicit wake.

The marker is intentionally in-memory: renderer restart also resets mounted workspace state, while persistence would reintroduce the stale-sleep-state approach previously reverted for #10205.

Linked Issue

Fixes #10205

Visual Proof

No styling change; these captures show the interaction behavior in the headed Electron regression test.

  1. Before Sleep: before Sleep
  2. After Sleep and activating an unrelated workspace; renderer and host PTY oracles remain zero: Sleep sticks
  3. Explicit activation recreates the PTY and accepts input: explicit wake

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.test.ts src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts src/renderer/src/lib/wake-sleeping-agents-in-background.test.ts — 4 files, 50/50 passed after rebasing onto current main
  • pnpm typecheck
  • pnpm lint
  • pnpm build
  • Headed Electron regression — 1/1 passed on macOS; Sleep reaches zero PTYs, unrelated activation keeps it cold, and explicit activation recreates a working PTY
  • Full pnpm test was not rerun after the latest rebase; changed-surface tests are green and CI will cover the full suite

AI Disclosure

AI-assisted implementation and review were used. All changed-surface tests, typecheck, lint, and build were run after the final rebase.

Review

  • Correctness: covers the ambient deferred-connect path, explicit plain-shell background wake, failed sleep recovery, and the in-flight spawn race.
  • Cross-platform: renderer state logic only; no platform-specific paths, shells, shortcuts, accelerators, or native APIs changed.
  • SSH/remote/local: local and direct-SSH cleanup stays on the existing owning transport. Paired-runtime cleanup uses exact host-owned shutdown. No local fallback or process-liveness inference was added.
  • Folder workspaces: activation clears intent for folder workspaces and git worktrees.
  • Remote compatibility: no RPC shape, terminal stream frame, opcode, or published-content contract changed.
  • Agents/integrations/providers: queued startup remains an explicit escape, preserving agent resume and background launch flows. No source-control or Git-provider behavior changed.
  • Performance: constant-time Set/store reads on the spawn path and one targeted tab mount on explicit plain-shell background wake.
  • Security: no dependencies, input parsing, credentials, commands, paths, auth, or IPC surface changed; the patch narrows unintended process creation.

Agent skill upstream boundary

  • Not applicable.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after proof attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, folder-workspace, and compatibility impact considered
  • pnpm lint, pnpm typecheck, targeted tests, and pnpm build pass; CI will cover the full test suite

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: d12b8086-2cd7-45e4-81a9-0b737e3af93c

📥 Commits

Reviewing files that changed from the base of the PR and between d8e9fa1 and 4810dc1fe3ef3e6fabcee618abd83b4eea937892.

📒 Files selected for processing (10)
  • src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.ts
  • src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.test.ts
  • src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/lib/wake-sleeping-agents-in-background.test.ts
  • src/renderer/src/lib/wake-sleeping-agents-in-background.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/lib/worktree-sleep-intent.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/renderer/src/lib/worktree-sleep-intent.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/lib/wake-sleeping-agents-in-background.ts
  • src/renderer/src/lib/wake-sleeping-agents-in-background.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts

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


📝 Walkthrough

Walkthrough

The change extends worktree sleep intent across shutdown, PTY startup, activation, and background wake flows. Shutdown marks all requested worktrees and clears intent for failed sleeps. PTY setup skips fresh spawning for hidden panes in inactive worktrees with sleep intent. Queued startup, visible panes, active worktrees, never-slept worktrees, and explicitly woken workspaces can still spawn. Activation and background wake clear sleep intent, including when no sleeping-agent records exist. Tests cover these paths.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #10205 by preventing ambient PTY respawns while preserving explicit activation, wake flows, and queued startup behavior.
Out of Scope Changes check ✅ Passed The implementation, documentation, and tests remain focused on sleep intent, PTY cold-start prevention, and related wake behavior.
Title check ✅ Passed The title clearly identifies the primary change: preventing deliberately slept workspaces from respawning their PTY.
Description check ✅ Passed The description is complete and relevant. It includes the required explanation, change scope, rationale, linked issue, visual proof, testing results, AI disclosure, review considerations, boundary con…
Full details: Description check

Explanation

The description is complete and relevant. It includes the required explanation, change scope, rationale, linked issue, visual proof, testing results, AI disclosure, review considerations, boundary confirmation, notes, and checklist status.

  • Fix all pre-merge checks with AI

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.

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4afafcd8-a90f-42ee-8023-566c81cb6343

📥 Commits

Reviewing files that changed from the base of the PR and between 34f2a62 and 471489a5e44a3ceb50a639f526eea9db941ba648.

📒 Files selected for processing (9)
  • src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.ts
  • src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.test.ts
  • src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/lib/wake-sleeping-agents-in-background.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/lib/worktree-sleep-intent.ts

@mmarabel

mmarabel commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

On the Docstring Coverage pre-merge warning (40% vs 80%): I have deliberately not raised it, and want to flag the reason rather than silently ignore the check.

The functions it counts are markWorktreeSleepIntent / clearWorktreeSleepIntent / hasWorktreeSleepIntent — three one-line Set operations whose names fully describe them. This repo's AGENTS.md is explicit on that:

Concise/Brief Non-obvious comments ONLY — DO NOT: be verbose, explain the obvious, walk through the code ("WHY not HOW")

Adding /** Marks the worktree's sleep intent. */ to markWorktreeSleepIntent is exactly the restatement that guidance forbids, so satisfying the threshold here would mean working against the repo's own standard.

What I did instead is put the non-obvious information where it earns its place:

  • a module-level comment on worktree-sleep-intent.ts explaining why the mark now outlives the sleep teardown and what clears it;
  • a JSDoc on shouldStayColdForDeliberateSleep covering the constraint it encodes;
  • a call-site comment on the ordering CodeRabbit correctly flagged, so the next reader knows why the clear precedes the no-work return.

Happy to add the missing docstrings if maintainers would rather have the threshold satisfied — just say so and I will, since it is a house-style call, not a technical one.

@mmarabel

Copy link
Copy Markdown
Contributor Author

Conflict resolved and rebased onto current main.

The conflict was modify/delete on pty-connection.test.ts: #14728 split that file off the max-lines list, while this PR had added two call-site tests to it. Those two cases now live in pty-connection-fresh-spawn-guards.test.ts (slept + hidden + another workspace active → no spawn; identical without the mark → spawn). Behavior is unchanged.

Local check: the four suites that cover this change (49 tests) pass, including the two ported call-site cases.

Nothing else from review is outstanding — CodeRabbit's wake-intent ordering catch is already in, and the docstring-coverage warning is the same house-style call noted earlier. The remaining GitHub banner is the first-time workflow approval, which needs a maintainer.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@mmarabel

Copy link
Copy Markdown
Contributor Author

Any further news on this? Still happens on latest version. I've rebased onto main to help with merging/review. Currently really annoying bug as it just wakes sleeping worktrees randomly. Happy to help with anything that can make the review faster/easier on your end!

@mmarabel
mmarabel force-pushed the gatsby74/sleeping-resume-bug branch from 4a78410 to e9b3446 Compare August 19, 2026 16:22
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker nwparker removed the P1 label Aug 19, 2026
@mmarabel
mmarabel force-pushed the gatsby74/sleeping-resume-bug branch from e9b3446 to 4810dc1 Compare August 20, 2026 17:18
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker

Copy link
Copy Markdown
Contributor

Readiness review — macOS local (2026-08-23)

Verdict: BLOCKED. I rebased and validated a corrected candidate at local commit 59886a195a2a84a8661a5d431e2bac9bd1d7841e, but the contributor fork rejected the required lease-protected push with remote rejected ... permission denied. The PR therefore remains at 4810dc1fe3ef3e6fabcee618abd83b4eea937892; the fixes and final proof described below are not yet on GitHub.

P0 / P1 / P2

  • P0: none found.
  • P1 — current PR head: a client/background wake for a deliberately slept plain-shell workspace clears the non-reactive sleep marker, then returns without remounting or requesting a targeted background mount when there is no sleeping-agent record (src/renderer/src/lib/wake-sleeping-agents-in-background.ts:168-181). A phone opening that workspace can therefore remain a no-op with no live PTY. The local candidate remounts the selected terminal tab and requests the targeted mount; its regression test passes.
  • P2 — current PR head: the pending-spawn branch runs before the deliberate-sleep guard (src/renderer/src/components/terminal-pane/pty-connection.ts:9274-9327), and onPtySpawn binds a late result without rechecking sleep intent (pty-connection.ts:3089-3107). A spawn already in flight when sleep begins can complete afterward and recreate the PTY. The local candidate adds a pre-spawn guard and retires late local/direct-SSH PTYs through the owning transport, while paired-runtime PTYs use exact host-owned shutdown; its race regression passes.

No P0/P1/P2 remains in the local corrected candidate.

Readiness checklist

  • Functional correctness: context-menu Sleep reaches zero renderer and host PTYs; activating an unrelated workspace leaves the target at zero; explicit activation creates a new PTY and accepts terminal input. Failed sleep still clears the intent and restores usability.
  • SSH/network failure: no local fallback or liveness verdict was added. Direct-SSH/local retirement stays on the existing owning transport; paired-runtime late-spawn cleanup calls exact host-owned shutdown with the raw runtime handle. Loss of contact is not treated as proof of exit.
  • Crash/cast/retry/unbounded growth: no new casts, retry loops, recursive work, unbounded queues, or retained payloads. The sleep marker remains an in-memory Set; the new hot-path checks are constant time. Late cleanup errors are caught and logged rather than becoming unhandled rejections.
  • Security/supply chain: no dependencies, IPC/RPC shapes, commands, paths, credentials, auth, secrets, or user-input parsing changed. The change narrows unintended process creation.
  • Performance/resources: one Set.has/store read on the spawn path; explicit plain-shell mobile wake mounts one selected tab, not every saved tab. Sleep now retires a spawn that loses the teardown race.
  • Backward compatibility/data loss/mobile: no persistence/schema migration and no terminal-stream/RPC wire change. Existing keep-identifier sleep semantics remain. The corrected candidate specifically covers mobile/background wake for plain shells and retains the existing sleeping-agent wake paths.
  • Cross-platform/remoting: renderer state logic is platform-neutral; no path, shell, accelerator, native-process, or Git command changed. Folder-workspace and git-worktree activation both clear sleep intent. Mixed-version remote wire behavior and GitHub/GitLab provider behavior are unchanged.

Tests by machine

Machine: macOS local, visible Electron via Playwright CDP.

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/sidebar/sleep-worktree-flow.test.ts src/renderer/src/components/terminal-pane/deliberate-sleep-cold-start.test.ts src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts src/renderer/src/lib/wake-sleeping-agents-in-background.test.ts — 4 files, 50/50 passed after the final rebase.
  • pnpm typecheck — passed.
  • pnpm lint — passed, including native/type-aware audits, reliability gates, max-lines and Electron-runtime ratchets, bundled-skill checks, and localization checks.
  • pnpm build — passed, including desktop, relay targets, CLI, renderer/web, and macOS native helpers.
  • ORCA_E2E_SLOWMO_MS=100 ORCA_E2E_FORWARD_APP_LOGS=1 ORCA_E2E_RECORD_VIDEO=1 pnpm exec playwright test tests/e2e/terminal-sleep-wake-restore.spec.ts --config tests/playwright.config.ts --project electron-headful --workers=1 --reporter=line — first post-rebase attempt timed out before the behavior under test while waiting 10s for its fixture marker on the saturated host; the identical rerun passed 1/1 in 1.2m and produced the proof below.
  • pnpm test — executed for 55 minutes on the heavily contended shared host, surfaced widespread timing/performance failures in untouched areas, and was externally terminated with exit 143 before Vitest printed totals. Examples included browser-cookie Electron tests, filesystem watcher timing, terminal-history large-checkpoint recovery, palette/plugin/orchestration performance budgets, and cross-version-wire tests skipped after 180s. Changed-surface tests remained green; this is the principal residual validation risk.

Visual proof (final rebased candidate)

All images are uncropped 1920×1170 captures from the passing headed run.

  1. Before Sleep: before Sleep
  2. After context-menu Sleep and activating the unrelated workspace; the target remains sleeping, while the test's renderer and host PTY oracles both remain zero: Sleep sticks
  3. Explicit activation recreates the PTY and accepts fresh input: explicit wake

Exact merge blockers

  1. Someone with write permission to gatsby74/orca:sleeping-resume-bug must push the corrected rebased commits (or grant permission); the attempted --force-with-lease push was rejected.
  2. After that push, GitHub workflows/checks must run (the PR previously required first-time workflow approval). The current remote head has no check rollup, so it cannot be called merge-ready.

mmarabel and others added 3 commits August 28, 2026 20:37
…s PTY

Sleeping a workspace kills its PTYs but leaves its panes mounted, and a pane's
deferred connect still runs on later render passes — including one caused by
activating an unrelated workspace. With no live handle to attach to, that connect
fell straight through to a fresh spawn, re-creating the PTY and flipping the
workspace the user just slept back to awake seconds later.

Captured in a running build: activating one workspace spawned a PTY for a
different, slept one ~50ms later, from runDeferredConnect -> pty-transport.connect.
This matches the field trace in stablyai#10205, where daemon.log shows session-attached on
the activated workspace immediately followed by session-created on a slept one.

The sleep-intent marker already existed but was set only for the focused
workspace and cleared as soon as teardown finished, so it could not describe a
workspace that stays slept. It now covers every slept workspace, survives
teardown, and is released by an explicit activation or background wake — the two
gestures that mean the user wants the workspace back. A pane with nothing to
attach to consults it and stays cold instead of spawning.

Visible panes, queued startup commands (agent resume, background launches), and
activation of the workspace itself are all unaffected.

Fixes stablyai#10205

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N3XFTKvDbdrkFXgzZw5xDZ
A workspace slept with only plain shells holds no sleeping-agent record, so the
background wake returned before clearing its sleep intent. Its panes then stayed
cold permanently and a client opening the workspace became a silent no-op.

Clear the mark first: the client's open is the explicit wake regardless of
whether there is any agent session to resume.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N3XFTKvDbdrkFXgzZw5xDZ
@mmarabel
mmarabel force-pushed the gatsby74/sleeping-resume-bug branch from 4810dc1 to df32e21 Compare August 28, 2026 18:39
@mmarabel

mmarabel commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@nwparker Addressed the readiness review and pushed the corrected candidate rebased onto current main (head df32e210a6).

  • Plain-shell client/background wake now remounts the selected terminal tab and requests a targeted mount.
  • Fresh spawn rechecks deliberate sleep; a late spawn is retired through the owning local/direct-SSH transport or exact paired-runtime shutdown.
  • PR is mergeable again.

Fresh validation after rebase: changed-surface tests 50/50, pnpm typecheck, pnpm lint, and pnpm build all pass.

Jinwoo-H added a commit that referenced this pull request Sep 3, 2026
…oken

Sleeping a workspace kills its PTYs but keeps its panes mounted and keeps each
tab's session id as a wake hint. Any later remount of those panes (recovery,
parking, portals) reattached that dead id, and the daemon's create-or-attach
spawned a fresh shell, so slept workspaces revived on their own (#10205).

The existing sleep-intent marker now outlives teardown and gates the deferred
connect itself, so both the reattach and fresh-spawn arms stay cold. It is
released by activating the workspace, by any PTY binding to one of its tabs
(CLI, automation, client wake), and by purge. A queued startup still connects.

Reproduces the community root cause from gatsby74 in #13343; the regression
e2e remounts a slept hidden pane and fails on main.

Co-authored-by: gatsby74 <gatsby74@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Cross-review from #20039, which I opened tonight for the same bug before finding this PR and #18051.

You identified the root cause first: the wake is the renderer pane-connect path, and manual sleep has no durable "stay dead until Wake" gate. I arrived at the same mechanism independently from field logs and then built a weaker fix (latching the terminal park on sleep so the panes never remount). Verifying it, I found the park gate leaks on exactly the paths a connect gate catches — candidateParkedTerminalTabIds refuses to park a tab with hasActivityTerminalPortal, one in terminalPaneSplitMountLeaseTabIds, or any tab while shouldMeasureHiddenWorktree is set. Your seam is the correct one. I'm standing my PR down.

Field evidence you may want, since neither this PR nor #18051 has a reproduced user journey attached — the dominant trigger in a long session is a background unpark sweep, not an activation. From a packaged build tonight, three self-wakes after three sleeps, each ~100ms behind another hidden workspace's pane remounting in the same pass:

05:15:37.086  session-attached  crash-closer@@9cc873ad      ← unpark sweep, live PTY → attach
05:15:37.212  session-created   fix-inline-…@@c490b5b6      ← dead session → fresh spawn
05:15:37.384  session-created   fix-inline-…@@cc62a5d4        (hasCommand: true → claude --resume)

Irregular 16–28 min gaps matching park-verdict churn, no sidebar_worktree_activate breadcrumb for that workspace in between. Full detail in my comment on #18051.

Credit for the design is yours; #18051 credits it too. Between the two, #18051 looks further along to me — it moves the gate to the connect entry so it covers both the reattach and fresh-spawn arms, adds clear-on-bind so non-activation wakes can't strand a workspace cold, and carries an e2e that fails on main and passes on the branch. Worth the two of you deciding which lands rather than a third PR competing with both.

cc @Jinwoo-H @gatsby74

nwparker added a commit that referenced this pull request Sep 11, 2026
…oken (#20075)

* fix(terminal): keep a deliberately slept workspace cold until it is woken

Sleeping a workspace kills its PTYs but keeps its panes mounted and keeps each
tab's session id as a wake hint. Any later remount of those panes (recovery,
parking, portals) reattached that dead id, and the daemon's create-or-attach
spawned a fresh shell, so slept workspaces revived on their own (#10205).

The existing sleep-intent marker now outlives teardown and gates the deferred
connect itself, so both the reattach and fresh-spawn arms stay cold. It is
released by activating the workspace, by any PTY binding to one of its tabs
(CLI, automation, client wake), and by purge. A queued startup still connects.

Reproduces the community root cause from gatsby74 in #13343; the regression
e2e remounts a slept hidden pane and fails on main.

Co-authored-by: gatsby74 <gatsby74@users.noreply.github.com>

Co-authored-by: mmarabel <mmarabel@users.noreply.github.com>

* fix(terminal): let a slept pane wait for its wake instead of latching cold

A pane whose connect ran while its workspace was slept used to mark itself
connected and stop; nothing re-armed it, so a wake that produced a live PTY
before the user clicked (CLI create, background agent resume, split panes)
left panes stranded. The connect now waits on the sleep marker and resumes
when the marker clears, and a torn-down pane drops its listener.

Tabs created with a live PTY clear the marker too, the sleep flow marks each
workspace only when its own teardown starts, and purge forgets the marker
without waking anything.

* fix(terminal): wake a waiting pane once, in its remounted generation

Activation clears the sleep marker after the set() that bumps dead tabs'
generations, and the waiting pane only resumes its connect when its tab
generation is still current. Otherwise the stale pane and its remounted
successor both reattached the same session id on a deliberate wake.

* fix(terminal): resolve the waiting pane's tab by either id and re-arm after wake

The wake listener looked the tab up by the pane's render id, which can be a
unified id whose terminal tab lives under entityId, so the generation check
declined forever for those panes. Mount, fresh spawn, and the wake listener now
share one live resolver. The wait flag resets when the listener fires so a
second sleep can hold the pane again, listener dispatch is guarded, folder
activation clears after its own set(), and the sleep flow re-asserts the marker
after each teardown while releasing a workspace the user activated meanwhile.

* fix(terminal): ignore PTY binds that land inside the sleep teardown window

A spawn resolving while shutdown was still awaiting the host bound a PTY and
cleared the marker, waking every waiting pane mid-sleep; re-marking afterwards
could not un-connect them. The sleep flow now scopes each teardown so binds in
that window are not wakes. The e2e asserts a deliberate wake yields exactly one
PTY, and the dispose test proves the listener is gone.

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: mmarabel <mmarabel@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Landed as #20075, via @Jinwoo-H's #18051 which built directly on your design. You called the root cause first — the wake is the renderer pane-connect path, and manual sleep had no durable stay-dead-until-wake gate. You're credited as Co-authored-by on the base commit of the merged work.

Closing as superseded rather than rejected. cc @Jinwoo-H @gatsby74

@nwparker nwparker closed this Sep 11, 2026
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]: Sleeping workspaces revive without user activation — hard to diagnose (open question on opt-in lifecycle logging)

4 participants