Repository navigation
perf(storage): coalesce per-step syncs to one durable commit per model step - #495
Merged
Merged
Conversation
🔍 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 (description of the change)
A model step now costs exactly 2
fdatasynccalls (read-only and Write tools alike; final answer 1) instead of ~4.8.Commitgainsdefer_sync(): the line is written and flushed but itssync_datais skipped, and the next durable commit'sfdatasyncpersists it too (fdatasync covers every earlier byte of the file). The turn loop defers the usage row, thePlanning → ToolCallhop,wrote_this_turnand the tool settlement (settle_ok_deferred, crate-private); every one of them is always followed by a durable commit before an effect runs, the next provider call starts, or the turn returns. The intent commit (begin),finish, the final answer and every error/settle-error path stay durable.settle_okpublic form is unchanged.docs/architecture.mddocuments the sync contract. New measurement harnesscrates/tole-core/tests/fsync_budget.rscounts actualsync_datacalls through a#[doc(hidden)] JsonlStorage::sync_count()and re-opens the file read-only to prove disk matches memory after a turn. CHANGELOG under [Unreleased].Why (the problem you're solving)
Closes #483. The issue measured ~4.8 fsync per model step (strace, aarch64) because the turn loop issues ~5 commits per tool step (usage, ToolCall hop, intent, settlement, finish) and each synced. The design decision here is Option 1's intent without changing the on-disk format: merging transitions into one commit would need a format change, so the syncs are deferred instead — one line per commit, same bytes, fewer waits.
Testing (how you verified this works)
cargo test --workspace --no-fail-fast(933 passed / 0 failed).cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test -p tole-core --no-default-features(362 passed / 0 failed),cargo build -p tole-cli --no-default-features: all pass. cora pre-commit gave a real verdict: "No issues found".