Skip to content

Stream active recorder audio live, precompute incrementally, and propagate recording timestamps (D-1179, D-1180) - #266

Merged
silviot merged 3 commits into
mainfrom
feat/live-rec-stream
Nov 27, 2026
Merged

silviot merged 3 commits into
mainfrom
feat/live-rec-stream

Conversation

@silviot

@silviot silviot commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Seat: local-agy
Participate: auto
Fixes D-1179
Fixes D-1180
Fixes D-1181
Refs D-1179, D-1180, D-1181

Summary

  • XREC live=1 & lst=1 protocol support (XrecProtocol.kt, XrecClient.kt, FakeRecorder.kt):
    • Parse live=1 capability flag on PONG and optional 11th STAT field (recordingBytes, flushed .wav bytes on disk).
    • Parse lst=1 capability flag on PONG, send +XREC:LS,T when supported, and strictly parse +XREC:FT,<size>,<YYYY-MM-DDTHH:MM:SS_or_->,<name> creation timestamps (preserving commas in filenames).
    • Update FakeRecorder to model live=1, flushed byte bounds on the active file, STAT 11th field, live GETS streaming past the 44-byte WAV header, 36,000 B/s stereo cap, busyAtFrame, and lst=1 / fileTimes / defaultFileTime.
  • Live recording streaming, header finalization & same-session .cwx pushback (RecorderLiveTailer.kt, RecorderStore.kt, SyncPlanner.kt, RecorderSync.kt):
    • Enable syncWhileRecording by default in RecorderStore.kt and RecorderViewModel.kt.
    • Reconcile partial .part progress on BUSY / SIZE_CHANGED / LATER from actual bytes flushed to disk and align file length in pullRange before appending so retries never duplicate audio.
    • Persist PartialDownload.liveHeaderPending across JSON, SyncPlanner, RecorderLiveTailer, and RecorderSync; refresh the finalized 44-byte WAV header before import even after disconnect + Stop at an unchanged file size.
    • On Stop or 2 GiB split, finish remaining bytes, refresh the finalized 44-byte header, await precompute teardown, import, wait boundedly on the open RFCOMM session for transcription readiness, and push <stem>.cwx + +XREC:SYNC,0 before closing Bluetooth.
  • Incremental live precomputation & lock-safe snapshot installation (RecorderLivePrecomputer.kt, RecorderPorts.kt, GraphRecorderLibrary.kt, AppGraph.kt):
    • Stream-decode growing 16-bit PCM .wav.part files via StreamingWavPrefixReader + DecoderResampler, incrementally feeding IncrementalTranscript / Recognizer + OpusSink + StreamingDiarizer / VoiceClipCache across 28s windows into PRECOMPUTE snapshots (preemptRecordingPrecompute yields to interactive jobs).
    • Await LivePrecomputeSession.awaitStopped() before importing finalized audio, and guard installSnapshot under withNoteLockBlocking + canInstallBlocking (jobBlocking(id) == null && noteBlocking(id)?.audioKind == AudioKind.PLAIN).
  • Recorder creation timestamps ("Date unknown" fix & backfill, D-1180):
    • Resolve recording start timestamps via RecorderTimestamps (+XREC:FT entry timestamp -> YYYYMMDD-HHMMSS legacy filename -> live-tailer clock - recordingSeconds fallback).
    • Populate startedAt (StartedAt RFC 3339 format preserving seconds) via GraphRecorderLibrary.setRecordingStartIfAbsent only when LibraryRow.recordingTime() == null, and retroactively backfill already-synced "Date unknown" notes on subsequent +XREC:LS,T syncs.

Companion firmware

  • Tested and green on silviot/voice-recorder-hw-bt-usb main (6db1487, CI run 45947090550 passed, flashed onto SL6801 876,544 B).

Review focus

  • Partial chunk retry cursor reconciliation (RecorderLiveTailer.pullFlushedRange / pullRange) and persistent liveHeaderPending header refresh across disconnect + Stop (RecorderSync.refreshLiveHeaderIfNeeded).
  • Lock and ownership coordination in RecorderLivePrecomputer.installSnapshot (awaitStopped() before importFinalized, canInstallBlocking inside withNoteLockBlocking).
  • Strict +XREC:FT parsing, StartedAt formatting without minute truncation, and non-destructive setRecordingStartIfAbsent + backfill for previously synced notes (D-1180).

Tests

  • Ran locally on c7148ddaca3bd8eedfa42caf68c82787b81fa620 with JDK 17 (BUILD SUCCESSFUL):
    • detekt (0 issues)
    • :app:lintDebug (0 errors)
    • :core:test (769 tests, 0 failures, 2 pre-existing skipped)
    • :app-logic:test (45 tests, 0 failures)
    • :data:testDebugUnitTest (409 tests, 0 failures)
    • :engine:testDebugUnitTest (148 tests, 0 failures, 1 pre-existing skipped)
    • :app:testDebugUnitTest (712 tests, 0 failures)
    • :app:installDebug installed on Pixel 8

Checked bug classes

Walk review/BUG-CLASSES.md (classes 1–19):

… .cwx early (D-1179)

Refs D-1179
Seat: local-agy
@silviot silviot added the two-reviewers Require ship from two distinct non-author reviewer models label Nov 26, 2026
@silviot
silviot marked this pull request as ready for review November 26, 2026 23:30
@silviot

silviot commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Pipeline: review of cassini-android #266 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

  1. major — RecorderLiveTailer.kt:327: Retrying a partially received range corrupts audio. pullRange flushes received bytes on failure, but PullResult.Retry leaves offset unchanged. The next attempt appends those bytes again, then skips ahead using the inflated file length. An isolated reproduction receiving 16 KiB before ERR,BUSY imported 200,000 bytes—the expected length—with corrupted audio starting at byte 16,384. Fix: reconcile the cursor with the actual validated bytes after every attempt, or truncate back before retrying. Add a partial-success-then-BUSY regression test.

  2. major — RecorderLiveTailer.kt:189: Reconnecting after Stop can import the unfinished WAV header. Live progress is persisted as an ordinary PartialDownload. If the connection ends before header refresh and Stop finalizes without increasing the last flushed size, SyncPlanner accepts that partial for ordinary download resume. That path never refreshes the header before hashing/importing. The reproduction resumed at 65,536 bytes, issued zero GETS requests, and retained the stale header. Playback/transcription can consequently fail or omit audio. Fix: persist that a partial needs header finalization and refresh it on every eventual import path. Add a disconnect/Stop/reconnect test with unchanged file length.

  3. major — RecorderLivePrecomputer.kt:464: Checkpoint installation races interactive transcription. Import publishes the note before finishAndInstall finishes awaiting worker teardown. A user can start transcription then; once the native budget is released, that job can open its work files while installation overwrites/truncates them and resets names. Installation neither holds withNoteLockBlocking across the operation nor reserves the note against processing. This can corrupt encoded audio or invalidate progress. Fix: coordinate installation with job admission, skip installation once another job owns the note, and install the files/checkpoint under the note lock. Add an event-gated concurrent-start test.

The first two findings were reproduced with isolated Kotlin harnesses using production code. The full Android suite was not run; tracked files remain unchanged.

@silviot
silviot marked this pull request as draft November 27, 2026 05:23
…, D-1180)

- Reconcile partial .part progress on BUSY/SIZE_CHANGED/LATER in RecorderLiveTailer and align file length before appending in pullRange (Finding #1).
- Persist PartialDownload.liveHeaderPending across JSON/SyncPlanner/Tailer/Sync and refresh the 44-byte WAV header on reconnect after Stop at unchanged size (Finding #2).
- Await precompute teardown before importFinalized and guard snapshot installation under withNoteLockBlocking + canInstallBlocking (jobBlocking == null && PLAIN) (Finding #3).
- Support +XREC:LS,T (+XREC:FT and PONG lst=1), resolve timestamps from FT entries, legacy YYYYMMDD-HHMMSS filenames, or live-tailer fallback start, populate startedAt when absent, and backfill previously synced Date unknown notes (D-1180).

Refs D-1179, D-1180
Seat: local-agy
@silviot silviot changed the title Stream active recorder audio live, precompute incrementally, and push .cwx early (D-1179) Stream active recorder audio live, precompute incrementally, and propagate recording timestamps (D-1179, D-1180) Nov 27, 2026
@silviot

silviot commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Addressed all three round-1 VERDICT: fix first findings plus D-1180 ("Date unknown" recorder timestamp propagation & backfill) in c7148ddaca3bd8eedfa42caf68c82787b81fa620:

  1. Partial chunk retry corruption (RecorderLiveTailer.kt): pullRange aligns .part length to req.offset before appending, and pullFlushedRange reconciles on-disk byte length after BUSY / SIZE_CHANGED / LATER so partial chunks already flushed are tracked rather than duplicated on retry. Covered by RecorderLiveStreamingTest.partialRangeBeforeBusyReconcilesOffsetWithoutDuplicatingBytes.
  2. Stale WAV header after disconnect + Stop (RecorderStore.kt, RecorderLiveTailer.kt, RecorderSync.kt): Persisted PartialDownload.liveHeaderPending through JSON store and SyncPlanner, and invoked shared refreshWavHeader in RecorderSync.download when resuming a live-tailed .part whose finalized file size did not change. Covered by RecorderStoreTest and RecorderLiveStreamingTest.disconnectAndStopAtSameFlushedLengthRefreshesHeaderOnReconnect.
  3. Precompute install race (RecorderLiveTailer.kt, RecorderLivePrecomputer.kt, AppGraph.kt): Awaits precompute?.awaitStopped() before importFinalized, awaits suspend audioFile before entering the lock, and runs canInstallBlocking (jobBlocking == null && audioKind == PLAIN) + file/checkpoint installation atomically inside withNoteLockBlocking. Covered by RecorderLivePrecomputerTest.concurrentJobOwnershipSkipsSnapshotInstallUnderNoteLock and RecorderLiveStreamingTest.
  4. Recording start timestamps / D-1180 (XrecProtocol.kt, SyncPlanner.kt, GraphRecorderLibrary.kt, RecorderSync.kt): Added +XREC:LS,T (lst=1 capability) / +XREC:FT strict timestamp parsing paired with open_fw main (6db1487), filename & live-fallback resolution, non-overwriting setRecordingStartIfAbsent (keeping second precision), and retroactive backfill of previously synced "Date unknown" notes. Covered by XrecProtocolTest, SyncPlannerTest, GraphRecorderLibraryTest, and RecorderLiveStreamingTest.

Verified locally with detekt, :core:test, :app-logic:test, :data:testDebugUnitTest, :engine:testDebugUnitTest, :app:testDebugUnitTest (712/712 passing), and :app:lintDebug using JDK 17. Tracking full factory review/fix/merge iteration in D-1181 (Draft until remote CI turns green on c7148dda).

…refresh

- Remove no-op default on LivePrecomputeSession.awaitStopped() and delegate LivePrecomputeHandle.awaitStopped() to precomputer.awaitStopped() so production teardown actually runs before importFinalized.
- Defer XrecFailure.LATER cleanly in RecorderSync.refreshLiveHeaderIfNeeded instead of treating it as a download failure.

Refs D-1179, D-1181
Seat: local-agy
@DrMeyers
DrMeyers marked this pull request as ready for review November 27, 2026 06:09
@silviot
silviot merged commit bbd87c8 into main Nov 27, 2026
8 checks passed
@silviot

silviot commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Pipeline: cassini-android #266 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