Repository navigation
feat: the dispatch coordinator runs as Claude Code through boat exec - #61
Merged
Merged
Conversation
boat prompt needs an agent connected on Boat's Agents page, which the owner will not do. The coordinator is now headless Claude Code inside the sandbox: one detached process per turn (boat exec --detach), followed by its pid with boat exec --status, so nothing on the owner's machine holds a turn open. - kontext dispatch credential set|rm: the agent's credential on this machine (<config>/dispatch/.agent-credential, 0600), read from stdin or a hidden prompt; dispatch refuses without it; status says only whether it is set. - The credential reaches the sandbox only as a file; the start script sets it 0600 at once and moves it to /dev/shm (else a 0600 file in the home); every clean-up ends the turn, removes it and then stops the sandbox. - A runner script runs claude -p with --session-id/--resume, every permission and --output-format json, refuses a second start of a turn, and leaves the result for boat exec to read. - dispatch fails, and cleans up, when the first turn fails within 15 s. - The start script clones the repo when the service did not, gives git an author from the sandbox's GitHub login, and stops at once when installing kontext fails (review finding 11). - The turn files, their lock and the hidden dispatch turn command are gone (review findings 1 and 8). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fifth layer of the
kontext dispatchstack. Real Boat answersboat promptwithprovider_not_configuredunless an AI provider is connected on its Agents page, and the owner will not connect one. With that answer the stack still printed "coordinator prompted", exited 0 and left the sandbox billing until its time limit. In this PR the coordinator is headless Claude Code running inside the sandbox. Each turn is oneboat exec --detachprocess, followed withboat exec --status. Nothing on the owner's machine holds a turn open any more.What changed and why
The agent's credential (
src/dispatch/credential.rs):kontext dispatch credential setreads it from stdin, or from a hidden prompt on a TTY, and never from an argument.credential rmremoves it.dispatch statussays only whether it is set and which kind it is.<config>/dispatch/.agent-credential, mode 0600. A project's name cannot start with a dot, so this name never collides with a project's folder.sk-ant-oat…goes to the agent asCLAUDE_CODE_OAUTH_TOKENandsk-ant-api…asANTHROPIC_API_KEY. Anything else is refused atset.dispatchrefuses with exit 2 and one line that says how to set it. It also refuses any[dispatch] providerother thanclaude.The credential reaches the sandbox only as a file, like the kontext token:
/dev/shm(or to a 0600 file in~/.kontext-dispatch/when there is no/dev/shm).boat exec --kill), remove the credential (boat exec -- sh -c 'rm -f …'), stop the sandbox, revoke the token. If thermfails, it says so and still stops the sandbox.boat execinto a sandbox the state records as stopped. A turn whose start was already on its way when the run was stopped can still reach it; fix: dispatch's second review — no sandbox without an id, no turn deciding nothing, a way out of a clean-up that cannot finish #63 ends that turn and stops the sandbox again, and real Boat refusesboat execon a stopped sandbox (409machine_not_running).The runner (
~/.kontext-dispatch-turn.sh, sent with--file):start <n> <uuid>runsclaude -pin the repo's clone with--output-format json,--dangerously-skip-permissions, the model, and--session-idon turn 1 or--resumeafter.claudeprocess.result.json,stderrandexitin~/.kontext-dispatch/turn-<n>/, and refuses to start the same turn twice (exit 90).read <n>prints a short summary for one synchronousboat exec.Following a turn (
src/dispatch/turn.rs, rewritten): the state keeps the session uuid and the turn's pid.turn::stateasks--status <pid>and gets one of five answers:is_error: false: the turn ended, and the ledger decides as before;is_error: true, a non-zero exit, or no result it can read: the turn failed, and the run is stuck at once with the reason;known: falseorlost: the turn cannot be followed; the watcher says so once and leaves the decision to the ledger and the time limit;Failure reasons have anything shaped like
sk-ant-…redacted.dispatchfails when the coordinator did not start: after starting turn 1 it watches it for 15 s. A turn that fails in that time fails the dispatch with its reason, everything is cleaned up, and the exit is non-zero. It never prints "coordinator started" for such a turn.The start script also:
[[repos]]' remote (as https, with the sandbox's GitHub login) when$REPO_DIR/.githas not appeared after 30 s;<login>and<id>+<login>@users.noreply.github.com, fromgh api user);install.shto a file and checks both the download andkontext --versionafterwards, so a failed install stops at once (review finding 11).Provider trait:
promptis replaced byexec,detach,processandkill. Boat implements them with the shapesboat execprinted in the probe, which are pinned in a unit test.Removed: the local turn-holding process, its lock, exit and started files, and the hidden
dispatch turncommand. With them go review findings 1 and 8.The fake
boat(tests/fixtures/fake-boat.sh) implementsexecsync,--detach,--statusand--killwith the captured shapes, and can be told to fail or lose each of them.Departures from the brief
--file; the start script does not write it. Both were allowed. Sending it as a file keeps the start script shorter and lets a test run the exact runner.mkdir). A dispatch killed between--detachand saving the pid then cannot lead to two coordinators. PR B uses this.claudeon the loginPATH. Doing that would mean runningbash -lin the tests, which can reach a realclaudeon a Mac. Instead the runner reports "claude is not on the PATH" (exit 127), and the 15 s check turns that into a failed dispatch.Not verified (no
boatcommand but--helpwas run)bash -lc 'exec sh "$HOME/.kontext-dispatch-turn.sh" …'keeps the pid Boat reports, and that--killreachesclaudethroughsh.boat execruns a synchronous command from the home folder, so$HOME-based paths resolve./dev/shmexists and is writable foruser.git clone https://github.com/…works through the sandbox's credential helper, and thatgh api user --jq .idanswers.boat exec --killon a process that already ended exits non-zero. Clean-up asks--statusfirst and only kills a running process.Test plan
cargo fmt --checkandcargo clippy --all-targets -- -D warnings: cleancargo testwithKONTEXT_REQUIRE_SERVER_TESTS=1: 507 tests passed, 0 failedtests/dispatch.rs, 17 tests against the fakeboatand the local server, covering:claude;calls.log, the output, the state or the-evalues; no prompt text in a command line;rmstill stops the sandbox;--resume <same uuid>, then stuck;claude,ghandcurl:gh;🤖 Generated with Claude Code