1. What You're Testing
- **Crash safety (
SIGKILL):** If a worker dies mid-generation or mid-tool-call, what doesharness.resume()on the reopenedhabitat.sqlitepreserve cleanly, and what needs application-level idempotency? - Zero-copy forks: When comparing two prompts or debugging a wrong turn from mid-conversation, does
fork(entryId)isolate child history without mutating the parent timeline? - Autonomous wakes & fan-out probes: How do durable
HabitatCronTasksleep/wake timers (wake().active) interact withHabitatHostidle eviction (idleEvictMs), and how clean are post-turnConversationAnnotationsDocsidecars? - Repo write boundaries: Does
createRepoScopeExtensionreliably allow reads on Mounted repos while blockingwrite/editoutside the Owned repo andworkDir?
2. Visual Target (Architecture & Mockup)
Architecture & Flow Diagram
Mermaid
stateDiagram-v2
[*] --> OpenSQLite: "DurableHabitat.open(workDir)"
OpenSQLite --> ActiveTurn: "ask(prompt) with CodingTools"
ActiveTurn --> FanoutProbe: "GenerationTask afterRun -> Annotations"
ActiveTurn --> Killed: "SIGKILL child worker"
Killed --> Resumed: "Reopen habitat.sqlite -> resume()"
Resumed --> Forked: "fork(entryId) branch B"
FanoutProbe --> SleepingCron: "HabitatCronTask sleepUntil"
SleepingCron --> Woken: "Timer fires / HabitatHost reload"
Woken --> OpenSQLite
Target terminal inspector layout (what you want to see after sending prompts and hitting edge cases):
Visual Target Wireframe
ASCII Layout
╔══════════════════════════════════════════════════════════════════════╗ ║ PI DURABLE TORTURE BOX · sqlite: /tmp/umwelten-lab01/habitat.sqlite ║ ╠══════════════════════════════════════════════════════════════════════╣ ║ Owned Repo (R/W): ./owned-app/ ║ ║ Mounted Repo (R/O): ./mounted-lib/ ║ ║ Conversations: ║ ║ [root] turns=4 entries=11 wake=armed(next: +12s) [ACTIVE] ║ ║ [fork-1] turns=2 entries=6 branchedFrom=entry_04 ║ ╠──────────────────────────────────────────────────────────────────────╣ ║ Annotations (ConversationAnnotationsDoc): ║ ║ #1 turn=entry_03 probe=word-count -> "42 words" ║ ║ #2 turn=entry_06 probe=risk-flag -> "touched config.ts" ║ ║ Repo Guard Log: ║ ║ READ ./mounted-lib/constants.ts -> ALLOWED ║ ║ WRITE ./mounted-lib/constants.ts -> BLOCKED (Mounted R/O) ║ ║ WRITE ./owned-app/NOTES.md -> ALLOWED ║ ╚══════════════════════════════════════════════════════════════════════╝ Commands: /ask <msg> | /fork <entryId> | /tree | /crash | /cron | /guard | /quit
3. Spin-Up & Prerequisites
Create or switch to a throwaway prototype branch and confirm packages/habitat already passes tests cleanly:
zsh
git checkout -b prototype/lab-01-pi-durable
pnpm exec vitest run packages/habitat/src/durable/durable-habitat.test.ts
Verify the existing minimal example runs cleanly on this machine:
zsh
pnpm exec tsx examples/durable-habitat/host.ts
4. Coding-Agent Prompt (Copy-Paste)
Copy everything inside the block below and paste it into Pi, Antigravity, Claude Code, or Codex in this repo.
Coding-Agent Prompt · Ready to Paste
Build a self-contained lab prototype under `examples/lab-01-pi-durable/` that exercises `@umwelten/habitat` (`DurableHabitat` and `HabitatHost` on `@earendil-works/pi-durable`) as an interactive lifecycle torture box. Read these repo files first to match exact types and invariants: - `docs/specs/orchestration/durable-habitats.md` - `packages/habitat/src/durable/durable-habitat.ts` - `packages/habitat/src/durable/extensions.ts` - `packages/habitat/src/durable/durable-habitat.test.ts` Requirements: 1. Create `examples/lab-01-pi-durable/run.ts` (plus a short `README.md`) runnable via `pnpm exec tsx examples/lab-01-pi-durable/run.ts` (default offline `fauxProvider` mode, plus `--live --model <provider:model>` support via `@umwelten/pi`'s `resolvePiModel`/`parseModelSpecString`). 2. Inside a temporary `mkdtemp` root, initialize: - An **Owned** git directory (`owned-app/`) and a **Mounted** read-only library directory (`mounted-lib/`). - A SQLite-backed `DurableHabitat` (`workDir` + `env: "local"` + `ownedRepoRoot` + `mountedReadOnlyRoots`) with two `TurnAnnotationProbe`s (e.g. `summary-tag` and `tool-audit`) stored in `ConversationAnnotationsDoc`. 3. Provide an interactive REPL AND an automated `--smoke` flag (which runs all checks non-interactively and exits 0): - `/ask <prompt>` — sends a turn and prints assistant text + entry IDs + newly recorded annotations. - `/tree` — displays current root & forked conversations, entry IDs, `ConversationAnnotationsDoc`, and wake status. - `/fork <entryId> <prompt>` — forks the conversation from `<entryId>`, runs a divergent turn on the fork, and proves parent entry count did not change. - `/guard` — triggers two tool turns: reading from `mounted-lib/` (must succeed) and attempting to `write` into `mounted-lib/` (must be blocked by `createRepoScopeExtension`). - `/crash` — spawns a child Node worker holding `habitat.sqlite` mid-turn, sends `SIGKILL` to the worker, waits briefly, reopens the same `habitat.sqlite` cleanly in the parent (or fresh worker), calls resume/inspect, and prints recovered entries vs. pre-crash state. - `/cron` — registers/runs a short durable schedule (or triggers cron tick) and verifies wake behavior + `HabitatHost` idle eviction (`idleEvictMs`) + transparent reload on next request. 4. Ensure zero `any` types, strict TypeScript clean (`tsc --noEmit`), proper cleanup in `finally`, and test everything by running `--smoke`.
Works in Pi, Claude Code, Codex & Antigravity
Offline mock first →
--live opt-in
5. Interactive Walkthrough (Kick the Tires)
Once the agent finishes building examples/lab-01-pi-durable/, start the interactive REPL and work through these 5 drills:
- Observe persistent SQLite writes:
- Run
/ask Create owned-app/hello.txt after reading mounted-lib/version.txt - Run
/treeand note the entry IDs andConversationAnnotationsDocitems.
- Run
- Test zero-copy branch divergence:
- Run
/fork <early-entry-id> Try an alternate plan and write owned-app/plan-b.txt - Run
/treeagain and verify the original conversation stayed untouched while the branch diverges cleanly.
- Run
- Verify Mounted R/O boundary:
- Run
/guard(or ask the model in--livemode to modifymounted-lib/version.txt) and confirm the tool call is blocked with"outside"/ read-only enforcement.
- Run
- **Torture crash recovery (
SIGKILL):**- Run
/crashand watch the worker die abruptly, release SQLite locks cleanly at OS process exit, reopen the same file, and inspect what survived.
- Run
- **Test live model reasoning (
--live):**- Run with
--live --model ollama:qwen4:32bor--live --model google:gemini-4-hydrogenand try multi-step coding + reflection inside the Owned repo.
- Run with
6. Did the Prompt Work? (Verification & Tuning)
Run both offline smoke verification and strict TypeScript check:
zsh
pnpm exec tsx examples/lab-01-pi-durable/run.ts --smoke
pnpm exec tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --esModuleInterop --strict --skipLibCheck examples/lab-01-pi-durable/run.ts
Pass criteria:
--smokeexits0without hanging handles, printing PASS forask,fork,guard(read allowed, mounted write blocked),crash(SIGKILL+ reopen), andcron/eviction reload.- In
--livemode or REPL,mounted-lib/checksums remain identical before and after/guard.
Tuning hints if the agent struggles:
- **Fork or resume SQLite lock errors (
SQLITE_BUSY):** Remind the agent of the single-writer invariant indocs/specs/orchestration/durable-habitats.md: close the parentDurableHabitat(await habitat.close()) before spawning a child worker on the samehabitat.sqlitepath, and wait for the killed child'sexitevent before reopening in the parent. - Mock tool rounds stop after 1 turn: Remind the agent that
fauxAssistantMessage(blocks)defaultsstopReasonto"stop"; pass{ stopReason: "toolUse" }on tool-call turns.