Repository navigation
Description
Item 4 of 9 in the Playbooks v2: one owner, flexible staffing milestone. It needs #788.
The problem
Once steps can be handed to other agents (#788), cancelling a run has to stop whoever is doing the current step. Today it just flips the run's status, and the holder keeps working on a step nobody needs anymore. Archive behaves backwards, too. Archiving a Crew cancels the run, even though the owner could carry on without it. Archiving my own conversation leaves the run active, even though that's the run's owner going away.
Where this sits
This is section 9 of the Playbooks proposal (26 October), "Interruption, cancellation, and archive":
- Cancel runs upstream's Stop (
thread.stop) on the holder's thread when the holder isn't the owner. That's the same path Stop crew uses. - The owner's own turn is never interrupted, because it's the turn doing the cancelling and it still has to reply.
- If Stop can't interrupt the holder, the cancel still succeeds, and the owner says the worker didn't stop. There's no retry.
- Archiving or deleting the owner's thread cancels its run. Archiving a Crew doesn't.
What we already have
- Cancel.
mcp.ts:121-127,229-231; its description says it "does not interrupt or archive your agent". The relay handles cancel outside the Crew lock and returnsdelivery: null(PlaybookCrewRelay.ts:318-319), and the store sets the status (PlaybookStore.ts:691). The response has nowhere to say the worker didn't stop (playbook.ts:131). - Crew archive cancels the run.
cancelForCrewis atPlaybookStore.ts:859-885, and its only caller isArchiveCrewService.ts:378-380, used at:386and:466. It's pinned byPlaybookCrewRelay.test.ts:633andArchiveCrewService.test.ts:151,252,274. - Captain archive goes from
CrewCaptainArchiveCascade.ts:251-259toretire(:87-102), thenArchiveCrewService.archive, thencancelForCrew. RemovingcancelForCrewdrops this path, so owner archive needs its own hook. The cascade's event handler plus boot sweep (:26-37) is the pattern to follow. - Owner archive doesn't cancel today.
cancelOrphans(PlaybookStore.ts:223-233) only checksdeleted_at, and only lazily, on reads, start, movement, and delete. That's pinned byPlaybookStore.test.ts:899("…while archived owners remain active"). - Stopping a thread.
stopThread(apps/server/src/j5/a2a/stopThread.ts:13-32) dispatchesthread.stop, thenstopDelegatedTasks, with an optionalDispatchModeLimit.CrewStopService.ts:167-176calls it and wraps failures asCrewStopOperationError{phase:"stopping a seat"}.- Results are
already_idleorinterrupt_requested, read throughlatestActiveRun(:178-182), and archived seats are skipped (:159-164).
j5_stop_agent(handlers.ts:834-921) uses a deterministiclifecycleCommandId(:906-911) and applies mode limits unless the caller is the Captain (:893-903).- What J5 calls. J5 goes through
ThreadManagementService.dispatch(:323,:672) andstopDelegatedTasks(:423,:1093), never the Orchestrator directly. The relay already depends onThreadManagementService(PlaybookCrewRelay.ts:92). - Who holds the step.
latestLanding(PlaybookStore.ts:813-821) plusdeliveryOf(PlaybookCrewRelay.ts:67-77) until Playbooks: the owner hands each step to someone #788 changes it.
Acceptance criteria
- Cancelling a run ends it first. Then, when the current step's holder isn't the owner, the platform runs
stopThreadon the holder's thread with a deterministic command id. It uses the same mode limitsj5_stop_agentwould apply for this owner. - The owner's own turn is never interrupted by cancelling, including when the owner holds the step.
- The cancel result says what happened to the holder: no holder or held by the owner, stop requested, already idle, or couldn't stop, with the reason. If Stop fails, the cancel still succeeds, and there's no retry.
- Completed work, artifacts, the conversation, the Crew, and workspaces remain after a cancel.
- Archiving or deleting the owner's thread cancels its active run right away, with a cancel reason, including when the server was down at the time (a boot sweep). Unarchiving doesn't reopen it.
- Archiving a Crew no longer cancels the owner's run.
cancelForCrewis gone. If a member of that Crew held the current step,j5_playbook_currentsays the holder is archived, and the owner reassigns the step or takes it back (Playbooks: the owner hands each step to someone #788). - Archiving a Captain cancels its run because it's the owner's thread, not because of the Crew.
- "Continue" after an interruption recovers the run, its current step, its holder, and its copy, and repeats no completed work.
- The
j5_playbook_canceldescription no longer says it never interrupts anyone. It says it stops the current holder but not the caller. - Focused tests cover:
- cancel with an owner-held step, where nothing is stopped;
- cancel with a member-held step, where Stop is issued once, also on retry;
- cancel when Stop fails;
- owner archive and owner delete cancelling;
- the boot sweep;
- Crew archive leaving the run active.
-
docs/j5/product/features/playbooks.mdAC11 and AC12, and the matching lines increws.md, are rewritten.
Surfaces
Codex, Claude, and Cursor as the holder being stopped. Turn interruption is part of every adapter's contract, so no per-provider work is expected, but each should be checked once.
Out of scope
- Stopping the other workers the owner started for the run. The owner does that with
j5_stop_agent; the guidance is in Playbooks: owner guidance for starting, working, and finishing #793.
Activity
[-]Playbooks: the owner hands each step to someone[/-][+]Playbooks: cancelling stops the step holder, and archiving a Crew keeps the run[/+]