orca icon indicating copy to clipboard operation
orca copied to clipboard

[Bug]: Session loss on first launch after upgrading from pre-#5232-fix version (1.4.65 → 1.4.68)

Open taifunk opened this issue 5 months ago • 3 comments

Summary

The fix for #5232 (PRs #5234, #5240) does not protect users upgrading from a version that predates the fix. On first launch after upgrading from 1.4.65 → 1.4.68, in-progress floating terminal sessions — including active Claude agent sessions — are lost and replaced with blank new sessions.

Root cause

The cold-restore mechanism added in PR #5240 requires that the previous Orca version wrote sleepingAgentSessionsByPaneKey at quit time. Pre-fix versions (e.g. 1.4.65) never wrote this field — that was the original bug. So on first launch after upgrading, 1.4.68 finds no session payload to restore from and falls back to spawning fresh sessions.

The fix only takes effect from the second restart post-upgrade, once 1.4.68 itself has written the quit-time state.

Steps to reproduce

  1. Run Orca 1.4.65 (or any version predating #5232 fix) with active floating terminal sessions — at least one running a Claude agent
  2. Apply the automatic update to 1.4.68
  3. Observe floating terminal sessions after Orca relaunches

Expected behavior

Existing sessions are restored, or at minimum the user is notified that session state from the previous version cannot be recovered.

Actual behavior

Active sessions (including in-progress Claude agent sessions) are silently replaced with blank new sessions. No warning is shown. Sessions are unrecoverable.

Additional detail

Two floating terminal sessions were active at update time — one plain shell, one with an active Claude agent mid-session. After relaunch, both were replaced with 2 new sessions created ~132ms apart (programmatic batch, not user action), confirming Orca initiated the replacement rather than the user.

Environment

  • OS: Windows 10
  • Orca version before update: 1.4.65
  • Orca version after update: 1.4.68

Related

  • Fixes the general case: #5232 (PRs #5234, #5240)
  • This issue covers the one-time transition loss for users upgrading from pre-fix versions

taifunk avatar Jun 14 '26 12:06 taifunk

Taking a look 👀

brennanb2025 avatar Jul 15 '26 05:07 brennanb2025

Reproduced — confirmed (source + logic + passing unit test)

The claim holds on current main (HEAD == origin/main). The #5240 cold-restore recovers in-progress agent sessions only from the persisted sleepingAgentSessionsByPaneKey map (written at quit with origin: 'quit'). Builds predating the #5232 fix never wrote that field, so on the first launch after upgrading, the map is absent and every live agent terminal cold-restores as a blank shell — silently and unrecoverably. The fix only engages from the second restart post-upgrade.

Root cause (file:line):

  • src/shared/workspace-session-sleeping-agents.ts:100-119 — the schema field is .optional() and preprocesses missing/empty to undefined, so a pre-fix payload validates cleanly with no resume records.
  • src/renderer/src/store/slices/terminals.ts:3220-3224 — the missing-field fallback session.sleepingAgentSessionsByPaneKey ?? {}: an absent field silently becomes an empty resume map. No migration from an older shape, no warning.
  • src/renderer/src/lib/resume-sleeping-agent-session.ts:145 — resumeSleepingAgentSessionsForWorktree iterates Object.values(...); empty map → 0 launched → blank shell. Nothing inspects the restored tab.launchAgent to detect the lost agent.

Unit test (src/renderer/src/lib/resume-sleeping-agent-session-prefix-upgrade-loss.test.ts, 3 passed):

  • pre-fix session validates but carries no resume records (sleepingAgentSessionsByPaneKey === undefined);
  • control (quit record present) → resume returns 1, resumed agent tab + restore banner;
  • bug (field absent) → resume returns 0, no resumed tab — a silent blank shell.
npx vitest run --config config/vitest.config.ts src/renderer/src/lib/resume-sleeping-agent-session-prefix-upgrade-loss.test.ts

Fix status: PR #5356 (commit 919a9f799) adds an agentSessionCaptureVersion capability stamp and a one-time non-destructive pre-upgrade-loss notice at hydration — but it is not on main (confirmed absent; it lives on origin/brennanb2025/fix-5356-session-loss-upgrade). It can't recover the lost session ids (the pre-fix build never persisted them); it replaces the silent blank shell with an explained notice. On current main the loss is still silent.

Full trace in docs/bug-reproductions/5356-session-loss-upgrade-prefix.md.

🔁 Reproduced via automated Windows bug-reproduction pass.

OrcaWin avatar Jul 18 '26 08:07 OrcaWin

Closing as not planned. The ongoing agent-session persistence issue was addressed by #5232/#5240. This issue covers only the one-time transition from sessions written before that support existed; those missing session IDs cannot be recovered retroactively, and we've decided not to add a permanent migration notice for that historical transition.

brennanb2025 avatar Jul 19 '26 20:07 brennanb2025