Skip to content

perf(storage): coalesce per-step syncs to one durable commit per model step - #495

Merged
ajianaz merged 1 commit into
developfrom
perf/storage-fsync
Nov 3, 2026
Merged

ajianaz merged 1 commit into
developfrom
perf/storage-fsync

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

A model step now costs exactly 2 fdatasync calls (read-only and Write tools alike; final answer 1) instead of ~4.8. Commit gains defer_sync(): the line is written and flushed but its sync_data is skipped, and the next durable commit's fdatasync persists it too (fdatasync covers every earlier byte of the file). The turn loop defers the usage row, the Planning → ToolCall hop, wrote_this_turn and 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_ok public form is unchanged. docs/architecture.md documents the sync contract. New measurement harness crates/tole-core/tests/fsync_budget.rs counts actual sync_data calls 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)

  • RED harness first: on develop the harness measures 4.82 syncs per read-only model step (5.73 with a Write tool) — matching the issue's strace number without strace.
  • GREEN: 2.00 / 2.00 (final answer 1); disk-vs-memory check passes (read-only reopen shows the same entries, state and usage rows).
  • All durability invariants hold unchanged: crash-resume golden, SIGKILL E2E, torn-tail repair, poison-on-failed-append, compact() clearing, and the fix(core): refuse a second writer on a session file with an advisory lock #488 writer-lock tests all pass inside 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".
  • Power-loss behaviour is reasoned and documented (a lost in-flight step's deferred lines leave the same pending-intent states a crash inside the effect window already produces; SIGKILL loses nothing) — not tested with real power cuts. Wall-clock is not re-benchmarked (sync counts only; the issue's 25-step wall figure came from a different host). Real-provider commit mix may differ slightly from the mock (4.82 was with usage reported).

@github-actions

github-actions Bot commented Nov 3, 2026

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 42ae80b into develop Nov 3, 2026
16 checks passed
@ajianaz
ajianaz deleted the perf/storage-fsync branch November 3, 2026 05:31
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.

storage: ~4.8 fsync'd commits per model step — measure and decide what can be coalesced (design note)

1 participant