Repository navigation
Commit 4f0a5f3
fix(plugin-audit, cli): isolate audit sealer faults per chain; os serve hands its crypto provider to an app-supplied AuditPlugin (objectstack-ai#33503)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DXuamRUC67fx2TTYrFfyuSH)_
Part of objectstack-ai#31908 (slice P4b1; seat ruling 6884540128 items 2 and 3)
Clause-②: yes (widening)
Metadata-protocol: none
## Maintainer quick read
- What changes: the audit sealer isolates faults per chain. When a
canonical rule refuses one of a chain's rows, or one of a chain's
checkpoints (its head included) is malformed, only that chain is
skipped, and the other chains seal as usual. Each chain has its own
cursor and resumes from its own oldest unsealed window. Past a window
that holds a skipped chain, `sealed_through` stops advancing. A lock
lapse or a signer, crypto or storage fault still aborts the object's
whole pass. Also: when an app puts its own `AuditPlugin` in `plugins`
without a `cryptoProvider`, `os serve` now hands it the host's crypto
provider. It does this only for the real `AuditPlugin` class, and it
never overrides an explicit provider.
- Why: before, one bad row stopped sealing for every chain of the
object. And an app's own `AuditPlugin` (one added to turn on
`readAudit`, for example) replaced the CLI's instance, got no crypto
provider, and sealed nothing.
- Risk and rollback: verdicts and refusal reasons are unchanged, and
every existing seal and verify pin passes as is. The PR adds one public
method, `AuditPlugin.adoptHostCryptoProvider` (widening). The sealer
pass is window-major, and `late` never sweeps a lagging chain. Both are
pinned per seat ruling 6885452378, the precondition for the verifier's
sealed-window rule, which lands in P4c. Rollback is a revert.
- Read first: in `sealer.ts`, `run`, `cursorOf`, `skip`, `writeChains`
and the catch in `readWindow`. In `serve.ts`, the
`handHostCryptoToAppAuditPlugin` line inside the stack plugins loop. In
`audit-plugin.ts`, `adoptHostCryptoProvider`.
- Two-minute check: `pnpm --filter @objectstack/plugin-audit exec vitest
run src/audit-seal/audit-seal-sealer.test.ts src/audit-plugin.test.ts`.
Expect 2 files and 65 tests, all green.
- Needed from you: nothing. The seat lands it.
## What changes
1. **S4, per-chain isolation (seat ruling 6884540128 item 2).**
`sealer.ts`:
- Only a chain-local fault skips a chain: a row a canonical rule refuses
(`CanonicalFormError` while reading the row), or a malformed checkpoint
of that chain (`SignedBodyError`/`CanonicalFormError` while reading it
back: its head in `headOf`, a lister in the late re-count, a lister in
`listedIn`, or its `window_start` while the cursors are read). The
skipped chain stays out for the rest of the pass; every other chain is
sealed. Lock lapse, signer, crypto-provider and storage faults (and the
Q6 coordinate bound) still throw out of the object's pass, as before.
- Each chain has its own cursor: the window after its last `window`
checkpoint at or past the object's floor (the stored `sealed_through`,
before which every chain is complete). A row is `late` only before its
own chain's cursor; at or past it the window pass seals it as `window`.
So a skipped chain (or one a stopped pass left) resumes from its own
oldest unsealed window as `window` checkpoints. This replaces the
object-wide `lastWindow` / `resumed` pair.
- `sealed_through` on every `window` checkpoint is `min(window start,
earliest window a skipped chain leaves unsealed)`, never below the
stored floor. So it never passes a window that has a skipped chain.
- The window walk starts at the floor. A window that only re-reads
chains already sealed (or skipped) past it does not count toward
`MAX_WINDOWS_PER_PASS`, so a stuck chain cannot stall the others behind
the cap.
- Each skipped chain is reported once at `error` per cause per hour,
naming the object, the chain, the fault (code and reason, never a
statement) and the window it is unsealed from. A chain sealed again is
forgotten.
2. **App-supplied AuditPlugin (seat ruling 6884540128 item 3).**
- `audit-plugin.ts`: new `adoptHostCryptoProvider(provider, { armSealer
})`. It takes the provider only when the instance was composed with no
`cryptoProvider`, so an explicit one is never overridden. `armSealer:
false` (a one-shot boot) keeps the sealer off. `true` leaves the
instance's own `armSealer` standing, so an app's `armSealer: false` is
never turned on. Kept in private fields; the app's options object is not
mutated.
- `packages/cli/src/utils/app-audit-plugin-host-crypto.ts`:
`handHostCryptoToAppAuditPlugin` hands over only to `instanceof` the
real class, as this host loads it. A same-named lookalike is never
touched. It never throws.
- `serve.ts`: the class is loaded once, best-effort, ahead of the stack
`plugins` loop. Each entry is handed `() => hostCrypto?.provider` and
`!migrateAndExit` (the same provider function and one-shot posture as
the 5d instance and the `requires: ['audit']` resolver) right before
`kernel.use`. Boot is never refused. An instance left with no provider
keeps D3's once-at-`error` report from its sealer.
Out of scope, untouched: S7, the item-5 DB session lock, verify's
bootStack crypto (item 4, P4c), any `lifecycle.seal` default, expiry
amendments, objectql lifecycle, `docs/adr/**`, `.claude/**`,
`skills/**`, `.github/workflows/**`.
## Tests
Tests first. Each new pin was run red before its fix.
- `audit-seal-sealer.test.ts`, new describe `per-chain isolation …`:
- A refused row in org_b's 08:00 window. The deployment chain and org_a
are sealed at 08:00, 09:00 and 10:00. org_b is not. Every
`sealed_through` stays at 08:00. One `error` line names the object,
`org:org_b`, `b1.payload` and "NOT being sealed".
- Once the row is fixed, org_b resumes: `window` checkpoints at 08:00
(seq 0) and 09:00 (seq 1), not `late`. A third pass writes nothing.
- A malformed head (org_b's checkpoint `root`). org_a is sealed at 09:00
and 10:00, both with `sealed_through` 09:00. org_b is skipped with one
`error` line naming `root`.
- A storage fault (`connection reset` on org_a's insert) still stops the
whole object: nothing is stored, and one object-level `error` line. This
one is green before and after; it preserves the abort.
- Verify stays loud: `verifyAuditLedger` over the first scenario answers
`ok: false`, with totals `unmodified: 2, late: 2, unsealed: 2`. This is
the verdict `os audit verify` exits 1 on.
- Window-major (seat ruling 6885452378): org_a writes every hour for 30
hours, which is more windows than one pass seals, and org_b writes only
at hours 0, 11, 23 and 29. After pass 1, both chains' newest `window`
checkpoint is at 23:00. After pass 2, both are at 29:00, and there is no
`late` checkpoint. It was green at first run, so no code change was
needed: the pass is one loop over windows that seals every due chain
under one shared budget. Giving org_b its own budget turns it red
(Verification).
- No late sweep (seat ruling 6885452378): org_x is skipped at 08:00
while org_a seals 08:00 and 09:00. In pass 2, org_x recovers into
`window` checkpoints at 08:00 (seq 0) and 09:00 (seq 1), and the only
`late` checkpoint is org_a's own late row at 08:00. It was green at
first run, so no code change was needed. Restoring the old every-chain
late rule turns it red (Verification).
- `audit-plugin.test.ts`, new describe: takes the host provider when
none was composed, and the sealer seals under it. Never overrides an
explicit one. A one-shot host keeps the sealer off, and an app's
`armSealer: false` stands. A host with no provider composes none, so the
sealer is built without crypto and reports at `error`.
- `cli/src/utils/app-audit-plugin-host-crypto.test.ts`: the real class
with no provider is fed. An explicit provider is not replaced. A
same-named lookalike with an `adoptHostCryptoProvider` of its own is
never called. The class missing or no plugin feeds nothing. A one-shot
host disarms the sealer.
- `serve-audit-registration.contract.test.ts`: every existing assertion
is kept. New: the hand-over call (exact spelling, with `() =>
hostCrypto?.provider` and `!migrateAndExit`) sits inside the stack
`plugins` loop before `await kernel.use(pluginToLoad);`, and the real
class is loaded ahead of the loop.
## Acceptance notes
- **Ruled: verify for a window where the skipped chain is the only
chain.** The verifier today reads a window as sealed when a trusted
`window` checkpoint names it, or when the window ends at or before the
highest `sealed_through`. Ruling item 2 holds `sealed_through` at the
skipped window. So if no other chain sealed that window, the skipped
chain's rows there get no verdict. Seat ruling 6885452378 (option A)
closes this in P4c: a window is also sealed when it starts at or before
the highest `window_start` among trusted `window` checkpoints. The
ADR-0154 D3 line is in objectstack-ai#33489. Its two preconditions, a window-major
pass and `late` never sweeping a lagging chain, are pinned in this PR
(Tests).
- **A row whose `created_at` will not parse, when it is the oldest row
of a span**, is met by the window walk's `firstRowAt` before any chain
is read. That still stops the object's pass, as before. In `readWindow`
the same fault skips only its chain.
- **Cost while a chain is stuck.** Each pass walks from the floor, so it
re-reads the windows other chains already sealed past it until the stuck
chain is fixed. This is bounded by how long the chain stays stuck. The
cursor read fetches the `window` checkpoints at or past the floor.
review#3 S1: bounding this re-walk is carried to P4b2.
- **A separately installed copy of `@objectstack/plugin-audit`** in the
app is a different class from the one the host loads, so an instance of
it is treated as a lookalike and is not fed. Its sealer reports the
missing provider at `error`.
- **`OS_MIGRATE_AND_EXIT=1` with an app AuditPlugin that composed its
own provider** arms its sealer, as before. The ruling feeds only
instances with no provider, so this PR does not touch them.
- **Stacked on P4a (objectstack-ai#33476).** Base is `claude/area-A2-31908-p4a`; the
area thread retargets it to `main` once objectstack-ai#33476 merges.
## Verification
All readings were taken at head `4cbd2fca9` unless they name another
commit; the follow-up block was taken at `22d4da3f6`.
<details><summary>Red before the fixes</summary>
```
# 5ada48f (sealer pins only)
× skips the chain of a row a canonical rule refuses, seals every other chain, and holds sealed_through at the skipped window
× resumes a skipped chain from its own oldest unsealed window, as window checkpoints and not late ones
× skips the chain whose head checkpoint is malformed, and seals the others past it
× keeps verify loud: the skipped chain's rows read unsealed and the verdict is not ok
Tests 4 failed | 30 passed (34)
os-verify-lock: VERDICT command-exit 1
# 03a059d (plugin pins only)
TypeError: plugin.adoptHostCryptoProvider is not a function
Tests 4 failed | 25 passed (29)
os-verify-lock: VERDICT command-exit 1
# cli pins before the helper and the serve wiring
Error: Cannot find module './app-audit-plugin-host-crypto.js'
× hands the host crypto provider to an app-supplied AuditPlugin in the stack `plugins` loop, before the kernel takes it (seat ruling 6884540128 item 3)
Tests 1 failed | 7 passed (8)
os-verify-lock: VERDICT command-exit 1
```
</details>
<details><summary>Green: the full plugin-audit suite, and the CLI tests
that read serve.ts</summary>
```
# pnpm --filter @objectstack/plugin-audit exec vitest run --maxWorkers=2
Test Files 93 passed (93)
Tests 1511 passed (1511)
os-verify-lock: VERDICT command-exit 0
# pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 (every test file that reads serve.ts, plus the helper's)
Test Files 40 passed (40)
Tests 600 passed (600)
os-verify-lock: VERDICT command-exit 0
```
48 files were named, and the `unit` project ran the 40 that are
unit-tier. The rest are integration-tier, which CI's `Test Core` runs.
</details>
<details><summary>Follow-up pins (seat ruling 6885452378): green at
first run, and each bites under ablation</summary>
```
# 22d4da3, sealer file: Tests 36 passed (36), VERDICT command-exit 0
# ablation: the sealLate accept against the chain's own cursor replaced by the every-chain rule (start before the pass end)
# no-late-sweep pin red, expected 5 to be 3; Tests 3 failed | 33 passed (36); restored blob == HEAD (5e40b51)
# ablation: a separate per-pass budget for org_b in the window pass
# window-major pin red, expected 25 to be 27; Tests 1 failed | 35 passed (36); restored blob == HEAD (5e40b51)
# full plugin-audit suite at 22d4da3: Test Files 93 passed (93), Tests 1513 passed (1513), VERDICT command-exit 0
```
</details>
<details><summary>Type-check, lint and gates</summary>
```
pnpm --filter '@objectstack/cli^...' build -> VERDICT command-exit 0
pnpm --filter @objectstack/plugin-audit typecheck -> VERDICT command-exit 0 (check:test-typecheck OK, 0 pinned)
pnpm --filter @objectstack/cli typecheck -> VERDICT command-exit 0 (check:test-typecheck OK, debt unchanged)
eslint --no-inline-config (the eight changed source files) -> exit 0
node scripts/check-test-source-alias.mjs (pnpm check:test-source-alias) -> exit 0
dispatch-gates --ran: 99 derived, 22 run (each exit 0), 0 NOT-MEASURED, 77 left to CI
```
The 22 run locally: `check-adr-0087-registration`,
`check-changeset-no-major`, `check-empty-changeset`,
`check-closing-keyword-parity`, `check-issue-citations` (both),
`check-plugin-teardown-shape`, `check-tenant-audit-census`,
`check-comment-mask-adoption`, `check:durability-log-level`,
`check:startup-registry-verdict`, `check:nul-bytes`,
`check:doc-authoring`, `check:engine-double-contract`,
`check:test-source-alias`, `check:cross-package-test-inputs`,
`check:optional-error-sink`, `check:system-context-census`,
`check:keyed-text-bounds`, `check:undeclared-dep-imports`,
`check:logger-receiver-detach` and `check:tier-file-adoption`. The
derivation is taken against `main`, so it includes P4a's files, and the
spec families are mostly P4a's. CI's `Lint & Repo Gates` runs the rest.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No spec change here.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (eslint on the changed
files; the repo-wide run is CI's).
- [x] 4. One issue, one branch, one pull request. (By the seat's
slicing, this branch carries slice P4b1 of objectstack-ai#31908, stacked on P4a's
branch until objectstack-ai#33476 merges.)
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` untouched: nothing to regenerate.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e411388 commit 4f0a5f3
9 files changed
Lines changed: 474 additions & 44 deletions
File tree
- .changeset
- packages
- cli/src
- commands
- utils
- plugins/plugin-audit/src
- audit-seal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
252 | 264 | | |
253 | 265 | | |
254 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
4978 | 4979 | | |
4979 | 4980 | | |
4980 | 4981 | | |
| 4982 | + | |
| 4983 | + | |
| 4984 | + | |
| 4985 | + | |
| 4986 | + | |
| 4987 | + | |
| 4988 | + | |
| 4989 | + | |
| 4990 | + | |
| 4991 | + | |
| 4992 | + | |
4981 | 4993 | | |
4982 | 4994 | | |
4983 | 4995 | | |
| |||
5014 | 5026 | | |
5015 | 5027 | | |
5016 | 5028 | | |
| 5029 | + | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
| 5034 | + | |
| 5035 | + | |
| 5036 | + | |
5017 | 5037 | | |
5018 | 5038 | | |
5019 | 5039 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
328 | 332 | | |
329 | 333 | | |
330 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
331 | 356 | | |
332 | 357 | | |
333 | 358 | | |
| |||
768 | 793 | | |
769 | 794 | | |
770 | 795 | | |
771 | | - | |
| 796 | + | |
772 | 797 | | |
773 | 798 | | |
774 | 799 | | |
775 | | - | |
| 800 | + | |
776 | 801 | | |
777 | 802 | | |
778 | 803 | | |
| |||
0 commit comments