Skip to content

fix(store): activation refuses stored balances outside the declaration; principals are principal ids (#1015) - #1020

Merged
jimhoyd merged 2 commits into
mainfrom
claude/store-legacy-rows
Sep 30, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/store-legacy-rows

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Activation refuses stored balances outside the declaration. On a collection declaring transfers, activation now holds rows written under an earlier declaration, or by an earlier release, to the rules every write under the current declaration already keeps. It refuses while:

  • a stored record lacks a whole-number amount property (for example, one created before the property was added);
  • a stored record exceeds maxRecordBytes with its amounts at their widest;
  • the stored balances could together grow past 2^53 - 1. The bound is how far each stored balance stands above the lowest min, plus that min's magnitude for every record maxRecords still allows.

The error names the record (or the property and the bound) and the fix. The check (Collection.balancesHeld) runs inside the BEGIN IMMEDIATE transaction that records the declaration fence: recordDeclarations takes a check callback. So no write through the previous declaration lands between the check and the switch, and a refused activation records nothing.

Principals are principal ids (#1015). Every StoreExports and host-transaction call refuses a principal whose id is not a principal id (core's principalIdPattern: 1 to 128 ASCII characters, so no lone surrogate or over-long id). The refusal is 401 principal_required, on shared collections too, before anything is read, stamped or recorded. As defense in depth, the collection also:

  • checks a supplied principal on ungated shared transitions and transfers;
  • checks the actor it stamps or audits;
  • judges each stamped value against its property.

503 text. A stored record the declaration cannot serve now answers 503 storage_unavailable with A stored record does not match this collection's declaration. The old text, "This collection was redeclared by a reload; try again", was wrong for a bad row, which no retry fixes.

Every write stays in BEGIN IMMEDIATE. The declaration fence and lease checks are unchanged. HTTP statuses are unchanged, so the OpenAPI is unchanged.

Docs

  • docs/STORE.md: stored balances at activation, the order of checks, the export's principal rule and the 503 text
  • packages/store/SECURITY.md, packages/store/CHANGELOG.md
  • docs/RUNTIME-IMPLEMENTATION.md: RIM-STORE-PERSIST-001 now covers the check that runs in the recording transaction

Tests

  • transfers.test.ts: redeclares a collection over existing rows in three cases: a balance added to records stored without one, a smaller maxRecordBytes, and a raised issuer min with a larger maxRecords. Each case covers the refusal, the fix, the accepted redeclaration, and a refused activation that leaves the previous one serving.
  • transitions.test.ts: tries a lone surrogate, a 200-character id, x y, an empty id and a non-ASCII id on the export's transition, create, update, get and list, and on a host transaction's transition and remove. Each is refused with nothing written; restart still works. Also checks the new 503 message on GET, list and PATCH.
  • test/direct.ts: open(next) reactivates with another declaration.

npm run verify and npm run test:package pass locally (macOS, Node 26). Passing CI is not an independent security review.

Fixes #1015

🤖 Generated with Claude Code

…n; principals are principal ids (#1015)

On a collection declaring transfers, activation now holds rows written under an
earlier declaration or release to the rules every write under the current one
keeps: a whole-number amount property, maxRecordBytes with the amounts at their
widest, and stored balances that cannot together grow past 2^53 - 1. The check
runs in the transaction that records the declaration fence, so no write through
the previous declaration lands in between; a refused activation records nothing.

StoreExports and host transactions refuse a principal whose id is not a
principal id (core's principalIdPattern) with 401 principal_required before
anything is read, stamped or recorded; the collection checks stamped and
audited actors again and a stamped value against its property. The 503 for a
stored record the declaration cannot serve names that cause instead of a reload.

Fixes #1015

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 30, 2026 00:35
@jimhoyd
jimhoyd merged commit cf5b1ea into main Sep 30, 2026
23 checks passed
@jimhoyd
jimhoyd deleted the claude/store-legacy-rows branch September 30, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant