Skip to content

fix(accounting): refuse oversized savings ledger token counts - #4727

Closed
ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/4447-savings-ledger-checked-token-encoding
Closed

ScriptedAlchemy wants to merge 1 commit into
masterfrom
fix/4447-savings-ledger-checked-token-encoding

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Root cause

Refs #4447 (partial accounting correctness).

The registered savings-ledger recorder accepts unsigned before_tokens and after_tokens, but persisted them with as i64. SQLite INTEGER columns are signed. A valid u64 exceeding i64::MAX became a negative persisted count, corrupting ledger evidence and downstream savings history. The adjacent project-total projection already uses checked conversion; the ledger did not.

Change

  • Refuse an unrepresentable before/after count with the existing typed database operation error before starting a write.
  • Use the checked i64 values in the existing registered, transactional savings-ledger insert. No schema, identity, authorization, scheduling, or policy changes.
  • Add a registered-store regression exercising oversized before, oversized after, maximum u64, zero writes after refusals, and successful round-trip of the largest representable count.

Validation

Reviewed the exact two-file commit diff against master at 32afec6f67644f4c9a9e777f757709557367b23a; no other files changed. Verified via a native Python/SQLite mechanism probe that the former lossy signed cast persists 2^63 as -2^63. This probe is not a Rust test pass.

Not run: Rust compilation, rustfmt, Bazel or new Rust regression: this execution has no TraceDecay checkout, Bazel or Rust formatting toolchain. Hosted CI should execute //crates/tracedecay-global-db:unit_test on this isolated branch before merge.

Remaining issue scope

This prevents one ledger data-corruption path, but does not complete #4447. Durable per-response deduplication, reset-epoch semantics for queued responses, and full MCP accounting lifecycle validation remain. The earlier project-total consolidation has already landed in #4698. Keep #4447 open. CI repair/merge belongs to the existing PR automation.


Devin Review

Reject unrepresentable before/after token counts before inserting into
SQLite's signed INTEGER columns. Preserve exact stored savings evidence.
Cover invalid boundaries and the largest representable count.

Refs #4447
@changeset-bot

changeset-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d8434bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Consolidated into #4742 (integrate/open-pull-requests) at the captured head shown in its description, as requested. Continue review and further fixes on #4742. This closure does not assert CI readiness; the replacement remains draft. Source branch retained.

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