mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4411] [Engine] session-file saves: ping-pong blocks and a writer thread so the source copy overlaps the previous block write #5037
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5037
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4411
Author: @sakuumomo
Created: 10/28/2026
Status: 🔄 Open
Base:
main← Head:pr/engine-save-overlap📝 Commits (4)
5b44337core(session-file): a test hook for the write path - every full block reports its OS-write nanosecond span, plus the pipeline witness test (a block write inside a source-read window) that the serialized copy->write loop cannot passa4a39a3core(session-file): pipelined FileSink - ping-pong 16 MiB blocks and a lazily started writer thread so a source copy overlaps the previous block's OS write; the file bytes, golden hashes, progress reports, fault latching, and publish semantics are unchanged36d1e8dcore(session-file): account for the pipeline - the save preflight reserves the two 16 MiB write buffers, the peak test band moves to 32..34 MiB (RED against the old single buffer first), and the header documents that progress reports follow real movement from the caller's thread8d944e7core(session-file): drain synchronously when no writer thread can start - std::thread construction is caught (system_error -> the un-pipelined serialized path), pinned by a deterministic tests-only "writer_thread" seam and a starved-writer test; the block_span header now names the calling thread contract📊 Changes
4 files changed (+271 additions, -21 deletions)
View changed files
📝
include/strata/core/conversation_file.hpp(+8 -2)📝
src/core/conversation_file.cpp(+130 -15)📝
src/core/conversation_file_test.cpp(+131 -3)📝
src/program/generate.cpp(+2 -1)📄 Description
The problem
A busy-live session save crawls at ~110 MB/s while the storage beneath it measures 500+ MB/s (the owner's bcachefs pool on the desktop host).
FileSinkserializes: the producer copies one 16 MiB block out of the K/V sources, hands it towrite_all, waits for the write, then copies the next block. The GPU-side copy and the disk write never overlap.What this does
FileSinknow ping-pongs two 16 MiB buffers with a lazily started writer thread: while the writer drains block N to the OS, the producer already copies block N+1 out of the sources. When both buffers are busy the producer waits — at most one block behind.Deliberately unchanged:
write_allfailure merges into the existingf.error()/kind()channel after a clean join; the temp file is never published;Publisheruntouched;finish()(pad → truncate → sync → close) runs only after the writer has joined.New pieces:
std::system_error),FileSinkfalls back to synchronous draining: the exact old serialized path. The pipeline can never crash a save.Tests (all CPU, no new dependencies)
block_spanhook records each full block's OS-write span; the test asserts a write begins during a source read — causally impossible in the serialized loop (verified RED against it, GREEN against the pipeline). The hook sits beside the existingfaulthook inSessionWriteOptions(same tests-only precedent)."writer_thread"fault seam forces the fallback; the save still completes, byte-identical, with no overlap witnessed.conversation_(file|split_failure|cache|memory)_test,session_save_reclaim_test: 5/5. ThreadSanitizer run ofconversation_file_test: 0 warnings.Independent of #4310: the pipelined code is the
FileSinkcore as it stands onmain; the chain here is these four commits onmainalone.Update (2026-10-30)
Rebased onto upstream
v0.2.8(870aedd9); content unchanged, branch tip2a8d10b8(still these four commits). Gates re-run on the rebuilt lineage: the CPU session test family 7/7 (conversation_append_test1969 checks,conversation_file_test263,session_watermark_test21), the ThreadSanitizer run 0 warnings (1969 + 260 checks), and the owner's HIP-only (gfx1030) and CUDA+HIP hybrid (gfx1150) flavor builds green with installCheck. Commits re-signed (GPG ed25519) on 2026-10-30; trees unchanged from the validated work.Update (2026-11-07)
Rebased onto upstream
v0.2.12(123bad4a, engine 0.1.58); content unchanged, branch tip8d944e7f(still these four commits, zero conflicts). Gates re-run on the rebuilt lineage: CPU session family 7/7 (append 1969, file 263, watermark 31), ThreadSanitizer 1969 + 260 checks 0 warnings, and the owner's HIP-only (gfx1030) and CUDA+HIP hybrid (gfx1150) flavor builds green with installCheck on the redeployed trainnixos@c3e4cdc4. metal-link and title jobs are green on the new head; the PR is mergeable against currentmain. Commits re-signed (GPG ed25519) on 2026-11-07; trees unchanged from the validated work. The pre-rebase tip2a8d10b8stays fetchable as an ancestor of the train tagpin-f6f00908.Numbers (live battery on the owner's desktop host, post-merge)
A 166k-token, 4.94 GB session file: the old build saved it in 42–54 s uncontended (160 s worst, running through a heavy prefill); this build saves it in 54.5 s. Storage probes on the same pool at the same moment: 265 MB/s direct, 475 MB/s buffered+fsync — so the save ends at 91 MB/s because the engine-side source chain (K/V streamed out of the live state) is the binding rate on this host, not the disk. What overlap buys here is that the producer never stalls on disk mid-stream (the writer thread drains blocks while the source keeps copying; a save whose source runs at 91 MB/s cannot stream faster than its source, and the live rows confirm that); the byte stream is unchanged, and the pipelined write path is the foundation for append-delta saves — saving only the dirty tail (a few MB per turn at this size), which is where this host's save time actually collapses.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.