Skip to content

Store: a transfers collection's sum never changes on delete or create (#928) - #935

Merged
jimhoyd merged 1 commit into
mainfrom
claude/transfer-delete-guard
Sep 29, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/transfer-delete-guard

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #928, found by the second agent trial: deleting a funded wallet changed the collection's sum.

Changes

  • Delete guard: on a collection with transfers, deleting a record with any nonzero amount property is refused with 409 balance_not_zero (a fixed message; the amount is never shown). It covers every delete path:

    • HTTP DELETE and a host transaction's remove, both through removeIn. The guard runs after scope and If-Match, so a stale ETag still gets 412.
    • Operator ownerless-delete: the whole command is refused if any ownerless record holds a balance.
    • The records export has no delete method, so there is nothing to guard there.

    A refused delete writes nothing and keeps no Idempotency-Key claim. Zero-balance deletes work as before.

  • Creates and replacements: activation now refuses an amount property that:

    • isn't in readOnlyProperties, so no body can set it and PUT keeps it;
    • has a default other than 0, so new records start at 0;
    • is set or stamped by a transition.

    Breaking: collections that opened records with a nonzero balance must fund them through a members-gated issuer transfer.

  • OpenAPI: DELETE lists 409 balance_not_zero on transfers collections.

  • Docs: STORE.md "Declared transfers" (only a transfer changes an amount, deleting, funding), the store README, llms, the schema descriptions, CHANGELOG, and FRAMEWORK's trial gap note.

Evidence (macOS, Node 26)

  • HTTP DELETE: a funded wallet and the issuer's negative wallet both get 409, with no row, claim or revision changed; the same key succeeds after the balance is repaid. Zero-balance deletes get 204.
  • Bodies: a POST with a balance is 422, PUT keeps the balance, PUT or PATCH naming it is 422, and null is 422.
  • Host transactions: remove gets 409 and rolls back with the transaction's other writes; draining a record by transfer and then removing it in one transaction succeeds.
  • Operator CLI: ownerless-delete is refused while any balance remains.
  • Activation: each of the three refusals is tested.
  • Conservation: the tests now fund accounts from a bank issuer; the collection sum stays 0.
  • Results: npm run verify passes on current main (store 176). npm run test:package passed before the rebase. Store unpacked budget raised to 480 KiB (measured 487,562 bytes).

🤖 Generated with Claude Code

…reate (#928)

On a collection declaring transfers, deleting a record whose amount property
is nonzero is refused with 409 balance_not_zero (fixed message, no amount)
and nothing is written, on every delete path: HTTP DELETE, a host
transaction's remove, and urlcode-store ownerless-delete (refused as a whole
when any ownerless record holds a balance). Zero-balance deletes are
unchanged.

Activation now requires the amount property to be in readOnlyProperties,
to default to 0 and not to be set or stamped by a transition, so a create,
PUT or PATCH cannot change the sum either. The OpenAPI description lists
the 409 on DELETE for such collections; STORE.md, the store README,
llms.txt and CHANGELOG document it. Store unpacked budget 480 KiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 29, 2026 17:07
@jimhoyd
jimhoyd merged commit 33cfff9 into main Sep 29, 2026
25 checks passed
@jimhoyd
jimhoyd deleted the claude/transfer-delete-guard branch September 29, 2026 17:16
jimhoyd added a commit that referenced this pull request Sep 29, 2026
… busy-timeout 503 in the cross-connection transfer race

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd added a commit that referenced this pull request Sep 29, 2026
jimhoyd added a commit that referenced this pull request Sep 29, 2026
…up refusal, single audit drainer (#927) (#936)

* feat(store,audit)!: several serving processes on one host: declaration fence, setup refusal, single audit drainer (#927)

Schema version 5 adds store_declarations, store_servers and the audit drain
lease. Each activation records its collections' declaration fingerprints; every
write transaction checks them and user_version under the write lock and answers
503 storage_unavailable on a mismatch, writing nothing. Activation refuses a
database on a network filesystem (Linux statfs; also for the audit database) and
a live peer on another host (boot id / hostname lease), and warns once that
throttles and caches are per process. Only the drain lease holder peeks and acks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(store): type the busy-timeout check in the cross-connection race

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(store): multi-process fixture follows #935's transfer rule (amount defaults to 0)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
jimhoyd added a commit that referenced this pull request Sep 29, 2026
…ate.members and a unique-handle directory (#956, #957) (#992)

* feat(store): editable/deletable states and unique values across owners (#952, #953)

editable and deletable, in the shape of a transition's from (a value or a
list per readOnly property), refuse PUT/PATCH and DELETE outside the named
states with 409 record_locked, under the write lock after If-Match, on HTTP,
StoreExports and host transactions. Creates, transitions, increments and
transfers are unaffected. Allow on a record and allow on a list are the hint.

unique: [prop] keeps a bounded string property unique across every record,
across owners on an owned collection, with 409 value_taken through a partial
expression index; activation refuses stored duplicates. Documented as an
existence oracle: public handles only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(recipes): store-approval recipe; booking and credits use slot grids, create.members and a unique-handle directory (#956, #957)

- store-booking: intervals length/step (PT1H) replace the hour pattern, and
  create: {members: staff} makes booking staff-only; seeded from tests/seed.json.
- store-credits: a unique lower-case handle and a projected readers directory
  (/api/directory, properties: [handle]) so pay-by-lookup cannot be spoofed;
  the issuer pattern and #935 transfer rules are unchanged.
- store-approval (new, YAML only): owner submit/withdraw, by: others
  approve/reject for a reviewers list stamping reviewedBy/reviewedAt,
  editable/deletable lock decided requests, a reviewers queue with showOwner.
- plan-feature ranks store-approval for approval goals; booking and credits
  stay excluded. recipes search approval finds it.
- READMEs drop the stale scratch-database advice and say plainly the fixtures
  need the stand-in bearer principal, and how to rewrite them as sign-in steps.
- The plumbing counterexamples follow the recipes; FRAMEWORK.md re-measured.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

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.

[Bug] store: DELETE of a record holding a transfer balance breaks the 'sum never changes' guarantee

1 participant