mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-27 11:20:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A core part of that experience is watching active agent runs without dropping into raw logs first > - Local and sandbox-backed adapters already record useful run output, progress, and tool activity > - But active issue threads could sit visually stale while the agent was syncing workspaces, tailing sandbox output, or emitting incremental tool-call updates > - Operators need timely, human-readable progress while preserving the raw transcript underneath > - This pull request streams sandbox run-log progress into runtime status, keeps visible issue threads refreshed, and folds repeated ACPX tool updates into stable transcript cards > - The benefit is that long-running agent work becomes easier to supervise without changing the task/comment control-plane model ## Linked Issues or Issue Description No public GitHub issue exists for this exact change. Problem/motivation: - During long-running sandboxed agent work, the issue UI can appear idle even though the agent is actively syncing, running tools, or producing incremental output. - Operators need realtime feedback at the issue-thread layer, not only after opening raw logs or waiting for the final heartbeat result. - Related public context: #1808 previously added live-run status dots to Projects; #4362 touches heartbeat wakeup behavior but is not a duplicate of this runtime/UI feedback change. ## What Changed - Added sandbox run-log streaming support and defaulted sandbox-capable local adapters into the richer live-feedback path. - Surfaced environment/sandbox sync progress through heartbeat runtime status with bounded, redacted snippets. - Added live issue-thread cache patching so visible active runs update as progress events arrive. - Folded repeated ACPX `tool_call` updates into one transcript card instead of stacking duplicate cards. - Updated adapter docs and added focused regression coverage for sandbox log streaming, runtime status, ACPX parsing, live updates, transcript rendering, and issue chat messages. ## Verification - `pnpm install --frozen-lockfile` - `pnpm exec vitest run ui/src/context/LiveUpdatesProvider.test.ts` - `pnpm exec vitest run server/src/services/heartbeat-run-runtime-status.test.ts server/src/__tests__/heartbeat-runtime-state.test.ts ui/src/context/LiveUpdatesProvider.test.ts` - `pnpm exec vitest run packages/adapter-utils/src/execution-target-sandbox.test.ts packages/adapter-utils/src/sandbox-managed-runtime.test.ts server/src/services/heartbeat-run-runtime-status.test.ts server/src/__tests__/agent-live-run-routes.test.ts server/src/__tests__/heartbeat-runtime-state.test.ts packages/adapters/acpx-local/src/ui/parse-stdout.test.ts ui/src/context/LiveUpdatesProvider.test.ts ui/src/components/transcript/RunTranscriptView.test.tsx ui/src/lib/issue-chat-messages.test.ts ui/src/components/IssueChatThread.test.tsx` - GitHub PR workflow on head `8397953e7b41ccd42e5d9457ee7e4dfb996e4ec5`: `verify`, build, typecheck/release-registry, e2e, general shards, serialized server shards, and canary dry run passed. - Greptile Review on head `8397953e7b41ccd42e5d9457ee7e4dfb996e4ec5`: Confidence Score 5/5, no unresolved review threads. ## Risks - Live issue-thread cache patching could miss an edge case for a route shape not covered by tests. - Surfacing active-run snippets needs continued care around redaction; this PR keeps snippets bounded and adds redaction-focused coverage. - More frequent active-run UI refreshes could expose performance issues on very large issue threads, though updates are scoped to visible run/query caches. ## Model Used OpenAI GPT-5 via Codex, operating as a tool-enabled coding agent with shell, git, and repository-editing capabilities. Context window size is not exposed in this runtime. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: Paperclip <noreply@paperclip.ing>
282 lines
8.4 KiB
TypeScript
282 lines
8.4 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
|
import { eq } from "drizzle-orm";
|
|
import {
|
|
agents,
|
|
agentRuntimeState,
|
|
agentWakeupRequests,
|
|
companies,
|
|
createDb,
|
|
heartbeatRunEvents,
|
|
heartbeatRuns,
|
|
} from "@paperclipai/db";
|
|
import {
|
|
getEmbeddedPostgresTestSupport,
|
|
startEmbeddedPostgresTestDatabase,
|
|
} from "./helpers/embedded-postgres.js";
|
|
import { subscribeCompanyLiveEvents } from "../services/live-events.ts";
|
|
import {
|
|
clearAllHeartbeatRunRuntimeStatuses,
|
|
getHeartbeatRunRuntimeStatus,
|
|
} from "../services/heartbeat-run-runtime-status.ts";
|
|
|
|
vi.doMock("../adapters/index.js", () => ({
|
|
getServerAdapter: vi.fn(() => ({
|
|
type: "process",
|
|
execute: vi.fn(),
|
|
testEnvironment: vi.fn(),
|
|
})),
|
|
listAdapterModelProfiles: vi.fn(() => []),
|
|
runningProcesses: new Map(),
|
|
}));
|
|
|
|
const { heartbeatService } = await import("../services/heartbeat.ts");
|
|
|
|
const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
|
|
const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;
|
|
|
|
if (!embeddedPostgresSupport.supported) {
|
|
console.warn(
|
|
`Skipping embedded Postgres heartbeat runtime-state tests on this host: ${embeddedPostgresSupport.reason ?? "unsupported environment"}`,
|
|
);
|
|
}
|
|
|
|
describeEmbeddedPostgres("heartbeat runtime state deduplication", () => {
|
|
let db!: ReturnType<typeof createDb>;
|
|
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
|
|
|
|
beforeAll(async () => {
|
|
tempDb = await startEmbeddedPostgresTestDatabase("heartbeat-runtime-state-");
|
|
db = createDb(tempDb.connectionString);
|
|
}, 20_000);
|
|
|
|
afterEach(async () => {
|
|
clearAllHeartbeatRunRuntimeStatuses();
|
|
await db.delete(heartbeatRunEvents);
|
|
await db.delete(heartbeatRuns);
|
|
await db.delete(agentWakeupRequests);
|
|
await db.delete(agentRuntimeState);
|
|
await db.delete(agents);
|
|
await db.delete(companies);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await tempDb?.cleanup();
|
|
});
|
|
|
|
it("deduplicates concurrent runtime-state creation", async () => {
|
|
const companyId = randomUUID();
|
|
const agentId = randomUUID();
|
|
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
|
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: "Paperclip",
|
|
issuePrefix,
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
|
|
await db.insert(agents).values({
|
|
id: agentId,
|
|
companyId,
|
|
name: "CodexCoder",
|
|
role: "engineer",
|
|
status: "idle",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
});
|
|
|
|
const heartbeat = heartbeatService(db);
|
|
const results = await Promise.all(Array.from({ length: 12 }, () => heartbeat.getRuntimeState(agentId)));
|
|
|
|
expect(results.every((row) => row?.agentId === agentId)).toBe(true);
|
|
|
|
const rows = await db.select().from(agentRuntimeState).where(eq(agentRuntimeState.agentId, agentId));
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0]).toMatchObject({
|
|
agentId,
|
|
companyId,
|
|
adapterType: "codex_local",
|
|
stateJson: {},
|
|
});
|
|
});
|
|
|
|
it("publishes runtime progress without persisting heartbeat run events", async () => {
|
|
const companyId = randomUUID();
|
|
const agentId = randomUUID();
|
|
const runId = randomUUID();
|
|
const issueId = randomUUID();
|
|
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
|
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: "Paperclip",
|
|
issuePrefix,
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
|
|
await db.insert(agents).values({
|
|
id: agentId,
|
|
companyId,
|
|
name: "CodexCoder",
|
|
role: "engineer",
|
|
status: "running",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
});
|
|
|
|
const [insertedRun] = await db.insert(heartbeatRuns).values({
|
|
id: runId,
|
|
companyId,
|
|
agentId,
|
|
invocationSource: "assignment",
|
|
status: "running",
|
|
contextSnapshot: { issueId },
|
|
}).returning();
|
|
const run = insertedRun!;
|
|
|
|
const liveEvents: unknown[] = [];
|
|
const unsubscribe = subscribeCompanyLiveEvents(companyId, (event) => {
|
|
liveEvents.push(event);
|
|
});
|
|
try {
|
|
const heartbeat = heartbeatService(db);
|
|
const status = await heartbeat.recordRuntimeProgress(run, {
|
|
phase: "config_sync",
|
|
message: "Syncing workspace to sandbox",
|
|
currentToolName: "bash",
|
|
lastAssistantSnippet: "Inspecting the repository",
|
|
lastEventAt: "2026-06-24T00:00:05.000Z",
|
|
}, issueId);
|
|
|
|
expect(status).toMatchObject({
|
|
companyId,
|
|
issueId,
|
|
agentId,
|
|
runId,
|
|
phase: "config_sync",
|
|
message: "Syncing workspace to sandbox",
|
|
currentToolName: "bash",
|
|
lastAssistantSnippet: "Inspecting the repository",
|
|
lastEventAt: new Date("2026-06-24T00:00:05.000Z"),
|
|
});
|
|
expect(heartbeat.decorateActiveRunStatus({
|
|
id: runId,
|
|
companyId,
|
|
agentId,
|
|
issueId,
|
|
status: "running",
|
|
})).toMatchObject({
|
|
currentStatusMessage: "Syncing workspace to sandbox",
|
|
currentToolName: "bash",
|
|
lastAssistantSnippet: "Inspecting the repository",
|
|
lastEventAt: new Date("2026-06-24T00:00:05.000Z"),
|
|
});
|
|
expect(liveEvents).toContainEqual(expect.objectContaining({
|
|
companyId,
|
|
type: "heartbeat.run.progress",
|
|
payload: expect.objectContaining({
|
|
runId,
|
|
agentId,
|
|
issueId,
|
|
phase: "config_sync",
|
|
message: "Syncing workspace to sandbox",
|
|
currentToolName: "bash",
|
|
lastAssistantSnippet: "Inspecting the repository",
|
|
lastEventAt: "2026-06-24T00:00:05.000Z",
|
|
}),
|
|
}));
|
|
|
|
const persistedEvents = await db.select().from(heartbeatRunEvents);
|
|
expect(persistedEvents).toHaveLength(0);
|
|
|
|
await heartbeat.cancelRun(runId, "test cleanup");
|
|
expect(getHeartbeatRunRuntimeStatus(runId)).toBeNull();
|
|
} finally {
|
|
unsubscribe();
|
|
}
|
|
});
|
|
|
|
it("ignores late runtime progress after the persisted run is terminal", async () => {
|
|
const companyId = randomUUID();
|
|
const agentId = randomUUID();
|
|
const runId = randomUUID();
|
|
const issueId = randomUUID();
|
|
const issuePrefix = `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`;
|
|
|
|
await db.insert(companies).values({
|
|
id: companyId,
|
|
name: "Paperclip",
|
|
issuePrefix,
|
|
requireBoardApprovalForNewAgents: false,
|
|
});
|
|
|
|
await db.insert(agents).values({
|
|
id: agentId,
|
|
companyId,
|
|
name: "CodexCoder",
|
|
role: "engineer",
|
|
status: "running",
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
});
|
|
|
|
const [insertedRun] = await db.insert(heartbeatRuns).values({
|
|
id: runId,
|
|
companyId,
|
|
agentId,
|
|
invocationSource: "assignment",
|
|
status: "running",
|
|
contextSnapshot: { issueId },
|
|
}).returning();
|
|
const staleRunningRun = insertedRun!;
|
|
|
|
const liveEvents: unknown[] = [];
|
|
const unsubscribe = subscribeCompanyLiveEvents(companyId, (event) => {
|
|
liveEvents.push(event);
|
|
});
|
|
try {
|
|
const heartbeat = heartbeatService(db);
|
|
await heartbeat.recordRuntimeProgress(staleRunningRun, {
|
|
phase: "config_sync",
|
|
message: "Syncing workspace to sandbox",
|
|
}, issueId);
|
|
|
|
expect(getHeartbeatRunRuntimeStatus(runId)).toMatchObject({
|
|
runId,
|
|
phase: "config_sync",
|
|
});
|
|
|
|
liveEvents.length = 0;
|
|
await db
|
|
.update(heartbeatRuns)
|
|
.set({
|
|
status: "succeeded",
|
|
finishedAt: new Date("2026-06-24T00:01:00.000Z"),
|
|
updatedAt: new Date("2026-06-24T00:01:00.000Z"),
|
|
})
|
|
.where(eq(heartbeatRuns.id, runId));
|
|
|
|
const lateStatus = await heartbeat.recordRuntimeProgress(staleRunningRun, {
|
|
phase: "finalize",
|
|
message: "Finalizing sandbox workspace",
|
|
}, issueId);
|
|
|
|
expect(lateStatus).toBeNull();
|
|
expect(getHeartbeatRunRuntimeStatus(runId)).toBeNull();
|
|
expect(liveEvents).not.toContainEqual(expect.objectContaining({
|
|
type: "heartbeat.run.progress",
|
|
}));
|
|
expect(await db.select().from(heartbeatRunEvents)).toHaveLength(0);
|
|
} finally {
|
|
unsubscribe();
|
|
}
|
|
});
|
|
});
|