Repository navigation
Description
Item 1 of 9 in the Playbooks v2: one owner, flexible staffing milestone. It goes first, since most of the others build on it.
The problem
A run only remembers which file its playbook came from (definition_path) and re-reads that file on every tool call. So if I edit or delete a playbook while it's running, the agent following it sees the change halfway through. A lot of code exists only because of that: missing-file and invalid-file handling, reselecting when the current step disappears, a file watcher, and the rule that I can't delete a playbook while a run uses it.
Where this sits
This is section 7 ("Each run keeps its own copy") and section 11 ("Upgrade") of the Playbooks proposal (26 October). Changing an active run's procedure on purpose is #787. This issue only makes the copy the run's source of truth.
What we already have
-
The run row.
fromRowis atapps/server/src/j5/playbooks/PlaybookStore.ts:86-105. The table is018_AgentLedPlaybooks.ts:6-14, pluscrew_instance_idfrom 029. The contract'sPlaybookRunexposesdefinitionPath(packages/contracts/src/j5/playbook.ts:92-103). There's no copy column and no cancel reason; cancelling only setsstatus(PlaybookStore.ts:226,:691,:868). -
Start. It reads the file at
PlaybookStore.ts:587, outside the transaction, and inserts at:611-612. Retries replay the recorded path (:422-446). -
Live reads on the run path:
view:288recordFinished:638, for analyticsmutate:671progressRows:751-757liveStep:797
The library's own reads stay:
definition:216,discover:383,readPath:455, export:525, rename:551. -
Missing and invalid files:
- "Cannot read the live playbook…" (
:199,:212) - the empty-steps fallback view (
:292-303) currentthrowing the issue (:740-745)- the relay going pending on an unreadable file (
PlaybookCrewRelay.ts:137-141) - Fleet's issue branch (
PlaybookCrewRelay.ts:351-361)
- "Cannot read the live playbook…" (
-
Reselect:
step_missing(PlaybookStore.ts:276-281) and the reselect branch (:695-698)- the tool (
mcp.ts:107-113,:223-225) - the instructions (
packages/provider-core/src/j5/playbookInstructions.ts:13,:16) - preapproval (
apps/server/src/j5/a2a/mcp/j5ToolPreapproval.ts:53,:68) - the tool-name lists in
registration.test.ts:290andhandlers.test.ts:246
-
The file watcher.
PlaybookDefinitionWatch.tswatches the folders holding active runs' files and callsdefinitionsChanged(PlaybookStore.ts:895-910). It's wired inruntimeLayer.ts:5. -
The delete guard.
PlaybookStore.ts:498-505, pinned byplaybookRpc.test.ts:445. -
How clients show a file problem.
PlaybookProgress.issue(playbook.ts:124) feedspresentPlaybook, which shows "Needs attention" and "Step unavailable" (packages/client-runtime/src/j5/playbooks.ts:289-324, sorting at:390-397). On web that'sPlaybookStages.tsx:50,80,159,PlaybookRunsSection.tsx:82,145, andfleet.logic.ts:51-53. On mobile it'sPlaybookComposerControl.tsx:79,88,157. -
Migrations. They're registered by hand in
apps/server/src/j5/a2a/Migrations.ts:57-104. The latest is 047, so this one is 048, andMigrations.test.tshard-codes the latest id.- The 019 trigger deletes movement receipts when a run leaves active (
019_PlaybookRunMaintenance.ts:15-20), so the upgrade's cancel will fire it. That's fine. neutraliseCopiedDatabase.ts:123-134already cancels runs in bulk and is a good pattern to copy.
- The 019 trigger deletes movement receipts when a run leaves active (
-
Tests that pin live edits. Rewrite these rather than keep them:
PlaybookStore.test.ts: 158, 215, 390, 443, 510, 949mcp.test.ts:356playbookRpc.test.ts: 289, 354, 391, 484PlaybookCrewRelay.test.ts: 550, 593PlaybookDefinitionWatch.test.ts- the
step_missingfixtures in client-runtime,PlaybookStages,fleet.logic, andfleetReadtests
Proposal
- Start parses the playbook once and saves the parsed copy on the run (title, description, and each step's id, title, prompt, and persona). It does this in the same transaction as the insert.
- Every run read uses the copy: current step, movement, progress, Fleet, and finish analytics. Only the library (list, read, save, rename, export, delete) touches files.
- Migration 048 adds the copy column and a cancel reason, and cancels the runs that are still active.
Acceptance criteria
- Starting a run saves a copy of the playbook on the run. Every later tool call for that run reads the copy, never the file.
- Editing a saved playbook changes future runs only. An active run's steps and prompts stay as they were when it started.
- Deleting a playbook while a run of it is active succeeds, and the run carries on from its copy. The delete guard and its test are gone.
- Migration 048 adds the copy column and a cancel reason. It marks every active run cancelled with the reason "started before runs kept their own copy; start it again." Completed and cancelled runs are untouched.
- The cancel reason reaches clients on the run, and run history shows it.
- Past runs without a copy show their name, status, and last step, without the step list, on web and mobile.
- The live re-read code is deleted:
- the missing-file and invalid-file paths
step_missing, and theissuefield on progressPlaybookDefinitionWatch- "Needs attention" and "Step unavailable" on web and mobile
-
j5_playbook_reselectis removed from the toolkit, the preapproval lists, and the instructions, since a step can no longer vanish from under a run. Playbooks: revise an active run's procedure #787 covers a revision that removes the current step. - A start retry returns the same run with its copy.
- A Crew following a playbook still starts and moves as today. The Crew's start check (
PlaybookCrewRelay.ts:292) compares the run's recorded path, and Crew proposals keep reading the file to plan seats until Playbooks: the owner hands each step to someone #788 removes that. - Focused tests cover:
- an edit during a run, which leaves it unchanged;
- a delete during a run, which leaves it running;
- the migration cancelling active runs with the reason and leaving completed and cancelled runs alone;
- run history for a run without a copy;
- a start retry.
-
docs/j5/product/features/playbooks.mdAC8, AC9, the AC12 clause about blocking deletion, and the "A live single-agent procedure" scenario are rewritten.docs/j5/user/playbooks.mdno longer says edits reach active runs.
Out of scope
- Changing an active run's procedure. That's Playbooks: revise an active run's procedure #787.
- Crew seat ownership and the Crew's recorded playbook path, which Playbooks: the owner hands each step to someone #788 removes.
Activity