fix: recover agent threads after laptop sleep instead of erroring - #56
Merged
Merged
Conversation
After laptop sleep, stale timers fire immediately and mark running threads as error even though the agent is still alive in the sandbox. Three changes prevent this: 1. Activity timeout: before erroring, attempts to reconnect the bridge and request replay. If the bridge is reachable, recovers the thread instead of marking it as failed. 2. Grace timer: on reconnect failure, silently cleans up the handler instead of marking the thread as error. Recovery is deferred to the next subscribe_project via reconcileAndReconnect. 3. reconcileAndReconnect: cleans up all stale active handlers and their timers for the project's threads before reconnecting. This prevents ghost timeouts from the pre-sleep session from firing during recovery. Made-with: Cursor
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
After laptop sleep, running agent threads would show "Error connecting to bridge" or "Agent stopped responding after 90 seconds" even though the agent was still alive in the sandbox. This happened because:
Three changes fix this:
reconcileAndReconnecton the nextsubscribe_project.reconcileAndReconnectnow cleans up all stale active handlers and their timers before reconnecting, preventing ghost timeouts from the pre-sleep session.Test plan
reconcileAndReconnectproperly restores running threads after sleepMade with Cursor