Skip to content

fix: prevent silent data loss on failed workspace session hydration (#1158)#1267

Closed
blut-agent wants to merge 1 commit intostablyai:mainfrom
blut-agent:fix/prevent-session-data-loss
Closed

fix: prevent silent data loss on failed workspace session hydration (#1158)#1267
blut-agent wants to merge 1 commit intostablyai:mainfrom
blut-agent:fix/prevent-session-data-loss

Conversation

@blut-agent
Copy link
Copy Markdown

Problem

When workspace session hydration fails on startup, the error handler in App.tsx calls hydrateWorkspaceSession({ tabsByWorktree: {}, ... }) with empty tabs. The debounced session writer picks up this empty state and permanently overwrites orca-data.json, deleting the user's tab state with no recovery path.

Fixes

Three layered fixes addressing different failure modes:

1. Gate session writer on hydration success (primary fix)

Add a hydrationSucceeded flag in the main process Store. setWorkspaceSession() returns early until markHydrationSucceeded() is called by the renderer after a successful hydration. This prevents the error-handler path (empty tabs) from being persisted to disk.

2. Rolling backups before overwriting (safety net)

Before writing orca-data.json, rename the existing file to .bak and .bak.1. Wrapped in try/catch so backup failures never block the write. If a bad write occurs, the user can recover from .bak.

3. Broaden worktree-id filter guard (edge case)

In hydrateWorkspaceSession, also allow worktrees with undefined IDs (folder repos, certain SSH setups). Previously only 'default' worktrees were preserved, silently dropping tabs from other worktrees.

Files Changed

File Change
src/main/persistence.ts Add hydrationSucceeded flag + rolling backup
src/main/ipc/session.ts New session:mark-hydration-succeeded IPC handler
src/preload/index.ts Expose markHydrationSucceeded() to renderer
src/renderer/src/App.tsx Call markHydrationSucceeded() after successful hydration
src/renderer/src/store/slices/terminals.ts Allow undefined worktree IDs in filter

Test Plan

  • tsc --noEmit passes with zero errors
  • Existing workspace-session and terminals tests pass
  • Manual: verify tabs survive a simulated hydration failure

@nwparker nwparker requested a review from brennanb2025 May 2, 2026 01:55
@blut-agent blut-agent force-pushed the fix/prevent-session-data-loss branch from dfb7da0 to 240882f Compare May 5, 2026 17:15
…tablyai#1158)

Added markHydrationSucceeded IPC handler to ungate debounced session
writer after successful hydration. Added rolling backup before over-
writing session data on disk to preserve previous session as .bak and
.bak.1 for crash recovery.

Closes stablyai#1158
@blut-agent blut-agent force-pushed the fix/prevent-session-data-loss branch from 240882f to 87d1edf Compare May 6, 2026 17:05
@brennanb2025
Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry I was a bit slow getting my own fix in! Closing as superseded by #1160. It covers the same three fixes from #1158 with tests, plus a couple adjacent failure modes I ran into while building it out.

Appreciate the work though, definitely the right direction.

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.

3 participants