Artifact 679cbe7dbfdc279a237ab677d87c35af346c0bdca78dd98013b767bde6d11bf8:
- File
docs/dev/architecture.md
— part of check-in
[eae917e9e9]
at
2026-11-21 12:03:36
on branch shared-store
— Shared journal store: several pic processes on one workspace, one conversation each
Each conversation has a lease (an exclusive flock beside the journal) that its process holds while it advances it and that the kernel drops when the process and its forked children are gone. Taking a lease claims the conversation's request and settles what a dead owner left; open recovers only conversations whose lease is free. The journal lock is held shared and taken exclusive only to create or migrate the schema. SQLite runs in normal locking mode with the fair busy handler; dev builds stop on a write begun under an open read.
pic run takes only requests nobody is running. A second pic asking into a conversation in use is refused with its owner's pid. An edit that misses in a file another conversation changed says so and shows the file; a write to such a file is refused once.
New test/pic/shared.sh: two-process crash matrix, kill -9 beside a live pic, claim and admission races, stale-file results. No schema change. (user: dmestas, size: 1762) [annotate] [blame] [check-ins using] [more...]
Architecture
State
pic's state lives in SQLite: the journal per workspace (WORKSPACE/.pic/journal.sqlite, pic_*
tables) and ~/.pic/pic.sqlite (picu_* tables) for settings, the model catalog, credentials,
trust decisions, process records and the conversation lines that ctx archives. Several pic
processes share a journal, one conversation each; durability says what is committed
when and who may work a conversation.
The operating system seams
What touches the operating system sits behind two interfaces: pic_platform (clocks, entropy, the
locks, input files, the SQLite VFS) and pic_executor (file operations and running commands).
Host-only code stays behind them, which is what makes the targets in where pic can
run reachable.
The terminal interface
The terminal interface is a module in the pic binary (src/tui/). It runs each request as a child
pic --json process and knows the run only through Pi's JSON events, so a fault in the interface
cannot touch a run.
The credential store
Each stored key is sealed with ChaCha20-Poly1305 (the provider's name bound as associated data), so
no plaintext key reaches the database, its WAL, a backup or a log. The sealing key comes from a
passphrase, stretched with PBKDF2-HMAC-SHA256 (600,000 iterations, a random salt; both kept in
picu_credential_key with a verifier, so a wrong passphrase is refused cleanly). What it protects
against is in credentials.
The behavioural reference
reference/pi.lock.json pins the Pi revision used as the behavioural reference. Pi's source is not
part of this repository. The decisions in force are in the implementation
plan.