Repository navigation
perf(platform): seal the audit chain off the write path - #4700
Merged
Merged
Conversation
WIP: writers insert unsealed rows; the worker's sealer chains them by position (chain_seq); the verifier and the retention sweep follow the chain's order; the nightly check is renamed so an older worker never walks the new order. Lock-site cleanup, integration lanes and docs follow.
Integration lanes for a burst of audited writes, a late commit, an older image's inline append during a roll and racing sealers; the verify panel shows entries not in the chain yet (EN/DE/FR); docs, AUDIT-R7 and GOV-F64.
Sealing moved off the write path, so an audited write no longer touches the chain head, yet writers still took the organization's chain lock first and kept every definition save, event dispatch, task write and wake write of an organization in one line. - Definition writers (save, deploy, bindings, trigger save and delete, the delete cascade), the event dispatch, the run delete and the retention sweep take no organization-wide lock: the name lock first, triggers stamped in id order, run rows before trigger rows. - Task writes and wake writes take a per-project work key before the project row or the wake row (lib/project-work-lock.ts); the wake scan try-locks it per project, so one busy project never stalls the scan. - The deployment history orders by the writing transaction's id (writer_xid), since ts no longer rises strictly per organization. - The sealing migration is renumbered 0194; 0182 is claimed elsewhere. - The standing-role wake lanes wait on the claim keys the writers now queue on.
A comment write used to end on the organization's chain head, so a loss anywhere in it queued the retry on the chain key. The chain is sealed off the write path now, but serializable isolation still aborts one of two comment writes on different tasks over an index page both touch, and a retry queued on its task alone could lose again to the rest of a burst. Every comment write now holds the organization's comment key shared, after its task's, so comment writes never wait for each other; a loss is marked with that key too, and the queued retry holds it exclusively from before its BEGIN. It waits for the writes already running, runs while later ones wait, and a writer loses to the organization's other comment writes at most once. The cross-task burst lane seals before it verifies and asserts that bound; the retry-queue notes no longer use the chain head as their example.
The loop read a flag only its stop() closure changed, which the linter cannot see; an AbortController's signal ends both the loop and its pause.
Main took AUDIT-R7 for key-made audit attribution while the sealing rule was in review; the sealing rule and the tests that cite it move to AUDIT-R8.
The member and create-member doubles still answered the chain head's statements and expected three audit writes; an audited write is now the one row insert, and any chain-head statement would be an unexpected query.
The phase-2 retention lane inserted its ancient audit rows already sealed, so migration 0194's trigger gave them the head's next chain positions, after every row the organization had, and the prefix sweep rightly stopped at the first row still inside the window. They are now sealed the way rows written before chain positions are, which the chain walks first.
yannickmonney
enabled auto-merge
October 10, 2026 15:09
5 tasks done
Only the sealer in the same module takes it now that the wake scan try-locks a project's work key, so it is no longer exported (Knip), and its note names the caller it has.
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.
Summary
Every audited write used to append to its organization's hash chain inside its own transaction: chain head locked
FOR UPDATE, prior hash read, row hashed, head bumped. UnderSERIALIZABLEthat made every audited write of an organization one queue — about one write per transaction duration per organization, and the biggest single limit on the path to a million concurrent users. This moves the chain off the write path:integrity_hashNULL,writer_xidstamped). No chain lock, no head row, no retry at the head.domains/audit_logs/sealer.ts) chains pending rows per organization under a try-lock, in batches, assigningchain_seq; the chain's order is the seal order. Same hash input as before, so existing rows verify unchanged. Rows sealed before this release keepchain_seqNULL and come first.chain_seq,writer_xid, the head'slast_seq, and a trigger that positions an older image's inline append during a rolling deploy. The nightly walk is renamedaudit.chain_check(the old name is retired) because an older worker would read seal order as a break.lib/project-work-lock.ts) instead of the organization's chain key; comment retries queue on an org comment key that first attempts hold shared.writer_xid, sincetsno longer rises strictly per organization.Checklist
bun run checkpasses (format, lint, typecheck, all tests). Run per part: format check, conflict markers, links, platform oxlint (type-aware) andtsc, server + pii unit suites, UI suite.bun run lint:sastpasses (Opengrep) — 0 findings.messages/{en,de,fr}.ymlcatalogs — the integrity panel's waiting note (settings.yml).docs/{en,de,fr}/— audit log integrity (self-hosted) and the admin audit-log page.README.md/README.de.md/README.fr.md— N/A, nothing they describe changes.Test plan
checkConversationApi(an API-key attribution assertion that fails on main today); every failure on this branch fails identically on main. The remaining lanes run filtered on both sides, with identical results.