Skip to content

feat(core): discussion ledger budget hard stops, crash-safe spend and caps (#588 part 2a) - #685

Merged
ajianaz merged 1 commit into
developfrom
feat/discussion-ledger-budget
Nov 13, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/discussion-ledger-budget

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 2a of #588: the discussion ledger (tole_core::discussion_log) gets the budget hard stop, crash-safe spend accounting, the digest fallback and caps the host driver needs. Still no model call and no command.

Why

The driver (next PR) must stop on a spent budget with an escalation (never a silent end), must not overspend after a crash, must fall back to the verbatim pass-1 text when the scribe's digest is refused, and must not be able to grow a record or the log without bound. The ledger refused a verbatim summary of a big round, had no way to stop mid-round, and capped the log only on read (an append could push it past the cap and make it unreadable).

Changes

  • reserve(round, what, tokens) before a provider call: counted at its estimate until settle(call, tokens) replaces it with what was spent. A call that does not fit what is left is not reserved: the gate's Escalate(Budget) is recorded at once, wherever the round is, and next() goes to Finish. A crash-interrupted call stays counted at its estimate. open_call and bind(call, handle) let a host find and poll a call that runs elsewhere (a delegated child) instead of starting it again.
  • RoundSummary::Fallback { round, contributions, reason }: only for a round big enough for the scribe, exactly the round's contributions, reason at most 300 characters; never counts as a stalled round.
  • Caps: one record at most 512 KiB, the log at most 16 MiB on write as well as read, with the last 128 KiB kept for the gate and the closing record (closing text capped at 16,000 characters).
  • The log is read with O_NOFOLLOW | O_NONBLOCK and a size cap checked on the opened file (read_plain_file); the log and its lock are opened with O_NOFOLLOW.
  • CHANGELOG.

No new dependency; tole-core still builds with --no-default-features.

Testing

  • New tests in discussion_log_tests.rs: reserve/bind/settle, the mid-round budget stop, reservation only for the open round, crash survival of an unsettled reservation, the fallback rules, record and log caps (with room to stop and close), and symlinked log and lock files. discussion_tests.rs covers the fallback's round, delta and fencing.
  • Mutation checks: each rule broken on purpose made a test fail (the mid-round stop in next(), the record cap, the close reserve, settle replacing the estimate, the fallback size rule, O_NOFOLLOW, the open-round check, the budget check, settle-once).
  • cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace, cargo test -p tole-core --no-default-features, cora review --no-llm --staged: all clean.

… caps (#588 part 2a)

Every provider call of a discussion is reserved before it runs and settled after it; a call that does not fit the budget records the budget escalation at once. A refused digest falls back to the round as written. Records and the log are capped on write as well as read, and the log and its lock are never opened through a symlink.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 5b2a25d into develop Nov 13, 2026
19 checks passed
@ajianaz
ajianaz deleted the feat/discussion-ledger-budget branch November 20, 2026 08:36
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.

2 participants