Repository navigation
fix: recover execution output and results after connection loss - #221
Open
lw-liuwang wants to merge 1 commit into
Open
lw-liuwang wants to merge 1 commit into
lw-liuwang wants to merge 1 commit into
Conversation
lw-liuwang
force-pushed
the
fix/execution-monitor-disconnect
branch
from
November 9, 2026 03:11
c6e0c57 to
7eb5c38
Compare
lw-liuwang
force-pushed
the
fix/execution-monitor-disconnect
branch
3 times, most recently
from
November 9, 2026 08:57
05f7421 to
7c1ea5b
Compare
lw-liuwang
force-pushed
the
fix/execution-monitor-disconnect
branch
from
November 10, 2026 02:26
7c1ea5b to
e99732d
Compare
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.
Fixes #220.
A transient connection failure can make Colab CLI lose the output and final result of work it has already submitted. Remote execution can continue independently, which is expected, but an agent then cannot reliably follow the existing task to completion.
Recover the original execution through a request-specific kernel journal. The kernel acknowledges recording before the CLI submits user code, then records output, errors, the reply, and idle status before delivery. The CLI retrieves missing messages through the Contents API, validates their request and sequence, and suppresses duplicate message IDs. It submits the original source once, preserving magics and top-level await.
Recovery refreshes rejected proxy credentials or routes with a bounded GET of assignments, matching the original endpoint. A proxy 404 alone no longer triggers pruning: live probes returned 404 for both an invalid token and a missing kernel. If the WebSocket worker stops, monitoring continues through HTTP. The next execution rebuilds the socket on the same kernel and Jupyter session, with distinct message IDs to avoid matching old replies.
Save the request ID and journal path before submission. After a timeout or CLI exit,
colab resume -s NAMEretrieves that execution without starting a kernel, submitting code, or allocating a replacement. It replays the transcript from the beginning, so output displayed by the previous process may repeat. For notebooks, it recovers the interrupted cell's transcript without executing later cells or rewriting the local notebook. New submissions cannot overwrite unresolved work. A resumed VM stays allocated; the command prints how to stop it.An unknown result exits nonzero and preserves state;
runalso skips automatic teardown. Confirmed completion and script errors retain normal cleanup, subject to--keep.--timeout 0disables the execution idle limit; unavailable records and missing completion still have bounded waits. Recovery requires accessible records and cannot restore a destroyed kernel's unfinished work, deleted records, or revoked access. Journaling adds a setup round trip and file writes. Confirmed records are removed; uncertain records remain for recovery. Preserved VMs consume resources until stopped or reclaimed by Colab.Validation
Run the focused regression tests from the repository root:
For live CPU tests, use Bash or WSL with Colab credentials available there:
The script closes TCP connections after output markers, injects invalid proxy credentials/routes, stops the WebSocket worker, and kills a CLI process after work starts. It checks recovered output and results, and uses independent receipts to verify one execution on the original kernel. Injected credential failures test recovery from rejection; they do not reproduce natural token expiry.
Live CPU checks with the development and PyPI kernel clients covered output and completion during outages, exceptions, rich displays, HTTP fallback beyond the reconnect limit, and recovery in a new CLI process. They also checked startup refresh, subsequent execution after socket rebuilding, a recorded kernel-shutdown error without a replacement kernel, runtime preservation, and normal cleanup. Tests isolate session state and release their own assignments. Linux and Windows regression tests cover invalid records, uncertain sends, recovery bounds, persisted identity, and non-OK results.