fix(recorder-core): slice progressive multipart uploads into uniform parts for Cloudflare R2 (#2275) - #2288
Conversation
…dflare R2 compatibility (CapSoftware#2275)
| sendProgressUpdate: vi.fn().mockResolvedValue(undefined), | ||
| }); | ||
|
|
||
| // Push a chunk larger than MIN_PART_SIZE_BYTES |
There was a problem hiding this comment.
Narrative comments violate guidance
The comments above the chunk creation and final assertions only restate what the test code already expresses. Repository guidance prohibits comments that merely narrate code, so both comments must be removed before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/recorder-core/__tests__/instant-recording-uploader.test.ts
Line: 1026
Comment:
**Narrative comments violate guidance**
The comments above the chunk creation and final assertions only restate what the test code already expresses. Repository guidance prohibits comments that merely narrate code, so both comments must be removed before merging.
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| }); | ||
|
|
||
| // Push a chunk larger than MIN_PART_SIZE_BYTES | ||
| const chunk = makeBlob(TOTAL_SIZE, "video/webm;codecs=vp9,opus"); |
There was a problem hiding this comment.
Repeated slicing remains untested
This test uploads only 7 MiB, so the non-forced loop emits one full 5 MiB part before finalization handles the remainder. It does not exercise a second full-part iteration, allowing regressions in repeated slicing to pass unnoticed. Use a payload above 10 MiB and assert two uniform full parts plus the trailing remainder.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/recorder-core/__tests__/instant-recording-uploader.test.ts
Line: 1027
Comment:
**Repeated slicing remains untested**
This test uploads only 7 MiB, so the non-forced loop emits one full 5 MiB part before finalization handles the remainder. It does not exercise a second full-part iteration, allowing regressions in repeated slicing to pass unnoticed. Use a payload above 10 MiB and assert two uniform full parts plus the trailing remainder.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Resolves #2275
Problem
When using Cloudflare R2 as the S3 storage backend, camera-only Instant Mode recordings fail during
CompleteMultipartUploadwithInvalidPart: All non-trailing parts must have the same length.In
packages/recorder-core/src/instant-mp4-uploader.ts,flushBuffer()previously dumped all buffered chunks into a single variable-sizedBlobwheneverthis.bufferedBytes >= MIN_PART_SIZE_BYTES(5 MiB). Unlike AWS S3 and MinIO, Cloudflare R2 strictly enforces that all non-trailing parts in a multipart upload must be identical in size.Solution
flushBuffer()to leveragetakeBufferedPart(partSize)in a loop, ensuring each non-final part upload is sliced to exactlyMIN_PART_SIZE_BYTES(5 MiB), matching the uniform chunking strategy already used for Google Drive resumable uploads.handleChunkto track combined in-flight and buffered bytes againstMAX_PENDING_UPLOAD_BYTESto protect memory limits.packages/recorder-core/__tests__/instant-recording-uploader.test.tsverifying that streamed buffers larger than 5 MiB are cleanly sliced into uniform 5 MiB non-trailing parts and a remainder trailing part.Verification
bun x vitest run packages/recorder-core/__tests__/instant-recording-uploader.test.ts(18/18 passed)bun x biome check packages/recorder-core/src/instant-mp4-uploader.ts packages/recorder-core/__tests__/instant-recording-uploader.test.ts(pass)The upload implementation appears behaviorally safe, but the explicit repository comment rule must be satisfied before merging.
Findings
Fix with agent prompt
Summary
Reviews (1) · Last reviewed commit: "fix(recorder-core): slice streamed chunk..."