feat(remote-comms): cross-incarnation wake detection#822
Merged
Conversation
Contributor
Coverage Report
File Coverage |
c2815c8 to
aa3187b
Compare
Write a `lastActiveTime` timestamp to persistent storage on remote comms initialization and compare it with the current time on the next startup. When the gap exceeds 1 hour, treat it as a wake event and reset all reconnection backoffs, complementing the existing runtime wake detector. Writing at startup (rather than only on graceful shutdown) ensures the timestamp is always recent, even after abrupt process termination. Closes #690 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move wake detection from remote-comms (transport-specific) to Kernel.initRemoteComms() for a cleaner architecture. The Kernel now reads/writes `lastActiveTime` in KV and calls the new `PlatformServices.resetAllBackoffs()` method when a wake is detected. This removes `crossIncarnationWake` from RemoteCommsOptions and the RPC initializeRemoteComms params, avoiding options pollution with runtime state. Detection is now general-purpose at the Kernel level. Design reasoning: - `lastActiveTime` is written on both init and stop, covering both abrupt shutdowns (crash/kill) and graceful stops. - No timer or crank hook is needed because false positives are harmless: `resetAllBackoffs()` on a fresh ReconnectionManager is a no-op. - The 1-hour default threshold is generous enough to avoid false positives from normal restarts while catching actual sleep events. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract lastActiveTime read/write/detect logic into KernelStore.detectCrossIncarnationWake() and recordLastActiveTime() methods, keeping the Kernel class clean. Detection now runs in #init() (general startup) rather than initRemoteComms(), with the result stored in a private field for later use. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ove wake detection to remote-comms Move the lastActiveTime persistence logic (detectWake, recordLastActiveTime) from inline functions in the store index into a dedicated store/methods/activity.ts file, following the existing store methods pattern. Move the cross-incarnation wake detection and backoff reset logic from Kernel into remote-comms initRemoteComms where it naturally belongs alongside transport initialization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove detectCrossIncarnationWake and DEFAULT_CROSS_INCARNATION_WAKE_THRESHOLD_MS from kernel-utils — the one-liner check is now inlined directly in store/methods/activity.ts. Add unit tests for activity.ts (detectWake, recordLastActiveTime) and resetAllBackoffs.ts (RPC spec and handler). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
294b065 to
a219b85
Compare
… tests, remove duplicate store tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
grypez
requested changes
Feb 10, 2026
Contributor
grypez
left a comment
There was a problem hiding this comment.
The jsdoc implies we need to await the subroutine
| if (!this.#resetAllBackoffsFunc) { | ||
| return null; | ||
| } | ||
| this.#resetAllBackoffsFunc(); |
Contributor
There was a problem hiding this comment.
Suggested change
| this.#resetAllBackoffsFunc(); | |
| await this.#resetAllBackoffsFunc(); |
Contributor
Author
There was a problem hiding this comment.
resetAllBackoffsFunc is typed as () => void (from initTransport), so it's not a thenable and doesn't need await. The async on the outer method is there to satisfy the PlatformServices interface which declares resetAllBackoffs(): Promise<void> (since it goes through RPC in the browser runtime).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Detects when the kernel process dies during system sleep and restarts after wake (#690). The runtime
installWakeDetectorcan't catch this since the process wasn't running. This feature persists alastActiveTimetimestamp, compares it on nextinitRemoteComms(), and resets reconnection backoffs if the gap exceeds 1 hour.How it works
store/methods/activity.ts:detectWake()reads the persistedlastActiveTime, checks if the gap exceeds 1 hour, writes a fresh timestamp.recordLastActiveTime()writes the current time (called fromKernel.stop()).remote-comms.ts:initRemoteComms()callsdetectWake()before transport init. If wake detected, callsresetAllBackoffs()after transport is up.PlatformServices.resetAllBackoffs(): New method across the full stack (type, RPC spec, Node/browser implementations). Delegates toReconnectionManager.resetAllBackoffs().Design notes
resetAllBackoffs()on a freshReconnectionManageris a no-op.stop()never runs (crash),lastActiveTimeis stale from the previousdetectWake(), so the gap is larger — correct behavior.Closes #690
🤖 Generated with Claude Code
Note
Medium Risk
Touches remote-communications initialization and transport reconnection behavior; incorrect wake detection or RPC wiring could change reconnect timing or introduce new startup-path failures, though changes are small and well-covered by tests.
Overview
Adds cross-incarnation wake detection by persisting a
lastActiveTimetimestamp in the kernel KV store (newactivitystore methods, recorded onKernel.stop()), and checking it duringinitRemoteComms().When the gap since the previous timestamp exceeds a 1-hour threshold,
initRemoteComms()now logs the event and calls a new platform service,resetAllBackoffs(), which is plumbed through types + RPC (resetAllBackoffsmethod spec/handler) and implemented in both browser and Node platform services by delegating to transport’s reconnection manager.Written by Cursor Bugbot for commit a219b85. This will update automatically on new commits. Configure here.