Skip to content

fix(agbossjs/agboss#727): the ledger adds each entry once — migration 0022 agboss_cost_entries; core at 53216599 - #42

Merged
PavelRavvich merged 1 commit into
mainfrom
fix/727-budget-cross-instance
Nov 4, 2026
Merged

PavelRavvich merged 1 commit into
mainfrom
fix/727-budget-cross-instance

Conversation

@PavelRavvich

Copy link
Copy Markdown
Member

Refs agbossjs/agboss#727
Refs agbossjs/agboss#732

The core (agbossjs/agboss#761, 53216599) writes each tallied spend to the ledger the moment it is made, under a ledgerId. CostLedgerRepository.saveAll now adds a record with a ledgerId once.

  • Store. PostgresCostLedgerRepository.saveAll is one statement. It inserts the entries' ids into agboss_cost_entries (ON CONFLICT DO NOTHING RETURNING), then adds the cost of the inserted ones, plus the records without an id, to the counters. A repeated id, or a racing save of the same id, adds nothing: the unique key makes the later save wait for the earlier one.
  • Migration. 0022_cost_ledger_entries adds the table. tests/migrations/cost-entries-migration.test.ts covers it: a counter written before 0022 keeps its spend, and an entry saved twice after it counts once. The other migration tests now leave out 0022 too.
  • Two-process test. tests/processes/spend-in-flight.test.ts runs two node processes on one database, one step slot each, with an execution budget of $1. A's child pays $0.60 and waits at A's gate. B's child pays its $0.60 and is held back at its next step, at $1.20. Bite: with the core pinned at 3f180577 (main before #761), B's child pays both of its next steps.
  • Contract. The core's three new costLedgerContract cases pass through storeConformance: a repeated entry counts once; concurrent saves count one entry once and lose none; a save with no counters keeps no entry.

Local: format, suppressions, installs, real-time, types, lint, typecheck, build, vitest with coverage (63 files, 690 tests, the explorer included) and the API report are all green.

🤖 Generated with Claude Code

https://claude.ai/code/session_012Kh8JmysuhZyQRSpNyJdPg

… 0022 agboss_cost_entries; a two-process test of a sibling child's spend in flight; core at 53216599

The core writes each tallied spend to the ledger at once, under a ledgerId, and
CostLedgerRepository.saveAll adds a record with a ledgerId once. PostgresCostLedgerRepository
inserts the ids into agboss_cost_entries (migration 0022) in the statement that adds their cost to
the counters: a repeated or racing save of an id adds nothing. tests/processes/spend-in-flight: two
processes, a child holding $0.60 at A's gate, the other child on B held back at $1.20.

Refs agbossjs/agboss#727, agbossjs/agboss#732

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Kh8JmysuhZyQRSpNyJdPg
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