fix(bot): never sweep a directory that holds a real recording (#399) #447
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/399-never-sweep-real-audio"
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?
Closes the data-loss half of #399 (CRITICAL).
The defect
The startup sweep deleted any session directory that was unmarked and older than an hour — and the marker meaning "the backend owns this" was only written after a successful upload ack. Four ordinary situations therefore left hours of captured speech looking exactly like abandoned scratch:
.s16lecapture on diskThat last one isn't in the issue. It was introduced by a fix, in this same milestone, and it's the sharpest version of the bug — it tells the GM in bold that "Nothing was lost — this recording is saved separately" and then returns without marking anything. The reassurance and the deletion are eleven lines apart.
The sweep's docstring asserted "the backend never received the upload so there is nothing to preserve." That sentence is exactly backwards: an upload the backend never received is precisely when the bot holds the only copy.
The fix
The test is no longer "is it marked and old" but "can I prove there is nothing here to lose." A directory or raw file containing a non-zero-byte track is kept regardless of age or marker, and reported in the log. Only provably-empty scratch is removed.
Disk growth is recoverable; a deleted session is not — the same standard #427 settled on for the backend, now applied to the bot.
Beyond stopping the loss, a failed handoff is retried on the next startup, before anything sweeps. A manifest written when the session directory is created carries the exact payload, so the retry replays the original request rather than reconstructing one. That matters concretely:
duration_secondswould otherwise default to0, which silently disables the backend's coverage guards — the mechanism behind #421. The backend refusing to overwrite is recorded as terminal, so that take is kept but not re-asked on every start.Two existing tests asserted the destructive behaviour
test_cleanup_removes_old_orphaned_session_dirwrote a non-empty123.wavand required the sweep to delete it.test_cleanup_removes_old_raw_wavdid the same for raw capture. They were the defect written down as the specification — exactly the pattern #441 exists to hunt — and are inverted here, with the history noted in their docstrings so nobody "fixes" them back.Verification
Mutation-checked: with the content guard bypassed, three tests fail, including the issue's own scenario (four-hour session, upload fails during maintenance, bot redeployed two hours later).
218 bot tests pass (was 211), 1,409 backend.
Not done here
Finalising a mid-recording crash's raw tracks into WAVs and handing them off. They're now preserved and logged with their path rather than deleted, which stops the data loss — but converting them needs session metadata the bot no longer holds at that point. #399 stays open for it rather than being closed on a partial.
Note on branches
This and PR #446 were briefly stacked by mistake — #446 also carried the gitleaks commit. Both have been rebased onto
mainand force-pushed, so each PR is now a single independent commit. Worth a fresh look at #446's diff if you'd already reviewed it.🤖 Generated with Claude Code
1f799f0942825ec24287