Skip to content

Store: several serving processes on one host — declaration fence, setup refusal, single audit drainer (#927) - #936

Merged
jimhoyd merged 4 commits into
mainfrom
claude/store-multiprocess-fence
Sep 29, 2026
Merged

jimhoyd merged 4 commits into
mainfrom
claude/store-multiprocess-fence

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

The store items of #927. The auth items are in #934. The Linux multi-process CI harness and the remaining docs are still open on #927.

Design

  • Schema step 4→5 adds three things:
    • store_declarations: collection, fingerprint, schema version;
    • store_servers: instance, host, boot id, pid, heartbeat, expiry;
    • a rebuilt store_audit_drain with holder and lease_until.
  • Declaration fence.
    • The fingerprint is the SHA-256 of the normalized collection declaration, with named schemas resolved.
    • The newest activation records its fingerprints, but only after every stored row validates.
    • Every write path first checks, inside BEGIN IMMEDIATE, that its fingerprint and the file's user_version are current. One indexed read covers HTTP writes, increments, transitions, transfers, clicks, the records export and host transaction().
    • A stale process gets 503 "The collection was redeclared by another process", and nothing is written. Reads keep working.
    • Blue/green is now safe: the retiring process just stops writing.
    • If the newest activation closes while an older one is still live, the older fingerprints are recorded again.
    • Operator CLI writes are refused only when a live server holds a different declaration.
  • Setup refusal.
    • On Linux, statfs refuses NFS, SMB, SMB2, CIFS, FUSE, 9P, Ceph and AFS for both the store and audit databases. It is skipped on macOS and Windows, which is documented.
    • A server lease (5 s heartbeat, 20 s expiry) refuses activation while a live peer reports a different boot id, i.e. another host. Containers on one host are accepted.
    • With a live peer, activation logs one warning that throttle policies and origin caches are per process.
  • One audit drainer. A 10 s lease means only the holder peeks and acks. Closing releases the lease, so a peer takes over at its next poll.

Evidence (macOS, Node 26), rebased onto main after the auth change

  • New multiprocess.test.ts (9 tests), with real node child processes, not threads:
    • two v1 children write, a v2 candidate fences both, reads still work, and nothing is written;
    • the same declaration in two registrations writes, and a user_version bump fences both;
    • a fake boot id is refused as another host, and the same boot id with a different hostname is accepted;
    • an expired lease is ignored;
    • the injected-statfs refusal and the CLI fence;
    • upgrading from v4 keeps drained_at;
    • drain-lease takeover delivers exactly once.
  • Reload tests changed on purpose: the retiring runtime's writes now get 503 and its reads work. A new test checks that a failed replacement re-records the older declaration.
  • npm run verify passes: store 182, audit 44, root 1226, plus the add-ons, proofs and ecosystem suites. npm run test:package passes.
  • Store budget raised to 132 / 502 KiB and 34 entries (measured 131,979 / 510,186 bytes).

Limits

  • A previous release on schema v4 running beside this one can't be fenced (noted in the CHANGELOG).
  • An audit-only site (no store) has no multi-host lease.
  • The Linux CI harness is not done: kill -9 and integrity checks, cross-process race suites, audit exactly-once across processes, and a sign-in burst.
  • Not updated: CAPACITY, the throttle and cache pages, OBSERVABILITY.

🤖 Generated with Claude Code

…n fence, setup refusal, single audit drainer (#927)

Schema version 5 adds store_declarations, store_servers and the audit drain
lease. Each activation records its collections' declaration fingerprints; every
write transaction checks them and user_version under the write lock and answers
503 storage_unavailable on a mismatch, writing nothing. Activation refuses a
database on a network filesystem (Linux statfs; also for the audit database) and
a live peer on another host (boot id / hostname lease), and warns once that
throttles and caches are per process. Only the drain lease holder peeks and acks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 29, 2026 17:10
jimhoyd and others added 3 commits September 29, 2026 12:22
… busy-timeout 503 in the cross-connection transfer race

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit 6ddfa61 into main Sep 29, 2026
26 checks passed
@jimhoyd
jimhoyd deleted the claude/store-multiprocess-fence branch September 29, 2026 17:40
jimhoyd added a commit that referenced this pull request Sep 29, 2026
jimhoyd added a commit that referenced this pull request Sep 30, 2026
…ock (#1050)

* One serving process per database: replace the host lease with an OS lock

Owner decision: several serving processes on one database are no longer
supported (they need a real database server, which URLCode does not provide),
to cut owned code. The multi-process support built in #927/#936/#941/#978/#1010
goes away and is replaced by an OS-enforced server lock.

- core: server-lock.ts replaces host-lease.ts. holdServerLock takes an
  exclusive SQLite file lock on <database>.server-lock (held by a transaction
  that never ends), refcounted per process so a dev reload shares it; the OS
  drops it when the process dies. serverLockHeld lets operator commands see a
  live server. refuseNetworkFilesystem stays; HostProbe keeps platform/statfs.
- store: the lock is taken before the database opens; the host lease, the
  per-write lease check (writeGuard), the audit drain lease and the peer
  warning are gone. Schema 6 drops store_servers and the drain lease columns.
  The declaration fence stays for a reload's retiring activation and for
  operator commands, which now ask serverLockHeld.
- auth: each activation holds the lock; the per-request renew and the
  temporary write triggers are gone; auth_servers is dropped.
- audit: the first activation holds the lock; the per-ingest check and
  AuditStore.lease are gone; audit_servers is dropped on open.
- tests: the multi-process harness, its CI job and the clock-skew, heartbeat,
  suspended-VM and trigger tests are removed. New focused tests prove a second
  server process is refused and a restart after SIGKILL is accepted (core,
  store with integrity_check after SIGKILL mid-burst, auth, audit). The
  disk-full harness keeps its CI job (renamed disk-full).
- docs: topology sections rewritten around one serving process per database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: bound the server lock tests on every platform (Windows hang in #1050)

test/server-lock.test.ts hung for ~10 minutes on windows-latest. Every wait on
a child process is now bounded with the child's stderr in the failure, stdout is
read to its end, a refused child exits only after its line is written, per-test
timeouts are set, and cleanups run newest first so a child is killed before its
directory is removed (Windows cannot delete a file another process holds open).
After a SIGKILL the core, store, auth and audit lock tests poll (at most 10 s)
for the lock to be released: Windows releases a terminated process's locks
after an OS-determined delay rather than at exit. STORE.md and holdServerLock's
comment document that a restart straight after a crash on Windows can be
refused once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant