Repository navigation
fix(terminal): launch prior/default agent when a woken terminal can't resume - #6277
Conversation
… resume Waking a sleeping worktree (or restoring terminals after an app restart) left an agent terminal as a BLANK shell while still showing the agent's icon: `buildColdRestoreAgentResumeStartup` returned null whenever the provider session couldn't be resumed, and the caller then spawned a bare shell. Now, when resume isn't possible, an agent terminal comes back as a FRESH session of the agent it previously ran (live status -> sleeping record -> persisted tab `launchAgent`); if that agent is unknown but the terminal was an agent terminal, the configured default agent is used. A genuine plain shell stays blank, and the existing resume path, SSH/remote, and WSL behavior are unchanged. Fixes stablyai#4557 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe pull request updates cold-restore handling in 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
870-879: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winGuard every
providerSessiondereference, not just duplicate clearing.Lines 903-915 handle records without
providerSession, but Line 875 and Line 2287 still dereference it directly. A no-provider sleeping record can still crash terminal restore before the fresh fallback runs.Potential fix
- const providerSessionKeys = new Set( - legacyMatches.map(([, record]) => - [ - record.worktreeId, - record.agent, - record.providerSession.key, - record.providerSession.id - ].join('\0') - ) - ) + const providerSessionKeys = new Set( + legacyMatches + .map(([, record]) => { + const session = record.providerSession + return session + ? [record.worktreeId, record.agent, session.key, session.id].join('\0') + : null + }) + .filter((key): key is string => key !== null) + ) + const allLegacyMatchesHaveProviderSession = legacyMatches.every( + ([, record]) => Boolean(record.providerSession) + ) @@ - (providerSessionKeys.size === 1 + (allLegacyMatchesHaveProviderSession && providerSessionKeys.size === 1 ? legacyMatches.length === 1 ? legacyMatches[0] : oldestLegacyMatch : null) @@ const matchingSleepingLaunchConfig = sleepingRecord?.launchConfig && (!useLiveEntry || (sleepingRecord.agent === agent && - sleepingRecord.providerSession.key === providerSession.key && - sleepingRecord.providerSession.id === providerSession.id)) + sleepingRecord.providerSession?.key === providerSession.key && + sleepingRecord.providerSession?.id === providerSession.id)) ? sleepingRecord.launchConfig : undefinedAlso applies to: 903-915, 2283-2289
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7ade0368-bdd4-4b35-a3ca-623ef7a06e89
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
|
walkthrough wake-terminal-before-after.mp4 |
…ume) launch Addresses CodeRabbit review on stablyai#6277. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Orca <[email protected]>
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks for the fix. I added a small maintainer follow-up to cover the cold-restore edge cases:
- Fresh fallback ignores stale completed live rows.
- Stored launch config/env is preserved when relaunching the agent.
- SSH fallback uses the known remote platform.
- Malformed sleeping records are handled defensively.
Validated with focused terminal-pane tests, typecheck, lint, and Electron smoke coverage.
Re-based onto the current shared remote tip (4110c29, which already carried an older main sync + windows-update-daemon-adoption); this brings in the 18 newer main commits through v1.4.124-rc.1. MERGE, not rebase. Conflict resolutions (our structure wins; main's semantics graft in): - update-check feature (update-check-click-options.ts + test, GeneralUpdateSettingsSection.tsx, SidebarSettingsHelpMenu.tsx + test, updater.ts + test): took main's shape — getUpdateCheckHint() centralizes the RC/perf hint, pointerdown modifier-capture handler, and the refined `checkVariant === 'prerelease'` guard so a perf check never permanently opts background retries into the RC channel. getUpdateCheckClickOptions (the actual behavior) was byte-identical on both sides. - Ctrl+K clear vs producer flow control (pty-subprocess.ts, session.ts, session.test.ts): kept BOTH — our pause()/resume() flow-control methods AND main's clear() ConPTY screen-state resync (#7413). Orthogonal. - orca-runtime.ts: took main's public visibility on clearHeadlessTerminalBuffer (ipc/pty.ts Ctrl+K path calls it); dropped main's createHeadlessEmulator factory — our Phase-5 query-authority emulator construction is restructured and has no caller for it. Incoming (auto-merged, off the byte-delivery path): #6277 agent cold- restore fallback (pty-connection.ts), node-pty ConPTY relocation (#7421), MiniMax rate limits, translations. Gates: typecheck 0 errors; ipc+daemon+terminal-pane+pane-manager 4204 passed; both fuzz suites pass; hand-resolved renderer files pass. No delivery/restore/flow-control/ACK/batching/scheduler bytes changed, so no 10MB bench required. Co-authored-by: Orca <[email protected]>
… resume (stablyai#6277) * fix(terminal): launch prior/default agent when a woken terminal can't resume Waking a sleeping worktree (or restoring terminals after an app restart) left an agent terminal as a BLANK shell while still showing the agent's icon: `buildColdRestoreAgentResumeStartup` returned null whenever the provider session couldn't be resumed, and the caller then spawned a bare shell. Now, when resume isn't possible, an agent terminal comes back as a FRESH session of the agent it previously ran (live status -> sleeping record -> persisted tab `launchAgent`); if that agent is unknown but the terminal was an agent terminal, the configured default agent is used. A genuine plain shell stays blank, and the existing resume path, SSH/remote, and WSL behavior are unchanged. Fixes stablyai#4557 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(terminal): assert default-agent cold restore is a fresh (non-resume) launch Addresses CodeRabbit review on stablyai#6277. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Fix cold restore agent fallback Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
Summary
Waking a sleeping worktree — or restoring terminals after an app restart — left a terminal that previously ran an agent as a blank shell while the tab still showed the agent's icon/title. You had to manually re-run
claude/codexto get going.Root cause: in
pty-connection.ts,buildColdRestoreAgentResumeStartup()returnsnullwhenever the agent's provider session can't be resumed (no provider session, or the resume plan can't be built). The caller then spawns a bare shell, and nothing clears the tab'slaunchAgent, so the stale agent icon remains.This change adds a fresh-launch fallback at exactly those
nullpoints. When resume isn't possible, an agent terminal now comes back as a fresh session (no--resume) of the agent it previously ran, resolved in priority order:agentType), elsetab.launchAgent(the durable signal across restarts), elselaunchAgent.If the prior agent is unknown but there's evidence the terminal was an agent terminal (a live status entry or sleeping record exists), the configured default agent is used — exactly like opening a new terminal. A genuine plain shell (no agent ever ran there, no default trigger) stays blank. No context is carried over (a clean session), and the correct agent icon is restored because the fresh startup flows through the existing cold-restore path that sets
launchAgent.Fixes #4557
Screenshots
Waking a slept agent terminal — before vs after (PII redacted):
wake-terminal-before-after.mp4
Testing
pnpm lintpnpm typecheckpnpm test—pty-connection.test.tspasses (193 incl. 4 new cases). The only full-suite failures are pre-existing, environment-only flakes unrelated to this change (src/relay/git-handler.test.ts,src/relay/subprocess.test.ts— they pass in isolation and flake under parallel load; they also fail on a cleanupstream/main).pnpm buildtab.launchAgent→ fresh prior agent after restart; agent terminal with unrecoverable agent → default agent; plain shell stays blank.AI Review Report
Ran an adversarial review of the diff. Risks checked and outcomes:
pendingStartupCommandguard returns null for any launch that already carries a startup command; the default-agent fallback only fires when a live entry or sleeping record exists; a brand-new blank terminal has none of those (even with a default agent configured), so it stays blank. New-terminal creation does not route through this builder.null; the successful-resume branch is untouched (existing resume tests pass).getColdRestoreAgentResumePlatform()andbuildAgentStartupPlan(same shell resolution/quoting) as the resume path; empty prompt avoids quoting risk; WSL→linuxmapping is identical. No shortcuts/labels/paths touched.ColdRestoreAgentResumeStartup.agentwidened fromResumableTuiAgenttoTuiAgent(a fresh launch can target a non-resumable agent). All consumers acceptTuiAgent(registerAgentLaunchConfigmetadata isAgentType;launchAgentfields areTuiAgent).clearSleepingRecordProviderDuplicatesto tolerate a record without aproviderSession(now reachable via the fresh-launch path).Security Audit
buildAgentStartupPlanused for new terminals; no user-derived strings are interpolated unquoted (empty prompt), and args/env come from the existing settings-resolution helpers.Notes