mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
fix(antigravity): give the follow-up after a swarm its result, and say each thing once in the thread (#22893)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A task thread shows an agent's runs, and each new run starts from the task's saved context > - A second hands-on check of Google Antigravity `/swarm` runs (after #22886) still found gaps > - The first ordinary follow-up after a swarm was slow: it spent minutes searching the instance's run logs to learn what the swarm did > - The thread also showed each file twice, lost the "Swarm" note after a reload, and read "Swarm Swarm started…" > - This pull request gives the next run the swarm's result in its opening context and removes the prompt's pointer to run records, and it fixes the four thread problems > - The benefit is a faster follow-up after a swarm and a thread that says each thing once ## Linked Issues or Issue Description Refs #22886 **What happened?** 1. After a finished `/swarm`, the ordinary follow-up "append three to v1.txt" took 4 min 6 s (an earlier one took 5.5 min). The agent read the server's raw run log of the swarm run with about 20 shell commands, searched the instance folder, and listed processes. Other follow-ups took 41 s and 105 s. 2. Each file showed twice: the run's file card, and a second card under the final reply (from the reply's "Download: v1.txt" link). This also happened on the ordinary follow-up. 3. The "Swarm" note on the user's message showed while live, but not after a page reload. 4. Swarm activity rows read "Swarm Swarm started in the task folder…", with the word twice. **Expected behavior** 1. The follow-up starts with what the swarm did, so it has no reason to search for it. 2. Each file shows once per run, as the run's file card. 3. The "Swarm" note shows after a reload. 4. A swarm row reads its sentence once. **Steps to reproduce** 1. Send `/swarm Create v1.txt containing "one" and v2.txt containing "two", one helper per file, then verify both.` to a Google Antigravity agent. 2. When it finishes, look at the files and the activity rows, then reload the page. 3. Send the ordinary follow-up `append three to v1.txt` and time it. 4. Put another task in Plan mode and send `/swarm do something`. ## What Changed - Follow-up context (cause of item 1). A swarm runs in the Antigravity CLI, and an ordinary turn runs on the registry route. The ordinary route cannot reopen the swarm's conversation, so the Runner refuses the saved session and the server starts a fresh one. That fresh session gets the same wake prompt as any other turn. Before this change, its only record of the swarm was the task continuation summary, and that summary listed no files ("No file or route paths were detected"; the path detector only knows repository folders such as `server/`). It also gave three run ids and said "Detailed shell/tool commands remain in the run log and transcript." The agent followed that line: its first searches matched the swarm's run id, and an earlier follow-up searched for `transcript*.jsonl` files. An ordinary follow-up after an ordinary turn gets the same prompt, but it resumes its own conversation, so it already knows what it did. - `issue-continuation-summary.ts` (shared by every harness): a new "Files Delivered" section lists, by name, the files the run handed in as deliverables (applied or duplicate receipts), newest first, and keeps earlier runs' names. These names are kept apart from "Files / Routes Touched", because a deliverable's name is not always its path. The run's own checks are listed, read through the shared accepted-result reader. The summary contains no run ids, adapter names or log locations. The "Commands Run" section is removed: it held only the run id and the log pointer. The summary reaches the next turn through the existing mechanism (the wake prompt's "Issue continuation summary" and the continuation evidence). - Server: `GET /issues/:id/recent-comments` and both chat bootstrap routes now add the swarm marker with the same shared rule (`withAntigravitySwarmMarkers`) as the comment list, the single comment and the POST response. A cold task page reads this recent window, so the marker was missing after a reload. - UI: a reply does not show a second card for a file that its own run already shows as a file card. The reply text and its links do not change. A later run's reply that links the same file still shows the file. - UI: a swarm progress row shows its sentence without the "Swarm" label. A failed or stopped row keeps its label and marker. Live and settled rows use the same rule. Not changed, by investigation: - "Check passed cat v1.txt one\nthree" and "verifier check on swarm board #6": the model wrote both strings in its `paperclip_finish` call. The Runner's first record of the result already holds the literal backslash and the board number, so this is model text, not Paperclip's presentation. - The inline "Download: v1.txt" links in the reply are the model's own words, so they stay. - No read-confinement policy is added. The agent finds the instance folder from its working directory, not from the prompt. - A refused send still shows its reason twice (inline under the composer and as a toast). Each attempt to remove the toast missed a send path, which could leave a refusal with no visible reason. A repeated reason is better than a missing one, so this PR does not change the toast. ## Verification - Red/green `server/src/__tests__/issue-continuation-summary.test.ts`: a swarm's accepted result (from a live run, with ids replaced) is built into the summary and rendered into the follow-up's wake prompt. The prompt contains the hand-in summary, `v1.txt` and `v2.txt` under "Files Delivered" (one with a different content reference and a duplicate receipt), and the verifier check. A later run lists its own delivered file first. A full path list still takes the latest run's path first. It contains no run id, "run log", "transcript", attachment path, digest or adapter name. A later run keeps the files listed. This failed before the change. - Red/green `server/src/__tests__/issue-chat-bootstrap-routes.test.ts` (embedded Postgres): for an ordinary task and a conversation, a recorded `/swarm` request carries `nativeCommand: "swarm"` on `GET /comments`, `GET /comments/:id`, `GET /recent-comments`, `GET /issues/:ref/chat-bootstrap` and the batch chat bootstrap. It failed on `recent-comments` before the change. - Red/green `ui/src/components/TaskChatThread.test.tsx`: a reply that links its run's file shows no second card; a later run's reply still shows it. It failed before the change. - Red/green `ui/src/components/task-chat/antigravity-thread.test.tsx`: the live swarm fixture's rows read "Swarm started in the task folder…" (no doubled word), and live rows equal settled rows. - Focused suites: UI `TaskChatThread.test.tsx` and `src/components/task-chat` (925 tests), server bootstrap routes (19 tests) and continuation summary (7 tests) pass. UI and server typechecks pass. - Not proved without a live run: that the next follow-up after a swarm is faster. The tests prove the opening input; the agent's behavior with that input needs a live Antigravity run. ## Risks - The continuation summary wording changes for every harness that runs on a task (every adapter whose finished run refreshes the summary, not only Antigravity): no run ids, no adapter name, no "Commands Run" section, and a new "Files Delivered" section when the run registered deliverables. Nothing in the code parses those lines. Older saved summaries keep their text until the next run refreshes them. - One extra indexed activity-log query for each recent-comments or chat-bootstrap read (the same query the comment list already runs). The bootstrap budget test still passes. - The second-card rule matches only a file whose card belongs to the same run as the reply. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, test runs). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3fbf872d9e
commit
5347c01de5
16 files changed
+234
-44
No files matched your search
@@ -353,7 +353,12 @@ function readAcceptedSemanticSummary(resultJson: Record<string, unknown>) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function semanticResultCandidates(resultJson: Record<string, unknown>) {
|
||||
export function isCommittedToolReceiptResult(result: unknown): boolean {
|
||||
const disposition = record(result).disposition;
|
||||
return disposition === "applied" || disposition === "duplicate";
|
||||
}
|
||||
|
||||
export function semanticResultCandidates(resultJson: Record<string, unknown>) {
|
||||
return [
|
||||
record(resultJson.nativeResult),
|
||||
record(resultJson.acceptedResult),
|
||||
@@ -782,7 +787,7 @@ export function findHeartbeatRunCompletionComment<T extends { id: string; presen
|
||||
receiptRecord.operationId === "register_deliverable" &&
|
||||
typeof receiptResult.attachmentId === "string" &&
|
||||
receiptResult.commandId === `deliverable-prepared:${receiptResult.attachmentId}` &&
|
||||
["applied", "duplicate"].includes(String(receiptResult.disposition)) &&
|
||||
isCommittedToolReceiptResult(receiptResult) &&
|
||||
Array.isArray(receiptResult.entityRefs)
|
||||
) {
|
||||
// File preparation binds an attachment to a generated comment. That
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Db } from "@paperclipai/db";
|
||||
import { documents, issueDocuments, issues } from "@paperclipai/db";
|
||||
import { ISSUE_CONTINUATION_SUMMARY_DOCUMENT_KEY, readRunFailureCause, withoutSqlStatementText, type SourceTrustMetadata } from "@paperclipai/shared";
|
||||
import { documentService } from "./documents.js";
|
||||
import { summarizeRunErrorForModel } from "./heartbeat-run-summary.js";
|
||||
import { isCommittedToolReceiptResult, semanticResultCandidates, summarizeRunErrorForModel } from "./heartbeat-run-summary.js";
|
||||
|
||||
export { ISSUE_CONTINUATION_SUMMARY_DOCUMENT_KEY };
|
||||
export const ISSUE_CONTINUATION_SUMMARY_TITLE = "Continuation Summary";
|
||||
@@ -70,6 +70,38 @@ function readResultSummary(resultJson: Record<string, unknown> | null | undefine
|
||||
);
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : null;
|
||||
}
|
||||
|
||||
function readDeliveredFiles(resultJson: Record<string, unknown> | null | undefined): string[] {
|
||||
const receipts = asRecord(resultJson?.semanticToolReceipts);
|
||||
if (!receipts) return [];
|
||||
const files = new Set<string>();
|
||||
for (const value of Object.values(receipts)) {
|
||||
const receipt = asRecord(value);
|
||||
if (receipt?.operationId !== "register_deliverable" || !isCommittedToolReceiptResult(receipt.result)) continue;
|
||||
const filename = asNonEmptyString(asRecord(receipt.input)?.filename);
|
||||
if (filename && filename.length <= 200 && !/[`\u0000-\u001f]/.test(filename)) files.add(filename);
|
||||
if (files.size >= 12) break;
|
||||
}
|
||||
return [...files];
|
||||
}
|
||||
|
||||
function readVerification(resultJson: Record<string, unknown> | null | undefined): string[] {
|
||||
const checks = semanticResultCandidates(resultJson ?? {}).map((candidate) => candidate.verification).find(Array.isArray);
|
||||
if (!checks) return [];
|
||||
return checks.slice(0, 6).flatMap((value) => {
|
||||
const check = asRecord(value);
|
||||
const name = asNonEmptyString(check?.commandOrCheck);
|
||||
const status = asNonEmptyString(check?.status);
|
||||
if (!name || !status) return [];
|
||||
const detail = asNonEmptyString(check?.detail);
|
||||
const oneLine = (text: string, max: number) => truncateText(text.replace(/\s+/g, " "), max).replace(/\n/g, " ");
|
||||
return [`Check ${oneLine(name, 160)}: ${status}${detail ? ` (${oneLine(detail, 240)})` : ""}.`];
|
||||
});
|
||||
}
|
||||
|
||||
function extractMarkdownSection(markdown: string | null | undefined, heading: string) {
|
||||
if (!markdown) return null;
|
||||
const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
@@ -150,13 +182,17 @@ export function buildContinuationSummaryMarkdown(input: {
|
||||
const modelError = summarizeRunErrorForModel(
|
||||
run.error ? withoutSqlStatementText(run.error, readRunFailureCause(run.resultJson)) : run.error, terminalFailureCategory);
|
||||
const recentActions = [
|
||||
`Run \`${run.id}\` finished with status \`${run.status}\`${run.finishedAt ? ` at ${run.finishedAt.toISOString()}` : ""}.`,
|
||||
`The latest run finished with status \`${run.status}\`${run.finishedAt ? ` at ${run.finishedAt.toISOString()}` : ""}.`,
|
||||
resultSummary ? truncateText(resultSummary, SUMMARY_SECTION_MAX_CHARS) : "No adapter-provided result summary was captured for this run.",
|
||||
...readVerification(run.resultJson),
|
||||
];
|
||||
if (modelError) {
|
||||
recentActions.push(`Latest run error${run.errorCode ? ` (${run.errorCode})` : ""}: ${truncateText(modelError, 500)}`);
|
||||
}
|
||||
|
||||
const previousDelivered = [...(extractMarkdownSection(input.previousSummaryBody, "Files Delivered") ?? "")
|
||||
.matchAll(/^[-*]\s+`([^`\n]+)`\s*$/gm)].map((match) => match[1]!);
|
||||
const delivered = [...new Set([...readDeliveredFiles(run.resultJson), ...previousDelivered])].slice(0, 12);
|
||||
const paths = extractPathCandidates(resultSummary, run.stdoutExcerpt, run.stderrExcerpt, input.previousSummaryBody);
|
||||
const objective = extractMarkdownSection(issue.description, "Objective") ?? issue.description?.trim() ?? "No objective captured.";
|
||||
const acceptanceCriteria = extractMarkdownSection(issue.description, "Acceptance Criteria") ?? "No explicit acceptance criteria captured.";
|
||||
@@ -170,8 +206,7 @@ export function buildContinuationSummaryMarkdown(input: {
|
||||
`- Status: ${issue.status}`,
|
||||
`- Priority: ${issue.priority}`,
|
||||
`- Current mode: ${mode}`,
|
||||
`- Last updated by run: ${run.id}`,
|
||||
`- Agent: ${agent.name} (${agent.adapterType ?? "unknown"})`,
|
||||
`- Agent: ${agent.name}`,
|
||||
"",
|
||||
"## Objective",
|
||||
"",
|
||||
@@ -189,16 +224,7 @@ export function buildContinuationSummaryMarkdown(input: {
|
||||
"",
|
||||
bulletList(paths.map((path) => `\`${path}\``), "No file or route paths were detected in the captured run summary."),
|
||||
"",
|
||||
"## Commands Run",
|
||||
"",
|
||||
bulletList(
|
||||
[
|
||||
`Heartbeat run \`${run.id}\` invoked adapter \`${agent.adapterType ?? "unknown"}\`.`,
|
||||
"Detailed shell/tool commands remain in the run log and transcript.",
|
||||
],
|
||||
"No command metadata captured.",
|
||||
),
|
||||
"",
|
||||
...(delivered.length > 0 ? ["## Files Delivered", "", bulletList(delivered.map((name) => `\`${name}\``), ""), ""] : []),
|
||||
"## Blockers / Decisions",
|
||||
"",
|
||||
bulletList(
|
||||
|
||||
@@ -3,6 +3,7 @@ import { and, eq } from "drizzle-orm";
|
||||
import { createHash } from "node:crypto";
|
||||
import { assets, companies, completionContracts, documents, documentRevisions, heartbeatRuns, issueDocuments, issueAttachments, issues, issueThreadInteractions, issueWorkProducts, mcpAttachmentUploads, dotRunnerAssignments, type Db } from "@paperclipai/db";
|
||||
import { projectHumanInteractionResponse } from "../execution-continuation.js";
|
||||
import { isCommittedToolReceiptResult } from "../heartbeat-run-summary.js";
|
||||
|
||||
export class NativeDeliverableEvidenceError extends Error {}
|
||||
|
||||
@@ -42,7 +43,7 @@ async function hasCurrentPublicationReceipt(db: Db, companyId: string, receipts:
|
||||
const receipt = record(value);
|
||||
const input = record(receipt.input);
|
||||
const result = record(receipt.result);
|
||||
if ((result.disposition !== "applied" && result.disposition !== "duplicate") ||
|
||||
if (!isCommittedToolReceiptResult(result) ||
|
||||
!Array.isArray(result.entityRefs) || result.entityRefs[0] !== attachment.id) continue;
|
||||
if (receipt.operationId === "publish_external_deliverable" && result.source === "authenticated_upload"
|
||||
&& result.commandId === `deliverable-uploaded:${attachment.id}` && typeof input.uploadId === "string"
|
||||
@@ -324,7 +325,7 @@ export async function publishedTaskDocuments(db: Db, binding: { companyId: strin
|
||||
const saved = await (binding.lockSources ? query.for("share", { of: [issueDocuments, documents, documentRevisions, heartbeatRuns], noWait: true }) : query);
|
||||
return saved.filter(document => Object.values(record(document.resultJson?.semanticToolReceipts)).some(value => {
|
||||
const receipt = record(value), result = record(receipt.result), published = record(result.document);
|
||||
return receipt.operationId === "write_document" && ["applied", "duplicate"].includes(String(result.disposition))
|
||||
return receipt.operationId === "write_document" && isCommittedToolReceiptResult(result)
|
||||
&& published.id === document.id && published.latestRevisionId === document.revisionId;
|
||||
})).map(({ id, revisionId, key, issuePrefix, issueIdentifier }) => ({ id, revisionId, key,
|
||||
href: `/${encodeURIComponent(issuePrefix)}/issues/${encodeURIComponent(issueIdentifier ?? binding.issueId)}#document-${encodeURIComponent(key)}` }));
|
||||
|
||||
Reference in new issue
Block a user