Skip to content

Refuse a pushed batch whose reusedFromBatch isn't a batch ID - #104

Open
selfie-bot wants to merge 2 commits into
mainfrom
fix/sync-reused-batch-id
Open

selfie-bot wants to merge 2 commits into
mainfrom
fix/sync-reused-batch-id

Conversation

@selfie-bot

@selfie-bot selfie-bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

The cloud sync route now refuses a pushed batch whose reusedFromBatch isn't a lowercase, hyphenated UUID, answering 400 bad-request the way it already does for a decision's batchId. Since #99, the store keeps reused_from_batch as 16 bytes, converting it with unhex(?, '-') (render-batches.ts). But receivedBatch still passed through any text:

  • text that isn't hex ("not-a-batch") became NULL, so the batch was silently stored as reusing nothing
  • hex of the wrong length ("abcd") failed the column's CHECK (length(...) = 16) and came back as a server error rather than a 400
  • an uppercase UUID was stored, then read back lowercase, which is a different ID from the one sent. docs/specs/renders.md → Schema says batch IDs are exchanged lowercase.

I checked the unhex results above against SQLite directly. The CLI always sends its own lowercase IDs, so this only matters for a malformed push. It follows #97, which closed the same gap for storyFilter.

Verification: a new case in ui/test/workerd/sync.workerd.test.ts pushes a batch that reuses a valid ID and reads it back through RenderBatches.getBatch. It then pushes each malformed value and expects a 400. The Selfie workflow doesn't run pnpm test (#105 adds that), so I ran the full suite on scratch branches carrying this PR plus #105's test job. With the fix, it passed (run). With the sync.ts change reverted, only the new test failed, with expected 200 to be 400 (run). I've since deleted both scratch branches.

The sync route took reusedFromBatch as any text, but since #99 the store keeps it as 16 bytes through unhex(?, '-'). Text that isn't hex became NULL, so the batch was stored as reusing nothing; hex of the wrong length failed the column's CHECK as a server error; and an uppercase UUID came back lowercase, a different ID from the one sent. It now goes through readBatchId like a decision's batchId, so each of these is a 400 bad-request.

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.

1 participant