Skip to content

feat(cli): continue, wait on, answer and stop maka run Sessions - #7210

Open
YongGoose wants to merge 1 commit into
apache:mainfrom
YongGoose:feat/cli-run-follow-up
Open

YongGoose wants to merge 1 commit into
apache:mainfrom
YongGoose:feat/cli-run-follow-up

Conversation

@YongGoose

Copy link
Copy Markdown
Member

Supersedes #7149, which GitHub closed when rust-preview was deleted after the switch to main. Rebased onto main (73f2333); the run:: tests, clippy and fmt below were rerun there.

Summary

#7094 added maka run for 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 with run failed, so there's nothing left to answer. This is the follow-up I offered in #6366 (reply in thread).

New options:

Call Does stdout
maka run --no-wait "<prompt>" Starts a Session and returns once the prompt is queued {"status":"submitted","sessionId":…}
maka run --session <id> "<prompt>" Queues a prompt to an existing Session and waits for its Run answer text, or waiting JSON
maka run --session <id> --wait Waits for the Session's current work without sending anything; returns the latest result when idle answer text, or waiting JSON
maka run --session <id> --answer '["Zeta"]' Answers the single pending question and waits for the same Run (--no-wait returns the receipt) answer text, or waiting JSON
maka run --session <id> --stop Stops the active Run and waits until it settles {"status":"stopped","sessionId":…}

A wait that reaches a pending interaction no longer cancels the Run. It prints {"status":"waiting","sessionId":…,"interactions":[…]} and exits 0, which is the convention the 0.2 maka run used. Questions include their text and options; other kinds only show kind.

How it works, using only existing Host operations (observe, queue, watch, work, pendingInteractions, interaction, respond, stop, workReadiness):

  • Every wait goes through one loop over 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.
  • Ended is now matched to the target Run. The old loop took the first Ended it saw, which is fine in a new Session but picks up an earlier Run's end when following up on an existing one.
  • A Run that is already terminal when the target resolves is read immediately instead of waiting for an Ended that may predate the subscription. Its failure row is found in the history tail by run_id, so the diagnostic no longer depends on the Ended sequence.
  • --wait picks the last queue entry that isn't held, then the active Run, then the latest Run. It reads the queue before observe, so a message admitted between the two reads shows up as the active Run instead of being skipped.
  • --stop was added because, without automatic cancellation, nothing in the CLI could abandon a waiting Run. It reuses cancel_work's settle loop.

Refs #6366

Review focus

  • Exit 0 for waiting matches 0.2, but a script has to parse stdout to tell an answer from a pending interaction. A distinct exit code is the alternative.
  • A completed ordinary run still prints only the answer, so continuing it needs --no-wait up front. I left --json out of this PR.
  • Approvals (--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.
  • While a Run waits for input, an ephemeral Host stays up until someone answers or stops it.

Verification

  • cargo nextest run -p maka-cli --test integration -E 'test(/^run::/)': 8 passed.
    • run_continues_a_session_started_without_waiting (new): --no-wait receipt, --wait returns the first answer, a second prompt on the same Session sees the first, --wait on 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): AskUserQuestion is reported with its question and options, --answer '["Zeta"]' finishes the same Run, and answering again fails with session has no pending question.
    • run_reuses_service_host_and_stops_on_pending_interaction (updated): a sandbox permission request is reported as waiting instead of exit 1, --wait returns the same report (the Run wasn't cancelled), --stop lets the service Host retire cleanly, and a second --stop fails with session has no active run.
    • The other five run:: tests pass unchanged, including the failure diagnostics after a model 400 and after a 429, which now come from the run_id lookup.
  • The three new or updated tests passed three times in a row.
  • cargo fmt and cargo clippy -p maka-cli --all-targets: no warnings in the changed files.
  • Not run: the full just check and the other maka-cli test binaries.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

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

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

`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
@github-actions github-actions Bot added the effort/L Under 1000 readable lines label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant