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 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 committed 2026-11-24 18:01:47 -06:00
1 parent a2decc65f3
commit aca24c780f
7 files changed
+39 -2

No files matched your search

+1 -1
View File
@@ -278,7 +278,7 @@ The endpoint refuses these requests with `422` and `{ "error": "<message>", "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.
+1
View File
@@ -2175,6 +2175,7 @@ export {
issueCommentMetadataSectionSchema,
issueCommentMetadataSchema,
addIssueCommentSchema,
addIssueSwarmCommentSchema,
sendChatMessageSchema,
markIssueReadSchema,
issueThreadInteractionStatusSchema,
+1
View File
@@ -464,6 +464,7 @@ export {
issueCommentMetadataSectionSchema,
issueCommentMetadataSchema,
addIssueCommentSchema,
addIssueSwarmCommentSchema,
sendChatMessageSchema,
markIssueReadSchema,
issueThreadInteractionStatusSchema,
@@ -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.",
+11
View File
@@ -1224,6 +1224,17 @@ export const addIssueCommentSchema = z.object({
export type AddIssueComment = z.infer<typeof addIssueCommentSchema>;
/**
* 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,
);
@@ -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.");
+3 -1
View File
@@ -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(