fix: crash-safe WAV headers + orphaned-chunk recovery (#79)#80
Merged
Conversation
WavFileWriter only patched the real size/format into the header in finalize(); the 0.5s periodic sync flushed data but not the header. A capture service killed mid-chunk left valid PCM behind a placeholder "0-frames" header, so the chunk read as empty, was skipped by archival, and dropped from the transcript (~26 min lost in the 2026-06-12 session). - WavFileWriter.flushHeader(): patch header in place; syncIfNeeded() now calls it every 0.5s so a crash leaves a readable WAV. finalize() reuses it. - WavFileWriter.repairHeader(path:): static recovery that rebuilds the RIFF/data size fields of an under-reporting header, preserving the format block; returns whether it changed anything. - ChunkProcessor.transcribeStream: repair each chunk WAV before reading it, so crash-orphaned chunks self-heal. - 3 new WavFileWriterTests; full suite 464/464 green. - scripts/test-checklist.md: crash-recovery manual test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Fixes #79.
Problem
WavFileWriteronly patched the real size/format into the header infinalize(); the 0.5 s periodic sync flushed audio data but never the header. When the capture service is killed mid-chunk (crash-recovery path),finalize()/swapWriters()never runs on the active writers, leaving valid PCM behind a placeholder "0-frames" header. The chunk then reads as empty → 0 transcript segments → archive step skipped → orphaned WAVs dropped from the transcript.Discovered on the 2026-06-12 session: chunk 0's two 152 MB WAVs survived un-archived and ~26 min of real two-way conversation was missing from the transcript.
Fix
WavFileWriter.flushHeader()— patches the header in place;syncIfNeeded()now calls it every 0.5 s so a crash leaves a readable WAV (loss bounded to the last sync interval).finalize()reuses it.WavFileWriter.repairHeader(path:)— static recovery that rebuilds the RIFF/data size fields of a WAV whose header underreports its payload, preserving the format block; returns whether it changed anything.ChunkProcessor.transcribeStream— callsrepairHeaderdefensively before reading each chunk WAV, so crash-orphaned chunks self-heal.Tests
WavFileWriterTests(flush-without-finalize, repair underreported size, leave consistent file unchanged).scripts/test-checklist.mdupdated with a crash-recovery manual test.Related (adjacent, not duplicate)
Verification status
🤖 Generated with Claude Code