delegation-layer 0.1.30 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,11 @@
3
3
  Use the response fields independently. A successful control command is not
4
4
  the same as a successful provider result.
5
5
 
6
- 1. Save `task_id` immediately after dispatch or continue.
6
+ 1. Save `task_id` immediately after dispatch or continue. It is the durable
7
+ Delegate identity. `supervisor.numeric_task_id` and a stop's
8
+ `numeric_task_id` are private, ephemeral queue addresses. The queue can
9
+ reuse a number for a later task, so a repeated number is not a binding
10
+ error; never use it as a task handle.
7
11
  2. For a dispatch or continue error, inspect `task_record` first. When it is
8
12
  `created`, observe the returned ID with `status`. Before applying the generic
9
13
  `not_created` stop rule, handle the sole migration exception: when
@@ -24,7 +28,13 @@ the same as a successful provider result.
24
28
  evidence for an existing task.
25
29
  3. If `status` is `timed_out`, follow the continuation procedure before treating
26
30
  pending publication as a reason to wait. `continuation.resumable: true`
27
- permits a linked successor even when no outcome has been published.
31
+ permits a linked successor even when no outcome has been published. An
32
+ `interrupted` task (`failure.code: "task_interrupted"`) follows the table in
33
+ [interrupted turn](continuation.md#interrupted-turn): continue only when
34
+ `failure.next_action` is `continue_task` and `continuation.resumable` is
35
+ `true`, otherwise report it. A `timed_out` task whose `failure.code` is
36
+ `task_cancelled` is `stop_and_report`: report it and stop, even though
37
+ `collect` exits `3`; that exit is not success.
28
38
  4. If `publication` is committed and `outcome.verdict` is committed, return
29
39
  the result and its payload/evidence descriptors.
30
40
  5. If `outcome.verdict` is rejected and `failure.next_action` is `recheck`,
@@ -51,7 +61,13 @@ from an inspection-worker or supervisor-observation failure.
51
61
  For `delegate models`, validate the complete JSON envelope before using any
52
62
  fact. Treat `available` and `partial` with exit `0` as observations, preserve
53
63
  `blocked` and `unavailable` with exit `2` as unresolved prerequisites, and
54
- preserve `failed` with exit `1` as a discovery failure. `complete` refers to
64
+ preserve `failed` as a discovery failure. Exit `1` with `failed` is an
65
+ operational failure; exit `2` with `failed` is an invalid or unsupported
66
+ request, not an authentication block. Status and exit are separate
67
+ observations. When the response
68
+ includes the optional `failure` object and `error` message, keep both in the
69
+ report and follow `failure.next_action`; report and stop on
70
+ `stop_and_report`. `complete` refers to
55
71
  model enumeration. Keep `efforts: null` distinct from `efforts: []`, and do not
56
72
  apply harness-wide effort choices to every model. Discovery is advisory and
57
73
  never an admission allowlist; a provider default remains valid and a listed
@@ -79,6 +95,18 @@ The provider outcome is immutable and the workspace `CaptureReceipt` is a
79
95
  separate immutable fact; a failed or unavailable capture must not be reported
80
96
  as a provider failure when native closure is already proven.
81
97
 
98
+ In task `status` or `collect`, a workspace with `state: "undetermined"`,
99
+ `evidence_state: "unknown"`, and `next_action: "watch_workspace"` means that
100
+ observer's bounded view expired before it read the workspace. It is an
101
+ unobserved view only. It does not imply corruption, change the task fields, or
102
+ revoke an eligible continuation, and it does not turn a committed task into a
103
+ failure. Follow the task fields above: return a committed result, handle a
104
+ rejection using its reported guidance, and keep observing only while the task
105
+ fields are pending. When useful, watch the same workspace with the same root.
106
+ Do not dispatch again, retry the provider, fall back to another integration,
107
+ or repair the environment because of it. A workspace view with `stop_and_report` remains a
108
+ concrete failure to report.
109
+
82
110
  Before a task record exists, a pending workspace provision returns
83
111
  `task_record: "not_created"` with
84
112
  `failure.code: "workspace_provision_pending"` and
@@ -112,6 +140,42 @@ Lead has terminal task/capture evidence and explicitly releases it. Read
112
140
  [managed workspace guidance](workspaces.md) for the exact command surface and
113
141
  review/capture/forgetting boundaries.
114
142
 
143
+ ## Checkpoint results
144
+
145
+ A `checkpoint` response has `command: "checkpoint"` and no `task_id` or
146
+ `outcome`. A checkpoint receipt is Git-content evidence; it never replaces a
147
+ provider outcome, and a provider outcome never proves a checkpoint. Read
148
+ `checkpoint.id`, `checkpoint.operation_id`, `checkpoint.current`,
149
+ `checkpoint.operation`, `checkpoint.reason_code`, `checkpoint.next_action`, and
150
+ `error` separately, together with the exit code. Exit `0` alone is not enough.
151
+
152
+ | Command and response | Meaning and next action |
153
+ | --- | --- |
154
+ | `create`: exit `3`, `id` C, `next_action: "watch_checkpoint"` | Accepted, not yet captured. Watch `status C`; never repeat `create`. |
155
+ | `create`: exit `3`, `requested_action_not_authorized`, `retry_create`, no `id` | Busy refusal; nothing was accepted. Apply the [busy rule](workspaces.md#checkpoint-before-fork). Never wait for your own turn or switch to `--cwd`. |
156
+ | `remove C`: exit `3`, `id` C, `operation_id` R, `watch_checkpoint` | Removal attempt R is accepted. Watch `status C --operation R`; never repeat `remove` to observe it. |
157
+ | `remove C`: exit `3`, `requested_action_not_authorized`, `retry_remove`, no `operation_id` | Not accepted, usually because creation is still pending. The `id` in your command is not a removal ID. Watch `status C` until it settles, then retry `remove C` once. |
158
+ | `remove C`: exit `0` with `operation_id` R | R already succeeded. No new attempt was registered. |
159
+ | `status C`: exit `0` | Successful observation. Fork only when `current.state` is `checkpointed` and `current.usable` is `true`. With `next_action: "stop_and_report"`, report the unavailable creation or latest removal; do not fork. |
160
+ | `status C`: exit `3`, `watch_checkpoint` | Creation or latest removal is still pending. Keep watching the same C. |
161
+ | `status C --operation R`: exit `0`, `1`, or `3` | R's own result: `removed` or `nothing_to_remove` is `0`; `unavailable` is `1` with `stop_and_report`; pending is `3`. A newer attempt in `current.removal` never replaces R's outcome. Keep watching R, not the newer head. |
162
+ | `list`: exit `0` | One metadata page. Entries may be pending, unavailable, or removed. Run `status C` for a reconciled verdict. |
163
+ | Exit `1` with `stop_and_report` | Concrete failure. Report `error` and every ID already returned; do not repeat the mutation. |
164
+ | Exit `2` | Invalid request. Parse errors print usage on stderr without guaranteed JSON; correct the request. |
165
+
166
+ Take `C` only from `checkpoint.id` and `R` only from `checkpoint.operation_id`
167
+ of a response that returned them. Never invent an operation ID or reuse a
168
+ creation ID as `--operation`. Returned IDs stay valid after a later read
169
+ fault; an unreadable `current` or `operation` is omitted rather than shown as
170
+ empty availability.
171
+
172
+ `status --watch` repeats the same observation of the same IDs until a settled
173
+ or failed result or the bound ends. It never begins another action, renews a
174
+ helper deadline, or cancels accepted work. The latest observation chooses the
175
+ exit. A watch that ends at exit `3` means keep observing; it is not a failure.
176
+ If writing the response itself fails (exit `1`), accepted work stays accepted;
177
+ observe it with `status` instead of repeating the mutation.
178
+
115
179
  ## Offline recovery
116
180
 
117
181
  When Delegate returns `failure.next_action: "recheck"`, use the same root and
@@ -4,7 +4,7 @@ Managed workspaces are an optional Delegate feature for tasks that need a
4
4
  retained Git worktree. Ordinary delegation, including ordinary work in a
5
5
  non-Git directory, is unchanged. Git is required only when a request creates
6
6
  or attaches to a managed workspace (`--isolation git-worktree` or
7
- `--workspace ID`).
7
+ `--workspace ID`), or creates or removes a [Git checkpoint](#git-checkpoints).
8
8
 
9
9
  This reference is self-contained guidance for using managed workspaces.
10
10
 
@@ -48,7 +48,10 @@ delegate --root ROOT dispatch --isolation git-worktree --cwd ABS \
48
48
  `--base` resolves to a commit; the default is `HEAD`. Dirty and untracked
49
49
  source changes are observed but excluded from the managed checkout. The
50
50
  provider runs in the retained detached worktree, with the source-relative
51
- working subdirectory preserved. A request that attaches to an existing
51
+ working subdirectory preserved. The source may itself be a managed checkout,
52
+ such as a sibling in the same workspace container. After provisioning, the new
53
+ workspace depends on the shared repository, not on the source checkout, so
54
+ removing that source does not block capture, release, or forget. A request that attaches to an existing
52
55
  workspace uses its recorded checkout and source identity:
53
56
 
54
57
  ```text
@@ -117,6 +120,36 @@ facts. Normal capture covers the initial committed base through the captured
117
120
  tree, including worker commits and added untracked files that belong to the
118
121
  Git-content view. It uses a private temporary Git index and records an owned
119
122
  base pin plus tree/snapshot reference.
123
+
124
+ Each provider turn also records its actual starting tree, `HEAD`, and index
125
+ identity just before launch, so Lead edits made between turns belong to the
126
+ next turn's start. The index identity covers every entry's mode, object, stage
127
+ (including conflicts), path, assume-unchanged or skip-worktree flag, and
128
+ intent-to-add (`git add -N`) state, but not stat caches or `HEAD`. A task capture's `candidate.turn` compares that start with the
129
+ final capture: `content`, `head`, and `index` are `changed` or `unchanged`, and
130
+ `baseline_ref` keeps the start tree. This is observed evidence, not
131
+ enforcement: a read-only turn that commits or edits is reported, not rejected,
132
+ and writes reverted before capture or ignored files are not observed.
133
+ `status: "unavailable"` with `reason_code: "baseline_unavailable"` means no
134
+ baseline exists, for example for a turn started before this evidence existed;
135
+ treat it as unknown, never as unchanged. A capture without `candidate.turn`,
136
+ such as one recorded before per-turn evidence existed or a release or exec
137
+ recapture, is also unknown, never unchanged. A failed baseline refuses the
138
+ provider launch for that task.
139
+
140
+ An observed turn adds `turn-diff.patch` and `turn-name-status.z`, which diff
141
+ that turn's start tree to the final tree with the same bounds as the
142
+ cumulative artifacts. Use them to see which files the current turn touched;
143
+ they exclude earlier turns and Lead edits made before its launch. Use the
144
+ cumulative `diff.patch` and `name-status.z`, from the workspace base, to land
145
+ or review the whole delegated result. Report a read-only turn whose `content`,
146
+ `head`, or `index` is `changed` as a mutation, even when its turn file list is
147
+ empty, and report an unavailable turn as unknown.
148
+
149
+ `status` and `collect` for a task report that task's own capture, even after a
150
+ later turn has used the workspace. The workspace `state` still reflects the
151
+ resource now, so a sealed earlier capture does not make a busy, released, or
152
+ forgotten workspace usable. `workspace status` reports the latest use.
120
153
  Optional binary patch and name-status artifacts are bounded to 8 MiB each; an
121
154
  overflow is omitted, never silently truncated. Verification diagnostics retain
122
155
  an 8 MiB prefix per stream, mark truncation explicitly, and continue draining
@@ -136,6 +169,98 @@ expired provider scope is never renewed or reused. If capture
136
169
  is unavailable after closure, the closure evidence can still preserve a valid
137
170
  continuation decision; it does not rewrite the provider outcome.
138
171
 
172
+ ## Git checkpoints
173
+
174
+ A checkpoint records the current Git content of one checkout as a synthetic
175
+ commit pinned by the owned ref `refs/delegate/ROOT_ID/checkpoints/CHECKPOINT_ID`.
176
+ It does not move `HEAD`, create or switch a branch, or change the real index.
177
+ The commit's tree is the full current Git-content view, built through a private
178
+ index with the capture algorithm above, so the same exclusions apply. Its single
179
+ parent is the `HEAD` the helper observed. Author, committer, and timestamp are
180
+ fixed Delegate values; trailers carry the checkpoint ID and request digest.
181
+ This is unrelated to a provider continuation `mode: "checkpoint"`.
182
+
183
+ ```text
184
+ delegate --root ROOT checkpoint create --cwd ABS [--budget DURATION] --json
185
+ delegate --root ROOT checkpoint create --workspace ID [--budget DURATION] --json
186
+ delegate --root ROOT checkpoint status CHECKPOINT_ID [--operation OP] [--watch DURATION] --json
187
+ delegate --root ROOT checkpoint list [--after CHECKPOINT_ID] [--limit 1..50] --json
188
+ delegate --root ROOT checkpoint remove CHECKPOINT_ID [--budget DURATION] --json
189
+ ```
190
+
191
+ - `create` names exactly one target: `--cwd` for an absolute ordinary Git
192
+ checkout directory, or `--workspace` for a managed workspace ID. Nothing is
193
+ inferred from the current directory. Select a managed checkout only by
194
+ `--workspace ID`; never pass its path as `--cwd`.
195
+ - `status` and `remove` take the checkpoint ID `C` from the create response.
196
+ `list` takes no target and runs no Git command.
197
+ - Only `create --cwd` may initialize a new state root. Every other checkpoint
198
+ command needs the existing root and fails with exit `1` without creating it.
199
+ Use one state root for every command about the same checkpoint.
200
+ - `--budget` is the finite helper budget (default 5m). It is persisted with the
201
+ operation and does not renew any provider task budget. `--watch` exists only
202
+ on `status`.
203
+
204
+ A managed checkpoint is a workspace use. It needs the workspace's use owner and
205
+ holds that workspace's usage reservation while its helper runs, so a concurrent
206
+ turn or `workspace exec` on that workspace gets the normal busy response. It
207
+ closes without content capture. Create it while the workspace is retained.
208
+
209
+ Delegate does not restore, apply, merge, or land a checkpoint into any checkout.
210
+ It does not control nested delegation budgets or lifetimes either. A fork from
211
+ a checkpoint is an ordinary new managed dispatch with its own task budget.
212
+
213
+ ### Checkpoint before fork
214
+
215
+ Use this sequence to start an isolated worker from current uncommitted work.
216
+ Save every response and exit code once; follow
217
+ [checkpoint results](result-handling.md#checkpoint-results) for each one.
218
+
219
+ 1. Run `checkpoint create` with one target. Exit `3` with `checkpoint.id` and
220
+ `next_action: "watch_checkpoint"` means the request was accepted. It does
221
+ not mean the content was captured. Save that exact ID as `C`.
222
+ 2. Run `checkpoint status C --watch 30s --json` until the exit is not `3`.
223
+ Never repeat `create` to observe it.
224
+ 3. Fork only when `status` exits `0` and `checkpoint.current.state` is
225
+ `checkpointed` and `checkpoint.current.usable` is `true`. A `commit_oid` or
226
+ `snapshot_ref` alone is not proof: an unavailable creation can still name a
227
+ retained candidate.
228
+ 4. Dispatch the worker with the qualified `checkpoint.current.commit_oid` as
229
+ the existing `--base` of a new managed workspace. Use an ordinary checkout of
230
+ the same repository as `--cwd`, normally the source the Lead already uses:
231
+
232
+ ```text
233
+ delegate --root ROOT dispatch --auto --brief ABS_BRIEF --cwd ABS_SOURCE \
234
+ --isolation git-worktree --base COMMIT_OID \
235
+ --permission workspace-write --budget 30m --json
236
+ ```
237
+
238
+ 5. Remove the checkpoint explicitly when the Lead no longer needs it.
239
+
240
+ `status` exit `0` means a successful metadata observation, not an available
241
+ checkpoint. `usable` is `true` only for a `checkpointed` creation with no
242
+ registered removal attempt, including a failed one. It is derived from
243
+ Delegate's records; it is not proof that an external Git command left the ref
244
+ in place.
245
+
246
+ If `checkpoint create --workspace ID` returns exit `3` with
247
+ `reason_code: "requested_action_not_authorized"` and `retry_create`, no
248
+ checkpoint was accepted and no ID was assigned. When that workspace is in use
249
+ by the turn you are running in, do not wait for yourself, retry in a loop, or
250
+ retry through `--cwd`. Finish and report; the Lead creates the checkpoint after
251
+ your turn closes. When another use holds it, the Lead observes that workspace
252
+ until it is retained again, then retries the same create once.
253
+
254
+ Checkpoint refs outlive `workspace release` and `workspace forget`: the forget
255
+ inventory covers only the workspace's own base, capture, and baseline refs.
256
+ `checkpoint remove C` is the only command that removes a checkpoint ref.
257
+ Removal needs only the shared Git common directory, so it works after the
258
+ source checkout or managed checkout is gone. A missing or replaced common
259
+ directory makes that removal attempt `unavailable`, never `removed`. Creation
260
+ history stays observable after removal: `current.state` keeps the creation
261
+ disposition, while `current.usable` becomes `false` and `current.removal`
262
+ shows the latest attempt.
263
+
139
264
  ## Retention and forgetting
140
265
 
141
266
  A created managed checkout is retained for every outcome, including no-op and
@@ -146,9 +271,10 @@ identity check retains the checkout and evidence for retry. `--discard` accepts
146
271
  loss of uncaptured checkout content; it does not waive native closure,
147
272
  ownership, or identity proof.
148
273
 
149
- Release leaves the pinned refs/blobs and capture receipts as evidence. After a
150
- proven release, `workspace forget ID` writes an exact inventory intent before
151
- removing only matching owned refs and optional artifacts by identity/CAS. It
274
+ Release leaves the pinned refs/blobs, turn-baseline refs, and capture receipts
275
+ as evidence. After a proven release, `workspace forget ID` writes an exact
276
+ inventory intent before removing only matching owned refs and optional
277
+ artifacts by identity/CAS. It
152
278
  retains capture receipts, tombstones, all provider outcomes, raw evidence, and
153
279
  payload descriptors. Readers should label an intentionally forgotten item as
154
280
  `forgotten`, not as corruption.