finitechat: single-writer store lease + read-only one-shots + deterministic home-topic key - #572
Merged
Merged
Conversation
…stic home-topic key Two processes sharing one client store could interleave MLS ratchet state and emit an application ciphertext other members can never process (mls_application_ciphertext poison entry, permanent per-device wedge) — the durable-smoke failure class on slow-I/O runners, where one-shot CLI reads raced the resident bridge on the same store. - SqliteClientStore::open takes an advisory exclusive writer lease (fs4); a second process fails fast with WriterLeaseHeld. New open_read_only: no lease, no migrations, all writes rejected. - hermes room-status and plain app state are read-only now; they no longer dispatch StartRuntime against a bridge-owned store. - ensure_home_topic uses a deterministic per-(room, device) idempotency key; a typed 409 conflict adopts the metadata into the local projection instead of appending a second, potentially unprocessable entry. Provisional device-link rooms stop re-firing it every tick. - repair skip-entry keeps the writer open and now enforcedly holds the lease; diagnose/capture are unaffected. Regression tests: cross-process lease fail-fast, read-only alongside a live writer, diverged double-fired home topic adopts without a second log entry, one-shot reads under a held lease.
This was referenced Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes the cross-process poison-entry incident class impossible instead of timing-dependent:
finitechat-client):SqliteClientStore::opennow takes an advisory exclusive lock on<db>.writer-lease(fs4 flock/LockFileEx). A second process opening the same store for write fails fast withClientStoreError::WriterLeaseHeldinstead of silently sharing MLS ratchet state. In-process handles share the lease through aWeakregistry (flock is per open-file-description). Newopen_read_onlyfor diagnostics: no lease, no migrations, every write rejected withClientStoreError::ReadOnly.finitechat-cli):hermes room-statusno longer opens a runtime at all (it dispatched a fullStartRuntimewrite tick against the store the resident bridge owns); it reads the store viaopen_read_onlyand computes the same summary. Plainapp state(no--start-runtime) opens a read-only runtime; read-only dispatch fails withFiniteChatCoreError::ReadOnly.finitechat-core):ensure_home_topicuseshome-topic:<room>:<account>:<device>(per-device because late-joining/linking devices cannot decrypt pre-membership entries and must publish their own create). On the server's typed 409idempotency_conflictthe runtime adopts the deterministic metadata into the local projection without appending — a second entry that members might never process is never written. Provisional device-link rooms no longer re-fireensure_home_topicon every sync tick.Why
The durable smoke failed 6/6 on slow-I/O CI runners: one-shot
docker exec finitechat hermes room-status/app stateexecs raced the resident bridge on the same store; diverged in-memory MLS ratchets emitted ciphertexts for the same generation, and the second entry permanently wedges every other member (mls_application_ciphertext, the 2026-08-06 poison-entry class). Chat correctness must not depend on I/O timing.Server idempotency was verified first: same key + byte-identical request replays the original receipt; same key + any different payload → typed 409. Exact replay of a re-sent MLS ciphertext is impossible (fresh randomness per
create_message), which is why conflict handling is local adoption, and why a fresh-key retry was rejected (it would append the very ciphertext that conflicted).repair skip-entryintentionally keeps the writer open (it repairs the real store with the service stopped) and now enforcedly holds the lease — it fails fast if the service is still running.diagnose rejected-entry(byte copies) andcapture room-log(no store) are unaffected.Tests
writer_lease_fails_fast_for_a_second_process(real cross-process re-exec),read_only_open_reads_alongside_the_writer_and_rejects_writesread_only_runtime_reports_persisted_state_and_rejects_dispatch,diverged_double_fired_home_topic_adopts_instead_of_poisoning_the_logroom_status_and_app_state_read_read_only_while_a_writer_holds_the_store(hermes_flow integration)cargo fmt --check,clippy --all-targets -D warningson all four touched crates, andcargo testfor client/core/cli/daemon all green;cargo checkfor hosted-device and rmp green; Swift bindings unaffected (gitignored, CI-regenerated; regen command verified locally).Not changed: other send paths keep random keys (only home-topic is check-then-send); the lease is advisory and same-machine by design; the durable docker smoke was not re-run (its concurrent one-shots are now read-only by construction and covered by the new integration test).