perf(wake-queue): omit unused native launch context from release reads (#17619)

Read native wake-release control context without saved launch payloads. Keep stored input, full legacy context, cancellation evidence, and release decisions. PostgreSQL response-budget regression, 785 lifecycle tests, typecheck, build, and all 55 CI checks pass. Apex reviewed the exact head at 5/5 with no findings.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip authored and GitHub committed 2026-10-25 09:40:28 -07:00
1 parent b792165ba4
commit e302f2098f
4 files changed
+69 -6

No files matched your search

+8 -4
View File
@@ -50,10 +50,14 @@ and leaves all existing cases passive. Source identities are not grants.
### Task query performance
The issue-lock adapter's release read omits `result_json.stdout` and
`result_json.stderr` before transferring a run to the controller. Every other result key, context field, and
stop, retry, lease, and workspace-recovery check stays intact. Full output remains
stored for execution history and detail reads. Terminal telemetry loads only its
run identity, timestamps, usage, and typed task identifier.
`result_json.stderr` before transferring a run to the controller. Native context
also omits saved launch text, execution-continuation bodies, workspace and
environment payloads, and the launch wake envelope. Task identity, retry and
continuation controls, interaction and comment references, execution policy, unknown context fields, and every other
result key stay intact. Legacy reads retain full context. Stop, retry, lease,
and workspace-recovery checks do not change. Full inputs and output remain stored
for execution history and detail reads. Terminal telemetry loads only its run
identity, timestamps, usage, and typed task identifier.
Recovery's latest-run queries return the context fields used by recovery
decisions. Prompts, execution continuation bodies, and workspace setup payloads
@@ -219,7 +219,8 @@ describeEmbeddedPostgres("wake-queue postgres adapter", () => {
executionCancellation: { state: "acknowledged" }, executionRecovery: { kind: "interrupted", providerStopped: true },
configurationIncomplete: { reason: "workspace_unavailable" }, unknownFutureReceipt: { retained: true } };
await db.update(heartbeatRuns).set({ runtimeMode,
...(runtimeMode === "native" ? { runnerProfileJson: { savedInput: payload }, stdoutExcerpt: payload, stderrExcerpt: payload } : {}),
...(runtimeMode === "native" ? { runnerProfileJson: { savedInput: payload }, stdoutExcerpt: payload, stderrExcerpt: payload,
contextSnapshot: { issueId, paperclipWake: { savedTask: payload }, paperclipTaskMarkdown: payload } } : {}),
resultJson: { ...evidence, stdout: payload.repeat(3), stderr: payload } }).where(eq(heartbeatRuns.id, runId));
await db.update(issues).set({ executionRunId: runId, checkoutRunId: runId }).where(eq(issues.id, issueId));
const [run] = await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, runId));
@@ -233,7 +234,9 @@ describeEmbeddedPostgres("wake-queue postgres adapter", () => {
expect(result.outcome.kind).toBe("released");
expect(rows).toHaveLength(1);
expect(rows[0]).toEqual([{ ...run, resultJson: evidence,
...(runtimeMode === "native" ? { runnerProfileJson: null, stdoutExcerpt: null, stderrExcerpt: null } : {}) }]);
...(runtimeMode === "native" ? { runnerProfileJson: null, stdoutExcerpt: null, stderrExcerpt: null,
contextSnapshot: { issueId } } : {}) }]);
expect(result.run.contextSnapshot).toEqual({ issueId });
expect(Buffer.byteLength(JSON.stringify(rows))).toBeLessThan(8 * 1024);
expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, runId)))[0]).toEqual(run);
expect((await db.select().from(issues).where(eq(issues.id, issueId)))[0]).toEqual(issue);
@@ -71,4 +71,53 @@ describe.skipIf(!support.supported)("wake release run reads", () => {
expect((await readReleaseRun(db, { companyId, runId: run.id })).run?.resultJson).toEqual(result);
},
);
it("keeps launch text in storage while releasing native runs with their control context", async () => {
const bulk = randomBytes(128 * 1024).toString("base64");
const context = {
issueId: randomUUID(), taskId: randomUUID(), taskKey: "saved-task",
retryReason: "execution_review_participant_recovery", wakeReason: "issue_commented",
explicitUserContinuation: true,
interactionId: randomUUID(), interactionKind: "review", interactionStatus: "resolved",
wakeCommentIds: [randomUUID()], queuedCommentSourceWakeIds: [randomUUID()],
chatConversationId: randomUUID(), executionPolicy: { requireApproval: true },
opaqueFutureContext: { retained: [null, false, "input"] },
};
const launch = {
executionContinuation: { instruction: bulk, state: "saved" },
paperclipWake: { savedTask: bulk }, paperclipWakeComment: bulk, paperclipTaskMarkdown: bulk,
paperclipTaskMarkdownCompact: bulk, paperclipTaskMarkdownAssignment: bulk,
paperclipTaskMarkdownAssignmentCompact: bulk, paperclipWorkspace: { files: bulk },
paperclipEnvironment: { input: bulk }, paperclipContinuationSummary: bulk,
};
const evidence = { nativeCancellation: { schema: "paperclip.native-cancellation.v1", dispatched: true },
executionCancellation: { state: "acknowledged" }, workspaceRestoreRecovery: { leaseIds: [randomUUID()] },
configurationIncomplete: { reason: "secret_binding_missing" }, unknownFutureReceipt: { retained: true } };
const [before] = await db.insert(heartbeatRuns).values({ companyId, agentId, runtimeMode: "native",
contextSnapshot: { ...context, ...launch }, resultJson: evidence }).returning();
const events: Array<Record<string, unknown>> = [];
const now = Date.now();
const capture = createDatabaseResponseCapture({ start: now - 100, end: now + 59_000 }, event => events.push(event));
installDatabaseResponseCapture(db, { heartbeatRuns }, capture);
let selected: Awaited<ReturnType<typeof readReleaseRun>>;
try { selected = await db.transaction(tx => readReleaseRun(tx as unknown as typeof db, { companyId, runId: before.id })); }
finally { capture.flush(); }
const summary = events.find(event => event.event === "paperclip.db_response_capture.summary.v1")!;
expect(summary.completedQueries).toBe(1);
expect(summary.responseValueBytes).toBeLessThan(8192);
expect(selected!.run?.contextSnapshot).toEqual(context);
expect(selected!.run?.resultJson).toEqual(evidence);
expect(JSON.stringify(events)).not.toContain(bulk.slice(0, 64));
expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, before.id)))[0]).toEqual(before);
await db.update(heartbeatRuns).set({ runtimeMode: "legacy" }).where(eq(heartbeatRuns.id, before.id));
expect((await readReleaseRun(db, { companyId, runId: before.id })).run?.contextSnapshot).toEqual(before.contextSnapshot);
});
it.each([null, ["paperclipWake", { savedInput: "keep" }], "scalar", 42].map(context => ({ context })))(
"preserves non-object native context $context", async ({ context }) => {
const [run] = await db.insert(heartbeatRuns).values({ companyId, agentId, runtimeMode: "native",
contextSnapshot: context as Record<string, unknown> | null }).returning();
expect((await readReleaseRun(db, { companyId, runId: run.id })).run?.contextSnapshot).toEqual(context);
},
);
});
@@ -7,6 +7,13 @@ export type ReleaseRun = Omit<Run, "runnerProfileJson" | "stdoutExcerpt" | "stde
export async function readReleaseRun(db: Db, scope: { companyId: string; runId: string }) {
const [selected] = await db.select({
...getTableColumns(heartbeatRuns),
contextSnapshot: sql<Run["contextSnapshot"]>`case when ${heartbeatRuns.runtimeMode} = 'native'
and jsonb_typeof(${heartbeatRuns.contextSnapshot}) = 'object'
then ${heartbeatRuns.contextSnapshot} - array['executionContinuation', 'paperclipWake', 'paperclipWakeComment',
'paperclipTaskMarkdown', 'paperclipTaskMarkdownCompact', 'paperclipTaskMarkdownAssignment',
'paperclipTaskMarkdownAssignmentCompact', 'paperclipWorkspace', 'paperclipEnvironment',
'paperclipContinuationSummary']
else ${heartbeatRuns.contextSnapshot} end`,
runnerProfileJson: sql<Run["runnerProfileJson"]>`case when ${heartbeatRuns.runtimeMode} = 'native'
then null else ${heartbeatRuns.runnerProfileJson} end`,
stdoutExcerpt: sql<Run["stdoutExcerpt"]>`case when ${heartbeatRuns.runtimeMode} = 'native'