Repository navigation
feat(cli): continue, wait on, answer and stop maka run Sessions - #7210
Conversation
`maka run` could only run one prompt in a new Session, and a run that stopped on a question or an approval was cancelled. A script or another agent had no way to answer it or follow up. Add `--session` to queue a prompt to an existing Session, `--no-wait` to return a JSON receipt once the prompt or answer is accepted, `--wait` to wait on the Session's current work, `--answer` to answer its pending question and `--stop` to stop its active Run. A wait that reaches a pending interaction now leaves the Run waiting and prints it as JSON. Ctrl+C withdraws only a message this invocation queued. Generated-by: Claude Code
M4n5ter
left a comment
There was a problem hiding this comment.
Thanks for taking this on! Reusing the existing Host operations and unifying the wait loop around Action / Target / Followed / Outcome keeps run.rs clean and readable, and the new black-box CLI integration tests are solid.
Before merging, there is one CLI contract decision we should align on (cc @Colafornia @me2seeks @Astro-Han), plus a couple of concrete bugs and small cleanups:
1. Single-shot maka run contract on pending interactions (design alignment)
Changing default maka run "<prompt>" from cancelling + exit 1 on pending interactions to returning {"status":"waiting",...} with exit 0 creates a few practical tensions while --json and --approve/--deny are still missing:
- Mixed stdout + exit 0: scripts, CI jobs, and eval harnesses (the main use case from #7094 / #6667) doing
out=$(maka run "...") || exit 1will treat a blockedpermissionsorquestionturn as success and pass the waiting JSON downstream as the model's answer. (0.2 had--jsonso scripted callers had a uniform structured envelope.) - Dangling ephemeral Host with no CLI resolution for permissions: as noted under Review focus, a waiting Run keeps an ephemeral Host alive until answered or stopped. Because
--approve/--denyisn't supported yet, hitting apermissionsprompt on an isolated--root(where no workbench is attached) leaves a resident ephemeral Host thatmaka runcan only--stop.
cc @Colafornia @me2seeks @Astro-Han — how would you like to shape the CLI contract here (e.g. distinct exit code for waiting, pairing with --json, or keeping single-shot calls without --session / --json fail-fast)?
2. Concrete bugs in products/maka/cli/src/run.rs
report_waitingcan emit{"status":"waiting","interactions":[]}with exit 0: when aQuestionis answered or closed betweenDeliveryPage::Interactionsand queryingagent.interaction,if record.outcome.is_some() { continue; }skips it, butreport_waitingstill returnsOutcome::Report(Report::Waiting { ..., interactions: [] })instead of continuing to watch. Resolving question details inside thefollowloop (and continuing ifinteractionsends up empty) fixes this and also letsstop.cancelled()cancel theagent.interactionquery (currentlyreport_waitingisn't guarded bystop.cancelled(), unlikeread_result).Action::StopignoresStopped.requestedand Ctrl+C duringsettle:let _: Stopped = mutate(..., "stop", ...).await?;discardsrequested: false(whichprepare_stop_runreturns when the Run already finished betweenobserveandstop, or when!may_control).settle()then immediately seesWorkReadiness::Ready, so--stopprints{"status":"stopped"}with exit 0 even though it didn't stop anything. Checkingif !stopped.requestedavoids a false receipt. Alsosettle_untilis reused fromcancel_work(post-Ctrl+C cleanup), so--stopignores Ctrl+C for up to 15s while waiting to settle.
3. Small cleanups & test gaps
- Skip redundant Host roundtrips:
Action::Sendcallsobserve(host, &session_id)even with--no-wait, wherethroughis discarded.Action::Waiton an already-idle Session (no runnable queue entry,observation.runisNone,latest_run_idisSome) still opens and closes anagent.watchsubscription and queriesagent.worktwice (once infollowdiscardinganswer, then again inread_result; the fast-completion path forMessage/Submitteddoes the same doubleagent.work). Handling idlelatest_run_iddirectly and passing the already-fetchedWork::Deliveredinto pagination avoids both.
- Tests (
products/maka/cli/tests/integration/run.rs):run_reuses_service_host_and_stops_on_pending_interactionstill has its old name now that the Run stays waiting.- Worth adding coverage for (a)
--waiton a failed idle Run (exercisingread_failure_diagnosticwiththrough: None+HistoryPosition::Tail) and (b) SIGTERM/Ctrl+C on--session <id> --waitconfirming it detaches without cancelling the active Run.
`maka run` reported `{"status":"waiting","interactions":[]}` when every
pending question was answered or closed between the Interactions page and
the `agent.interaction` read. The questions are now described inside the
follow loop, where Ctrl+C can interrupt the read, and an empty result keeps
following instead of reporting.
`--stop` ignored `Stopped.requested`, so a Run that ended between `observe`
and `stop` printed a stopped receipt. It now fails with `session has no
active run`, and Ctrl+C interrupts the wait for the Run to settle.
`--wait` on an idle Session reads the latest Run's result without opening a
watch, a result already read to check for completion is reused instead of
read again, and `--no-wait` skips the `observe` it never used.
Generated-by: Claude Code
|
Thanks for the thorough review. 8daa5ff addresses sections 2 and 3. For section 1, I'll wait for the CLI contract you settle on and implement it in this PR. Bugs
Roundtrips
Tests
|
|
Let's go ahead and settle section 1 so you aren't blocked waiting:
|
|
+1 on @M4n5ter's split. Keeping single-shot |
…waits A `maka run "<prompt>"` without `--session` or `--no-wait` cancels its Run and exits 1 with `execution blocked by pending interaction(s): ...` when the Run stops on a question or approval, as apache#7094 did. Nothing can answer it later, and scripts, CI and evals treat a non-zero exit as failure. Session follow-ups (`--session` with a prompt, `--wait` or `--answer`) leave the Run waiting, print the `waiting` report and exit 3, so a script can tell a pending decision from an answer without parsing stdout. clap uses 2 for usage errors. Generated-by: Claude Code
|
Done in d03d375: a single-shot |
M4n5ter
left a comment
There was a problem hiding this comment.
d03d3752b looks great — OnPending::Fail / OnPending::Report keeps single-shot maka run "<prompt>" fail-fast while --session follow-ups report waiting and exit 3, and all 10 run:: integration tests pass cleanly on top of latest main. Merging!
|
[P2] Synchronize the new SIGTERM test with the waiter attaching The first post-merge full CI on The test sends SIGTERM after a fixed two-second sleep (lines 1063–1068), which does not establish that this new waiter has connected. Scope: I checked this test, its connection/signal path, and the raw CI failure log. This is a focused post-merge CI finding, not complete validation of the CLI feature.
|
Supersedes #7149, which GitHub closed when
rust-previewwas deleted after the switch tomain. Rebased ontomain(73f2333); therun::tests, clippy and fmt below were rerun there.Summary
#7094 added
maka runfor a single prompt in a new Session. A script or another agent still can't follow up on that Session, and a run that stops on a question or an approval is cancelled withrun failed, so there's nothing left to answer. This is the follow-up I offered in #6366 (reply in thread).New options:
maka run --no-wait "<prompt>"{"status":"submitted","sessionId":…}maka run --session <id> "<prompt>"waitingJSONmaka run --session <id> --waitwaitingJSONmaka run --session <id> --answer '["Zeta"]'--no-waitreturns the receipt)waitingJSONmaka run --session <id> --stop{"status":"stopped","sessionId":…}A Session follow-up (
--sessionwith a prompt,--waitor--answer) that reaches a pending interaction leaves the Run waiting, prints{"status":"waiting","sessionId":…,"interactions":[…]}and exits 3, so a script can tell it from an answer without parsing stdout (clap uses 2 for usage errors). Questions include their text and options; other kinds only showkind. A single-shotmaka run "<prompt>"keeps #7094's behavior: it cancels the Run and exits 1 withexecution blocked by pending interaction(s): …, since nothing can answer it later. Multi-turn callers start with--no-wait.How it works, using only existing Host operations (
observe,queue,watch,work,pendingInteractions,interaction,respond,stop,workReadiness):agent.watch. Only the target differs: a message this invocation queued, a message or Run started elsewhere, or the Run that received an answer. Ctrl+C withdraws only a message this invocation queued; observing someone else's work just detaches.Endedis now matched to the target Run. The old loop took the firstEndedit saw, which is fine in a new Session but picks up an earlier Run's end when following up on an existing one.Endedthat may predate the subscription. Its failure row is found in the history tail byrun_id, so the diagnostic no longer depends on theEndedsequence.--waitpicks the last queue entry that isn't held, then the active Run, then the latest Run. It reads the queue beforeobserve, so a message admitted between the two reads shows up as the active Run instead of being skipped.--stopwas added because, without automatic cancellation, nothing in the CLI could abandon a waiting Run. It reusescancel_work's settle loop.Refs #6366
Review focus
--no-waitup front. I left--jsonout of this PR.--approve/--deny) aren't included: permission decisions need a scope and a granted set, so I'd rather handle them separately. Until then they're reported as{"kind":"permissions"}and handled in the workbench.Verification
cargo nextest run -p maka-cli --test integration -E 'test(/^run::/)': 10 passed, three runs in a row.run_continues_a_session_started_without_waiting(new):--no-waitreceipt,--waitreturns the first answer, a second prompt on the same Session sees the first,--waiton the idle Session returns the latest answer, and the ephemeral Host releases the Root.run_reports_a_pending_question_and_continues_with_the_answer(new): after a--no-waitstart,--waitreportsAskUserQuestionwith its question and options and exits 3,--answer '["Zeta"]'finishes the same Run, and answering again fails withsession has no pending question.run_reuses_service_host_and_keeps_a_pending_permission_until_stopped(updated): a single-shot run that hits a sandbox permission request exits 1 withexecution blocked by pending interaction(s): permissions(…)and leaves the service Host running. A Session started with--no-waitreports the same request from--waitwith exit 3, twice (the Run wasn't cancelled);--stopstops it, a second--stopfails withsession has no active run, and the service Host retires cleanly.run_wait_reports_the_failure_of_an_ended_run(new):--waitreports a model 400 asrun failed: …both while following the Run and after it ended.run_sigterm_detaches_a_wait_without_cancelling_the_run(new): SIGTERM during--waitexits 1, and releasing the model afterwards still completes the Run.run::tests pass unchanged, including the failure diagnostics after a model 400 and after a 429, which now come from therun_idlookup.--waitexits 0 instead of 3, and the single-shot run exits 0 instead of 1.cargo fmtandcargo clippy -p maka-cli --all-targets: no warnings in the changed files.just checkand the othermaka-clitest binaries.AI use
Select exactly one:
Tool(s) and scope: Claude Code drafted the implementation, tests and this description under my direction; I reviewed the design and the results. The commit carries
Generated-by: Claude Code.Checklist
Does this PR entail a change in behavior?