Skip to content

fix(daemon): hand off slept v29 history to v30 - #11423

Merged
nwparker merged 2 commits into
mainfrom
fix/daemon-prev30-seed-drop-visibility
Jul 30, 2026
Merged

nwparker merged 2 commits into
mainfrom
fix/daemon-prev30-seed-drop-visibility

Conversation

@nwparker

@nwparker nwparker commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a session owned by a preserved pre-v30 daemon is intentionally slept, wait for its final checkpoint and then release its legacy route. On wake, the current v30 daemon reads the shared checkpoint and transfers large history through the bounded chunk protocol.

This replaces the warning-only approach. Live legacy sessions remain on their original daemon and are not interrupted.

Why

Protocol v30 has not shipped yet, so no released build currently has this regression. The compatibility boundary still matters for the first v30 release because stable v29 daemons and their live sessions survive an Orca update.

#10647's bounded history-transfer protocol is the correct root fix for oversized NDJSON messages. The degradation came from a stale router assumption: keepHistory retained the old daemon route because history was once assumed to be adapter-specific. Current and legacy adapters now share the same history directory, so a successfully checkpointed sleeping session can safely wake on v30.

Failure safety

  • Still-live v29 sessions remain routed to v29.
  • A failed checkpoint or shutdown preserves the v29 route.
  • Same-generation and non-history shutdown behavior is unchanged.
  • The old adapter's sticky restore cache is released only after successful handoff; the disk checkpoint remains v30's recovery authority.

User behavior

After sleep/wake, users see their restored scrollback above the fresh shell. Unlike the previous renderer-only fallback, that history is also present in the daemon's authoritative buffer and remains recoverable after another remount or reload.

Restored scrollback above the fresh shell

Proof

The new two-daemon regression starts a real v29 server, writes a history seed over 1 MiB, sleeps the session, and wakes it through a real v30 server. It verifies:

  • v30 uses startHistorySeedTransfer, appendHistorySeedTransfer, and finishHistorySeedTransfer;
  • the full marker is present in v30's authoritative buffer;
  • the v30 history writer is active after recovery.

Additional unit coverage verifies successful rerouting and failure preservation.

Validation:

Test Files  6 passed (6)
Tests       281 passed (281)

pnpm run typecheck:node
pnpm run check:code-quality:changed
pnpm run check:max-lines-ratchet

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 665279cd-e76e-493f-9072-e7d6b2cbf620

📥 Commits

Reviewing files that changed from the base of the PR and between be729f214f3bc03857b50a3b5b2979524d06c6b5 and 30fa9e6.

📒 Files selected for processing (4)
  • src/main/daemon/daemon-history-handoff.ts
  • src/main/daemon/daemon-pty-router-history-handoff.test.ts
  • src/main/daemon/daemon-pty-router.test.ts
  • src/main/daemon/daemon-pty-router.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/daemon-history-handoff.ts

📝 Walkthrough

Walkthrough

Adds a history-handoff predicate for legacy and current daemon adapters. Updates DaemonPtyRouter.shutdown to acknowledge cold restore during eligible migrations and conditionally remove session routing. Adds integration tests for v29-to-v30 history seed transfer and router tests for successful and failed checkpointed shutdown behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers behavior and testing, but it does not follow the required template sections or include AI review, security, screenshots, or notes. Rewrite it using the repo template with Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: handing off slept v29 history to v30.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/daemon/daemon-pty-adapter.test.ts (1)

2386-2410: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Restore the warning spy on every test path.

If spawn() or an assertion throws before warn.mockRestore(), console.warn stays mocked and can affect later tests; Vitest config has no suite-wide mock restoration. Wrap the spawn and assertions in try/finally.

Proposed cleanup
       const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
-      const result = await historyAdapter.spawn({ cols: 80, rows: 24, sessionId })
+      try {
+        const result = await historyAdapter.spawn({ cols: 80, rows: 24, sessionId })
         ...
-      warn.mockRestore()
+      } finally {
+        warn.mockRestore()
+      }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cf68fdec-8eab-40a6-9056-efef3359038a

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8013a and 8b18f00.

📒 Files selected for processing (2)
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR implements history handoff from slept legacy v29 sessions to the v30 daemon, replacing a warn-only approach. When a session owned by a pre-v30 daemon is intentionally slept (keepHistory=true with a v29 adapter), the router now clears the legacy route and releases the in-memory cold-restore cache, letting the current v30 adapter recover the session via its bounded chunk protocol using the on-disk checkpoint.

  • daemon-history-handoff.ts extracts the version-boundary check into a pure helper (shouldHandoffDaemonHistory) gated on keepHistory, adapter identity, and HISTORY_SEED_TRANSFER_PROTOCOL_VERSION.
  • daemon-pty-router.ts shutdown is updated so that a qualifying sleep calls ackColdRestore on the legacy adapter (releasing the sticky in-memory cache) and then deletes the legacy route; failure during adapter.shutdown preserves both, and the identity guard prevents double-deletion when an onExit fires concurrently.
  • The integration regression test starts real v29/v30 DaemonServer instances, seeds history exceeding the inline threshold, and verifies the chunk-transfer protocol and authoritative buffer recovery end-to-end.

Confidence Score: 5/5

Safe to merge — the change is gated behind a precise four-condition predicate and all prior keepHistory paths are provably unchanged.

The migration path fires only when keepHistory is true, the owning adapter is a different object from current, and a strict version boundary is crossed in both directions. The identity guard on sessionAdapters.delete handles the concurrent-onExit edge case correctly. All existing keepHistory scenarios retain their original behaviour, verified by both the existing suite and two new unit tests. The integration regression test uses real daemon sockets and asserts the full chunk-protocol sequence and authoritative-buffer recovery end-to-end.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/daemon/daemon-history-handoff.ts New pure helper that encapsulates the four-way version-boundary predicate for history migration; logic is correct and well-tested.
src/main/daemon/daemon-pty-router.ts Shutdown now conditionally releases the legacy route and ackColdRestore on migration; identity guard handles concurrent onExit; all other keepHistory paths unchanged.
src/main/daemon/daemon-pty-router-history-handoff.test.ts New integration test exercises the full sleep/wake handoff with real sockets and large history, verifying chunk protocol and authoritative buffer recovery.
src/main/daemon/daemon-pty-router.test.ts Adds two unit tests for the migration (successful rerouting) and failure preservation (route kept on checkpoint error) paths; existing tests are unaffected.

Reviews (2): Last reviewed commit: "fix(daemon): hand off slept legacy histo..." | Re-trigger Greptile

@nwparker nwparker changed the title fix(daemon): warn when legacy seed transfer degrades fix(daemon): hand off slept v29 history to v30 Jul 30, 2026
@nwparker
nwparker force-pushed the fix/daemon-prev30-seed-drop-visibility branch from be729f2 to 30fa9e6 Compare July 30, 2026 02:58
@nwparker
nwparker merged commit 0c861d7 into main Jul 30, 2026
46 of 48 checks passed
@nwparker
nwparker deleted the fix/daemon-prev30-seed-drop-visibility branch July 30, 2026 03:20
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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.

1 participant