| 1 | # Delegated coordination contract |
| 2 | |
| 3 | Codewhale records the small amount of shared state that parallel work needs to |
| 4 | remain attributable. This is coordination metadata, not an approval system and |
| 5 | not a store for model reasoning or transcripts. |
| 6 | |
| 7 | ## Launch and write ownership |
| 8 | |
| 9 | Every write-capable child persists the same `ChildLaunchManifest` used by the |
| 10 | runtime. Its mutation claim contains normalized repo-relative directory roots, |
| 11 | exact files, and named contracts. Paths that are absolute or escape with `..` |
| 12 | fail validation. |
| 13 | |
| 14 | A prompt-only general child starts read-only. Callers that want a writer must |
| 15 | declare at least one `write_roots`, `exact_files`, or |
| 16 | `coordination_contracts` value. Codewhale does not infer a repo-wide `.` claim. |
| 17 | An active shared-workspace claim blocks another active owner when either tree |
| 18 | contains the other, exact files collide, or a named contract matches. A real |
| 19 | isolated worktree may proceed concurrently. Scope expansion uses |
| 20 | `agents/coordinate action=claim`; a collision records a bounded contention |
| 21 | receipt and fails before mutation without opening a permission modal. |
| 22 | |
| 23 | Fleet workers follow the same rule. Write-capable Fleet tasks declare |
| 24 | `workspace.writable_paths` or `metadata.coordination_contracts`, and the |
| 25 | resolved values are persisted in their launch manifest. |
| 26 | |
| 27 | This record is a cooperative Codewhale coordination boundary, not an operating |
| 28 | system sandbox. Fleet carries a machine-readable outer cap into each worker, |
| 29 | rechecks structured mutation targets, rejects symlink aliases, and denies |
| 30 | unbounded shell, Git, code, plugin, and mutating MCP execution. Those checks |
| 31 | prevent one Codewhale worker from silently exceeding its declared claim; they |
| 32 | do not promise containment against a separate hostile process racing filesystem |
| 33 | paths. Use an OS sandbox or an isolated host when that adversarial boundary is |
| 34 | required. |
| 35 | |
| 36 | Authority-bound Fleet subprocesses are explicit leaves in v0.9.1. Their MCP, |
| 37 | LSP, snapshot, custom-tool, plugin, shell, and nested-agent startup surfaces are |
| 38 | disabled so configured background executables cannot bypass the structured |
| 39 | mutation path. The persisted receipt reports `max_spawn_depth = 0`. |
| 40 | |
| 41 | ## Decisions and projected context |
| 42 | |
| 43 | Coordination schema version 1 persists decision records with a stable id, |
| 44 | subject, proposed/accepted/superseded status, one owner, applicability scope, |
| 45 | concise constraints, evidence handles, version, and sequence. Only the owner |
| 46 | may change a decision's status. A second accepted decision for the same subject |
| 47 | cannot silently replace the first. |
| 48 | |
| 49 | At child launch, Codewhale projects only accepted decisions whose scope matches |
| 50 | the child's declared paths, contracts, role, or tool capabilities. The |
| 51 | projection is deduplicated, limited to eight decisions and 4096 UTF-8 bytes, |
| 52 | and receipted by child id and decision ids. The task prompt may separately |
| 53 | carry at most eight explicit dependency facts and eight observable acceptance |
| 54 | checks. Parent transcripts, secrets, and raw reasoning are never projected. |
| 55 | |
| 56 | ## Neutral fan-in |
| 57 | |
| 58 | Conflicting candidates remain preserved as branch, patch, or artifact handles. |
| 59 | The neutral owner is the nearest common Planner/manager/operator in the |
| 60 | persisted parent tree, falling back to the root release owner. Neither candidate |
| 61 | author may claim that role. Reconciliation records: |
| 62 | |
| 63 | - both or all input decision ids and candidate handles; |
| 64 | - a retry count and a limit of at most three; |
| 65 | - distinct independent Reviewer and Verifier evidence handles; |
| 66 | - a verified, failed, or blocked verification outcome; and |
| 67 | - the neutral disposition and bounded evidence handles. |
| 68 | |
| 69 | Retry exhaustion is a terminal, inspectable receipt, not permission to discard |
| 70 | either candidate. Restart/replay preserves the schema, decisions, claims, |
| 71 | contention, projections, and reconciliation sequence. |
| 72 | |
| 73 | ## Inspection |
| 74 | |
| 75 | `agents/list` exposes concise per-child claims and accepted decisions. |
| 76 | `agents/coordinate action=inspect` exposes bounded decision, claim, contention, |
| 77 | projection, and reconciliation receipts plus deterministic hottest-path counts. |
| 78 | Metrics without an authoritative source, such as package growth or route cost, |
| 79 | remain explicitly null instead of being inferred. |
| 80 | |
| 81 | ## The workspace lock, and what losing it does and does not mean |
| 82 | |
| 83 | The ledger lives in one file, `.codewhale/state/subagents.v1.json`, written as a |
| 84 | whole-document atomic replace. Two processes rewriting that file would be |
| 85 | last-rename-wins, and the loser's `write_claims` would vanish — which silently |
| 86 | re-opens concurrent overlapping mutation of the same paths after a restart. So |
| 87 | one per-workspace advisory flock (`subagents.v1.lock`) decides who may *write* |
| 88 | the file. That is the whole of its job. |
| 89 | |
| 90 | Opening a second Codewhale session in the same workspace is ordinary usage, so |
| 91 | losing that flock is an ordinary state, not a failure: |
| 92 | |
| 93 | - **It does not affect liveness.** A session that cannot write the ledger runs |
| 94 | its own agents normally. Whether an agent is alive is decided by heartbeat |
| 95 | evidence, never by lock ownership. (Before v0.9.4 the cleanup pass |
| 96 | terminalized every running agent with no live task handle purely because this |
| 97 | process lacked the flock; that coupling is gone.) |
| 98 | - **It does not affect reads.** The boot-time load is unconditional. A second |
| 99 | session sees the workspace's decisions and write claims even though it cannot |
| 100 | append to them. Gating the load on the write flock previously left the second |
| 101 | session holding an empty default ledger, which it would write straight over |
| 102 | the real one the moment the first session exited and the flock became |
| 103 | acquirable. |
| 104 | - **It does mean no durable ledger appends.** Decision, claim, contention, and |
| 105 | reconciliation mutations still require the flock, and so does any |
| 106 | shared-workspace write-capable launch, because such a launch must be durably |
| 107 | replayable before it executes. A second session can therefore delegate |
| 108 | read-only and isolated-worktree work, but not shared-workspace writers. |
| 109 | |
| 110 | Known gap: a lock-less session holds the ledger as of its own boot. If the lock |
| 111 | owner appends more records and then exits, the second session can acquire the |
| 112 | flock and persist its boot-time snapshot, losing the records appended in |
| 113 | between. Closing that — and letting a second session launch shared-workspace |
| 114 | writers — needs per-session ledger segments unioned on read, so that no two |
| 115 | processes ever write the same file and the claim-overlap check runs against the |
| 116 | union. That work is not done. |
| 117 |