mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
fix(antigravity): a deleted /swarm comment withdraws its request
Deleting a swarm comment keeps its request record but clears its text, so a later wake found an empty request and failed with "This swarm has no request to run", even after the swarm had succeeded. A deleted request is now withdrawn (no swarm, no failure, ordinary work), a deleted latest message never falls back to an older request, and a fulfilled request is checked before its text so it can never fail a later wake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2a34a538b6
commit
62b60fc442
2 files changed
+51
-6
No files matched your search
@@ -205,6 +205,42 @@ describe.skipIf(!support.supported)("trusted /swarm run selection (database)", (
|
||||
await expect(automatic(g, (await insertRun(g, {})).id)).rejects.toMatchObject({ message: expect.stringMatching(/three attempts/) });
|
||||
});
|
||||
|
||||
describe("a deleted /swarm comment withdraws its request", () => {
|
||||
const remove = (f: Awaited<ReturnType<typeof seed>>) => issueService(db).tombstoneComment(f.comment.id, { actorType: "user", userId: USER });
|
||||
|
||||
it.each(["issue_assigned", "issue_blocker_stalled", "issue_continuation_needed"])(
|
||||
"runs a %s wake as ordinary work, with no failure, after an unfulfilled request was deleted", async wakeReason => {
|
||||
const f = await seed();
|
||||
await remove(f);
|
||||
expect(await automatic(f, (await insertRun(f, {})).id, wakeReason)).toBeNull();
|
||||
// Even a wake that still names the deleted request (its fresh wake, or a retry of it) is ordinary work.
|
||||
expect(await resolve(f, { runId: (await insertRun(f, {})).id })).toBeNull();
|
||||
const failed = await insertRun(f, { status: "failed", contextSnapshot: { issueId: f.issue.id, antigravitySwarmCommentId: f.comment.id } });
|
||||
expect(await resolve(f, { runId: (await insertRun(f, { retryOfRunId: failed.id })).id, context: { issueId: f.issue.id } })).toBeNull();
|
||||
expect(await antigravitySwarmQuotaScope(db, { companyId: f.company.id, issueId: f.issue.id, runId: randomUUID(), agent: f.agent,
|
||||
context: { issueId: f.issue.id, antigravitySwarmCommentId: f.comment.id } })).toBeNull();
|
||||
});
|
||||
|
||||
it("runs ordinary work after a fulfilled request was deleted", async () => {
|
||||
const f = await seed();
|
||||
const first = await insertRun(f, {});
|
||||
expect(await automatic(f, first.id)).toMatchObject({ request: "two helpers" });
|
||||
await setStatus(first.id, "succeeded");
|
||||
await remove(f);
|
||||
expect(await automatic(f, (await insertRun(f, {})).id, "issue_continuation_needed")).toBeNull();
|
||||
});
|
||||
|
||||
it("never lets a fulfilled request fail a later wake, even when its text no longer has a request", async () => {
|
||||
const f = await seed();
|
||||
const first = await insertRun(f, {});
|
||||
expect(await automatic(f, first.id)).toMatchObject({ request: expect.any(String) });
|
||||
await setStatus(first.id, "succeeded");
|
||||
// Comments have no edit path today; this stands in for any later change to the stored text.
|
||||
await db.update(issueComments).set({ body: "/swarm" }).where(eq(issueComments.id, f.comment.id));
|
||||
expect(await automatic(f, (await insertRun(f, {})).id, "issue_assigned")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it("starts exactly one swarm for one request when two wakes arrive together", async () => {
|
||||
const f = await seed();
|
||||
const [a, b] = [await insertRun(f, {}), await insertRun(f, {})];
|
||||
|
||||
@@ -113,11 +113,12 @@ async function inheritedSwarmCommentId(db: Db, companyId: string, issueId: strin
|
||||
}
|
||||
|
||||
async function pendingSwarmCommentId(db: Db, companyId: string, issueId: string): Promise<string | null> {
|
||||
const [latest] = await db.select({ id: issueComments.id }).from(issueComments)
|
||||
// A deleted latest message withdraws whatever it asked for; it never falls back to an older request.
|
||||
const [latest] = await db.select({ id: issueComments.id, deletedAt: issueComments.deletedAt }).from(issueComments)
|
||||
.where(and(eq(issueComments.companyId, companyId), eq(issueComments.issueId, issueId),
|
||||
isNotNull(issueComments.authorUserId), isNull(issueComments.authorAgentId)))
|
||||
.orderBy(desc(issueComments.createdAt), desc(issueComments.id)).limit(1);
|
||||
return latest?.id ?? null;
|
||||
return latest && !latest.deletedAt ? latest.id : null;
|
||||
}
|
||||
|
||||
export async function recordAntigravitySwarmRequest(db: Db, input: { companyId: string; issueId: string; commentId: string; userId: string }): Promise<void> {
|
||||
@@ -176,10 +177,14 @@ export async function antigravitySwarmQuotaScope(db: Db, input: {
|
||||
if (!isAntigravityAgent(input.agent)) return null;
|
||||
const requested = await recordedRequest(db, { ...input, remote: false, planning: false });
|
||||
if (!requested) return null;
|
||||
return await requestFulfilled(db, input.companyId, requested.commentId) ? null : ANTIGRAVITY_CLI_QUOTA_SCOPE;
|
||||
}
|
||||
|
||||
async function requestFulfilled(db: Db, companyId: string, commentId: string): Promise<boolean> {
|
||||
const [fulfilled] = await db.select({ id: heartbeatRuns.id }).from(heartbeatRuns)
|
||||
.where(and(eq(heartbeatRuns.companyId, input.companyId), eq(heartbeatRuns.status, "succeeded"),
|
||||
sql`${heartbeatRuns.contextSnapshot}->>'antigravitySwarmCommentId' = ${requested.commentId}`)).limit(1);
|
||||
return fulfilled ? null : ANTIGRAVITY_CLI_QUOTA_SCOPE;
|
||||
.where(and(eq(heartbeatRuns.companyId, companyId), eq(heartbeatRuns.status, "succeeded"),
|
||||
sql`${heartbeatRuns.contextSnapshot}->>'antigravitySwarmCommentId' = ${commentId}`)).limit(1);
|
||||
return Boolean(fulfilled);
|
||||
}
|
||||
|
||||
/** The recorded user /swarm request this run serves, if any (before any replacement). */
|
||||
@@ -191,8 +196,10 @@ async function recordedRequest(db: Db, input: Parameters<typeof resolveAntigravi
|
||||
const commentId = explicit ?? (isAntigravityAgent(input.agent) ? await pendingSwarmCommentId(db, input.companyId, input.issueId) : null);
|
||||
if (!commentId) return null;
|
||||
const [requested] = await db.select({ id: activityLog.id, body: issueComments.body }).from(activityLog)
|
||||
// A deleted request is withdrawn: no swarm and no failure, so the run is ordinary work.
|
||||
// The prompt therefore never comes from text the user has since deleted.
|
||||
.innerJoin(issueComments, and(eq(issueComments.id, commentId), eq(issueComments.issueId, input.issueId), eq(issueComments.companyId, input.companyId),
|
||||
isNotNull(issueComments.authorUserId), isNull(issueComments.authorAgentId)))
|
||||
isNotNull(issueComments.authorUserId), isNull(issueComments.authorAgentId), isNull(issueComments.deletedAt)))
|
||||
.where(and(eq(activityLog.companyId, input.companyId), eq(activityLog.action, ANTIGRAVITY_SWARM_REQUESTED_ACTION),
|
||||
eq(activityLog.entityId, input.issueId), eq(activityLog.actorType, "user"), eq(activityLog.actorId, issueComments.authorUserId),
|
||||
sql`${activityLog.details}->>'commentId' = ${commentId}`))
|
||||
@@ -220,6 +227,8 @@ async function decideSwarm(tx: Db, input: Parameters<typeof resolveAntigravitySw
|
||||
}
|
||||
selected = { commentId: newest.id, body: newest.body };
|
||||
}
|
||||
// A fulfilled request never fails a later wake, whatever its text says now.
|
||||
if (await requestFulfilled(tx, input.companyId, selected.commentId)) return null;
|
||||
const replacedCommentIds = recordedInWake.filter(id => id !== selected.commentId);
|
||||
// The swarm's only instruction is this recorded comment's own text.
|
||||
const request = antigravitySwarmRequestFromComment(selected.body);
|
||||
|
||||
Reference in new issue
Block a user