@parcha/pi-durable-disk 0.0.0-stage → 0.1.0-beta.13

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +329 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +695 -2
  5. package/bin/archil-scoped +165 -0
  6. package/dist/app.d.ts +40 -0
  7. package/dist/app.js +47 -0
  8. package/dist/claim.d.ts +222 -0
  9. package/dist/claim.js +722 -0
  10. package/dist/cli.d.ts +64 -0
  11. package/dist/cli.js +664 -0
  12. package/dist/commands.d.ts +67 -0
  13. package/dist/commands.js +299 -0
  14. package/dist/confine.d.ts +91 -0
  15. package/dist/confine.js +341 -0
  16. package/dist/env.d.ts +129 -0
  17. package/dist/env.js +608 -0
  18. package/dist/errors.d.ts +47 -0
  19. package/dist/errors.js +55 -0
  20. package/dist/fork.d.ts +41 -0
  21. package/dist/fork.js +181 -0
  22. package/dist/hosts/daytona-launch.d.ts +52 -0
  23. package/dist/hosts/daytona-launch.js +270 -0
  24. package/dist/hosts/daytona.d.ts +147 -0
  25. package/dist/hosts/daytona.js +368 -0
  26. package/dist/hosts/docker.d.ts +103 -0
  27. package/dist/hosts/docker.js +362 -0
  28. package/dist/hosts/local-host.d.ts +71 -0
  29. package/dist/hosts/local-host.js +356 -0
  30. package/dist/index.d.ts +16 -0
  31. package/dist/index.js +17 -0
  32. package/dist/lease.d.ts +7 -0
  33. package/dist/lease.js +6 -0
  34. package/dist/local-run.d.ts +10 -0
  35. package/dist/local-run.js +63 -0
  36. package/dist/park.d.ts +92 -0
  37. package/dist/park.js +229 -0
  38. package/dist/run.d.ts +290 -0
  39. package/dist/run.js +785 -0
  40. package/dist/serve.d.ts +101 -0
  41. package/dist/serve.js +393 -0
  42. package/dist/status.d.ts +123 -0
  43. package/dist/status.js +264 -0
  44. package/dist/store.d.ts +103 -0
  45. package/dist/store.js +217 -0
  46. package/dist/supervise.d.ts +340 -0
  47. package/dist/supervise.js +528 -0
  48. package/dist/watchdog.d.ts +39 -0
  49. package/dist/watchdog.js +137 -0
  50. package/package.json +87 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,329 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.1.0-beta.13 (2026-10-14)
6
+
7
+ **pi-durable 1.1**
8
+ - The peer ranges of `@earendil-works/pi-durable` and `@earendil-works/chord` widen from `~1.0.4` to `>=1.0.4 <1.2.0`:
9
+ the package installs beside pi-durable 1.1 and still beside 1.0.4. It is developed against 1.1.0, and a CI job
10
+ (`pi-durable-disk-pi-floor`) runs its whole suite again on pi-durable, chord and pi-ai 1.0.4, the lowest the range
11
+ accepts. The conformance minimum follows the installed version (23 cases on 1.0.4, 24 on 1.1), and the scan-order
12
+ control is skipped, with its reason, where the installed `Storage` contract has no order.
13
+ - pi-durable 1.1.0 requires a `Storage` to honour `order` on its conversation, entry, task and submission scans and to
14
+ continue a cursor in the order it was returned with. The store's scans are pi's `SqliteStorage` behind the fenced
15
+ database, so they do: pi-durable 1.1.0's storage conformance suite (24 cases, one of them the scans in either order)
16
+ passes on both profiles, and a control shows the runner fails a storage that drops `order`.
17
+ - What the package reads of pi's internals is unchanged in 1.1.0: `durable_metadata.next_seq` for the seal, and the
18
+ `retry` and `poll` checkpoints of generation and compaction for parking. Each is read off what the installed pi wrote:
19
+ the seal test commits through pi's storage, a park test waits on a real retry, and a new test waits on a real
20
+ deferred answer (pi's poll phase), so a version that moved either shape fails a test rather than this sentence.
21
+ - The Docker runtime image installs pi-durable, pi-ai and chord 1.1.0.
22
+
23
+ **A dead client's private directories**
24
+ - Each client holds delegations on its own private directories too, `.archil/client-<clientId>` and its `unlinked/`, which the
25
+ control API lists with no path. A client that dies (its FUSE daemon killed under a running instance, a lost host) leaves them
26
+ orphaned after the run's own delegation is revoked and its directory deleted. They block no run (they are on the client's
27
+ own directories, never a run's), but nothing revoked them, so they piled up and resurfaced in listings: a scratch disk held
28
+ 96, from 86 clients, all from the live suites' daemon kills. Revoking them is hygiene.
29
+ - `revoke` (and so `takeOver`), the supervisor's takeover in `ensureRunning` (an orphaned holder or an expired lease), and
30
+ `deleteRunTree` now also revoke those private-directory delegations, from the same listing, and only for the clients they
31
+ are already revoking on the run: never as a sweep. One `Disk.exec` (`stat`) confirms each inode is the client's own private
32
+ directory, and a client that holds anything else (it may hold another run) keeps everything but the run's delegation.
33
+ Best effort: without `exec`, or when it or a revoke fails, they stay, and the run's revoke never fails for them. The run's
34
+ own delegations, which every count and decision uses, are unchanged, and `revoke` still returns only those.
35
+ - `revokeBestEffort` revokes what `revoke` revokes and skips every revoke that fails (`revoke` stops at the first); only the
36
+ listing can fail it. `deleteRunTree` uses it, and the live suites' cleanups revoke through it (by path or by inode, and the
37
+ holders' private directories) before they delete a run's tree; the Docker, Daytona and lifecycle suites matched by path
38
+ only. The run suite's daemon-kill and host-loss tests check that no delegation of a killed client is left.
39
+ - New exports: `revokeBestEffort`, `revokeCompanions`, `companionsOf`.
40
+ - **`beforeResume`: an awaited step before the run resumes**
41
+ - `openDurableRun` and an app (`AppOptions`) take an optional `beforeResume(run)`, awaited once per incarnation after the
42
+ Harness is open (its registry installed) and the run is live, and before the Harness resumes. No resumed task takes a
43
+ step until it settles, and what it admits (a submission, a write) is committed before anything a resumed task's steps
44
+ commit. It sees the open Harness, the open's context, the generation, the run record and the claim.
45
+ - It also gets the store the Harness was opened over, read-only, and its head: `storage` has `scanConversations`,
46
+ `scanTasks`, `scanDocuments` and `document` on a frozen object of its own, with no `commit` or `mintId` even through a
47
+ cast, and `head` is the store's last committed sequence once the Harness is open. A recorder snapshots every document
48
+ at `head` in the hook; until the hook commits, the current state is the state at `head`, which is how a document that
49
+ keeps no history (`latest`, session and task documents) reads.
50
+ - Use: a host reconciling what a resumed tool depends on (a browser, a mount) before the task that uses it continues;
51
+ `onStep` cannot, since it is synchronous and gets no Harness.
52
+ - A rejection fails the open like any open step (`before-resume`), and the claim is released.
53
+ - New exports: the `BeforeResume` and `StoreReads` types.
54
+ - **`localRun(root)`: a run on a plain local directory, one machine**
55
+ - New export `localRun(root)` returns `openDurableRun`'s `acquire` and `claimDir` for a run in a directory of this
56
+ machine: the claim is the directory (made when missing), with no mount; `claimDir` is `openClaimDir(root, { fstype:
57
+ null })`. Its barrier refuses once fenced and syncs nothing (SQLite makes the store's commits durable; `work/` is the
58
+ OS's to flush). It is for one machine and says so: only the owner lock keeps a second process off the run.
59
+ - `mountToken` is optional: required only with the default `acquire` (refused with `INVALID_ARGUMENT` before anything
60
+ mounts when missing); a replaced `acquire` is handed an empty token.
61
+ - A local run needs Linux, for now, and the README says why: the run's root is held open through `/proc/self/fd`
62
+ (`openClaimDir`), and the default environment needs `setpriv` (`noNewPrivs`) and `/proc/self/fd` (`confineFiles`).
63
+ macOS has neither.
64
+ - Installs beside pi-durable 1.2: the peer ranges of `@earendil-works/pi-durable` and `@earendil-works/chord` widen to `>=1.0.4 <1.3.0`, so the package installs beside 1.0.4, 1.1 and 1.2. It is still developed against 1.1.0; CI runs its whole suite at 1.2.0 (`pi-1-2`) and at 1.0.4 (`pi-durable-disk-pi-floor`).
65
+ - pi-durable 1.2 reads a tool result's `output` and sends the model an empty result for one that says `content`, with no error (1.0.4 and 1.1 read `content`). The package's own source builds no tool result. The test apps' tools (the lifecycle app, the acceptance app, the live instance) and the paid-effect example give their text through `api.output()` and name neither key, which every version reads; tests assert the model gets a tool's text, not an empty result.
66
+ - pi-durable 1.2 fails a Session on any error a `Storage` throws, except its own `StorageRequestError` (an invalid request) and a read its caller cancelled. The store is pi's `SqliteStorage` behind the fenced database and the lease's commit observer, neither of which rewraps an error, so an invalid read (a cursor that is not one, an unknown conversation) fails only that call. A fenced commit still fails the Session: on 1.2 later operations refuse with `SessionFailed`, its `cause` the fenced error, where 1.0.4 and 1.1 said the Session was poisoned.
67
+ - pi-durable 1.2's `bash` answers a nonzero exit with an error result where 1.0.4 and 1.1 threw. The workspace barrier runs after it either way, with the command's writes on disk before the error result commits.
68
+ - The floor job measured a mixed family: its install left pi-durable 1.0.4 at the root loading chord and pi-ai 1.1.0, and the version guard checked only what the package resolved. The guard now also checks chord and pi-ai as the installed pi-durable loads them, and reads `PI_EXPECT_VERSION` beside `PDA_EXPECT_PI_DURABLE`; the job installs one copy of each family package through `scripts/pi-leg.mjs`.
69
+ - The test helpers that signal a process (`killQuietly`, `alive`) refuse a pid of 0 or below: a test that never learned its child's pid passed 0 from its `finally`, and `kill(0)` signalled the test runner's whole process group. A test removes a directory a run still writes into without racing its heartbeat (from #251).
70
+ - `@parcha/pi-durable-disk/lease` exports the four types its own signatures name: `AcquireOptions`, `PersistRecord` and `ClaimDir` (in `OpenRunLeaseOptions`) and `Unmounted` (in `Claim`). A host that imports only this entry can now write the type of every option it passes to `openRunLease`. They are type-only exports, so the entry's bundle still leaves out the supervisor, the host drivers, the CLI and the app contract. A test checks that every type of the package the entry's declarations name is exported by the entry.
71
+ - **A run on a local directory ends the commands a killed instance left running, before it resumes**
72
+ - pi makes each command the leader of its own process group, so a SIGKILL of the instance does not reach its commands,
73
+ and a local run has no unit cgroup to end them: a command kept running, and writing in `work/`, beside the next
74
+ incarnation. Now a local run's environment marks each command it starts (`PI_DURABLE_DISK_COMMANDS=<its token>` in the
75
+ command's environment) and records each of its commands' groups (the leader and every descendant it has seen, each by
76
+ pid, start ticks and boot) under `<root>/commands/`: another environment's commands in the same process, or the app's
77
+ own detached helpers, are never its to record. Each walk follows every recorded process still alive, so a background
78
+ worker whose leader exited, and the children it starts later, are recorded too, and the next open, holding the owner lock, kills what is
79
+ still the recorded process, waits until it is gone and clears the records, before the Harness opens (a new open step,
80
+ `commands`, after `layout`).
81
+ - A kill reaches a process only when its pid, start ticks and boot all match a record, and never pid 1 or below
82
+ (`kill(-1)` would reach every process the user may signal), the opening process or its group. Only the instance writes records; a command that forged one could already kill what it names (it runs as
83
+ the same user, or with `runAs` cannot write the instance's 0700 directory), so a record grants nothing.
84
+ - What is still alive at the reap's deadline (a process in an uninterruptible wait, or one it may not signal) refuses the
85
+ open: `HeldError` with holder `commands` (`COMMANDS_ALIVE`, exit 76), naming each pid and its command line and saying
86
+ what to do (end them, then open the run again). The run never resumes beside it, its record stays, and the next open
87
+ tries again. A record that cannot be written (a full disk) is said once on
88
+ stderr and the recorder keeps trying. A command started within the last walk's interval (about 0.1 s) before the kill
89
+ can be missed.
90
+ - A claim opts in with `Claim.commands` (the directory); `localRun`'s claim sets it. A mount's run is unchanged: its host
91
+ ends commands with the unit's cgroup or the container.
92
+ - **Stopping an instance never signals pid 1 or below, whatever its handle or state file says, nor does the lease watchdog**
93
+ - `localHost`'s `stop` of a development-mode (`child`) handle signals the handle's pid as a group. A handle comes back
94
+ from `run.json` with whatever was written there: pid 1 with pid 1's real start ticks made it `kill(-1)`, every process
95
+ the supervisor's user may signal, and pid 0 (or a pid that is not an integer) with no start ticks made it `kill(-0)`,
96
+ the supervisor's own group. It now signals only an integer pid above 1 whose handle carries start ticks.
97
+ - The Daytona launcher's `stop` had the first of those: a state file naming pid 1 with its real start ticks made it
98
+ SIGTERM pid 1 and `kill(-1, SIGKILL)`. Its liveness check now takes only an integer pid above 1 with start ticks.
99
+ - The lease watchdog's sweep killed a direct child's process group unless it was the instance's own or 0 and below; a
100
+ child in group 1 (possible in a container whose init's group is in the instance's session) made it `kill(-1)`. A
101
+ child in group 1 is now killed alone.
102
+ - **A tool may write in the temp directory it was given**
103
+ - `archilEnv`'s confinement made all of `<root>/tmp/` read-only to file operations, including the directories its own
104
+ `createTempDir` (and `createTempFile`) hands out, so a tool that writes into the temp dir it asked for was refused
105
+ `outside_work`: pi-vision's `read` of any media file failed on a disk run. A directory `createTempDir` returns is now
106
+ writable, for the run's environments; the rest of `tmp/` (another run's directories, `tmp/` itself) stays read-only.
107
+ - The tool may remove that directory (`env.remove`, as vision does when it is done), and its grant goes with it.
108
+ - It is made through a held handle of `tmp/` that does not follow a link, and granted by name under the canonical `tmp/`:
109
+ a `tmp/` a command replaced with a link is refused, and a directory swapped for a link grants nothing beyond itself.
110
+ - **The self-fence watchdog starts in a host launched with `--input-type=module`**
111
+ - The watchdog's worker is eval'd CommonJS and inherited the host's Node flags. Under `--input-type=module` (a host that
112
+ runs inline ESM through `-e` or stdin) Node read it as ESM, it threw `require is not defined`, and the run died at
113
+ open. The worker now starts with no inherited flags (`execArgv: []`); it needs none of the host's.
114
+ - An example's test can no longer hang past its timeout: `runExample` waits for the example's output only until the timeout
115
+ and a 2 s grace, then drops the pipes a process outside the example's group still holds and reports the run as timed out.
116
+ The package's tests run with `--test-timeout=240000`, so a test that hangs fails with its name.
117
+ - **An example, `audit-across-crashes`: the store is the record**
118
+ - A run on a local directory is killed twice in the middle of a tool call. A recorder in `beforeResume` snapshots every
119
+ task, document and transcript entry at each incarnation's `head`, and the example prints a per-generation account (who
120
+ asked what, who answered, which calls were cut and which generation settled them as `interrupted`) read from those
121
+ snapshots alone. No disk, no key: `node examples/audit-across-crashes/main.ts` after the build, with pi-ai's faux model.
122
+ A test runs it in `npm test`.
123
+ - **An examples index and the conventions every new example follows**
124
+ - `examples/README.md` lists the examples with what each shows, what it needs, and whether CI runs it, and states how a
125
+ new one is written: one directory and one property per example, self-contained imports, `node examples/<name>/main.ts`
126
+ on a local directory with pi-ai's faux model (no key, no network), one closing `ok: ...` line, and a test under
127
+ `test/examples/` that runs it on every change.
128
+ - `test/examples/conventions.test.ts` checks what code can: each example's files, its imports (read from the parse tree),
129
+ its test and its row in the index. `test/examples/_run-example.ts` runs an example from a scratch directory as its own
130
+ process group and reaps the group whatever ends it, and `assertExampleOk` fails a run that exited 0 while a
131
+ process it started still held its output; the quickstart's test uses both.
132
+ - **A quickstart on one machine: no disk, no key**
133
+ - The README opens with a durable chat on a directory of this machine (`localRun`) and pi-ai's faux model: one process
134
+ is killed (`SIGKILL`) after its third answer, a second opens the same run and answers the rest, and the transcript read
135
+ back from the store has every message answered once. It is `examples/01-durable-chat/on-a-directory.mjs`.
136
+ - The stranger test installs the packed package and its peers in an empty directory, runs the README's script and
137
+ expects that line, so the quickstart a reader copies is the one that is checked.
138
+ - The README's bundle sizes for the two entries are re-measured: about 60 KB for `@parcha/pi-durable-disk/lease` against about 620 KB for the root entry (it said 52 KB and 493 KB), with the esbuild command that produces them.
139
+ - **The README starts with a path chooser and states how a run on a local directory fails**
140
+ - "Choose your path" maps what a reader has (Linux and Node only, Docker and an Archil account, a Linux host with FUSE, an
141
+ app of their own) to the quickstart or section to start with, and points to the examples index.
142
+ - The failure table gains the rows for a run on a local directory (`localRun`): a crash or SIGKILL (the next open ends
143
+ the commands the killed instance left running, then resumes), a power loss (the store holds, `work/` may be older), a
144
+ second process on the machine (refused, exit 76), a process of the killed incarnation that will not die (the open is
145
+ refused, exit 76, naming it), and another machine reaching the directory (unsupported: no fence).
146
+ The layout names a local run's `commands/`.
147
+
148
+ ## 0.1.0-beta.12, 2026-10-09
149
+
150
+ Renamed from `@parcha/pi-durable-archil`. The package is now `@parcha/pi-durable-disk` and its command is `pi-durable-disk`, for branding:
151
+ other disks may follow, and none is promised. It supports Archil only, because Archil gives a run's directory an exclusive claim and fences
152
+ the old holder's writes on takeover; a disk without both cannot carry the package's guarantees. The entries below name the package as it was
153
+ published.
154
+
155
+ - Moved with the name: the Docker image (`pi-durable-disk:local`), the tarball name (`parcha-pi-durable-disk-<version>.tgz`), the install
156
+ paths `/usr/local/lib/pi-durable-disk/archil-scoped` and `/etc/sudoers.d/pi-durable-disk`, the token directory `/run/pi-durable-disk`, and the
157
+ `X-Daytona-Source` header. An existing host's sudoers drop-in and wrapper copy need the new paths.
158
+ - Unchanged, because they name the Archil disk: `bin/archil-scoped` (and the `./bin/archil-scoped` export), `ARCHIL_API_KEY`, `archilEnv`,
159
+ `ArchilCodingTools`, the claim's internals and the `archil` client it runs.
160
+
161
+
162
+ **A holder the control API lists without a path**
163
+ - Archil's control API resolves a delegation's path best-effort and can list one with no path, live or orphaned, even on a
164
+ run id used once. `findDelegations` matched by path only, so such a holder read as none everywhere it is used
165
+ (`ensureRunning`, `revoke`, `takeOver`, `deleteRunTree`, `fork`): the supervisor started a second instance into a live
166
+ holder (refused, exit 76), kept starting into a dead holder's refused mount, and S3 kept refusing the run's deletes.
167
+ `sweepTokens` judged such a run unheld too, so it could remove a live mount's token user once `run.json` said released.
168
+ - When nothing matches by path and some delegation has none, the pathless delegations are attributed by inode: one
169
+ `Disk.exec` (`find runs -inum`, whose inode numbers are the control API's inode ids) maps their inodes to run
170
+ directories, and those on the inode `runs/<id>` names now are the run's. A listing, a supervisor pass and a token sweep
171
+ each share one resolver (`pathlessResolver`), so one costs at most one exec however many runs it decides. Nothing is
172
+ recorded, so a deleted and recreated run directory matches as it is now. An inode on no run directory is no run's and
173
+ is reported once on stderr.
174
+ - `ControlApi` gains an optional `exec(command)`; an SDK `Disk` has it and the CLI passes it. Without it, when the exec
175
+ fails, or when the disk root or `runs/` cannot be read, a pathless delegation that could be the run's fails
176
+ `CONTROL_API_FAILED` instead of reading as none: the supervisor's pass starts nothing, `takeOver` falls back to
177
+ `mount --force`, and the token sweep keeps the run's users.
178
+
179
+ ## 0.1.0-beta.11, 2026-10-08
180
+
181
+ **Serve, sleep parking and fork**
182
+ - `run --serve PORT` puts an HTTP front on the open run: `POST /submit` (pi's submit with the caller's `requestId`, which pi
183
+ deduplicates per conversation in the run's store, so a retry that reaches the next incarnation, even on another host, gets
184
+ the same submission and, with `wait: true`, its answer), `POST /abort`, `GET /events` (pi's agent events as server-sent
185
+ events) and `GET /status`. The instance listens before it opens and writes its address into `run.json`'s holder
186
+ (`holder.serve`); it answers 503 `OPENING`, `PARKING` or `RELEASED` while it opens, parks or is gone.
187
+ - A bearer token: optional on 127.0.0.1, required on any other `--serve-host` (`SERVE_TOKEN_REQUIRED` before anything binds).
188
+ It is read from a file of mode 0600 (`--serve-token-file`, never argv or the environment) and compared in constant time
189
+ on every route. A wildcard bind (0.0.0.0, ::) also needs `--serve-url`, the address clients reach, which is what
190
+ `run.json` carries (`SERVE_URL_REQUIRED`).
191
+ - `requestRun(ref, request, { host, ensure, token })`, the client: it finds the instance through `run.json`, sends while the
192
+ holder's lease is fresh (a request is dropped when the lease lapses under it), and otherwise calls `ensureRunning` with
193
+ demand. After a start, its own or one the supervisor reports `starting`, it waits for that generation instead of asking
194
+ again, so one cold request makes one start.
195
+ - Sleep parking (`run --park-threshold`; the local driver passes 60 s, `supervise --park-threshold 0` turns it off): after
196
+ every commit the instance classifies pi's tasks; when everything that could run only sleeps in a retry or deferred-poll wait
197
+ longer than the threshold, it writes `run.json` `sleeping` with `wakeAt` (the deadline), releases and exits 0, and the
198
+ supervisor starts it at `wakeAt`. With `--serve`, a run with no live work parks after `--park-idle` with `wakeAt` null (a
199
+ request wakes it). Open requests and event streams keep the instance up; a blocked task does not. The deadline is read from
200
+ pi's retry and poll checkpoint in one function; any other shape counts as busy.
201
+ - The app module's `wake` hook replaces how the wake is recorded: a refusal keeps the instance up through the wait, while a
202
+ failed `run.json` write is a fence (exit 75; the lease path resumes the run and pi sleeps out the remainder). `root` gives
203
+ the options for the root conversation serve creates.
204
+ - A drain on SIGTERM: no new submissions, then up to `--drain-timeout` (the local driver: its stop timeout minus the smaller
205
+ of 5 s and half of it) for running work; the wake it writes is now, the wait's deadline, or null when idle. Work cut at the
206
+ deadline resumes on the next open (safe tools rerun, unsafe ones report the interruption). The app's work rejecting when a
207
+ park's release closes the Harness under it does not end the instance before its release, as for a drain.
208
+ - `leaseParkTarget(lease, harness)`: parking for a Harness a host opened over `openRunLease` (the wake through the lease's
209
+ `setStatus`; the release closes the host's Harness, then the lease).
210
+ - `fork --id A --new-id B` (`fork(ref, newId, { control, mountRoot })`): copies a released, sealed run (paused, sleeping, done
211
+ or failed, with no delegation) under two short exclusive mounts of its own into a new run that starts `paused` at
212
+ generation 0 with the source's `sealedSeq`, so its first open is generation 1 and a lossy copy is refused
213
+ (`STORE_BEHIND_SEAL`). The source is only read. `run.json`, `owner.lock`, the start mark and `tmp/` are not copied. A fork
214
+ owns the new run's directory only while it holds that directory's mount: one that fails after that empties it through
215
+ its own mount and removes it; one that lost the directory to another fork or start leaves it alone.
216
+
217
+ **The Docker host driver**
218
+ - `dockerHost` (`supervise --host docker --image IMAGE`): one container per instance, from the image `docker/Dockerfile`
219
+ builds (Node 24, the archil client 0.8.42 checked by sha256 per architecture, FUSE, tini, the run user `pda`, this
220
+ package). Nothing on the machine that runs the supervisor needs root, FUSE or the archil client.
221
+ - `docker create` named `pda-<run>-<disk key>-g<attempt>` (the disk key is 8 hex digits of the disk and region) and
222
+ labeled `pda.fleet`, `pda.run`, `pda.disk`, `pda.region`: a retry of the same attempt adopts a running container that
223
+ carries all four labels, and the supervisor removes the token it minted for that start; a dead one is replaced, and a
224
+ container by that name with other labels is refused. `--device /dev/fuse --cap-add SYS_ADMIN`, `--security-opt
225
+ no-new-privileges`, no restart policy, and `--security-opt apparmor=unconfined` only where the daemon applies
226
+ AppArmor (Docker's default profile denies mount(2); `apparmor: "auto"`, the default, decides from `docker info` and
227
+ reports why once through `note`).
228
+ - The mount token is copied into the created container as a root-only file (`docker cp -` of a tar built in memory),
229
+ which the entrypoint makes the instance's stdin and removes before the instance starts. It is never in `docker
230
+ inspect`, argv or an environment variable.
231
+ - Status from `docker inspect` (exit 0 stopped, any other exit failed, paused running), `describe` with the exit code,
232
+ stop as `docker stop` (drain) then `docker rm`. A dead container takes its mount with it: nothing is left on the host.
233
+ - The app's directory (`--app-root`) is bind-mounted read-only with its `node_modules` hidden, so the app shares the
234
+ image's single pi-durable.
235
+ - Docker instances park and drain like local ones (`--park-threshold` 60 s by default, the drain from the stop timeout),
236
+ and a `--restart` policy other than `no` in `dockerArgs` is refused, so a parked container stays exited until the
237
+ supervisor starts the next.
238
+ - `archilEnv(claim, { runAs })` and `run --run-as USER`: for an instance that runs as root (in a container), every command
239
+ runs as `runAs` with every capability set empty and no_new_privs, and `work/` plus every entry pi's in-process write,
240
+ append and mkdir create under it are handed to that user (`lchown` through the confinement's pinned directory). The
241
+ run's root, store and `run.json` stay root's; a command can neither change them nor read the archil daemon's environment.
242
+ - `HostDriver.start(ref, token, { attempt })`: the supervisor passes the generation the instance will open, so a driver can
243
+ key its start on it. Drivers that ignore it are unchanged.
244
+ - The image installs one version of this package: the checkout's `package.json` version, from a tarball `npm pack` wrote
245
+ into `docker/package` (which must be that version) or else from npm; `--build-arg PDA_VERSION` names another version or
246
+ a dist-tag, never by default. A package without the Docker path (a release from before it) is refused.
247
+ - `examples/docker-quickstart.sh`, and `--host docker` for both examples' demos. It reuses an image only when the image was
248
+ built from this checkout's package version, and rebuilds it otherwise.
249
+ - Measured with Docker Engine 29 on Ubuntu 24.04: a killed container is replaced in about 1 s and the run resumes about
250
+ 2 s after the kill; a frozen one is replaced 7 to 8 s after the freeze (6 s test lease) and exits 75 within 0.5 s of its
251
+ thaw; a commit from a container costs what it costs from the host. macOS is not verified.
252
+
253
+ **Fixes**
254
+ - Known issue in 0.1.0-beta.10, fixed here: an idle `run` instance (no `--serve`, nothing running) exited without draining or
255
+ releasing once its work finished; the supervisor then revoked and restarted it. It now stays up until it parks, drains or fails.
256
+
257
+ ## 0.1.0-beta.10, 2026-10-08
258
+
259
+ First release of `@parcha/pi-durable-archil`, versioned with the other packages in this repository. It is the package developed
260
+ as `pi-durable-archil` 0.2.0 before it was imported; its notes follow, and its earlier history is not here.
261
+
262
+ Not in this release: `serve` (wake a released run on a request, `requestRun`), sleep parking (an instance that only waits
263
+ releases its host and is started again at the deadline), `fork` of a sealed run, a Docker host driver and a Docker
264
+ quickstart.
265
+
266
+ First release: a pi-durable host on an Archil disk. Each run is the subtree `runs/<id>/`, which holds pi's store and the
267
+ agent's workspace.
268
+
269
+ **The claim and the fence**
270
+ - One exclusive mount of `runs/<id>/` per run, verified by the delegation and an fsynced probe write. A second mount is
271
+ refused (exit 76). The supervisor revokes a stale holder through the control API; the old holder's next fsync fails and its
272
+ instance exits 75.
273
+ - Mount tokens are reusable, 24 h, one per start attempt, passed on the root-owned wrapper's stdin
274
+ (`bin/archil-scoped`), never in argv or in an environment `sudo` sees; swept when no live mount needs them.
275
+ - Release: barrier, seal, unmount; a dead mount is cleaned, and where the kernel refuses every unmount (a Sysbox box) the
276
+ mount is checked in, moved aside and its daemon killed (`archil-scoped retire`).
277
+ - Acquire deals with a dirty mountpoint. A non-empty mountpoint with no mount on it (files written by path after a mount
278
+ vanished) is moved aside to `<mountRoot>/.stray/<run>-<tag>` before mounting, because archil refuses to mount over
279
+ entries; the error is `MOUNTPOINT_NOT_EMPTY` when it cannot. An archil daemon left on the mountpoint with no mount (a client
280
+ that dropped its mount after an authentication failure keeps its process and its control socket) is killed first
281
+ (`archil-scoped stale`; it needs `/proc` to show root's processes). archil's "an older Archil process is still running" and
282
+ "Failed to bind control socket" refusals are `MOUNT_FAILED` (exit 1), no longer `CLAIM_HELD` (exit 76); 76 now means a live or
283
+ orphaned delegation.
284
+
285
+ **The store, the environment, the run**
286
+ - pi's `SqliteStorage` at `synchronous = FULL` in two profiles (exclusive, shared) behind a fence-aware facade: an I/O-class
287
+ error marks the claim fenced and nothing is retried on it.
288
+ - The execution environment: pi's `NodeExecutionEnv` rooted at `work/`, commands under `no_new_privs`, the in-process
289
+ `read`, `write` and `edit` confined to `work/` (resolved real paths, no-follow opens from a pinned directory), `read`
290
+ declared replay-safe.
291
+ - `openDurableRun`: claim, owner lock, `run.json` (status, generation, holder, heartbeat, seal), the store, the seal check
292
+ (`STORE_BEHIND_SEAL`, exit 65), pi's Harness, resume. The lease self-fence runs on a worker thread, so a main thread stuck in
293
+ a FUSE request cannot keep a zombie's commands alive. The lease writes `run.json` and creates its directories through the
294
+ claim directory opened at acquire, checked against the mount table, never by path: a mount that leaves the table under a
295
+ live instance fences it (`CLAIM_UNMOUNTED`, exit 75) at the next heartbeat, and nothing lands under the bare mountpoint.
296
+ An open that fails after the lease is up, including an environment factory that throws (`setpriv` missing), releases the
297
+ claim and the owner lock and stops the heartbeat before it throws.
298
+ - `openRunLease`, the same lifecycle without a store or a Harness, and the `@parcha/pi-durable-archil/lease` entry for a host that
299
+ owns its Harness (`"sideEffects": false`: a bundle of that entry is about 52 KB against 493 KB for the whole package).
300
+
301
+ **The supervisor and the hosts**
302
+ - `ensureRunning` (orphaned, lease fresh, lease expired with best-effort stop of the holder, revoke, start) and the CLI:
303
+ `run --app MODULE`, `supervise` (`--every`, `--check`, `--create`, `--app`, `--sweep-tokens`), `status`, `release`. Exit
304
+ codes 65, 70, 75 and 76 are terminal for the host's process supervisor.
305
+ - `run` drains on SIGTERM: release closes the Harness, then seals and unmounts, and the drain's outcome is the exit code.
306
+ An app's work that rejects when the Harness closes under it ("Session is closed") does not end the instance before its
307
+ release, so no delegation is left orphaned where the FUSE daemon dies with the instance (a container).
308
+ - The start grace: every start writes `runs/<id>/start.json` (the generation the new instance will write, and when) before
309
+ the host driver runs. Until `run.json` reaches that generation or the grace passes (`startGraceMs`,
310
+ `supervise --start-grace`; default the lease expiry, 0 off), a tick reports `starting` and neither revokes nor starts,
311
+ so a short tick never fences the instance it just started.
312
+ - The start backoff: a start that ends before its first `run.json` write (76, `MOUNT_FAILED`) is counted in the
313
+ next start's mark (`failures`, `lastExit`), and that start's grace is doubled per consecutive failure up to
314
+ `startBackoffMaxMs` (`supervise --start-backoff-max`, default 10 min). One `start-backoff` line per step; the first
315
+ `run.json` write resets the count.
316
+ - `localHost`: systemd transient units (`KillMode=control-group`, restart in place), or a detached child for development.
317
+ Its `stop` kills the unit's FUSE scope while it is active, whatever the mount table says: a client whose filesystem
318
+ failed at a token refresh drops its mount but keeps the mountpoint's control socket, which refuses the next mount.
319
+ - `daytonaHost`: a Daytona sandbox per instance with an in-box launcher; power-off, freeze and partition takeovers measured
320
+ live.
321
+ - `deleteRunTree`: revoke, delete, and require an empty prefix.
322
+
323
+ **Package and docs**
324
+ - Compiled `dist/` with declarations (Node 22.19 or later), `exports` for `.` and `./lease`, a `bin`, peer ranges
325
+ `@earendil-works/pi-durable` and `@earendil-works/chord` `~1.0.4`.
326
+ - README (the Durable Object mapping, the failure table, the security model), `examples/01-durable-chat`,
327
+ `examples/02-paid-effect` (a charge cut in flight is never sent twice, across a kill and a freeze) and
328
+ `examples/verify-production-path.sh`.
329
+ - Live suites against a scratch disk (`test/live/`), an acceptance suite on two hosts, and `npm run verify:tarball`.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ AgentRun
2
+ Copyright 2026 Parcha Labs, Inc.