fix(approvals): reject contentless approval payloads at create - #310
Merged
Merged
Conversation
An approval created with an empty payload ({}) passed validation,
returned 201, and queued a blank card next to real decisions in the
operator queue. Pending approvals cannot be cancelled or edited by
their author, so a blank card was unfixable and indistinguishable
from a real request.
POST /companies/:companyId/approvals now returns 422 with code
"approval_payload_empty" when the payload record has no keys. The
rule is deliberately minimal: any payload with at least one key is
accepted, all approval types keep their existing semantics (hire_agent
secret normalization included), and the reject/approve/request-
revision/resubmit paths are untouched. Shape errors (missing or
malformed payload) keep returning 400 from the shared validator, so
no global validation behavior changed.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
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.
Thinking Path
Linked Issues or Issue Description
No public GitHub issue exists for this. In-PR problem statement:
payload: {}was accepted and queued.POST /api/companies/{companyId}/approvalswith{"type": "request_board_approval", "payload": {}}on master returns201.c4b3c00de.Related in-flight PR: #296 (
feat/approval-request-integrity) also hardens approval payloads, with a different, larger shape: per-type required fields (title+summary) returning400, plus a new withdraw route. This PR is the deliberately smaller complement: one type-agnostic rule (payload must have at least one key) returning422, and no new routes. The two compose: #296 tightens per-type content at the validator; this PR guarantees no type can queue a fully empty card.What Changed
packages/shared/src/validators/approval.ts: addisEmptyApprovalPayload(payload)helper. It returns true for a payload with no keys.server/src/routes/approvals.ts:POST /companies/:companyId/approvalsreturns422withcode: "approval_payload_empty"and a clear message when the payload is empty. The check runs after run-context authorization and before any persistence, so no approval row, issue link, or activity-log entry is written.server/src/__tests__/approval-routes-empty-payload.test.ts: new route suite. It drives real requests through an express app, asserts422plus no persistence for{}, and pins the boundaries (one key accepted, valid create unchanged, missing payload still400).Rule choice: the guard is "payload must have at least one key" only. It is the smallest rule that catches the observed defect. A per-type or non-empty-string-value rule would invent payload schemas this change deliberately avoids. Any card with a key at least declares content;
{"note": null}is accepted, which the new test pins.Verification
Local, from
server/(fork master basec4b3c00de, Node on this host neededNODE_OPTIONS=--max-old-space-size=4096):pnpm exec tsc --noEmitinpackages/sharedand inserver: both clean.201and calls the create service.Flake note:
approval-routes-idempotency.test.ts > does not emit duplicate approval side effects when approve is already resolvedtimed out once per multi-file batch on this loaded host. A/B on a pristinec4b3c00deworktree reproduces the same timeout (2-file batch, no change from this PR involved), and the file passes 11/11 in isolation. Pre-existing load flake, unrelated to this change; single rerun per the CI rerun policy.Risks
422instead of201. Previously such creates produced an unfixable card, so no known caller depends on them.hire_agentsecret normalization runs only after the guard, so valid hires are unchanged. Reject/approve/request-revision/resubmit paths are untouched.request_board_approvalempties with400at the validate middleware, before this guard runs. This guard remains the type-agnostic backstop for every other type. No semantic conflict; whoever lands second rebases on the same route file.docs/api/approvals.mddescribes create generally and does not enumerate per-route error codes today (matching the other route-level422s in the codebase). feat(approvals): require usable request payloads and add agent withdraw #296 already extends that doc for its scope; this PR adds no doc surface to update beyond it.Model Used
Claude (Anthropic) via the Paperclip agent runtime (JSON event-stream CLI driven by a local Paperclip adapter), extended thinking + tool use + code execution. Exact model id not exposed to this session; operating as agent "Coder" under the Paperclip runtime.
Checklist
Fixes: #/Closes #/Refs #OR (b) described the issue in-PR following the relevant issue template (path b, bug template fields)#NNN/github.com/paperclipai/paperclipURLs)docs/...,fix/...) and contains no internal Paperclip ticket id or instance-derived details422s; error shape is self-describing in the response)verifycheck will be confirmed before merge)Compliance statement: Follows
CONTRIBUTING.mdPR template — sections present: Thinking Path, Linked Issues or Issue Description, What Changed, Verification, Risks, Model Used, Checklist. Path-1 (small, focused) change: 5 files, one logical change, no bundled cleanups. No internal issue references in branch, title, description, or commits.