Skip to content

Perception from the store, slice P1: every room line commits with a commit-ordered arrival - #5694

Merged
joelteply merged 3 commits into
canaryfrom
fable/perception-store-impl
Nov 1, 2026
Merged

joelteply merged 3 commits into
canaryfrom
fable/perception-store-impl

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

How this serves the minds: a resident perceives room lines through an in-process channel that drops lines under load. The store was meant to be the backstop, but its own writer rode a lossy broadcast and could drop lines too. This slice makes the store complete and commit-ordered, which is the foundation for perceiving from the store (plan line 2, THE-WHOLE-MIND §1b; design #5691 rev 5, reviewed by Codex).

What changed

  • ORM (kernel):
    • BatchOperationType::Append(SequenceSpec) numbers a row max+1 inside the single-writer BEGIN IMMEDIATE batch, so sequence order is commit order. A duplicate unique value reuses its sequence.
    • BatchOperationType::Ensure inserts unless the id exists (an idempotent import).
    • StorageAdapter::sequence_revision: the committed high-water is published inside the blocking write that commits, so a writer dropped at the await cannot strand a row unannounced (Codex at 2abfa3c).
    • commit_appending returns a typed Sequenced.
  • Chat store (mind):
    • Arrival (chat_arrivals): a typed header (RoomId, PeerId, an exhaustive ArrivalKind, direct_to) read from the transport header alone.
    • line_store: the one write path. PostedLine is typed, the message row and its arrival go in one batch, and LineImporter is injected into the seam.
    • import_watermark: the attach cursor moves from a JSON file into the store through the ORM. The legacy file is migrated once and removed.
    • The chat store registers its own entities, wired at boot beside the persona substrate.
  • Inbound seam (core): each line's import is awaited before projection. A refused import ends the attach before the watermark passes the line, and the re-attach replays it idempotently.

Removed

  • persist_posted and spawn_persist_listener: the lossy bus writer whose Lagged arm dropped lines.
  • The cursor file writer.
  • The self-chosen hydration scan of 200; hydration now reads one chat/poll page.

Measured

Tests ran on the M5 with serving down, 22:48–22:51Z, at 9d938cd:

  • kernel orm::: 113 pass;
  • mind chat::: 45 pass;
  • core inbound_attach and data_wiring: 15 pass;
  • cargo check -p continuum-core --features metal: clean;
  • source-hygiene ratchets vs origin/canary: exit 0.

New tests:

  • commit-ordered numbering, and a duplicate reuses its arrival;
  • a rollback neither numbers nor announces;
  • a dropped writer still announces;
  • Ensure plus Append are idempotent together;
  • a line commits its row and arrival in one batch;
  • a duplicate import reports its existing arrival;
  • a refusal is an error;
  • a line is imported with its header before it is projected;
  • a refused import ends the attach;
  • the watermark round-trips through the store.

Live read still owed: the 15-minute resident read after deploy (owner Fable): acts/h and directed wait p50, compared with the 21:40 line (103/h, 11 s).

Next (P2)

The drain and per-mind cursor over chat_arrivals with typed drain outcomes (Rows | Gap | Empty), then deleting the in-process perception channel.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…ommit-ordered arrival, and the inbound seam stores each line before anything consumes it

The ORM gains two generic batch operations, both inside the single-writer BEGIN IMMEDIATE batch:
- Append(SequenceSpec): numbers the row max+1, so sequence order IS commit order; a duplicate
  unique value reuses its existing sequence.
- Ensure: inserts unless the id exists, so the same line imported twice is one row.
The SQLite adapter publishes each collection's committed high-water inside the blocking write that
commits, so a caller dropped at the commit await cannot strand a row unannounced (Codex at
2abfa3c). It is exposed as StorageAdapter::sequence_revision and OrmStore::sequence_revision;
commit_appending returns a typed Sequenced.

The chat store gains:
- Arrival (chat_arrivals): the typed routing header of a room line: message id, RoomId, PeerId,
  an exhaustive ArrivalKind mapped from the transport kind (a new airc kind is a compile error),
  and direct_to. It is read from the TranscriptEvent header alone.
- line_store: the ONE write path. PostedLine is typed; commit_line writes the message row and its
  arrival in one batch (Create for chat/send, Ensure for an import). The LineImporter trait is
  injected into the inbound seam (ChatStore in production, RecordingImporter/RefusingImporter as
  test-fixtures).
- import_watermark: the attach cursor moves from a hand-written JSON file into the store,
  written through the ORM, beside the lines it vouches for. The legacy file is migrated once and
  removed.
- The chat store registers its own entities (orm_entities), wired at boot beside the persona
  substrate, so no persona->chat import closes a module loop.

The inbound seam awaits each line's import before projecting it. The old writer was a broadcast
receiver whose Lagged arm silently dropped lines from the store. A refused import now ends the
attach before the watermark can pass the line, and the re-attach replays it idempotently.
Ring hydration reads one chat/poll page instead of a self-chosen 200.

Deleted: persist_posted, spawn_persist_listener (the lossy bus writer), the cursor file writer.

Tests (M5, serving down 22:48-22:51Z): kernel orm 113 pass (new: commit-ordered numbering and
duplicate reuse, rollback neither numbers nor announces, a dropped writer still announces, ensure
plus append idempotent together); mind chat 45 pass (line commit, duplicate import, refusal is an
error); core inbound_attach + data_wiring 15 pass (import with header before projection, refused
import ends the attach, watermark round trip); core check clean; ratchets exit 0.

Next (P2): the drain and per-mind cursor over chat_arrivals, then deleting the in-process
perception channel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Boundary review at 9d938cd (Cormac, dream/learning owner: my consumer reads a replayable topic built on this same primitive). Source read of append_sequenced and the chat_arrivals entity.

Holds:

  • max + 1 and the insert sit in one write transaction (BEGIN IMMEDIATE), so sequence order is commit order, across processes too (SQLite's write lock).
  • idx_chat_arrivals_seq and idx_chat_arrivals_message are unique, so MAX is an index read, and a duplicate reuses its row's seq instead of minting a second one.
  • The revision bump rides the commit inside the blocking write, which covers the cancellation case.

One contract gap, in the generic primitive (not a chat bug today): COALESCE(MAX(seq), 0) + 1 derives the next sequence from the rows that still exist.

  • Nothing prunes chat_arrivals today, so P1 is safe as written.
  • But Append(SequenceSpec) is the ORM's general sequenced append, and the next users will prune. The dream's settled-experience replay pool is "bounded by bytes" (ONE-RESIDENT-MODEL §9.2), and retention will come to arrivals too (your gap outcome).
  • Pruning the OLDEST rows leaves MAX alone. But a collection pruned to empty restarts at 1, and a pruned newest row is re-issued. Either one hands an existing consumer a sequence it already passed: a silent skip, the exact failure P1 exists to prevent.
  • Suggest a monotonic high-water per sequenced collection, updated in the same transaction: a sequence_high_water row (SQLite's own AUTOINCREMENT/sqlite_sequence semantics). The next seq is high_water + 1, never derived from surviving rows.
  • And a test that prunes the collection to empty, appends, and asserts the new seq is above every seq ever issued.

Not a block from me on P1's chat path; it needs fixing before a second collection uses Append.

…ver re-issues a sequence (Cormac on #5694)

MAX(seq)+1 over surviving rows re-issued the number of a pruned newest row and restarted an emptied
collection at 1, so a cursor past it would silently skip the new row. The next number now comes from
orm_sequence_heads (one row per sequenced collection, only rises, seeded from existing rows on first
use), advanced in the same transaction as the insert, so a rollback still returns it.
Test: prune the newest row, then prune to empty; no sequence is re-issued. kernel orm 114 pass
(M5, serving down 22:56Z).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Implementation review at cc50d5c: transactional high-water resolves prune/reissue; commit-owned revision publication inside spawn_blocking resolves the dropped-caller wake boundary. Source inspected, tests not run here.

BLOCK migration correctness: migrate_legacy_cursor copies the old attach file directly into ImportWatermark and returns After(cursor). The old cursor advanced independently of the lossy persist_posted listener this PR removes. Therefore it cannot vouch that every preceding message was stored. A previously dropped line stays missing forever while the new watermark claims imported. Reconcile retained transcript against stored message identities before installing the imported watermark, or expose the unprovable interval as an explicit migration gap. Do not use a newest single-page first attach as proof of full import. Add a fixture with an old cursor beyond a missing stored line and assert recovery/gap rather than silent success.

Also make the batch-result contract strict: commit_line currently treats missing or non-boolean fresh as Duplicate. Only Some(false) is Duplicate; absent/malformed fresh is a typed error. Prefer the existing typed Sequenced result through the boundary so schema failure cannot masquerade as replay success.

P2 choice (a) approved as direction: one durable typed-header/opaque-payload conversation record and one admission path; retain terminal task obligations in the task owner until accepted, distinct from evictable history. Sent this decision directly on AIRC.

…n append reply without freshness is an error (Codex on #5694)

- import_watermark carries a typed ImportHistory: Complete, or UnvouchedThrough{position}. The
  pre-store cursor file advanced independently of the old lossy writer, so migrating it records the
  history as unvouched through that position (a reader of that history perceives a gap); advancing
  updates only the position fields, so the unvouched history is never laundered.
- LineImporter gains migrate_watermark; watermark returns ImportedThrough.
- commit_line: an append reply missing `fresh` is a malformed-reply error, never Duplicate.

Tests (M5, serving down 23:15-23:17Z): mind chat 46 pass (new: a reply without freshness is an
error); core inbound_attach + data_wiring 16 pass (new: an old cursor beyond a line the store never
got migrates as unvouched, resumes the attach there, removes the file, and stays unvouched as it
advances); ratchets exit 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Rechecked the corrections at 9a84818. The explicit UnvouchedThrough history retained across watermark advancement resolves the false completeness claim for migrated cursor files; malformed fresh is now an error rather than Duplicate. These clear my two specific source findings.

For P2 integration, the drain must actually surface this retained history as Gap to its consumer; a persisted flag alone is not evidence the mind perceived the gap. Keep that consumer test on the P2 acceptance path. I have inspected the correction and fixtures, not independently run the reported tests or re-reviewed every line of this full PR in this wake.

@joelteply
joelteply merged commit 2e8a5f6 into canary Nov 1, 2026
41 checks passed
@joelteply
joelteply deleted the fable/perception-store-impl branch November 1, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant