Skip to content

Control Plane rotation storage and broker channel requests (§3.5, §4.3) - #10

Merged
Yoshiofthewire merged 24 commits into
mainfrom
kyguard/broker-vault
Nov 25, 2026
Merged

Yoshiofthewire merged 24 commits into
mainfrom
kyguard/broker-vault

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: The Control Plane can now hold rotation state for brokers: one rotation lock per account, secret_version allocation, verified envelope and receipt storage, rotation intents, and atomic completion, all reached over the broker channel.

What changed

  • Migration 101: assets, a minimal accounts, target_descriptors, secret_envelopes, envelope_receipts, rotation_locks, rotation_runs (§9.2), all in migrationTables.
  • Channel requests (reserve, envelope, intent, receipts, status, sync, sync_account): request/response over the WebSocket with stable refusal codes. Frames are capped at 4 MiB; sync pages manifests 64 at a time and sync_account sends one account's chains above the broker's version plus its current and unterminated ones, so history growth never outgrows a frame (Guide finding).
  • secret_version is one more than the highest ever allocated or reported by the broker, under the account's single lock; a retry by the same operation gets the same version (§3.5, §3.7).
  • Envelopes and receipts are verified against the current manifests (New: true, signed by this broker) before they are stored; receipt append is a compare-and-swap in the store too; a byte-identical re-send is a no-op (§3.5, 1A test 13).
  • Completion appends the receipts, moves current_envelope_id and deletes the lock by operation_id in one transaction; the outcome is derived from the verified receipts, never the broker's word (§4.3 rule 7).
  • Every request re-checks that the broker is its pool's active member and the account's current managed policy names that pool.

Review this

Safe to skip: messages.go types, brokertest fixtures, docs.

Checked: full suite with -race and with GODEBUG=fips140=on, SQLite (k83) and PostgreSQL 17 (k82), exit 0; go vet, gofmt. 11 mutations, each failing its test (Detail). Not checked: a test for the two-query Chains read racing a writer (guarded, not proven); concurrent PostgreSQL writers on one account (the row lock SELECT … FOR UPDATE is there; no race test yet); CodeQL and reviewers.

Decided for you (docs/DECISIONS.md 39–41): a minimal accounts table (the inventory worker adds columns); outcome derived from receipts only; every channel request re-authorized.

You need to: nothing. There is no route yet to upload a target descriptor (inventory work); tests insert them through the store.

§13 checklist: Phase 1A "Envelopes, receipts, CAS append, … current-envelope rule, secret_version allocation" (Control Plane side) and "idempotent completion". Stacked on #9.

Detail
Property Mutation Failing test
One lock per account drop the ErrLocked branch TestOneLockPerAccountAndVersionsNeverGoDown
Version never below the broker's report ignore reported same
Envelope only under its reservation skip requireLock same
Store-level receipt CAS drop seq/prev check TestReceiptAppendCASInTheStore
A different receipt at a stored seq is a conflict treat it as a retry same
Lock deleted only by its own operation delete by account TestCompleteReleasesOnlyItsOwnLock
Account must be in the broker's pool drop policy pool check TestChannelScopesWorkToTheActiveBrokersPool
Revoked mid-connection is refused drop active check same
Receipts belong to the request's operation drop check TestReceiptAppendIsCompareAndSwap
New receipts verified as new work verify as history same
Envelopes verified accept unverified TestChannelScopesWorkToTheActiveBrokersPool

Also covered: TestSyncIsPaged (paging and the per-account filter); forked and gap receipts (invalid_receipt_chain), a receipt by a key outside the pool (unknown_signing_key), a user recipient on a managed envelope (invalid_recipient_set), an aborted version never reused.

internal/pqcrypto/sealenv.go adds Seal, OpenDEK, OpenPassword and WrapTo over the existing primitives (no new crypto).

Review fixes (25 Nov, Guide "Unbounded frames", "Unbounded reads")

  • Manifest sync pages stop at SyncBudget (encoded size, with framing) as well as at 64 manifests and always carry at least one, so every page progresses; the Control Plane refuses a manifest over 512 KiB (cptrust.MaxManifest) at upload, so one manifest always fits a frame (DECISIONS 61).
  • sync_account and receipts read only the chains they need: new store queries OpenChains, ChainsAfter(…, limit) and Chain, SQLite and PostgreSQL; Chains is now for tests only (DECISIONS 62).
Property Mutation Failing test
Manifest page within its byte budget drop the budget TestManifestPagesAreBudgeted
A page always progresses no "at least one" rule same
Oversized manifest refused at upload drop the MaxManifest check TestSubmitRefusesAnOversizedManifest
A sync page reads only its chains back to Chains TestAccountSyncAndReceiptsReadOnlyWhatTheyNeed (13 chains read for one page)
Receipts read only the chains they name back to Chains same (14 chains read)
Range query bounded drop the LIMIT TestChainQueriesReadOnlyTheirSlice (SQLite and PostgreSQL)

Review fixes, round 2 (25 Nov: security review, Guide "RPC Stall", "Stale Completion")

  • Security review at 0ce6144: addressed in 0964e57 (sync paging and store limits; DECISIONS 62 rewritten). sync_account now pages with a from cursor (replaces continue), and a sync page reads at most SyncPage manifests (ManifestsPage), which also closes the "Not changed" item below.
  • Guide "RPC Stall": a push that finds the broker's 16-slot queue full is dropped and logged, never waited for, so results for pending calls keep flowing (DECISIONS 70).
  • Guide "Stale Completion": a completion whose receipts are all already stored changes no derived state, and current_envelope_id only ever moves to a higher secret_version (DECISIONS 71).
Property Mutation Failing test
Sync reply bound (security) drop the byte budget for the first chains of a page TestOpenChainsArePagedWithinTheBudget, TestAccountSyncIsBudgeted
Sync reply bound (security) leave the descriptor out of the budget TestOpenChainsArePagedWithinTheBudget
Sync read bound (security) read every manifest again TestManifestSyncReadsOnlyOnePage
Store size limits (security) drop the chain cap / envelope cap / descriptor cap TestChainsAndDescriptorsAreCapped (3 mutations)
Pushes never stall results block on a full queue TestUndrainedPushesNeverBlockResults
Delayed duplicate completion is a no-op drop the "nothing new" check TestADelayedDuplicateCompletionChangesNothing

The version guard on current_envelope_id is a second, independent guard behind the "nothing new" check; no test removes both.

Round-2 checks (stack tip ca19e6a): full suite -race and GODEBUG=fips140=on, SQLite (k81, exit 0) and PostgreSQL 17 (k80, exit 0); Docker connector suites -race on Major under kslot (26 tests, 0 skipped); go vet at every branch head, gofmt.

Review fixes, round 3 (25 Nov, Guide "State Regression", "Unbounded Pagination")

  • "State Regression": only a mutating run can become write_outcome_unknown (§4.2). A late or retried status report no longer moves a target_verified, release_authorized or aborted run back (6ba10aa).
  • "Unbounded Pagination": PoolAccounts takes an ID cursor and a limit (id > ? ORDER BY id LIMIT ?, backed by a new (pool_id, id) index in this PR's unmerged migration). The sync checks each row as it is read, with no GetAccount per candidate, so one page reads about SyncAccountsPage+1 rows in one query while Trust.View is held. SyncAccountsPage is now a variable so tests can lower it (6ba10aa).
Property Mutation Failing test
A late unknown status never undoes an outcome drop the state = 'mutating' guard TestLateUnknownStatusNeverRegressesARun (target_verified moved to write_outcome_unknown)
No per-account read in the account list check each row with l.account again TestAccountListReadsOnlyOnePage (10 per-account reads)
The account list reads one page drop the LIMIT same (7 rows read for a page of 2)

Round-3 checks (stack tip a805e71): full suite -race and GODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (k83, exit 0); Docker connector suites -race on Major under kslot (30 tests, 0 skipped, exit 0); go vet and the broker/store tests at every merged branch head; gofmt.

Review fixes, round 3b (25 Nov, Guide "Reservation retries", "Unbounded scanning" at 662225f)

  • Unbounded scanning: a sync page scans at most SyncAccountsPage rows, eligible or not. The reply carries accounts_next (the last row scanned), so the next page continues past filtered rows; the broker follows it (Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11). This is a wire change between unmerged PRs (3cc19cf).
  • Reservation retries: Reserve refuses (conflict) an operation that already has receipts on the account, so a late retry of a finished reservation takes no version and no lock. The lookup uses a new index on envelope_receipts(operation_id), in this PR's unmerged migration (3cc19cf).
Property Mutation Failing test
A sync page scans one batch of rows scan 10× the page size TestAccountListReadsOnlyOnePage (12 rows read for a page of 2)
A finished operation never reserves again drop the receipts check TestRotationRoundTripOnTheControlPlane (retry got version 2)

Checks (stack tip 96c38fd): full suite -race and GODEBUG=fips140=on, SQLite (k83, exit 0) and PostgreSQL 17 (see #16); Docker connector suites -race on Major under kslot (30 tests, 0 skipped, exit 0); go vet and the broker, store and brokerproto tests at every merged branch head; gofmt.

Review fixes, round 3c (25 Nov, Guide "Retry Race" at 306c30f)

  • PutEnvelope and RecordIntent now take the account row lock before checking for an existing row. Two identical concurrent retries on PostgreSQL could both miss the row, and the second then failed on the primary key instead of succeeding (98a3a05).
Property Mutation Failing test
Concurrent identical retries succeed check before the lock (old order) TestConcurrentIdenticalRetriesSucceed (PostgreSQL 17: duplicate key on secret_envelopes_pkey and rotation_runs_pkey)

Checks (stack tip e8bdff0): see #16 for the full suite; go vet and the broker, brokerproto and store tests (-race) at every merged branch head.

Review fixes, round 3d (25 Nov, Guide "Suppressed Error" at 48b1d3c)

  • syncAccount now returns the descriptor lookup error instead of answering with a state that has no descriptor; the broker retries the sync (d33cf4a).
Property Mutation Failing test
A sync never omits the policy's descriptor ignore the lookup error TestAccountSyncNeedsTheDescriptor

Checks: see #16 for the full suite at the tip; go vet and the broker, brokerproto, store and api tests (-race) at every merged branch head.

Round 4 (25 Nov): Guide "Unfinishable Rotation", main merged up

Property Mutation Failing test
The largest admitted envelope can still take its abort and release its lock MaxEnvelope = MaxChain TestTheLargestEnvelopeCanStillBeFinished (k83)

Checks: at #8 ec97af5 the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its own postgres:17-alpine container, exit 0). At the top of the stack (#16, same tree as a350929) PostgreSQL 17 passed with -race + FIPS on k82 (exit 0). gofmt and go vet (also -tags docker) are clean at every branch head. The mutation proofs ran on throwaway copies.

Round 4b (25 Nov): security review at 684c48d (detail on the private board)

  • Addressed in 6b2f65e. A policy may name at most 32 standing recipients (pqcrypto.MaxStandingRecipients, refused as invalid_body). MaxEnvelope now keeps 96 KiB of the 256 KiB chain free, and a signed commit_target plus a release carrying all 32 X-Wing wraps measures about 66 KB (5,202 + 60,875 bytes). DECISIONS 77.
Property Mutation Failing test
The chain room fits commit_target plus the largest release reserve back to 32 KiB TestChainRoomFitsTheLargestRelease
A policy cannot name more standing recipients than a release can carry drop the cap TestPolicyStandingRecipientsAreBounded

Checks (round 4b): at #8 f212849 and at #16 bdb9adf, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), all exit 0. #16's last head 5ef228b changes only PutTx and its test since bdb9adf: internal/store and internal/api -race passed on SQLite (k82), and the PutTx test passed 3 × 20 rounds on PostgreSQL 17. gofmt and go vet (also -tags docker) are clean at every branch head. The mutations ran on throwaway copies.

Round 4c (25 Nov): Guide "Concurrent retries" at f40ee12

  • PutTargetDescriptor now inserts with ON CONFLICT DO NOTHING (10c54bb). The digest names the content, so identical stores racing on PostgreSQL are all no-ops, where before one could fail on the primary key.
Property Mutation Failing test
Identical concurrent descriptor stores succeed the old count-then-insert TestConcurrentIdenticalDescriptorStoresSucceed (PostgreSQL 17, own container: 5 of 5 runs fail)

Checks (round 4c): at #16 9fb8788, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), both exit 0. gofmt and go vet (also -tags docker) are clean at every changed branch head. The race tests ran on PostgreSQL 17 in my own container; the mutations ran on throwaway copies.

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-10, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/broker-daemon branch 2 times, most recently from 9531029 to 7056bdb Compare November 25, 2026 09:55
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
The sync reply carried every manifest, envelope and receipt of the pool
in one frame, so a long enough history would exceed the read limit and
close the channel on every reconnect. Sync now pages manifests 64 at a
time and lists the pool's accounts; sync_account returns one account's
chains above the broker's version plus its current and unterminated
ones. Frames are capped at 4 MiB on both ends.

Chains read envelopes and receipts in two queries; a receipt for an
envelope committed between them dereferenced a nil chain. Such a
receipt is now left for the next read. (PR Reviewer Guide on #10.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
The sync reply carried every manifest, envelope and receipt of the pool
in one frame, so a long enough history would exceed the read limit and
close the channel on every reconnect. Sync now pages manifests 64 at a
time and lists the pool's accounts; sync_account returns one account's
chains above the broker's version plus its current and unterminated
ones. Frames are capped at 4 MiB on both ends.

Chains read envelopes and receipts in two queries; a receipt for an
envelope committed between them dereferenced a nil chain. Such a
receipt is now left for the next read. (PR Reviewer Guide on #10.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

PR Reviewer Guide:

  • Response limit: fixed in f51936d. Frames are capped at 4 MiB on both ends; sync pages manifests 64 at a time and lists the pool's accounts; sync_account returns one account's chains above the broker's version plus its current and unterminated ones. Test TestSyncIsPaged (and TestSyncFollowsEveryPage on Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11).
  • Inconsistent reads: fixed in f51936d. A receipt whose envelope was not in the first read is left for the next call instead of dereferencing a nil chain. Not covered by a test (the race needs a writer between the two queries).

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Lock and run uniqueness was global on operation_id, so a broker could
take an ID another pool's account would later use and block its
reservations and intents. rotation_locks no longer has a global unique
operation_id, rotation_runs is keyed by (account_id, operation_id), and
every lookup names the account.

sync_account returned every chain above the broker's version in one
reply. It now stops at a 2 MiB encoded budget and sets more; the broker
continues from the highest version received. The account list is paged
too (security review of #10). Migration 101 is edited in place: it has
not merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security review at f51936d, both P2s fixed (commits f2e595b 0d3b4ae ):

  • Account sync budget: sync_account stops at a 2 MiB encoded budget and sets more; the broker continues from the highest version received. The account list is paged (4096 per page, cursor accounts_after); manifests stay 64 per page. TestAccountSyncIsBudgeted (budget lowered, 12 chains, multi-page, all arrive) fails with the budget removed.
  • Operation IDs scoped to the account: rotation_locks has no global unique operation_id; rotation_runs is keyed by (account_id, operation_id) and every lookup names the account (migration 101 edited in place; unmerged). TestOperationIDsAreScopedToTheAccount fails with the global unique back.
  • Also: a byte-identical re-sent envelope is acknowledged before verification, so a recovered run is not refused after a policy change.

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
A retained current chain counted against the page budget, so when it and
the next newer chain could not share a page, each continuation repeated
the current chain alone and never advanced (security review of #10). A
page with more now always carries at least one newer chain, and
continuations (continue: true) skip the chains the first reply already
carried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security P2 (continuation progress) fixed in a4f142d: a page with more always carries at least one newer chain, and continuations (continue: true, set by the broker in #11) skip the chains the first reply already carried. TestAccountSyncIsBudgeted now starts from a current chain the broker already holds and sets the budget so the current chain and one newer chain cannot share a page; all 13 chains arrive within the page bound. Each guard alone guarantees progress; with both removed the test fails.

— rowan (Claude Opus 5.5)

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

PR Reviewer Guide: both items fixed in 1bd59fa.

  • Unbounded frames: manifest pages are budgeted by encoded size and always carry at least one manifest. Uploads over 512 KiB are refused, so any one manifest fits a frame.
  • Unbounded reads: sync_account and receipts read only the chains they need (OpenChains, ChainsAfter with a limit, Chain).

Mutation rows are in the description.

Yoshiofthewire and others added 7 commits November 25, 2026 07:56
The Control Plane side of rotation (spec §3.5, §4.3): migration 101 adds
assets, minimal accounts, target descriptors, secret envelopes, receipts,
rotation locks and rotation runs. Over the channel a broker reserves the
account's one lock and a secret_version that never goes below what it
reports, stores its sealed candidate, records its mutating intent (the
acknowledgement it waits for before writing) and sends receipts. Each
object is verified against the current manifests before it is stored;
receipt append is a compare-and-swap, and completion moves the current
envelope and deletes the lock by operation_id in one transaction, so a
re-sent result changes nothing. Every request re-checks that the broker
is its pool's active member and the account is in that pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sync reply carried every manifest, envelope and receipt of the pool
in one frame, so a long enough history would exceed the read limit and
close the channel on every reconnect. Sync now pages manifests 64 at a
time and lists the pool's accounts; sync_account returns one account's
chains above the broker's version plus its current and unterminated
ones. Frames are capped at 4 MiB on both ends.

Chains read envelopes and receipts in two queries; a receipt for an
envelope committed between them dereferenced a nil chain. Such a
receipt is now left for the next read. (PR Reviewer Guide on #10.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lock and run uniqueness was global on operation_id, so a broker could
take an ID another pool's account would later use and block its
reservations and intents. rotation_locks no longer has a global unique
operation_id, rotation_runs is keyed by (account_id, operation_id), and
every lookup names the account.

sync_account returned every chain above the broker's version in one
reply. It now stops at a 2 MiB encoded budget and sets more; the broker
continues from the highest version received. The account list is paged
too (security review of #10). Migration 101 is edited in place: it has
not merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A broker re-sends a run's envelope with its receipts; after a policy
change the re-send was re-verified as new work and refused, stranding a
recovered run. A byte-identical stored envelope is now acknowledged
before verification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retained current chain counted against the page budget, so when it and
the next newer chain could not share a page, each continuation repeated
the current chain alone and never advanced (security review of #10). A
page with more now always carries at least one newer chain, and
continuations (continue: true) skip the chains the first reply already
carried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sync page was limited to 64 manifests but not by size, so a page of
large manifests could exceed MaxFrame; the broker's read limit closed
the connection and every retry asked for the same page. Pages now stop
at SyncBudget encoded bytes but always carry one manifest, and
cptrust.Submit refuses any manifest over MaxManifest (512 KiB, the API's
existing body cap), so that one manifest always fits a frame.
Compile-time checks keep both bounds under MaxFrame (decision 61).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every sync_account page and every receipts request loaded the account's
whole history through Chains and then discarded most of it, so paging
a long history did nearly quadratic database work. The store gains
ChainsAfter (a version range with a limit), OpenChains (current or
unterminated chains at or below a version) and Chain (one envelope),
each reading only those envelopes and then their receipts by envelope
ID. sync_account reads the open chains on the first request and at
most SyncChains+1 newer ones; receipts reads only the chains its
receipts name. Paging semantics are unchanged (decision 62).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sync paging and store limits are tightened. A push that finds the queue
full is dropped instead of blocking the channel reader, and a completion
whose receipts are all stored changes no derived state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Both Guide notes are fixed in 6ba10aa:

  • State Regression: the run-state update now requires state = 'mutating' before it sets write_outcome_unknown, so a late status report cannot undo target_verified, release_authorized or aborted. Test: TestLateUnknownStatusNeverRegressesARun.
  • Unbounded Pagination: PoolAccounts(pool, after, limit) uses id > ? ORDER BY id LIMIT ? on a new (pool_id, id) index. Each row is checked in memory, with no GetAccount per candidate. Test: TestAccountListReadsOnlyOnePage counts both the rows read and the per-account reads.

The mutations are listed in the PR body.

Yoshiofthewire and others added 3 commits November 25, 2026 10:07
A sync page now scans at most SyncAccountsPage rows, eligible or not,
and returns accounts_next so the next page continues past the accounts
it filtered out. Before, a pool full of ineligible accounts was scanned
whole in one request while Trust.View was held.

Reserve refuses (conflict) an operation that already has receipts on the
account. A late retry of a finished reservation used to take a new
version and a lock that nothing would release. The receipt lookup has an
index on envelope_receipts(operation_id).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Both Guide notes at 662225f are fixed in 3cc19cf:

  • Unbounded scanning: a sync page scans at most SyncAccountsPage rows, eligible or not, and returns accounts_next to continue past filtered rows. The broker side is in Broker journal and rotation state machine (§4.2, §4.3, §4.6) #11 (1ada978). Test: TestAccountListReadsOnlyOnePage, which adds 5 ineligible accounts to the pool.
  • Reservation retries: Reserve refuses (conflict) an operation that already has receipts on the account, so no new version or lock is taken. Covered in TestRotationRoundTripOnTheControlPlane. The lookup is indexed on envelope_receipts(operation_id).

Yoshiofthewire and others added 2 commits November 25, 2026 11:02
PutEnvelope and RecordIntent checked for an existing row before taking
the account lock. On PostgreSQL two identical concurrent retries could
both miss it, and the second insert failed on the primary key instead
of succeeding as a retry. Both now lock the account first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Re the Guide's "Retry Race" note: fixed in 98a3a05. PutEnvelope and RecordIntent now lock the account row before the existence check. TestConcurrentIdenticalRetriesSucceed runs 16 concurrent identical retries. With the old order it fails on PostgreSQL 17 with duplicate-key errors; with the fix it passes.

syncAccount dropped every TargetDescriptor lookup error and answered
with a state the broker cannot use. The error now reaches the broker,
which retries the sync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Re the Guide's "Suppressed Error" note: fixed in d33cf4a. syncAccount now returns the descriptor lookup error, so the broker retries instead of getting a state with no descriptor. TestAccountSyncNeedsTheDescriptor fails if the error is ignored.

Yoshiofthewire and others added 4 commits November 25, 2026 11:50
PutEnvelope took an envelope up to MaxChain, but appendReceipt caps the
envelope plus its receipts at the same MaxChain, so a candidate near the
cap could never take its abort or release and kept the account's lock
(Guide on #10, "Unfinishable Rotation"). This moves #15's MaxEnvelope
(MaxChain - 32 KiB) down to #10, unchanged; #15 merges it as the same
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SQLite's LENGTH() on text stops at the first NUL, so a zero-filled
envelope counted as empty and the test passed even with MaxEnvelope =
MaxChain. Fill it with printable bytes, as #15's copy of the test does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

"Unfinishable Rotation" is fixed in db09c8d and 684c48d. PutEnvelope refuses anything above MaxEnvelope (MaxChain − 32 KiB), so every stored envelope still has room for its terminal receipt. TestTheLargestEnvelopeCanStillBeFinished fails with MaxEnvelope = MaxChain.

Yoshiofthewire and others added 2 commits November 25, 2026 16:01
The 32 KiB reserve covered an abort but not commit_target plus a release
carrying a wrap per standing recipient, and the policy did not bound
that list, so an admitted rotation could fail to complete and keep its
lock (security review of #10). A policy now names at most 32 standing
recipients, and MaxEnvelope keeps 96 KiB of the chain free, which a
signed commit_target and a 32-wrap release fit (DECISIONS 77).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Security review at 684c48d: addressed in 6b2f65e. The details are in the PR body.

PutTargetDescriptor counted, then inserted, so two identical stores
racing on PostgreSQL could see one fail on the primary key (Guide on
#10, "Concurrent retries"). The digest names the content, so it now
inserts with ON CONFLICT DO NOTHING.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

"Concurrent retries" is fixed in 10c54bb. PutTargetDescriptor inserts with ON CONFLICT DO NOTHING. TestConcurrentIdenticalDescriptorStoresSucceed (16 stores behind a barrier, 20 rounds) fails on PostgreSQL 17 in 5 of 5 runs with the old count-then-insert, and passes with the fix.

@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/broker-daemon to main November 25, 2026 22:28
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Merger (saltmarsh-merge): closing and reopening right away so CodeQL runs now that the base is main. The branch is unchanged.

@Yoshiofthewire
Yoshiofthewire merged commit e38bca2 into main Nov 25, 2026
24 of 27 checks passed
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