Repository navigation
fix(ios): forward Apple Watch audio chunks without holding the whole recording - #21072
aryanorastar merged 3 commits into
Conversation
…recording The iPhone kept every Watch chunk in `audioChunks` until the last one, then stitched them into one buffer for `onAudioData`, whose Flutter handler is empty. Flutter's only consumer of Watch audio is the per-chunk `onAudioChunk` stream, so the stored copy was never used, yet it grew about 115 MB per recorded hour plus a second full copy at the end. A long session could get the app killed in the background; after relaunch `isRecordingActive` is false and every later chunk is dropped (BasedHardware#20479). Each chunk now goes straight to Flutter and nothing is kept. The final chunk is an empty end marker and is skipped as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moves the chunk-to-Flutter step into a stateless WatchAudioChunkRelay so a swiftc harness can prove every chunk is forwarded as it arrives and the empty end marker is dropped, and asserts AppDelegate keeps no chunk store (BasedHardware#20479). Adds the manifest check and the iOS changelog fragment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reviewed against the merge-base diff (3bb93db..1b8e07e). The core claim checks out. app/ios/Runner/AppDelegate.swift drops the audioChunks dictionary and reassembleAndSendAudioData(), which previously accumulated every Watch chunk (~115 MB per recorded hour) and then re-sent the whole stitched buffer via onAudioData. I verified onAudioData is a dead consumer: its Dart handler in app/lib/services/bridges/apple_watch_bridge.dart:26 is an empty body, the Android side is a stub, and the Pigeon-generated plumbing has no other caller. The real audio path is onAudioChunk -> AppleWatchFlutterBridge.onChunk -> WatchTransport._audioControllers (app/lib/services/devices/transports/watch_transport.dart), which forwards bytes only and ignores isLast - so deleting the stitched copy loses no audio. Per-file notes:
Caveat: I could not execute the ruby test on this review host (Linux, no swiftc); it is declared as a macOS-lane check consistent with its siblings and Mobile Release Eligibility passed on the PR head, but it hasn't been observed running in CI on this diff. The out-of-scope items (relaunch session handling, transferFile) are reasonable deferrals. Nice fix - clear root-cause analysis, verified on simulators with a memory A/B, and a test that pins the memory invariant. Leaving for human maintainer review before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Thanks for checking the audio path end to end. On the caveat: |
What changed and why
Part of #20479: an 11-hour Apple Watch recording ended with almost nothing saved.
What happens today. While the Watch records, the iPhone app forwards each 1.5 s chunk to Flutter's capture path, which is the real audio path. It also keeps every chunk in
AppDelegate.audioChunksuntil the last one arrives. Then it stitches them into one buffer and sends it to Flutter'sonAudioData, whose handler is empty (apple_watch_bridge.dart), so that copy is thrown away. The stored copy grows by about 115 MB per recorded hour (16 kHz, 16-bit mono), roughly 1.3 GB at 11 hours, plus a second full copy at the end. iOS kills a background app long before that.What this PR does. The iPhone keeps nothing:
WatchAudioChunkRelay.audioChunksstore are deleted.Flutter's chunk handler (
watch_transport.dart) ignoresisLastand only forwards bytes, so the audio Flutter receives is unchanged.Not in this PR:
isRecordingActiveis false and later chunks are dropped. Turning recording back on when a stray chunk arrives would create phantom recordings: queued background chunks can arrive after Stop. That needs a session id from the Watch.transferFileis a separate change.Product invariants affected
none
How it was verified
End to end on simulators: a watchOS 27 Watch simulator paired with an iPhone 16 Pro simulator (iOS 26.5), and the Watch app installed as a dependent app.
reachable: YES, paired: YES, appInstalled: YES.Memory A/B:
mainvs this branch, both run the same way: app opened from the Home Screen, 388 chunks each.phys_footprint(footprint -f bytes) every 15 s. RSS can't show this in a simulator: its mic records silence, macOS compresses the all-zero chunks out of RSS, and both builds look flat.mainBoth curves rise and fall as Flutter's normal capture work runs, so the difference is in the trend, not every sample.
Not verified:
Tests
app/ios/test/watch_audio_chunk_relay_test.rb, wired into.github/checks-manifest.yamlasios-watch-audio-chunk-relay:WatchAudioChunkRelay.swift, plays a 40-chunk Watch session, and checks:AppDelegateroutes chunks through the relay and has no chunk store.With
main'sAppDelegate.swiftrestored, the second test fails ("Watch chunks must go through the relay"). On this branch both pass.The iPhone app built and ran on the simulator with the new file in both app targets.
UI evidence
UI-Evidence: none -- native memory fix with no UI change
Failure class (fixes)
Failure-Class: none
🤖 Generated with Claude Code