Repository navigation
fix(agbossjs/agboss#771): the ledger's entries are pruned under a mark — migration 0023; core at a8fe1124 - #44
Merged
Conversation
…k — migration 0023; a save of a pruned entry refused, never counted twice; core at a8fe1124 The core (agbossjs/agboss#771) dates every ledger entry by its `madeAt`, prunes them with `deleteEntriesByMadeAtBefore` and refuses a save of one made before the store's pruning mark that it no longer holds. - migration 0023_cost_entries_pruned: `agboss_cost_entries.made_at` (indexed; rows of before dated 'infinity': never pruned, never refused) and `agboss_cost_entries_pruned`, the one-row mark, seeded at '-infinity'. Its header corrects 0022's (kept as is: migrations are checksummed), which described ids derived from the step, a design that was dropped. - saveAll: one statement — the mark read FOR SHARE (a prune's UPDATE waits, or the save waits and reads the new mark), an entry made before it never inserted, one not held refusing the whole save (CostLedgerEntryExpiredError). A missing mark row fails the save with PostgresLedgerMarkMissingError and adds nothing. - deleteEntriesByMadeAtBefore: the mark raised (greatest) and the entries deleted in one statement. - tests: the contract's four pruning cases; 40 lost answers retried on two instances while a third prunes ten times count once each (red without FOR SHARE: $5.875 for $5); the mark row missing; 0023 on a database at 0022. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Kh8JmysuhZyQRSpNyJdPg
This was referenced Nov 5, 2026
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.
Refs agbossjs/agboss#771
What changed
Migration
0023_cost_entries_prunedadds:agboss_cost_entries.made_atwith an index. Rows written before 0023 get'infinity', so they are never pruned and never refused; their pass's retry finds them held.agboss_cost_entries_pruned, a one-row table holding the pruning mark, seeded at'-infinity'.COMMENT ON TABLEonagboss_cost_entries.0022 stays unchanged because migrations are checksummed. 0023's header corrects 0022's: a
ledgerIdis the pass's own id, and a step run again counts again. The README's row for 0022 now says the same.saveAllis one statement. It works like this:FOR SHARE. If a prune'sUPDATEof the mark is in progress, this read waits and then sees the new mark, because a locked row is read at its latest version.CostLedgerEntryExpiredError.PostgresLedgerMarkMissingError(postgres.ledger-mark-missing). Without that check, a save would silently drop its entries.deleteEntriesByMadeAtBeforeis one statement:UPDATE … SET pruned_before = greatest(…)(the mark only goes up), thenDELETE … WHERE made_at < mark.The test reset (
truncateAll) seeds the mark again, as the migration does.How it was tested
npm run checkandnpm run test:faultsgreen against PostgreSQL 16 under the lock, at2a5b4641with the core packed ata8fe1124.costLedgerContractnow includes the 4 #771 pruning cases. They run here throughstoreConformanceagainst the real database.tests/stores/cost-ledger.test.ts:FOR SHAREremoved, the same test counts $5.875 for $5, i.e. 7 entries counted twice. With the mark filter removed, it fails too.tests/migrations/cost-entries-migration.test.ts: 0023 run on a database at 0022. An entry held from before is dated'infinity'; a prune at 2030 keeps it, and a save of it adds nothing.Wiki to update after merge
None here. agbossjs/agboss Wiki → FinOps "Pruning the entries (#771)" and Your-own-store already describe this store (published with agbossjs/agboss#783).
Deviations from the spec
None
Not auto-verifiable
None
🤖 Generated with Claude Code
https://claude.ai/code/session_012Kh8JmysuhZyQRSpNyJdPg