Repository navigation
feat(core): discussion ledger budget hard stops, crash-safe spend and caps (#588 part 2a) - #685
Merged
Merged
Conversation
… 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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
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 untilsettle(call, tokens)replaces it with what was spent. A call that does not fit what is left is not reserved: the gate'sEscalate(Budget)is recorded at once, wherever the round is, andnext()goes toFinish. A crash-interrupted call stays counted at its estimate.open_callandbind(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.O_NOFOLLOW | O_NONBLOCKand a size cap checked on the opened file (read_plain_file); the log and its lock are opened withO_NOFOLLOW.No new dependency; tole-core still builds with
--no-default-features.Testing
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.rscovers the fallback's round, delta and fencing.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.