Reconnect pull-wake stream after sleep#4634
Open
KyleAMathews wants to merge 3 commits into
Open
Conversation
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix-child-wake-delivery #4634 +/- ##
===========================================================
- Coverage 58.01% 58.00% -0.02%
===========================================================
Files 342 342
Lines 40345 40364 +19
Branches 11778 11779 +1
===========================================================
+ Hits 23407 23413 +6
- Misses 16900 16913 +13
Partials 38 38
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Electric Agents Mobile BuildLocal mobile checks ran for commit The EAS Android preview build was skipped because the |
…x-wake-resume-after-sleep
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.
Detect long heartbeat timer gaps in the pull-wake runner and reconnect the wake stream after a computer resumes from sleep or a long event-loop stall. This keeps desktop agents listening for wake notifications instead of staying attached to a stale long-lived stream.
Root Cause
The pull-wake runner already reconnects its wake stream after repeated heartbeat failures. After a laptop sleep/resume, though, the long-lived wake stream can become stale while new heartbeat requests succeed again. In that state the runner can continue reporting a connected stream but stop receiving wake notifications.
This PR is stacked on #4632, which preserves deferred same-stream wake delivery and fixes stale in-flight heartbeat ownership across runner restarts. This change handles a separate failure mode: the process was suspended long enough that the existing wake stream should be considered suspect even if the next heartbeat succeeds.
Approach
Track wall-clock time between heartbeat timer ticks:
If the elapsed gap is larger than
resumeGapResetMs, the runner sendsSTREAM_RESETto the pull-wake lifecycle machine. The default threshold is the runner lease duration, so normal short event-loop delays do not reconnect the stream, while sleep/resume-sized gaps do.The test simulates sleep by advancing wall-clock time before the heartbeat timer gets CPU again, then verifies that the current stream is cancelled and a new stream connection is opened.
Key Invariants
Non-goals
Trade-offs
The runner may reconnect after any event-loop stall longer than the lease, not only literal OS sleep. That is intentional: after a lease-sized gap, the long-lived stream is cheap to re-establish and safer than assuming it is still delivering wake events.
Verification
Also run from the repository root for changeset coverage:
Verified locally:
pull-wake-runner.test.ts: 65 passed@electric-ax/agents-runtimetypecheck: passed after building the fresh worktree dependency@electric-ax/agents-mcpFiles changed
packages/agents-runtime/src/pull-wake-runner.tsresumeGapResetMsconfiguration.STREAM_RESETwhen the gap exceeds the configured threshold.packages/agents-runtime/test/pull-wake-runner.test.ts.changeset/reconnect-wake-stream-after-sleep.md@electric-ax/agents-runtime.Stacking
Stacked on #4632.