Skip to content

Fix macOS OTA updates failing image validation - #233

Open
rileykeen wants to merge 2 commits into
masterfrom
cursor/mac-ota-chunk-size-8013
Open

rileykeen wants to merge 2 commits into
masterfrom
cursor/mac-ota-chunk-size-8013

Conversation

@rileykeen

@rileykeen rileykeen commented Nov 16, 2026 •

Copy link
Copy Markdown

Mac OTA updates were rejected with OTA FAIL END <byte count> ESP_ERR_OTA_VALIDATE_FAILED while Windows succeeded. The running firmware never changed, so this has to be fixed in the Device Manager.

updateFirmware() wrote the image in 128-byte chunks. 128 is a multiple of the full-speed USB packet size (64), so macOS appends a zero-length packet after each write. The keyboard's TinyUSB CDC stack then delivers a corrupted stream and esp_ota_end fails validation. 256, 512, and 1024 are still multiples of 64 and fail the same way.

Writes are now 4095 bytes. A trailing chunk whose length is still a multiple of 64 (including 128, 256, 512, and 1024) is shortened by one byte so that write does not get a zero-length packet either. Each chunk is still a fresh Uint8Array.

On failure the update threw before suspend(), so the serial port stayed open and the next Connect failed with InvalidStateError: The port is already open until the page was refreshed. The port is now closed when the update throws, and the device's validation error is still the one reported to the page.

Testing

  • pnpm exec vitest run --project ui src/lib/serial/device.svelte.spec.ts (OTA chunk sizes 64–1024, failure path closes port and allows reconnect)

Note

Medium Risk
Changes firmware OTA streaming and serial port teardown in a critical user-facing path; behavior is platform-specific but covered by expanded unit tests rather than broad integration coverage.

Reviewed by Cursor Bugbot for commit 390a84e. Bugbot is set up for automated code reviews on this repo. Configure here.

Mac OTA updates were rejected with OTA FAIL END <byte count> ESP_ERR_OTA_VALIDATE_FAILED while Windows succeeded. The running firmware never changed, so this has to be fixed in the Device Manager.

updateFirmware() wrote the image in 128-byte chunks. 128 is a multiple of the full-speed USB packet size (64), so macOS appends a zero-length packet after each write. The keyboard's TinyUSB CDC stack then delivers a corrupted stream and esp_ota_end fails validation.

macOS (field-validated): transfer plans match the standalone DevTools updater that succeeded on CC2: [63, 5], [63, 12], [31, 8], [127, 15] ms between writes. Each failed plan re-issues RST OTA after a short pause until one returns OTA OK.

Other platforms: 128-byte chunks, no pacing (unchanged throughput). Every write still avoids a length that is an exact multiple of 64 bytes (including the last chunk).

On failure the update threw before suspend(), so the serial port stayed open and the next Connect failed with InvalidStateError until refresh. The port is now closed when the update throws.

Testing

  • pnpm exec vitest run --project ui src/lib/serial/device.svelte.spec.ts
  • Hardware: Mac OTA on CC2 (validated with console updater; same plans in app)
Open in Web Open in Cursor 

macOS appends a zero-length packet after a write whose length is a
multiple of 64. TinyUSB CDC then corrupts the image and the device
reports ESP_ERR_OTA_VALIDATE_FAILED without changing firmware. Write
4095-byte chunks and split a trailing multiple of 64.

Close the port when the update throws so the next Connect can open it.

Co-authored-by: rileykeen <rileykeen@users.noreply.github.com>
@rileykeen
rileykeen requested a review from Theaninova November 16, 2026 21:06
Replace theoretical 4095-byte writes with the console-updater plans
that succeeded on Mac: 63/31/127-byte chunks with inter-write delays,
tried in order until OTA OK. Non-Mac hosts keep 128-byte chunks; every
write still avoids a multiple of the 64-byte USB packet size.

Co-authored-by: rileykeen <rileykeen@users.noreply.github.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: OTA tests assume non-Mac chunks
    • The OTA streaming test now pins the user agent and asserts both the default 128-byte schedule and the Macintosh 63-byte schedule, and the failure test pins a non-Mac agent so it still stops after one attempt.

Create PR

Or push these changes by commenting:

@cursor push 97e8a34b1e

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 390a84e. Configure here.

[127, 300],
[254, 300],
[300, 300],
]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OTA tests assume non-Mac chunks

Medium Severity

updateFirmware picks MAC_OTA_PLANS whenever navigator.userAgent contains Macintosh, but the streaming test hardcodes progress [127, 300], [254, 300], [300, 300] from the 128-byte default plan. Playwright Chromium on macOS includes Macintosh, so that assertion fails and the Mac path this PR exists to fix is never what CI (Linux) actually runs.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 390a84e. Configure here.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants