← All Labs Lab 07 / 28 Forks copy nothing
Lab 07 · Durable agents · Learned

Forks copy nothing

Forking a DurableHabitat conversation at an entry creates one conversations row with a parent, copies no entries, and leaves the parent's entries unchanged.

Learned Needs: tool-calling Smoke: pnpm exec tsx examples/07-durable-forks/run.ts --smoke Run: pnpm exec tsx examples/07-durable-forks/run.ts Source: examples/07-durable-forks

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

zsh
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

CheckWhat it proves
inherits-to-fork-pointThe fork sees exactly the parent's entries up to the fork point, not the parent's later turn.
parent-unchangedThe parent's entry records are identical (ids and content) before and after the fork's turn.
one-rowhabitat.sqlite has exactly one conversations row with parent: { conversationId, at }, pointing at the root.
zero-copyThe 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

Coding-Agent Prompt · Ready to Paste
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`.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --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 record column 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 bash before write. No check depends on which tools ran.
  • --live through Mycel needs MYCEL_URL. It defaults to localhost:7438. Use MYCEL_URL=https://mycel.thefocus.ai.

Not tested

  • Forking a fork, and forking at a non-answer entry.
  • How docs with a fork policy (such as ConversationAnnotationsDoc, fork: "initial") behave on a fork. The probe and tool-audit material moved out of this lab; what we learned about it is in docs/specs/orchestration/durable-habitats.md.
  • Concurrent turns on parent and fork.

Changes from the torture box

  • The SQLite one-row and zero-copy checks are new; before, the lab only compared entry counts.
  • The fork-docs-empty check 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

Visual Target Wireframe ASCII Layout
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)