Skip to content

Live recorder transcription recovery: durable precompute, prompt Stop catch-up, resumed growing downloads (D-1202) - #268

Merged
silviot merged 4 commits into
mainfrom
participate/d-1202
Nov 28, 2026
Merged

silviot merged 4 commits into
mainfrom
participate/d-1202

Conversation

@silviot

@silviot silviot commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Seat: local-claude
Participate: auto
Fixes D-1202

Summary

Brings in branch feat/live-precompute-resilience (7cae2a00, 66fb7bbd, unchanged) and adds one review-fix commit on top.

Branch changes:

  • The live precompute stages into <part>.precompute/ (checkpoint, append-only word log, Opus and clips) next to the .part file. It verifies PCM slices only, never the 44-byte WAV header that Stop rewrites, so progress survives a Bluetooth disconnect, preemption, and reconnecting after Stop. The verification also accepts older checkpoints that kept a separate live-source.json.
  • Live transfer re-polls STAT every 64 KiB (4 × RECORDING_GETS_WINDOW), so Stop lifts the recording-speed limit even when a large backlog remains. After Stop, the remaining download wakes inference every 256 KiB.
  • A growing .part with liveHeaderPending resumes after Stop. It checks the head (44..512) and the tail of the downloaded PCM against the recorder, refreshes the finalized header, and installs the staged checkpoint at import (installLivePrecompute). The planner accepts a live partial whose size grew.
  • Wake lock renewed every 60 s. Precompute runs at default priority, or nice +2 while the app is visible, instead of the background cgroup. The round-trip hold is 30 min.

Review fixes (04bed1b3):

  1. Staging race: a closed LivePrecomputeHandle freed its AppGraph slot at once, though close() only cancels its worker. The next createRecorderLivePrecompute on the same part (from the tailer's ensureActive retry or a post-Stop RecorderSync.download) skipped the join. It could then load or clear staging files while a cancelled saveStaged was still writing them. The slot is now freed only when the worker stops, and PrecomputeHolder awaits the old worker before it reopens.
  2. Discard race: discardRecorderLivePrecompute deleted the directory while a cancelled worker could still be writing into it. RecorderLivePrecomputer.discard() now deletes it once the worker has stopped.
  3. Auto sync stall: RecorderRunner.attempt(FULL) waited up to 30 min in the round-trip hold before returning its outcome. That stopped RecorderAutoSync from polling, so a recording started during the hold was not tailed live. The outcome now returns at once, and a detached coroutine keeps only the service run through the hold.

Second review round (091d64e9):
4. Discard/reopen race: a coroutine job counts as completed before its completion handlers finish, so awaitStopped()'s cancelAndJoin() could return while the deletion handler from discard() was still running. A replacement worker could then open staging files that were still being deleted. RecorderLivePrecomputer now completes a stopped deferred only after the worker finishes and any requested discard deletion is done. awaitStopped, finishAndInstall and invokeOnStopped all wait on it. A discard that arrives after the worker has stopped deletes under the same lock that the join waits on.

Review focus

  • Discard serialization in RecorderLivePrecomputer (lifecycle lock, stopped deferred, joinStopped()): this replaces the earlier reliance on completion-handler order.
  • verifiedLiveOffset now passes non-link transfer errors up instead of restarting from 0 (the branch does this on purpose: "a failed transfer leaves the prefix intact").

Verification

  • Docker SDK image: detekt ciTest :app:lintDebug :data:lintDebug :ui:lintDebug passes at 091d64e9; earlier, :app:testDebugUnitTest --tests 'io.codemyriad.cassini.recorder.*' pass. New tests: discardDeletesStagingOnlyAfterTheWorkerStopsSaving, reopeningWaitsForAnInFlightDiscardDeletion (event-gated: it blocks the deletion and reopens undispatched; it fails against the previous handler-only discard) and fullAttemptReturnsAtOnceAndHoldsServiceUntilRoundTripTranscriptionEnds. Full CI on this PR.
  • Not measured: end-to-end Stop-to-transcript latency on physical hardware (as the ticket says).

Checked bug classes

🤖 Generated with Claude Code

silviot and others added 3 commits November 28, 2026 01:48
…cked

- Renew PARTIAL_WAKE_LOCK periodically in RecorderSyncService and extend RecorderRunner round-trip hold to 30m (including full syncs with downloads)

- Split RecorderLivePrecomputer inference step priority (normal/nice +2 instead of THREAD_PRIORITY_BACKGROUND cgroup throttling)

- Persist .part precompute staging (checkpoints, append-only word log, PCM slice hashes, audio.opus.part move) via RecorderLivePrecomputeStore across reconnects and preemption

- Retry blocked live precompute in RecorderLiveTailer, enable catch-up precompute in RecorderSync downloads, and use StreamingWavPrefixReader for .part WAV whistle replay
…rn full syncs before the round-trip hold (D-1202)

- A closed LivePrecomputeHandle now keeps its AppGraph slot until the worker stops, so the next session over
  the same `.part.precompute/` directory joins it instead of loading or clearing files a cancelled save still
  writes. RecorderLiveTailer's PrecomputeHolder awaits the old worker before re-opening.
- discardRecorderLivePrecompute deletes the staging directory once the active worker has stopped
  (RecorderLivePrecomputer.discard), not while a checkpoint save can recreate it.
- RecorderRunner.attempt returns the outcome at once and keeps only the service run through the 30 min
  round-trip hold, so Auto sync keeps polling and a new recording is tailed live meanwhile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silviot silviot added the two-reviewers Require ship from two distinct non-author reviewer models label Nov 28, 2026
@silviot
silviot marked this pull request as ready for review November 28, 2026 09:11
@silviot

silviot commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Pipeline: review of cassini-android #268 says fix first. One round: fix every blocker and major, put the PR back to draft, push, mark ready on green. If you disagree with a finding, last line of PR body or comment: WAITING-ON-COORDINATOR: .


VERDICT: fix first

  • major — RecorderLivePrecomputer.kt:347: Reopening can race the discard handler and lose transcription progress. A coroutine job becomes completed before its completion handlers finish. If createRecorderLivePrecompute() calls awaitStopped() while the deletion handler is running, cancelAndJoin() returns immediately. The replacement worker can then open staging files that the old handler is still deleting. Registering deletion before the join does not protect this case. I reproduced this ordering against the pinned coroutines 1.11.0 using latches.

    Make discard an awaited, serialized operation: cancel/join the worker, finish deleting staging, then permit reopening. Add an event-gated regression test that blocks deletion and attempts reopening after deletion has begun; the existing test waits for a subsequent completion handler and misses this race.

@silviot
silviot marked this pull request as draft November 28, 2026 09:18
…letion, not just the worker job (D-1202)

A coroutine job counts as completed before its completion handlers run, so
awaitStopped()'s cancelAndJoin() could return while discard()'s deletion
handler was still removing the staging directory, letting a replacement
worker open files that were being deleted. awaitStopped, finishAndInstall and
invokeOnStopped now wait on a deferred that completes only after the worker
finished and any requested discard deletion is done; a discard arriving after
the worker stopped deletes under the same lock that the join waits on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silviot
silviot marked this pull request as ready for review November 28, 2026 09:39
@silviot
silviot merged commit 81e6b1d into main Nov 28, 2026
8 checks passed
@silviot

silviot commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Pipeline: cassini-android #268 is merged (review: ship). Continue with your next item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

two-reviewers Require ship from two distinct non-author reviewer models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant