The lab runs two turns on a DurableHabitat root, forks at the first answer, and runs a different turn on the fork. It checks what the fork sees and that the parent is untouched, then reads habitat.sqlite to show the fork is one row that points at its parent and stores only its own entries.
Run it
pnpm exec tsx examples/07-durable-forks/run.ts # narrated, offline faux model
pnpm exec tsx examples/07-durable-forks/run.ts --smoke # PASS/FAIL lines, exit 0 when all pass
MYCEL_URL=https://mycel.thefocus.ai pnpm exec tsx examples/07-durable-forks/run.ts --live --model mycel:z-ai/glm-5.3-flash
Add --keep to keep the temp root.
Checks
| Check | What it proves |
|---|---|
inherits-to-fork-point | The fork sees exactly the parent's entries up to the fork point, not the parent's later turn. |
parent-unchanged | The parent's entry records are identical (ids and content) before and after the fork's turn. |
one-row | habitat.sqlite has exactly one conversations row with parent: { conversationId, at }, pointing at the root. |
zero-copy | The entries rows stored under the fork are only its own new entries. |
Break it
In DurableHabitat.fork (durable-habitat.ts), fork from the parent's latest entry instead of atEntryId. inherits-to-fork-point fails (the fork sees 7 entries instead of 3) and the smoke exits 1.
Files
run.ts— the fork drill and the SQLite checks.PROMPT.md— prompt to rebuild this lab.FINDINGS.md— what we learned.
Prompt
Build a standalone lab under `examples/07-durable-forks/` that tests one thing: forking a SQLite-backed `DurableHabitat` conversation (`@umwelten/habitat` on `@earendil-works/pi-durable`) copies nothing and leaves the parent unchanged.
Read these files first to match exact types and invariants:
- `docs/specs/orchestration/durable-habitats.md`
- `packages/habitat/src/durable/durable-habitat.ts` (`ask`, `fork`)
Requirements:
1. One file, `examples/07-durable-forks/run.ts`, runnable via `pnpm exec tsx examples/07-durable-forks/run.ts`. Do not import from other example folders.
2. Default to an offline `fauxProvider` from `@earendil-works/pi-ai` (a self-replenishing `FauxResponseFactory`: "write <file>" becomes a `write` tool call into `owned-app/`, with `{ stopReason: "toolUse" }`). Support `--live --model <provider:model>` via `resolvePiModel(parseModelSpecString(spec))` from `@umwelten/pi`.
3. In a `mkdtemp` root, create `owned-app/` and open `DurableHabitat` with `workDir`, `env: "local"` and `ownedRepoRoot`. No probes or hooks: this lab is about forks only.
4. Run two root turns (a plain one, then one that writes `notes.txt`), so the parent has entries after the fork point. Fork at the first answer's entry id with `habitat.fork(id, { from: root })`, then run a different turn that writes `plan-b.txt` on the fork.
5. Checks, each printed as `PASS <name>: ...` or `FAIL <name>: ...`: inherits-to-fork-point (the fork's entry ids equal the parent's ids up to the fork point), parent-unchanged (the parent's full entry records are identical before and after the fork turn, and the fork added entries of its own). After closing the habitat, open `habitat.sqlite` read-only with `node:sqlite` and check one-row (exactly one `conversations` row has a `parent` pointing at root) and zero-copy (`entries` rows with the fork's `conversation_id` equal only its new entries).
6. `--smoke` prints only the PASS/FAIL lines and exits 0 only if all pass; without it, narrate each turn. `--keep` keeps the temp root.
7. Strict TypeScript, zero `any`. Close the habitat and the DB and remove the temp root in `finally`. Verify with `pnpm exec tsc --noEmit -p examples/tsconfig.json` and `--smoke`.
Also write `README.md` (frontmatter: title, track, status, tests, needs, run, smoke), `PROMPT.md`, and `FINDINGS.md`.
--live opt-in
What we learned
The answer
A fork is one conversations row with parent: { conversationId, at }. No entries are copied: the entries table holds only the fork's own new entries under its id (4 rows for one tool turn), and it reads the 3 inherited entries through the parent. It does not see the 4 entries the parent wrote after the fork point. The parent's entry records were identical, id for id and byte for byte, after the fork's turn.
Gotchas
- Fork ids are record ids. The fork's conversation id (20 in the smoke run) comes from the shared id sequence, not a small counter.
- Querying the SQLite file directly: the
recordcolumn is JSON. Close the habitat before opening the file, and open it read-only. - Live models may use extra tools. On GLM, turn 2 ran
bashbeforewrite. No check depends on which tools ran. --livethrough Mycel needsMYCEL_URL. It defaults tolocalhost:7438. UseMYCEL_URL=https://mycel.thefocus.ai.
Not tested
- Forking a fork, and forking at a non-answer entry.
- How docs with a
forkpolicy (such asConversationAnnotationsDoc,fork: "initial") behave on a fork. The probe and tool-audit material moved out of this lab; what we learned about it is indocs/specs/orchestration/durable-habitats.md. - Concurrent turns on parent and fork.
Changes from the torture box
- The SQLite
one-rowandzero-copychecks are new; before, the lab only compared entry counts. - The
fork-docs-emptycheck is new; before, it was stated but not checked.
Trimmed to forks only
The probes, tool-audit, fork-docs-empty, fork-probes and fork-side-effect checks are gone. They tested annotation probes, a tool hook and the write tool, mostly on the root, not forks. parent-unchanged now compares full entry records instead of counts, and inherits-to-fork-point is new: it is the check the break test trips.
Smoke run
PASS inherits-to-fork-point: fork 20 sees entries [7, 10, 11]; parent up to #11: [7, 10, 11]; 4 later parent entries left out
PASS parent-unchanged: parent's 7 entry records identical before and after; fork added 4 of its own
PASS one-row: 1 conversations row with a parent: {"conversationId":1,"at":11}
PASS zero-copy: entries rows stored under the fork = 4 (only its new entries; nothing copied)