Pause runs at breakpoints, then steer or cancel them
A breakpoint parks every call to a named tool at the approval boundary: the run ends successfully with the call pending, and nothing has run. Set the breakpoints for a runtime from Studio’s Runtimes page, or with PUT /api/runtimes/{id}/breakpoints. They park every run the runtime starts. To have them park your app’s own runs too, build the agent with runtime.Breakpoints(). A parked playground run is decided from Studio; a running one can be steered or cancelled.
Opt an agent’s own runs in, in playground/main.go:
agt := weft.New(model, weft.Name("acme-support"), weft.Options(supportTools()...), runtime.Breakpoints(), // Studio's breakpoints park this agent's own runs too)Pass that agent to runtime.Agents, then set a breakpoint on refund. Your app’s next agt.Generate that calls refund returns with res.Pending holding the call.
Breakpoints
Section titled “Breakpoints”The set is per runtime: a list of tool names, each a tool some registered agent of that runtime exposes. An empty list clears it. Against the example program:
curl -s -X PUT http://127.0.0.1:8080/studio/api/runtimes/rt_6ea843dccc7741ff/breakpoints -d '{"tools":["refund"]}'{"tools":["refund"]}A name nobody registers can never fire, so it is refused as a typo:
{"error":{"code":"bad_request","message":"tool delete_account is not registered by any agent of runtime rt_6ea843dccc7741ff"}}The route needs the capability breakpoints and the server token, or setup A’s loopback. Its other answers store nothing:
| Status | When |
|---|---|
| 400 | a tool no registered agent of the runtime exposes |
| 403 | any panel token: the set parks every future run of the runtime |
| 404 | an unknown runtime ({"error":{"code":"not_found","message":"unknown runtime rt_0000000000000000"}}) |
| 503 | the runtime is registered but holds no command stream |
On the Runtimes page, each runtime’s card has one checkbox per tool of its agents, with clear all. Ticking or clearing a box sends this PUT at once. The new set parks every later run the runtime starts, whatever you run next, until someone changes it. Studio stores the set in its database (the obsdb.CommandStore), so it survives a Studio restart. A refused change, such as the 503 for a disconnected runtime, is undone, and the card shows the error. Since 0.19.0 the editor lives there only. The playground form and the replay drawers carry no Break on box any more. They show a link, “breakpoints for the whole runtime live on Runtimes”, followed by the count in force (”· 1 tool break on every run”). Settings’ Runtimes card is a summary with a link.
{"tools":[]} clears the set; the answer then reads {"tools":null}. Studio sends the set over the runtime’s command stream, and again every time that stream opens, before any queued command. When a runtime registers and Studio holds no set for it, Studio adopts the one the runtime reports, so a restarted Studio shows the rule that is parking its runs: GET /api/runtimes lists it as breakpoints, with breakpoints_set_at when this Studio delivered it.
On the runs the runtime starts, the set becomes the run’s own weft.ParkOn, filtered to the agent’s tools and written into its override fingerprint. A breakpoint’s park is never substituted from the record, whatever the command’s side_effects mode. The replay drawer’s ack preview shows it as “breakpoint · parks”.
Breakpoints on your own runs
Section titled “Breakpoints on your own runs”An agent is immutable after weft.New, and your call sites know nothing about a debugger, so the runtime cannot add ParkOn to your runs. runtime.Breakpoints() is a weft.ParkSource instead (ADR 0030): a function the loop reads once per run, at its start, and merges into the run’s park set as ParkOn would. It is bound lazily to the links runtime.Install started and has not stopped, so the agent can be built before Install runs. With several links live, a run parks on the union of their sets.
| Run | Parks on a breakpoint? | Who decides it |
|---|---|---|
a plain Generate or Stream | yes | your app: Generate again with weft.Messages(res.Messages...) and weft.Approve, weft.Deny or weft.Resolve |
a weft/thread turn, with runtime.Sessions set and a session created with thread.PublicID | yes | Studio or the panel, through your Session (Approve and steer your app’s own turns) |
| a thread turn without both | no: the source answers nothing for a run carrying weft.session.id | — |
a Subagent child run | the child parks | nobody: the parent’s call reads SUBAGENT_PENDING and the parent continues |
a playground run (weft.playground metadata) | its own filtered ParkOn decides | Studio |
The thread rule keeps a breakpoint from wedging a session: a park nobody could decide would hold the session, and every later Send would queue behind it. Studio decides app runs by public id through runtime.Sessions, so a plain Generate parked this way is read-only on the run page. From TestBreakpointParksTheAppsRun, Studio’s answer to an approval of such a run:
{"error":{"code":"forbidden","message":"app-owned turn · read-only: run 076ad3b18e69a583ed066d3ac6b8420b is the app's own, and no connected runtime of its service acme-support acts on the app's sessions"},"fix":"set runtime.Sessions(resolver) at runtime.Install in the app (service acme-support): its turns then take approvals and steer"}The test then resumes it the app’s way, weft.Approve(res.Pending[0].ID), and refund runs once.
The set is process-wide: every agent built with the option parks on it, whether or not you gave it to runtime.Agents. The registration’s breakpoints_own is true when an agent given to Agents carries the option, and GET /api/meta reads "debug_scope":"own+runtime" while a connected runtime registered breakpoints_own or runtime.Sessions (otherwise "runtime-started runs"; the field is there only with the breakpoints capability).
The option is inert without a link: with no Install, an Install not enabled, a stopped link or an empty set, the source answers nothing and the run is byte-identical to one built without it. A source’s parks are behaviour, not an override: they write no weft.override.* and leave the override hash alone. A link whose stream dropped, but which was not stopped, keeps its last set until it reconnects and Studio re-sends it. ExampleBreakpoints runs the agent with no link: Refunded. 0, nothing pending.
Decide a parked run
Section titled “Decide a parked run”A parked playground run is decided with POST /api/runs/{id}/approvals, one call at a time. The decisions are the approval boundary’s own (Require human approval for a tool), and the playground’s result card names them (before 0.18.0 its verbs read continue, skip and resolve):
decision | The card’s verb | Effect |
|---|---|---|
approve | approve | the handler runs for real |
deny | deny | the model sees a denied result; reason is the text, else “skipped from the devtools panel” |
resolve | resolve… | content is the tool’s result, computed outside the process; the handler never runs |
The body is {"call_id": …, "decision": …, "reason": …, "content": …}. Studio forwards it to the runtime that started the run and answers 202 {"command_id", "state":"queued"}; poll the command like any other. The run resumes once, when every parked call has a decision, under all of them, as a new run whose row reads resumed_from (the parked run’s reads resumed_by). A decision is checked against the run’s pending calls, read from its stored run_finish. From TestNeverToolIsSubstitutedOrParked:
{"error":{"code":"bad_request","message":"call nope is not pending on run pg_01M5762FPMD2GSF8AQE40AHXK1 (pending: c1)"}}A run that did not park answers:
{"error":{"code":"bad_request","message":"run pg_01M5780D5BYHQNGQDWRXR84HAZ is not parked: it finished with no pending call"}}The route’s other answers: 400 for an unknown decision (unknown decision maybe) or a body with no call_id (an approval needs a call_id), 404 for an unknown run, and 503 when the runtime that started the run is not connected. The runtime keeps the newest 128 parked runs for a decision; an older one is rejected on the command row, no parked run "…" on this runtime (it may already have been resumed), so send the run again. The runtime checks again and rejects the command row when the call is not parked there, or is already decided: a second decision on a call never replaces the first, so concurrent decisions cannot run an approved handler twice. A parked run whose resume never started is restored, so it can be decided again. A parked call in a fork is decided through the fork’s session and resumes as the fork’s next turn. Your app’s own turns go through runtime.Sessions; otherwise the route is 403 “app-owned turn” (below). A read-scoped panel token cannot decide.
Since 0.19.0 Studio remembers the decisions, steers and cancels sent to a run: GET /api/runs/{id}/commands (capability run_commands, with the playground) lists them, oldest first, each with its lifecycle row (state, the runtime’s answer) and its verb, call_id and decision. The run page reads it, so a parked call whose decision was lost still says so after a reload or a Studio restart: your approve at … was lost: <why> — decide again. The devtools panel reads the route once per parked turn and marks a lost decision by the same rule, each call’s latest decision. A Studio restarted over its command store logs one INFO line naming the runtimes it restored and the commands still open and lost. RuntimeServer.CommandsOn is the Go side (The Studio HTTP API).
Steer and cancel
Section titled “Steer and cancel”Steer delivers one user message into a run in flight: POST /api/runs/{id}/steer with {"message": …}, capability steer. An ephemeral playground run carries a steering source, so the message joins the run at its next drain point (Steer a running turn); a fork’s running turn takes it as a thread steer under that turn’s run options, so the park rule still binds a follow-up turn. The route answers 202 once the message is on the runtime’s stream:
{"steered":true}On your app’s own thread turn it goes through a connected runtime.Sessions runtime of the run’s service. It answers 202 {"command_id","state":"queued","run_id","runtime_id"}, the command to poll. A turn that is parked, or whose row reads succeeded or failed, is 409 at once (no running turn to steer: run <id> is parked: …, … already finished (<status>)). With no such runtime, it is 403 “app-owned turn”. That is all it promises. A steer for a run that is no longer in flight is dropped by the runtime with a Debug line, and the route still says "steered":true. The playground’s result card has a steer box (“a message delivered mid-flight”) while its run runs.
Cancel asks the runtime holding a runtime-started run to stop it: POST /api/runs/{id}/cancel, capability cancel. The runtime cancels that run’s own context, never kills anything; the run ends failed with context canceled and its partial transcript, its command finished failed, and it has no run_finish (the live stream carries the failed run row). The answers:
| Status | When |
|---|---|
202 {run_id, command_id, runtime_id, state: "cancelling"} | the cancel frame is on its way |
| 404 | an unknown run |
| 403 “app-owned turn” | the app’s own run, and no connected runtime of its service registered runtime.Sessions (the app’s runtime gone, one connected without Sessions, the link dialled another Studio, or none connected); or the run is not a turn of a session with a public id (the five refusals) |
| 409 | a parked run (“decide its pending calls (approve/deny) instead”), or one already finished; on the app’s own turn with a Sessions runtime connected, always (cancel is not supported on an app turn: run <id> is the app's own turn) |
| 503 | its runtime is disconnected |
For a finished run:
{"error":{"code":"conflict","message":"run pg_01M5780D5BYHQNGQDWRXR84HAZ already finished (succeeded): there is nothing to cancel"}}Cancel is best effort: one lost to a stream reconnect is not retried, so cancel again. An app’s own session turn is never cancelled from Studio, since thread has no per-turn cancel: with a runtime.Sessions runtime of its service connected, cancel answers 409 at once (before 0.20.0 it answered 202 and the command row was then rejected). The 403 cases above apply alike to the approvals and steer routes.
Steer, cancel and the approvals share one rule for who may act: the dev token or setup A’s loopback, a playground-scoped panel token inside its public id; a read-scoped panel token is 403.
Complete example
Section titled “Complete example”TestBreakpointParksTheAppsRun in main_test.go builds newDebuggableAgent (the region above) on a script that calls refund, registers it through runtime.Local, and checks breakpoints_own and debug_scope. It PUTs {"tools":["refund"]}, waits until the agent’s park source (Agent.ParkSources) answers [refund], runs agt.Generate and finds refund pending with the handler not run. Studio’s approval is 403, and the app’s weft.Approve runs refund once:
go test -run TestBreakpointParksTheAppsRun -v ./playground=== RUN TestBreakpointParksTheAppsRun main_test.go:471: PUT breakpoints: 200 {"tools":["refund"]} main_test.go:493: approve the app's own run in Studio: 403 {"error":{"code":"forbidden","message":"app-owned turn · read-only: run 04bdddd0f389b6a8afc7cd2d05d4f642 is the app's own, and no connected runtime of its service acme-support acts on the app's sessions"},"fix":"set runtime.Sessions(resolver) at runtime.Install in the app (service acme-support): its turns then take approvals and steer"}--- PASS: TestBreakpointParksTheAppsRun (0.04s)PASSok weftgo.dev/docs/examples/playground 0.041sBest practices & gotchas
Section titled “Best practices & gotchas”- Build the agent with
runtime.Breakpoints()to break on your own runs. Without it a breakpoint parks only the runs the runtime starts. (Source:runtime.Breakpointsgodoc; CHANGELOG 217) - A thread turn parks only with
runtime.Sessionsand a public id. Otherwise the source answers nothing for it, so the session is never held by a park nobody can decide. (Source:runtime/breakpoints.go:42-52) - Resume a parked plain
Generatein your code. Studio decides session turns only, so it answers 403 “app-owned turn”. (Source: the example’sTestBreakpointParksTheAppsRun) - Stopping the link does not unpark a parked run. The park set is read once, at the run’s start; a turn parked before the stop has no decider until your app decides it or a link with
Sessionscomes back. (Source:runtime/breakpoints.go:61-68) - Read
"steered":trueas sent, not delivered. A steer for a run not in flight is dropped. (Source:runtime/link.go:1127-1155) - Decide a parked run; do not cancel it. Cancel answers 409 for a run parked at the approval boundary. (Source:
studio/cancel.go:112-117)
See also
Section titled “See also”- Require human approval for a tool
- Approve and steer your app’s own turns
- Steer a running turn
- How does the playground work?
- Watch runs live
Symbols used: runtime.Breakpoints · runtime.Install · runtime.Agents · runtime.Sessions · weft.New · weft.ParkSource · weft.ParkOn · weft.Approve · weft.Deny · weft.Resolve · weft.Messages · weft.Subagent · thread.PublicID · Agent.ParkSources · Agent.Generate