Skip to content

fix(android): require a nonzero chunk before a recorder counts as ready - #4559

Merged
thymikee merged 2 commits into
callstack:mainfrom
shahjahanpak:fix/4550-android-rollover-zero-byte-chunk
Nov 16, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
shahjahanpak:fix/4550-android-rollover-zero-byte-chunk

Conversation

@shahjahanpak

@shahjahanpak shahjahanpak commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4550. A rollover chunk counted as ready as soon as its file existed. When the device refuses a second concurrent screenrecord, the new recorder exits and leaves a 0-byte file. The rotation committed that chunk, the sequential fallback never ran, and record stop failed with artifact is not stable.

waitForReady now needs a non-zero size, as the readiness check did before #1724 moved it onto exists. A dead recorder with an empty file now fails the start, so the existing concurrent-start recovery runs. A live recorder still counts as ready after the bounded wait; while its file is empty, a start waits up to two 250 ms polls. If the sequential start also fails, the rotation gives today's typed error.

Partial-recording return and the close/claim path are unchanged.

2 files: chunks.ts and runtime.test.ts (two new cases; the SIGINT case now counts calls after start). No scope expansion.

Validation

Base d78be6c88, head 5630ceb28.

pnpm exec vitest run --project unit-core packages/platform-android/src/recording/runtime.test.ts: base 1 failed, 16 passed; head 17 passed. 39d18960c adds a pin test (18 passed).

pnpm check:quick: passed. pnpm check:affected --run --base upstream/main --head 5630ceb28 (exactCommit: true): format, lint, typecheck, layering, fallow and build passed. vitest-related failed by 5 s timeouts across 67 provider files on a loaded host. android-recording.test.ts alone times out on base and head alike. CI owns these.

Live run at 5630ceb on an Android 16 emulator: see the review reply. The refusal path is covered only by mocks.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

A rollover chunk whose recorder exits without writing left a zero-byte
file. Its existence counted as readiness, so the sequential fallback never
ran and record stop later failed on the empty artifact.

Closes callstack#4550

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

The code change at 5630ceb looks right for the reported case, but there is no live Android run of the route it changes yet. All 14 checks pass at this head.

waitForReady is shared by every Android recorder launch through startChunkAt: the first start and every rotation. This PR swaps the exists probe for a size probe, which is a second adb call on the real transport, and a dead recorder with a 0-byte file now fails the start. That changes live device dispatch for all Android recordings. The tests use a mocked transport, so CI cannot show the real size probe working. Please attach a live run at 5630ceb: record start <file> --scope device on an emulator or device, then record stop, with the returned video playing, plus the device used. A run past about 175 s that shows a second chunk committed with nonzero bytes (ls /sdcard/agent-device-recording-*) would be ideal. If no device refuses a second recorder, please say the refusal path is only covered by mocks.

Not blocking, and you can take or leave these: waitForReady still returns true when the recorder stays alive at 0 bytes for all 3 polls, so a recorder rejected late, or one that never writes, would still be committed and record stop would still hit artifact is not stable. Do you know from a device whether the refused recorder exits promptly? If it can stay alive at 0 bytes, the rotation path could wait longer for size > 0 inside the same function, so the sequential fallback runs. If it exits promptly, no code change is needed. The first start now waits about 500 ms when the first write lags, which is a small latency change you could mention in the PR body. A test where an alive recorder reports size 0 on the first polls and then a positive size, asserting the chunk commits without the fallback, would pin the slow-first-write case in runtime.test.ts.

@shahjahanpak

Copy link
Copy Markdown
Contributor Author

Thanks. Live run at 5630ceb on an Android 16 (API 36) emulator, image sdk_gphone64_arm64-userdebug, with Settings in front:

  1. record start <file> --scope device, then record stop after a 194.2 s recording window.
  2. ls -l /sdcard/agent-device-recording-* at about 180 s, before the stop:
    178154 agent-device-recording-1794816202712.mp4
      3232 agent-device-recording-1794816373333.mp4
    
  3. record stop returned recording: stopped, recorder: confirmed, nativePathDisposition: retired, two chunks and the 180 s split warning. Host files: long.mp4 178,154 bytes and long.part-002.mp4 59,163 bytes.
  4. Both files play. ffprobe reads H.264 720×1600: 171.3 s (43 frames) and 0.57 s (2 frames). record contact-sheet decodes 48 of 48 and 3 of 3 sampled frames. The screen changed little, so the clips hold few frames.

This emulator accepts a second concurrent recorder, so the refusal path is covered only by mocks.

The size probe replaces the exists probe, so each poll is still one adb call.

Your other points:

  • (a) I have no device that refuses a second recorder, so I do not know if a refused recorder exits promptly. I kept the rule that a live recorder at 0 bytes counts as ready after the wait. The original check admitted it on purpose, because some builds keep the file at 0 bytes briefly after start. A longer wait on the rotation path can follow if a device shows the need.
  • (b) Yes. While a live recorder's file is still empty, a start (first or rotation) now waits up to two 250 ms polls. Before, the poll ended as soon as the file existed. I added this to the PR body.
  • (c) Added in 39d18960c: a live recorder reads 0 bytes on its first probe and then has data, and the chunk commits with no fallback. The test pins current behaviour, so it passes on base too. I checked that it fails when a 0-byte poll is treated as not ready while the recorder is alive.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

This PR is ready at 39d1896. The slow-first-write pin test is now in, the live Android run is posted, the production code is unchanged since that run, and all 14 checks pass. Not blocking, and you can take or leave it: on the real transport a size poll runs test -e and then stat -c %s (https://github.com/callstack/agent-device/blob/39d1896/src/platform-runtime-screen-recording-android-host.ts#L30-L37), so a present file costs two shell round trips per poll, not one. Please correct that claim in the PR body or a reply; no code change is needed.

The review thread on the slow-first-write test does not apply, so you can resolve it: that test is a pin that passes on base, and the empty-artifact test is the one that fails on base (#4559 (comment)).

The sequential fallback is covered only by mocks, as you noted.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 16, 2026
@shahjahanpak

Copy link
Copy Markdown
Contributor Author

You are right, and my claim was wrong. On the real transport, size runs test -e and then stat -c %s, so a poll on a present file costs two shell round trips, not one. Thanks for the correction. The PR body does not make that claim, so only this reply corrects it.

I resolved the thread on the pin test, as you suggested.

@thymikee
thymikee merged commit 74633f7 into callstack:main Nov 16, 2026
14 checks passed
thymikee added a commit that referenced this pull request Nov 16, 2026
* origin/main:
  fix(alert): derive the request envelope from an alert wait window (#4581)
  fix(android): require a nonzero chunk before a recorder counts as ready (#4559)
  chore(deps): clear astro and node-forge security alerts (#4577)
  fix(ios): establish the screen origin of a full-screen private AX root (#4573)
  docs(agents): trace behavior claims during review (#4576)
  fix(mcp): trim the press plan text back under the always-loaded byte budget (#4572)
  refactor(alert): one helper owns the alert runner budget (#4563)
  feat(interaction): multi-ref press plan lowered through the ordinary press lane (#4296)
  fix(ios): use the caller's budget for alert get and type the watchdog outcome (#4540)
  feat(recovery): bound remote health and runner-busy recovery by the command's deadline (#4541)
  fix(ios): find the navigation bar back button outside the bar's subtree (#4542)
  feat(open): report device kind, model and osVersion on open and session identity (#4543)
  fix(apple): use typed screenshot timeouts and observed shutdown recovery (#4544)
  feat(device-status): report per device whether a new session can take it (#4547)
  fix(runner): type the refusals for a control the target cannot supply (#4548)
  refactor(transport): share outgoing transfer phase ownership (#4551)
  fix(remote): bound artifact preparation and upload phases (#4552)
@shahjahanpak
shahjahanpak deleted the fix/4550-android-rollover-zero-byte-chunk branch November 21, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android device recording over ~170 s: rollover chunk stays 0 bytes, record stop and close fail, device claim is left behind

2 participants