feat(guardian): one AttemptLedger for every guardian repair budget - #799
Open
WiktorStarczewski wants to merge 2 commits into
Open
feat(guardian): one AttemptLedger for every guardian repair budget#799WiktorStarczewski wants to merge 2 commits into
WiktorStarczewski wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The four hand-rolled guardian retry/budget ledgers become one
AttemptLedgermodule, closing the defect class rounds 9–14 of #786's review re-fixed piecemeal: the same charge/refund/keying/reset rules were hand-rolled into four module-level Maps, and each mechanism got a different subset wrong (the F-058 → F-172 chain).lib/miden/guardian/attempt-ledger.ts—createAttemptLedger(policy, clock?):mayAttempt/begin→ handle (chargeEarly,settle('charged' | 'refunded' | 'closed')) /budgetSpent/clearForAccount. Encoded once: charge at SETTLE (a slow/configurestill buys its full gap), refund attempts that never reached the operator, close a budget an attempt proved unwinnable, key by the full subject (account + endpoint + guardian key), reset per account regime. Flat and doubling curves; pure, clock-injected (lazyDate.nowread so module-scoped ledgers stay spy-visible).createRateCooldown— the 429 path's deadline (floor 30s / cap 120s), monotonic clock, lazy expiry; a rate limit is the operator asking for silence, not a failed repair, so it deliberately carries no attempt count.guardian-sync.tsmigrations: cold re-register budget (persistence gate stays onconsecutiveAuthFailures; retry+cooldown on the ledger, now endpoint-scoped), missing-registration push (composite subject, begin-stamp-before-guards, chargeEarly-before-await, settle-time re-stamp — all preserved bit-for-bit against the round-13/14 timing tests), 429 cooldown.decideColdReRegisterSelfHealand the bespoke state types are gone; its boundary tests are ported into the ledger's own suite (1ms-before-cooldown, refund-forever, closed-jumps-to-cap, doubling sequence, prefix clears).attempt-ledger-fence.test.tspins the two repair modules to their exact remaining module-level Maps (streak counters + identity state only;guardian-drift's probe-cooldown pair stays deliberately — arm-on-entry semantics and a constant that doubles as the persisted-run contiguity floor). A new hand-rolled ledger fails CI with the fence in the diff.604→605 suites / 10,002 tests, ts, lint, i18n all green — the existing guardian-sync timing suites (fake clocks, thresholds, endpoint-change resets) pass unchanged, which is the behavioral-equivalence claim.
Part 3 of 4 of the seam plan from #786's review. Stacked on #796 (Seam B).
Reviewers: the settle-outcome mapping is the part worth your time —
attempted→charged,refused-permanently→closed,refused-transiently→refunded, and preflight-refused on the push path; a wrong mapping either burns budget on local failures or retries a provably-dead repair.