Skip to content

feat(core,auth,audit): refuse a second host and a network filesystem without the store (#941) - #949

Merged
jimhoyd merged 3 commits into
mainfrom
claude/host-lease-941
Sep 29, 2026
Merged

jimhoyd merged 3 commits into
mainfrom
claude/host-lease-941

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #941

What changes

  • Core gains packages/core/src/host-lease.ts, re-exported from @jimhoyd/urlcode/extensions: refuseNetworkFilesystem(directory, what, probe?), joinHostLease(db, {table, what, probe?, now?}), hostProbe, NETWORK_FILESYSTEMS, SERVER_LEASE, and the types. It is the store's topology.ts logic made generic: the table name and the database name in the error are parameters. The lease table is created when it is missing (CREATE TABLE IF NOT EXISTS). db can be a plain node:sqlite DatabaseSync (the helper runs its own BEGIN IMMEDIATE, and does it outside its try, so a failed BEGIN never rolls back a transaction someone else opened) or an object with transaction/run/all (the store's StoreDatabase).
  • Store: topology.ts is now a thin wrapper. joinServers calls joinHostLease(db, {table: 'store_servers', what: 'store'}) and re-exports the rest. The store's behavior, table, messages and tests are unchanged, and its test files are untouched.
  • Auth: activation and the urlcode-auth commands (migrate, create-user, find-user) refuse a database directory on a Linux network filesystem, using the same statfs list. Each activation joins auth_servers in auth.sqlite and is refused while a live peer runs on another host. close() releases the lease. createAuthExtension takes a probe test seam.
  • Audit: drops its own copy of NETWORK_FILESYSTEMS/refuseNetworkFilesystem and uses core's. The first activation joins audit_servers in audit.sqlite, and the audit host holds that lease until close(). A refused join is retried by the next activation. activate is now async. createAudit/openAuditStore take a probe test seam.

Why a core helper

Before this PR the logic had two copies (store, audit), and #941 would have added a third (auth). Core's @jimhoyd/urlcode/extensions already exports shared extension helpers for exactly this reason: assertSafePattern "instead of maintaining its own copy that can drift", isSameOriginRequest, clientKey, readBody. The helper is generic: it has no store tables or types and no knowledge of any package. Each extension names its own table in its own database. Core still imports no package (the core boundary check passes). I did not make it a store-exported helper, because auth and audit would then depend on the store, and the point of #941 is sites that do not have it.

Tests

  • test/host-lease.test.ts (core rules):
    • a live peer with another boot id refuses the join, and a refused join leaves no row;
    • a peer with the same boot id but another hostname (a container) is accepted;
    • an expired lease (by row or by the now clock) does not count;
    • without a boot id, peers are compared by hostname;
    • close deletes the row;
    • the lease never ends a transaction someone else opened;
    • a bad table name is refused;
    • network filesystem types are refused on Linux (including a negative 32-bit f_type); ext4 passes, and darwin/win32 are not checked.
  • packages/auth/test/auth.test.ts:
    • a network filesystem is refused on Linux via probe, and not checked on darwin;
    • a peer on another boot id refuses startServer, a same-kernel container starts, and an expired leftover lease does not count.
  • packages/audit/test/audit.test.ts: the same lease cases through createAudit/activate, including that the refused audit stays inactive and activates once the peer closes.
  • The existing multi-process auth tests (two real serving processes on one host) and npm run test:multiprocess still pass, so several processes on one host stay supported.
  • Windows: the new tests are sequential and hold no lock across processes. The lease heartbeat swallows a busy lock and retries at the next beat.

Run locally on macOS, Node 26: npm run verify (everything up to the package audit passed on the first run; the rest passed after the budget update), npm run audit:packages, npm run test:addons, test:proof, test:proof:authjs, test:ecosystem, test:multiprocess, npm run test:package.

Budgets

Core measured 1019347 packed / 4025827 unpacked bytes and 519 entries (Node 26). Its budget goes to 1000 KiB packed and 3935 KiB unpacked, which leaves room for Node 24's roughly 800 extra packed bytes plus about 3 KiB of headroom. The audit and store packages shrank (27304 and 130904 packed bytes); auth is at 18276, under its 21 KiB budget.

Docs

  • docs/STORE.md: "Only the store detects another host" becomes "Every SQLite extension detects another host".
  • docs/EXTENSIONS.md: the helper table.
  • docs/FRAMEWORK.md, docs/OPERATIONS.md, docs/CAPACITY.md.
  • docs/RUNTIME-IMPLEMENTATION.md: the RIM-STORE-PERSIST-001 card now points at the core seam.
  • The auth and audit READMEs and the auth, audit and store CHANGELOGs.
  • The llms-full.txt copies of these pages.

Limitations

  • Not tested on two real hosts; the tests fake the boot id and hostname through probe.
  • Each lease guards only its own file. On macOS and Windows a network filesystem is noticed only through the lease, and only while both hosts are serving.
  • The auth lease shares Better Auth's connection. A heartbeat that fires while a Better Auth transaction is open is skipped (BEGIN fails) and retried 5 s later, well inside the 20 s TTL.

🤖 Generated with Claude Code

…ork filesystem without the store (#941)

The network filesystem check and the host lease move from the store into core
(packages/core/src/host-lease.ts, exported by @jimhoyd/urlcode/extensions as
refuseNetworkFilesystem and joinHostLease). Each SQLite extension keeps its
lease in its own database: store_servers (unchanged), auth_servers (one row per
auth activation) and audit_servers (from the first audit activation until the
audit host closes). Auth now also refuses a database directory on a Linux
network filesystem, at activation and in the urlcode-auth commands. Audit drops
its own copy of the filesystem list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 29, 2026 19:00
jimhoyd and others added 2 commits September 29, 2026 14:48
…se and hermetic seeding compose

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y is removed (Windows hang)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit a2c29e2 into main Sep 29, 2026
28 checks passed
@jimhoyd
jimhoyd deleted the claude/host-lease-941 branch September 29, 2026 20:12
jimhoyd added a commit that referenced this pull request Sep 29, 2026
jimhoyd added a commit that referenced this pull request Sep 29, 2026
* fix(scripts): pack-addons refuses unbuilt add-ons, and install names a missing ./extension file (#960)

pack-addons packs with --ignore-scripts, like every pack in the repository, so it
never builds. It now refuses, before packing anything, a package whose exports or
bin name a file that is not there, naming each file and the build that makes it.

Installing an add-on whose ./extension export points at a missing file now says
so and names the file, instead of claiming the package has no ./extension entry.

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

* Merge main into claude/pack-addons-960 (#949, #967); re-measure budgets

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.

[Request]: auth and audit without the store do not refuse a second host (auth also not a network filesystem)

1 participant