From aca24c780f169928412d3b1f14a414701ebad591 Mon Sep 17 00:00:00 2001 From: Dotta Date: Tue, 24 Nov 2026 18:01:47 -0600 Subject: [PATCH] fix(issues): answer an empty /swarm request with the documented 422 refusal A comment request with nativeCommand "swarm" and an empty body failed the ordinary non-empty body check and got a generic 400, while docs/api/issues.md documents 422 antigravity_swarm_unavailable for a request with no text. The route now validates /swarm requests with addIssueSwarmCommentSchema, which allows an empty body so the swarm refusal answers it; ordinary comments keep addIssueCommentSchema and its unchanged non-empty check. Co-Authored-By: Claude Opus 5.5 --- docs/api/issues.md | 2 +- packages/shared/src/index.ts | 1 + packages/shared/src/validators/index.ts | 1 + packages/shared/src/validators/issue.test.ts | 10 ++++++++++ packages/shared/src/validators/issue.ts | 11 +++++++++++ .../__tests__/issue-comment-reopen-routes.test.ts | 12 ++++++++++++ server/src/routes/issues.ts | 4 +++- 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/api/issues.md b/docs/api/issues.md index 604fe472d44..ae854440f2c 100644 --- a/docs/api/issues.md +++ b/docs/api/issues.md @@ -278,7 +278,7 @@ The endpoint refuses these requests with `422` and `{ "error": "", "cod | The instance setting is off | `Swarm is not turned on for this Paperclip. An instance admin can turn on "Google Antigravity swarm" in Settings, Experimental.` | | The assignee is not a Google Antigravity agent | `Swarm works only for tasks assigned to a Google Antigravity agent.` | | The task is in Plan mode | `Swarm is not available while the task is in Plan mode: helpers change files. Approve the plan first, then send /swarm.` | -| `body` is empty | `This swarm has no request to run. Send /swarm followed by what the swarm should do.` | +| `body` is empty or only whitespace | `This swarm has no request to run. Send /swarm followed by what the swarm should do.` | | `body` is longer than 16,000 characters | `This swarm request is too long. Keep what follows /swarm under 16,000 characters.` | Deleting a request comment withdraws it: the swarm does not run and later work is ordinary. A later `/swarm` on the same task replaces an earlier request that has not completed. The earlier request never runs, neither as a swarm nor as ordinary work. Other comments sent in the meantime reach the agent in an ordinary turn, never inside the swarm's request. diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 47cbbc2e6ea..2f03c96ef64 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -2175,6 +2175,7 @@ export { issueCommentMetadataSectionSchema, issueCommentMetadataSchema, addIssueCommentSchema, + addIssueSwarmCommentSchema, sendChatMessageSchema, markIssueReadSchema, issueThreadInteractionStatusSchema, diff --git a/packages/shared/src/validators/index.ts b/packages/shared/src/validators/index.ts index 7018de658c8..c6d21d8635e 100644 --- a/packages/shared/src/validators/index.ts +++ b/packages/shared/src/validators/index.ts @@ -464,6 +464,7 @@ export { issueCommentMetadataSectionSchema, issueCommentMetadataSchema, addIssueCommentSchema, + addIssueSwarmCommentSchema, sendChatMessageSchema, markIssueReadSchema, issueThreadInteractionStatusSchema, diff --git a/packages/shared/src/validators/issue.test.ts b/packages/shared/src/validators/issue.test.ts index c66108342e6..0dda20eec5e 100644 --- a/packages/shared/src/validators/issue.test.ts +++ b/packages/shared/src/validators/issue.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import { MAX_ISSUE_REQUEST_DEPTH } from "../index.js"; import { addIssueCommentSchema, + addIssueSwarmCommentSchema, paperclipQuestionSetPayloadSchema, issueCommentMetadataSchema, issueDocumentBatchQuerySchema, @@ -450,6 +451,15 @@ describe("issue validators", () => { ).toBe(false); }); + it("lets only a /swarm request through with an empty body, so the route refuses it in its own words", () => { + expect(addIssueSwarmCommentSchema.parse({ body: "", nativeCommand: "swarm" })).toMatchObject({ body: "", nativeCommand: "swarm" }); + expect(addIssueSwarmCommentSchema.safeParse({ body: "", nativeCommand: undefined }).success).toBe(false); + // An empty ordinary comment is refused exactly as before. + expect(addIssueCommentSchema.safeParse({ body: "" }).error?.issues).toEqual([{ origin: "string", code: "too_small", minimum: 1, + inclusive: true, path: ["body"], message: "Too small: expected string to have >=1 characters" }]); + expect(addIssueCommentSchema.safeParse({ body: "", nativeCommand: "swarm" }).success).toBe(false); + }); + it("normalizes escaped line breaks in issue comment bodies", () => { const parsed = addIssueCommentSchema.parse({ body: "Progress update\\r\\n\\r\\nNext action.", diff --git a/packages/shared/src/validators/issue.ts b/packages/shared/src/validators/issue.ts index a54beaa3bbc..f9b02da4054 100644 --- a/packages/shared/src/validators/issue.ts +++ b/packages/shared/src/validators/issue.ts @@ -1224,6 +1224,17 @@ export const addIssueCommentSchema = z.object({ export type AddIssueComment = z.infer; +/** + * A comment request that carries `nativeCommand: "swarm"`. Its body is the swarm's + * request, and an empty one passes validation so the route answers every request + * without one with the same documented refusal (422 `antigravity_swarm_unavailable`). + * Ordinary comments keep `addIssueCommentSchema` and its non-empty body. + */ +export const addIssueSwarmCommentSchema = addIssueCommentSchema.extend({ + body: multilineTextSchema.pipe(z.string()), + nativeCommand: z.literal("swarm"), +}); + export const issueThreadInteractionStatusSchema = z.enum( ISSUE_THREAD_INTERACTION_STATUSES, ); diff --git a/server/src/__tests__/issue-comment-reopen-routes.test.ts b/server/src/__tests__/issue-comment-reopen-routes.test.ts index 133e1b31ebd..b08805f2739 100644 --- a/server/src/__tests__/issue-comment-reopen-routes.test.ts +++ b/server/src/__tests__/issue-comment-reopen-routes.test.ts @@ -1343,6 +1343,7 @@ describe("issue comment reopen routes", () => { }); it.each([ + ["an empty request", "", /no request/], ["no request", " ", /no request/], ["a request that is too long", "x".repeat(16_001), /too long/], ])("refuses a /swarm with %s at submit and posts nothing", async (_name, body, message) => { @@ -1357,6 +1358,17 @@ describe("issue comment reopen routes", () => { expect(mockSwarm.record).not.toHaveBeenCalled(); }); + it("still rejects an empty ordinary comment with the validation error it always had", async () => { + mockIssueService.getById.mockResolvedValue(makeIssue("todo")); + const res = await request(await installActor(createApp())) + .post("/api/issues/11111111-1111-4111-8111-111111111111/comments") + .send({ body: "" }); + expect(res.status).toBe(400); + expect(res.body).toMatchObject({ error: "Validation error", + details: [expect.objectContaining({ code: "too_small", minimum: 1, path: ["body"] })] }); + expect(mockIssueService.addComment).not.toHaveBeenCalled(); + }); + it("returns the original receipt for an accepted /swarm resent after the setting was turned off, starting nothing twice", async () => { // The first send committed but its response was lost; then the swarm setting was turned off. mockSwarm.refusal.mockResolvedValue("Swarm is not turned on for this Paperclip."); diff --git a/server/src/routes/issues.ts b/server/src/routes/issues.ts index 76652e0992d..8a7bd2b8d45 100644 --- a/server/src/routes/issues.ts +++ b/server/src/routes/issues.ts @@ -109,6 +109,7 @@ import { } from "@paperclipai/db"; import { addIssueCommentSchema, + addIssueSwarmCommentSchema, acceptIssueThreadInteractionSchema, resolveConfirmationFromCommentSchema, attachmentArtifactWorkProductMetadataSchema, @@ -19351,7 +19352,8 @@ export function issueRoutes( router.post( "/issues/:id/comments", - validate(addIssueCommentSchema), + // A /swarm request without a request text gets the route's documented refusal, not a validation error. + (req, res, next) => validate(req.body?.nativeCommand === ANTIGRAVITY_SWARM_COMMAND ? addIssueSwarmCommentSchema : addIssueCommentSchema)(req, res, next), async (req, res) => { const id = req.params.id as string; const issue = await getAccessibleResource(