Repository navigation
feat: the dispatch watcher closes, resumes and stops sandboxes by the ledger - #57
Merged
Merged
Conversation
… ledger `kontext dispatch watch` (started detached by `dispatch`, one per project and machine, under a lock) pulls the ledger and, for each live sandbox: stops it and revokes the token when the epic closes; resumes the coordinator once in the same conversation when its turn ended with the epic open; marks it stuck when it stops again or its time limit passes (a question to the pm as agent:dispatcher, then stop and revoke). A turn that could not be followed, or one whose end was seen while the pull failed, decides nothing. Everything is in the saved state and the turns' files, so a restarted watcher (`dispatch watch --detach`) picks up; `dispatch status` says when it is not running and how to start it. It exits when nothing is live, deciding that under the state lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as started On a fast machine `dispatch watch --detach` could start a watcher that took its lock, marked the last live run stuck and exited before the 50 ms check saw the lock, and then reported "the watcher did not start". It now counts a watcher that wrote its own pid as started, and says it ran and stopped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OmarAlex24
force-pushed
the
dispatch/watcher
branch
from
November 16, 2026 22:53
8ef0a7c to
7cfe98c
Compare
6 tasks done
OmarAlex24
marked this pull request as ready for review
November 17, 2026 14:30
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.
Third of the
kontext dispatchstack: the watcher, which decides by the ledger, never by what the agent says.What changed and why
kontext dispatch watch [--detach](src/dispatch/watch.rs): a background process on the owner's machine, started bydispatchwhen it is not running. Its lock file is its liveness:statussays whether it is alive and, when it is not and runs are live, the command to start it again.boat stop(never delete), revoke the token,closed;[dispatch] hours): stuck;boat prompt --resume <conversation>), stateresumed; if that turn ends with the epic still open: stuck;agent:dispatcher("Epic X is stuck in its sandbox: ", with how to look and how to redispatch), then stop and revoke.A turn only counts as ended after a sync that succeeded, so a stale ledger never resumes or sticks an epic that closed. Each action is taken under the state lock after re-reading the run, so a watcher and
dispatch stopcannot both act on it.dispatch watch --detachcounts as started a watcher that wrote its pid, even if it already did all there was to do and left (commit 7cfe98c: CI's faster runner caughtensurereporting such a watcher as "did not start"; reproduced locally by delaying the first check, and fixed).Departures from the brief
lost(its process died, the Mac slept,boat promptfailed) neither resumes nor makes the epic stuck: the watcher logs it once and goes on, and the time limit still applies.Test plan
cargo fmt --check,cargo clippy --all-targets -- -D warningsand the fullcargo test(42 suites, 497 tests) passed with the fix--resumeand the same conversation id; it ends again: stuck, the pm gets the question fromagent:dispatcher, the sandbox is stopped and the token revokedensure's first check delayed 2 s (a temporary local edit, not committed): it failed before the fix with CI's message and passes afterboatandserver/dev.mjs: the refusals, a dispatch,status, the resume, the close once the tasks were done,kontext tree, the watcher's log; nokxt1.in the fake's calls, the state or the watcher's log🤖 Generated with Claude Code