Repository navigation
One serving process per database: replace the host lease with an OS lock - #1050
Merged
Merged
Conversation
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]>
jimhoyd
enabled auto-merge (squash)
September 30, 2026 13:51
…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]>
jimhoyd
added a commit
that referenced
this pull request
Sep 30, 2026
Takes main's side for the host lease and multiprocess removal (#1050) and keeps the OpenAPI security scheme changes (#1047). Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd
added a commit
that referenced
this pull request
Sep 30, 2026
… the paths-filter plan Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 30, 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.
Owner decision
URLCode now serves each SQLite database (store, auth, audit) from one process. Running several servers on one database needs a real database server, and URLCode does not provide one. The goal is less owned code. This removes the multi-process support from #927, #936, #941, #978 and #1010: the host lease with its heartbeats, liveness watching and clock-skew handling; the per-write lease checks in store and audit; auth's per-request
renew()and its temporary write triggers; the audit drain lease; and the multi-process harness. An OS-enforced lock that only serving processes take replaces all of it. The owner is the only user, so this PR has no back-compat, aliases or migration shims. The one exception is a forward-only drop of the old lease tables.Refs #1041 (row 1, "One serving process per database").
The lock
packages/core/src/server-lock.tsreplaceshost-lease.ts.holdServerLock(database, what, probe?)works like this:refuseNetworkFilesystem, unchanged).<database>.server-lock(0600) and runsPRAGMA locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE. That transaction stays open for the life of the server.The lock is SQLite's own
fcntl/LockFileExlock, so the OS releases it when the process dies. There are no heartbeats, timestamps, hostnames, boot ids or clocks, and no native modules. Node has noflockAPI, so this was the cleanest OS-backed option without native code. It was checked empirically: afterkill -9of the holder, a new process takes the lock at once.A second serving process is refused before it reads or writes the database:
Another process is already serving this store database (<path>): URLCode serves each database from one process. Stop that server first. Several servers need a real database server, which URLCode does not provide.Dev reload: holders in one process share the lock through a refcount. The refcount lives on
globalThisunder aSymbol.forkey, so a second copy of core shares it too. A reload's two activations therefore never refuse each other.serverLockHeld(database)lets an operator command check for a live server without taking the lock. It holds a momentary shared lock that fails while a server holds the exclusive one. The server's acquire waits 500 ms, so this brief check can never refuse a starting server.Operator commands (
urlcode-store members/ownerless-*/reassign/backup,urlcode-auth migrate/create-user/find-user,urlcode-audit list/backup/restore) never take the lock. They share the database through SQLite's own locking, as before.Hermetic runs use fresh data directories, so their locks never meet a served site's lock.
HostProbeis now{platform, statfs}.bootId,monotonic,sleepandhostnameare removed.Per extension
openStoreDatabase, since opening can migrate and so write. The PR removestopology.ts,StoreDatabase.writeGuardandtransaction'sguardedargument,holdsAuditDrain,auditDrainHolder,releaseAuditDrainandliveServer, and the live-peer warning. The serving process is the only audit drainer: peek, and ack as a plain delete. Schema 6 dropsstore_serversand the drain columnsholderandlease_until. The upgrade from versions 4 and 5 is tested.guardWrites, the TEMP triggers,urlcode_auth_lease, and the per-requestserving()/renew().auth_serversis dropped on activation. A failed activation releases its share ([Bug]: auth activation that fails after joining the host lease leaves the auth_servers row and a heartbeat timer running #979).close(). Removed:AuditStore.lease()and the per-ingestverify().audit_serversis dropped when the database opens.Declaration fence (#936): kept, only the liveness source changed
The fence is still needed with one process, for two cases:
servingfence stops it writing rows the new declaration forbids.operatorFencerefuses a write when the server has recorded a different declaration. "Is a server live" used to bestore_serversexpiry and is nowserverLockHeld(db.path).The 503 message is now
The collection was redeclared by a newer activation.Behaviour change to note: a pinned
urlcode validateorurlcode routesactivates against the site's livedata/, so it is now refused while the site is served. Before, it joined the lease as a peer and recorded its declarations, which could fence the running server's writes.test/private-requests.integration.tsnow stops its server before the MCPrun_validate/run_teststep.--local-reviewand hermetic runs are unaffected.docs/OPERATIONS.md's deployment procedure for SQLite-backed sites is now: check the candidate on a copy or--local-review, then stop the old process and start the new one.Tests
test/multiprocess.integration.ts,npm run test:multiprocess, its CI job and gate entries,test/host-lease.test.ts,packages/store/test/multiprocess.test.ts(the lease, heartbeat, clock-skew, suspended-VM and drain-lease tests), auth's lease, trigger and [Bug]: Host lease: a resumed suspended VM passes verify() without reading the table; auth's per-request check misses a mid-request stall; docs overclaim #1010 tests, audit's lease tests, andrace-worker.ts. Worker threads are other connections in the same process and now correctly hit the lock, sorace()now runs its racers as several registrations/connections of the one process, interleaved.test/server-lock.test.ts: a real child process holds the lock and this process is refused;kill -9frees it at once; in-process holders share it; the network filesystem refusal is checked before the lock.packages/store/test/server-lock.test.ts: a second server process (and this process) is refused and writes nothing. The first process isSIGKILLed in the middle of a 50-write burst, thenPRAGMA integrity_checkisok, every answered write is stored, and the restart is accepted at once. The file also covers the fence between activations, the operator fence against a server in another process and in this one, the network filesystem refusal, and the v4/v5 → v6 upgrade.test/disk-full.test.tsis unchanged. The CI job formerly namedmultiprocessis nowdisk-fulland runs only the tmpfs harness. Only the lease/heartbeat prose was dropped from its docs.Line counts (
git diff --numstat origin/main)CI means
.github/workflows/ci.yml,package.json,scripts/ci-plan.tsand their two tests (test/ci-plan.test.ts,test/ci-workflow.test.ts).Source detail:
host-lease.ts−279 →server-lock.ts+124;store/src/topology.ts−23; storedatabase.ts+18/−54,store.ts+35/−62; authauth.ts+22/−46; auditstore.ts+4/−17.Package budgets
Both sides were measured locally on Node 26 with
npm run audit:packages,origin/main(df0cfd52) against this branch:Every drop is small (at most about 4%), so under the policy comment in
scripts/package-audit.tsthe table is not reset. Separately,main's core packed size (1,091,595) already measured 11 bytes over its limit (1066 * 1024) on local Node 26. This branch brings it back under. The core table needs its own reset in a later change.Docs
#one-serving-process-per-database, the lock, what it does not do, what the tests prove), CAPACITY.md, OPERATIONS.md (deployment and rollback), OBSERVABILITY.md, CI.md, EXTENSIONS.md (helper table), FRAMEWORK.md, and the throttle and cache policy pages.llms.txt, the storellms.txt, and the regeneratedllms-full.txt.Evidence
npm run verify: green locally (macOS, Node 26), after rebasing ondf0cfd52.npm run test:package: green.npm run test:disk-full: green on a 16 MiB HFS+ disk image (macOS).Known limitation: the lock is per file, so pointing store and auth at different directories lets two servers each hold one lock. The docs say to keep a site's data in one
data/. On macOS and Windows a network filesystem is not detected. CI passing is not an independent review.🤖 Generated with Claude Code