Repository navigation
fix(execution): stop a run with an explicit Cancel, not only by closing the stream - #9
Merged
Merged
Conversation
…ng the stream The backend is changing so that closing a Run stream no longer stops the run. This is what lets ResumeRun recover the output after a network drop. Until now Stop only aborted the stream, except while reconnecting, so after that change a stopped program would keep running on the server. runSession now owns the stream's AbortController. When the caller's signal aborts (Stop, reset, unmount): - After Accepted: send Cancel(execution_id), then close the stream. - Before Accepted: keep the stream open for up to 3 s to learn the execution id, then cancel. If the id never arrives, close the stream. - While reconnecting or polling: send Cancel, as before. The result changes to "cancelled" once Cancel answers, or after at most 1 s, so a failing Cancel never leaves the UI stuck. A run that already finished is never cancelled.
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
Stop now always sends
ExecutionService.Cancel(execution_id)instead of only closing the Run stream.The backend is changing so that closing a Run stream no longer stops the run, which is what lets
ResumeRunrecover output after a network drop. Before this change, Stop only aborted the stream, except while reconnecting. After the backend change, a stopped program would therefore keep running on the server until its time limit.Design (
src/lib/rpc/run-stream.ts)runSessionnow owns the stream'sAbortController. The caller'ssignal(Stop,reset()or unmount) no longer closes the stream directly. Instead it triggers the following:Accepted: sendCancel(execution_id), then close the stream.Accepted: the execution id is not known yet. The stream stays open for up toACCEPT_GRACE_MS(3 s), so the client can learn the id whenAcceptedarrives and then cancel. IfAcceptednever arrives, the stream is closed without a Cancel.Cancel, as before. This now also applies when Stop comes during the last retry.cancelledonce Cancel answers, or afterCANCEL_WAIT_MS(1 s) at most. A failing Cancel cannot leave Stop hanging.Testing
npm run test:coverage: 437 tests pass and the thresholds are met. New tests:cancelled.Accepted: no Cancel is sent untilAcceptedarrives, then Cancel is sent.Acceptednever arrives: the stream closes after the grace period and no Cancel is sent.cancelled.useCodeExecution().cancel()reaches the server'sCancelhandler.npx playwright test tests/e2e/fake: 22 tests pass, including the existing "Stop ends a long run".npm run typecheck: passes.npm run lint: 0 errors and 12 warnings, as on main.Not verified