← All Labs Lab 12 / 28 A pi-durable store as Explorations
Lab 12 · Durable agents · Learned

A pi-durable store as Explorations

Projecting a directory with @umwelten/sessions turns a pi-durable habitat.sqlite into one Exploration per conversation, forks included, without writing to the store.

Learned Needs: chat Smoke: pnpm exec tsx examples/12-durable-store-as-explorations/run.ts --smoke Run: pnpm exec tsx examples/12-durable-store-as-explorations/run.ts --keep Source: examples/12-durable-store-as-explorations
bash
pnpm exec tsx examples/12-durable-store-as-explorations/run.ts --smoke

The script runs one DurableHabitat turn, forks the conversation at the answer and runs a different turn on the fork, and closes the habitat. Then it makes habitat.sqlite and its directory read-only and projects the directory with @umwelten/sessions (projectSessions, then the pi-durable adapter's getMessages). It uses an offline faux model.

CheckWhat it shows
one-per-conversationThe root and the fork are two source sessions and two Explorations
root-unchangedThe root's messages are its own two; nothing from the fork leaks in
fork-inherits-and-divergesThe fork starts with the root's question and ends with its own answer
store-untouchedThe read-only store projects, and its files hash the same with no new -wal/-shm files

Break it

Put back the adapter from before the read-only fix (git show 51cfcdd:packages/sessions/src/adapters/pi-durable-adapter.ts). It opens the store read-write to run migrations, so it can't read a store it can't write. The first three checks fail and the smoke exits 1.

Session search and knowledge promotion used to be part of this lab. They're out until each can be its own lab; see FINDINGS.md.

Prompt

Coding-Agent Prompt · Ready to Paste
Build a self-contained script that runs one turn in a SQLite-backed DurableHabitat with a faux model, forks the conversation at the answer with habitat.fork and runs a different turn on the fork, and closes the habitat. Make habitat.sqlite and its directory read-only, then project the directory with @umwelten/sessions projectSessions and read each pi-durable session's messages through the registered pi-durable adapter. Check, one PASS/FAIL line each and exit 1 on any failure: the root and the fork become two Explorations; the root's messages contain nothing from the fork; the fork's messages start with the root's question and end with its own answer; every habitat.sqlite* file hashes the same before and after, with no new files.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in

What we learned

The answer

A pi-durable store reads cleanly as Explorations. A root conversation and a fork of it become two Explorations. The fork's transcript starts with the root's question, then has its own turn; the root's transcript has nothing from the fork. Projection works on a store whose file and directory are read-only, and leaves the files byte-for-byte unchanged.

What going through it found

  • Projection opened habitat.sqlite read-write. pi-durable's SqliteStorage.open always runs migrations, so reading a store written by an older pi-durable would have migrated it in place, and a store the user can't write couldn't be read at all. The adapter now reads on a read-only connection that creates no files, and skips an older-schema store with a warning (D-31). With the old adapter this lab's read-only store projects 0 sessions.
  • A hash alone didn't catch it. The first version only compared file hashes, and the old read-write reader passed: on a current store, pi-durable's migration writes left no trace in the main file. Making the store read-only is what turns a writing reader into a failure.
  • The lab tested three things. It also loaded @umwelten/pi onto a stand-in host to promote a hard-coded rule into FACTS.md, and printed that session search can't find the conversation. Both are out:
  • Promotion promoted a constant, not something read from the conversation, so it showed the tool writes a file and nothing about Explorations. It becomes its own lab once it promotes from a projected conversation.
  • Search (umwelten_session_search) only scans Claude Code *.jsonl under ~/.claude/projects, so it can't find pi-durable or pi JSONL sessions, although the tool's description says it can. It becomes its own lab once that's fixed; the options are to search what projectSessions(cwd) finds, add each adapter's roots, or narrow the description.
  • Forks weren't tested before. They are now, and each fork is its own Exploration as the spec says.

Gotchas

  • Register the adapters before projecting. projectSessions uses whatever adapters are registered; with none it returns no sessions and no error. Call getAdapterRegistry() (or initializeAdapters()) first.
  • A fork's transcript includes what it inherited. The adapter reads a fork's entries the way pi-durable presents them, parent entries first, so a fork's Exploration has the same name as its root (the first question).

Not tested

  • A live writer holding the store open while it's projected (the adapter then uses a plain read-only connection rather than an immutable one).
  • Stores from an older pi-durable schema (the adapter's unit tests cover the skip).

Smoke run

Visual Target Wireframe ASCII Layout
  PASS  one-per-conversation: 2 pi-durable session(s), 2 Exploration(s) for root + 1 fork
  PASS  root-unchanged: root has 2 message(s) and none from the fork
  PASS  fork-inherits-and-diverges: fork has 4 message(s): the root's question, then its own turn
  PASS  store-untouched: read-only habitat.sqlite: hash 285625d2d34a543a -> 285625d2d34a543a, no new files

  4/4 passed