feat(workers): add Zod request body validation to auto-fix, auto-triage, code-review workers#1259
Open
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
Conversation
…ge, code-review workers Replace manual if (!body.field) checks with Zod schemas on POST /fix/dispatch, POST /triage, POST /review, and POST /reviews/:reviewId/cancel. Invalid bodies now return 400 with structured Zod error details. Add zod dependency to cloudflare-auto-fix-infra and cloudflare-code-review-infra (already present in cloudflare-auto-triage-infra).
…ata parsing
Use z.record().catch({}).parse() to safely parse JSON metadata instead of
a bare JSON.parse() assignment which triggered no-unsafe-assignment lint errors.
Wraps each c.req.json() call in a try-catch so malformed or absent request bodies return a structured 400 JSON response rather than bubbling up as an unhandled exception. Affects POST /fix/dispatch, POST /triage, POST /review, and POST /reviews/:reviewId/cancel.
| customInstructions: z.string().nullable().optional(), | ||
| modelSlug: z.string(), | ||
| prBaseBranch: z.string(), | ||
| prBranchPrefix: z.string(), |
Contributor
Author
There was a problem hiding this comment.
CRITICAL: Required prBranchPrefix breaks the current auto-fix dispatch payload
DispatchFixRequestSchema and prepareFixPayload() never populate sessionInput.prBranchPrefix, so existing /fix/dispatch requests will now fail validation with a 400 before the orchestrator starts. This makes the Zod migration a breaking change unless the field is made optional here or the dispatcher begins sending it.
Contributor
Author
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)CRITICAL
Other Observations (not in diff)None. Files Reviewed (7 files)
Reviewed by gpt-5.4-20260305 · 1,783,680 tokens |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces manual
if (!body.field)checks with Zod schemas for structured request body validation in three orchestrator workers. Invalid request bodies now return 400 with Zod error details rather than silent missing-field errors.Changes per worker:
POST /fix/dispatch: newfixRequestSchema(with nestedsessionInputSchemaandownerSchema);zodadded as dependencyPOST /triage: newtriageRequestSchema(with nested schemas)POST /reviewandPOST /reviews/:reviewId/cancel: newcodeReviewRequestSchemaandcancelRequestSchema;zodadded as dependencyAll endpoints wrap
c.req.json()in a try-catch to return a structured 400 on malformed/absent JSON before Zod validation runs.Verification
src/types.tsfor each worker — fields and optionality matchzodis now a declared dependency in all threepackage.jsonfilesif (!body.field)checks remain on validated endpointsc.req.json()calls are guarded against JSON parse errorsVisual Changes
N/A
Reviewer Notes
The
cancelRequestSchemahas all-optional fields (reason?: string), so an empty-but-valid JSON body{}is accepted. The try-catch beforec.req.json()handles requests with no body at all. The phase-3 (structured logging) convoy runs independently on the same workers;console.logcalls visible in this diff are not in scope for this bead.