Skip to content

feat(store): audit log in the store with a core tap; name is the role; cut ownerless (#1052 S4, #1041) - #1066

Merged
jimhoyd merged 6 commits into
mainfrom
claude/audit-into-store-1052
Sep 30, 2026
Merged

jimhoyd merged 6 commits into
mainfrom
claude/audit-into-store-1052

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Part of #1052 and #1041.

Slice S4 of #1052, plus #1041 items 2 and 6.

What changed

The audit log belongs to the store now.

  • A collection with audit: true records its event as a row of store_audit_events in store.sqlite. The row is written in the same BEGIN IMMEDIATE transaction as the change, so the event and the change commit together or not at all.
  • The log keeps the newest extensions.store.config.auditRetention events (1000 to 10000000, default 100000). Older events are pruned in that same transaction.
  • Removed: the outbox, the drain loop, peek/ack delivery into a separate audit database, backoff, flush, the 503 audit_backlog backpressure and the drain marker (with the operator output's undeliveredEvents, lastAuditDrain and warning).
  • Schema step 6 → 7 is forward only. It moves any events still waiting in store_audit_outbox into the log, in order, then drops the outbox and store_audit_drain.

Query, retention and the CLI are store features.

  • urlcode-store audit --database <abs> [--source|--actor|--subject|--action|--action-prefix|--from|--to|--after|--limit|--order] prints one page. It opens the database read-only and never creates or upgrades it.
  • New: urlcode-store restore --backup --destination, and restoreStore.
  • The two SQLite backup modules are merged into one copyStore path. A store backup includes the audit log.

The tap, in core.

  • @jimhoyd/urlcode/extensions now exports the audit contract: AuditEvent, AuditStoredEvent, AuditQuery, AuditPage, AuditTap (peek(limit)/ack(ids)), AuditLog (the tap plus query), AuditError, auditLimits, validateAuditEvent and validateAuditQuery. The source is packages/core/src/audit-events.ts, a pure module.
  • StoreExports.audit implements AuditLog.
  • Delivery is at least once: ack marks events as forwarded, and a sink deduplicates on id. Pruning ignores whether an event was forwarded.
  • Neither the store nor a sink depends on an audit package.

packages/audit is deleted.

  • Everything in it that is still useful now lives in core (the contract, validation and query) or in the store (the log of record, retention, CLI and backup).
  • I did not keep it as a thin optional sink that writes the tap into a separate file. That sink would bring back a second database, a delivery loop and a second retention and backup story. The tap lets an owner forward events to the destination they actually want in about 20 lines.
  • A sink named audit is conformance-tested instead.

The name is the role.

  • addAddons now lets an independent package whose descriptor names a first-party role (audit, store, auth, …) install while the first-party package of that name is not installed.
  • It is refused while the first-party package is installed (remove it first).
  • urlcode extensions add <name> of the first-party package is refused while an independent stand-in provides that name.
  • Conformance test in packages/store/test/audit.test.ts: an in-test extension named audit (requires: [store], core types only) is composed with the store. It forwards through the tap, and the test checks that events are delivered again after a restart when they were never acknowledged.
  • Unit test in test/addons.test.ts. The Auth.js proof now installs a stand-in named auth.

Ownerless commands cut (#1041 item 6).

  • Removed: urlcode-store ownerless, ownerless-assign, ownerless-delete and reportOwnerless/assignOwnerless/deleteOwnerless, with their tests and docs.
  • reassign/reassignOwner stays. It now refuses the whole move, dry run included, when it would record more events than auditRetention keeps.

Unchanged constraints.

Documentation and tooling updated.

  • Docs: docs/STORE.md, EXTENSIONS.md, OPERATIONS.md, OBSERVABILITY.md, CAPACITY.md, RESILIENCE.md, CI.md, VERSION-ALIGNMENT.md, and FRAMEWORK.md (package list and counts only).
  • Package docs: the store README, SECURITY, AGENTS and llms, the top-level README, SECURITY, AGENTS.md, ROADMAP, llms.txt and llms-full.txt.
  • RIM cards: new RIM-EXT-AUDIT-001; RIM-STORE-PERSIST-001 and RIM-ADDON-001 updated.
  • Tooling: scripts/package-audit.ts, ci-plan.ts and its test, ci.yml, publish.yml, check-workspace-links.ts, tsconfig.json, the lockfile, and the bench:store script.

Lines removed and added (git diff --numstat origin/main)

Area Files Added Removed Net
Source (packages/*/src) 29 +465 −1271 −806
Tests (test/, packages/*/test, *.integration.ts) 36 +375 −1468 −1093
Docs (*.md, *.txt, excluding generated) 30 +400 −937 −537
Generated (lockfile, urlcode.json, store-schema config, llms-full, extension reference) 8 +85 −158 −73
Tooling, CI, config, bench, proofs 13 +28 −103 −75
Total 116 +1353 −3937 −2584

Evidence

  • npm run verify passed locally after the final merge of origin/main. It includes lint, typecheck, docs checks, the root suite, every workspace's verify, audit:packages, test:addons, test:proof, test:proof:authjs and test:ecosystem.
  • npm run test:package passed.
  • origin/main was merged three times while this was in progress (S5, S2 @jimhoyd/urlcode/sqlite, S7 and S6). The conflicts were resolved by merge, not rebase.

Limitations and follow-ups

  • docs/CAPACITY.md still carries audit-on throughput figures measured with the old outbox design. The page says so; npm run bench:store has not been re-run.
  • test/disk-full.integration.ts (a real ENOSPC filesystem) runs only on CI's Linux tmpfs leg. I updated it but did not run it locally.
  • A sink that falls further behind than auditRetention loses events silently. Only the page's oldest cursor shows that pruning passed it.

CI passing is not an independent security review.

🤖 Generated with Claude Code

jimhoyd and others added 5 commits September 30, 2026 10:27
…me is the role; cut ownerless (#1052 S4, #1041)

- Audited writes record their event in store.sqlite (store_audit_events) in the
  same BEGIN IMMEDIATE transaction, pruned to auditRetention; the outbox, drain,
  backoff, flush, backlog refusal and drain marker are gone. Schema 7 moves any
  waiting outbox events into the log.
- The audit event contract, validator, query and tap (AuditTap/AuditLog) move to
  core (@jimhoyd/urlcode/extensions); StoreExports.audit implements it.
- urlcode-store audit (read-only list) and restore; one backup module.
- packages/audit is deleted.
- An independent package may take a first-party name while the first-party one
  is not installed; conformance test with an in-test sink named audit.
- urlcode-store ownerless* and their API are removed; reassign stays.

Part of #1052 and #1041.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…udit-into-store-1052

Keeps packages/audit deleted and drops it from the exports test's manifests and sibling-resolution check.

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