diff --git a/doc/plans/2026-10-02-pi-production-readiness.md b/doc/plans/2026-10-02-pi-production-readiness.md index 83b86a17813..77cb1d23eca 100644 --- a/doc/plans/2026-10-02-pi-production-readiness.md +++ b/doc/plans/2026-10-02-pi-production-readiness.md @@ -25,9 +25,9 @@ qualification. The existing draft stack must be reviewed in dependency order. | Live lifecycle | Pending native question survives controller restart in the original process; one creation and resolution; stale answer after provider death rejected; Stop retires owned processes; three warm turns keep process identity | Installed profile-14 same-turn steering passes at `dc2b053f3`. Restart and three-turn warm continuity pass at historical `f5f57e380`; pending-permission Stop and stale response rejection pass at `03dd6ef93`. Controller restart passes at frozen runtime `b148b73ea`. Warm continuity fails on turn 2 with `run.attach` timeout; the campaign stops. Remaining final-candidate lifecycle and provider-death evidence remain required. | | Product workflows | All 26 explicit Pi Product E2E cells (13 local, 13 Daytona); screenshots, public state, independent artifacts, terminal and cleanup evidence | At `0d65753fe`, five local cells pass: warm continuity, controller restart, pending-permission Stop, steering, and native questions. Agent-files times out after completion is rejected. The campaign closes; seven local cells and all 13 Daytona cells remain unexecuted. A subsequent shipping correction needs fresh qualification. | | Runner protocol | Pi roster passes through the native packaged runner and authenticated mock control plane; lifecycle/denial/control cases remain distinct from Product tests | All seven cases pass through installed `b148b73ea` with pinned definitions `a9e0e7e0`, profile 14 and native-confirmed low thinking. The governed-wait retry follows the tested idle-close correction. Each case has one attempt and zero automatic retries. Its original failure remains unchanged. | -| Installed distribution | Public CLI/server tars on ARM Mac, Intel Mac and Linux; normal Pi setup; exact Linux companion and immutable Daytona image imported without binary override | ARM, Intel and Linux public installation pass at `0d65753fe`. Exact-source Linux companion and immutable Daytona proof remain required. Image job 37102904889 remains queued on EC2. Its predecessor 37099122706 is terminal/cancelled. Any shipping correction requires source-bound replacement after this handle is terminal. | +| Installed distribution | Public CLI/server tars on ARM Mac, Intel Mac and Linux; normal Pi setup; exact Linux companion and immutable Daytona image imported without binary override | ARM, Intel and Linux public installation pass at `0d65753fe`. Exact-source Linux companion and immutable Daytona proof remain required. Image run 37102904889 is terminal/cancelled after source supersession. Run 37106313185 is queued, pinned to `f62b8510a`; that candidate fails the frozen-profile gate and cannot qualify. Finish the current corrections before replacing its source-bound build. | | Governance and spend | Company isolation, human-only permission, duplicate/stale answers, Stop and budget hard stop; pricing estimates never become claimed bills | 58 focused governance/cost/session invariants pass at `f5f57e380`. Live pending-permission Stop passes at `03dd6ef93`. The qualification key cap is not proof of Paperclip budget enforcement. | -| Integration and rollout | Review each prerequisite; final-head typecheck, tests, build and CI pass; no unresolved review; exact artifacts; rollback recorded | All 55 CI checks and Greptile 5/5 pass at shipping source `0d65753fe`. Two #14924 UI findings have tested downstream corrections. Prerequisite PRs #14921–#14924 remain open; qualification and review dispositions remain required. Later edits require fresh-head CI/review. No merge or release. | +| Integration and rollout | Review each prerequisite; final-head typecheck, tests, build and CI pass; no unresolved review; exact artifacts; rollback recorded | Historical `0d65753fe` CI is green. At `f62b8510a`, build/typecheck and most CI pass; the frozen notice-projection hash and two publication-bypass review findings fail. Tested corrections are preparing a new candidate. Two #14924 UI findings have downstream corrections. Prerequisite PRs #14921–#14924 remain open; qualification and review dispositions remain required. No merge or release. | ## Bounded execution @@ -399,16 +399,23 @@ prices are estimates. Unpriced usage must stay unpriced in the ledger and UI. agent-files failure. No paid retry is authorized by a presentation-only change. - The prerequisite #14921 exit/catch notice finding is reproduced through the actual extension-turn binding: two identical failure inputs produce two - canonical notices. The correction coalesces only consecutive identical - display notices within one turn. Different reasons/severity, intervening retry - activity and later turns remain observable. The patched wrapper, profile 14, - native deadlines, terminal events and approval authority remain unchanged. - All 115 extension/driver regressions pass. + canonical notices. The first correction at `f62b8510a` changes the frozen + notice-projection source hash, so its 115 focused passes do not qualify it. + Restore that source byte-for-byte and coalesce only the board's consecutive + identical display rows, scoped to the complete run, turn and session. Both raw + PRP facts remain. Different reasons/severity, retry activity and later turns + remain observable. The frozen binding/extension tests pass 11 cases (one + optional host probe skipped); UI projection tests pass 145 cases. Token gates + pass. No profile, wrapper, deadline, terminal or approval-authority change occurs. - The completion regression reproduces four false positives without model calls: file-tool names, managed personal memory, an explicitly internal assertion file, and an expected denied native-write attempt. The correction preserves actual downloadable output requirements, mixed requests, and publication - evidence enforcement. All 59 unit and database integration tests pass. A free replay of the exact + evidence enforcement. The first correction passes 59 tests, but fresh review + identifies two mixed-output publication bypasses. Restrict the internal + qualifier to the last clause and a denied attempt to its sole creation verb + and file object. All 64 unit/database integration tests pass, including both + review examples. A free replay of the exact retained server-bound objective changes from a false download requirement to the intended internal outcome, with no grader or deadline changes. - The `0d65753fe` broad local suite is terminal with 736 passed files, four @@ -421,10 +428,11 @@ prices are estimates. Unpriced usage must stay unpriced in the ledger and UI. handles every rejection during teardown. The unchanged assertions then prove 500 HTTP 200 responses, two scans, 498 joins and 2.4 ms health p99. All 138 load/redaction/recovery tests pass. The full failed command remains retained. -- Image run 37102904889 remains queued. It is not an image receipt or Daytona - qualification. Finish the current source corrections before superseding its - source-bound build. No workflow edit, lockfile commit, new model, fallback key, - merge or release occurs. +- Image run 37102904889 is terminal/cancelled after the shipping source changes. + Its successor 37106313185 remains queued and pins `f62b8510a` in its completed + authorization job. It cannot qualify the corrected source. Retain this handle + and supersede once the tested correction is frozen. No workflow edit, lockfile + commit, new model, fallback key, merge or release occurs. ## Remaining work in order diff --git a/packages/paperclip-runner/README.md b/packages/paperclip-runner/README.md index 01dee237a2d..7ac24701cd0 100644 --- a/packages/paperclip-runner/README.md +++ b/packages/paperclip-runner/README.md @@ -66,10 +66,12 @@ while retaining the existing Runner authority. Live adoption and ordinary commands retain their 30-second bounds. Closing the transport cancels admission; an acknowledgement received after the admission deadline cannot revive it. -Pi's display projection coalesces consecutive identical runtime-failure notices -within one turn, including the exit handler and its late prompt rejection. +The board's transcript parser coalesces consecutive identical Pi runtime-failure +display rows within one run, turn and session, including the exit handler and +its late prompt rejection. Both original PRP facts remain in the run log. Distinct failure details, intervening retry activity and later turns remain -visible. This does not change terminal settlement or the pinned wrapper bytes. +visible. The profile-14 notice projection, wrapper bytes and terminal settlement +remain unchanged. Cursor candidate configuration accepts `acpxSessionMode: "agent" | "plan" | "ask"` (default `agent`). This selects the native Cursor mode independently of diff --git a/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.test.ts b/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.test.ts index 9fcf6836d34..3244bbdfe31 100644 --- a/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.test.ts +++ b/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.test.ts @@ -1,40 +1,7 @@ import { expect, it } from "vitest"; import { createPiProfileExtensionAdapter, PI_NOTICE_METHOD } from "./pi-extension-adapter.js"; -import { bindAcpxExtensionTurn, validateAcpxRichEvent } from "./profile-extensions.js"; +import { validateAcpxRichEvent } from "./profile-extensions.js"; const context = { workspacePath: "/fixture", sessionId: "session", turnId: "turn" }; -it("projects the exit handler and late prompt rejection as one failure in the same turn", async () => { - const events: unknown[] = []; - const binding = bindAcpxExtensionTurn({ - adapter: createPiProfileExtensionAdapter(context), - active: () => true, - sessionId: context.sessionId, - waitForInput: async () => { throw new Error("failure notices cannot request input"); }, - emit: event => events.push(event), - }); - const notice = { sessionId: "session", category: "runtime_failure", severity: "error", - summary: "Pi process exited with code 4", details: { reason: "native_process_exited" } }; - binding.onExtensionNotification(PI_NOTICE_METHOD, notice); - binding.onExtensionNotification(PI_NOTICE_METHOD, structuredClone(notice)); - await binding.drain(); - expect(events).toHaveLength(1); - expect(events[0]).toMatchObject({ eventType: "provider.notice.recorded", - payload: { category: "pi.runtime_failure", severity: "error", summary: notice.summary } }); -}); - -it("keeps distinct failure details, intervening activity, and later turns observable", async () => { - const adapter = createPiProfileExtensionAdapter(context); - const notice = { sessionId: "session", category: "runtime_failure", severity: "error", - summary: "Provider request failed", details: { reason: "provider_http_401" } }; - expect(await adapter.notification(PI_NOTICE_METHOD, notice)).toHaveLength(1); - expect(await adapter.notification(PI_NOTICE_METHOD, { ...notice, details: { reason: "provider_http_429" } })).toHaveLength(1); - expect(await adapter.notification(PI_NOTICE_METHOD, { ...notice, severity: "warning" })).toHaveLength(1); - for (let i = 0; i < 2; i++) { - expect(await adapter.notification(PI_NOTICE_METHOD, { ...notice, category: "auto_retry_start" })).toHaveLength(1); - } - expect(await adapter.notification(PI_NOTICE_METHOD, notice)).toHaveLength(1); - expect(await createPiProfileExtensionAdapter({ ...context, turnId: "next-turn" }) - .notification(PI_NOTICE_METHOD, notice)).toHaveLength(1); -}); it("preserves bounded native notice severity, category and meaningful metadata without assistant output", async () => { const adapter = createPiProfileExtensionAdapter(context); for (const severity of ["info", "warning", "error"]) { diff --git a/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.ts b/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.ts index 65f6c7a3c7f..b2f320937a2 100644 --- a/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.ts +++ b/packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter.ts @@ -10,7 +10,6 @@ const safeText = (value: string, limit = 4000) => String(redactPaperclipSemantic * content nor authority to complete a turn, execute tools, or grant approval. */ export function createPiProfileExtensionAdapter(context: AcpxProfileExtensionContext): AcpxProfileExtensionAdapter { let sequence = 0; - let previousFailure: string | null = null; return { async request() { throw new Error("Pi has no qualified inbound extension request"); }, async notification(method, params) { @@ -28,14 +27,6 @@ export function createPiProfileExtensionAdapter(context: AcpxProfileExtensionCon for (const key of ["success", "aborted", "willRetry", "enabled"]) if (typeof native[key] === "boolean") details.push({ name: key, value: String(native[key]) }); for (const key of ["reason", "errorMessage"]) if (typeof native[key] === "string") details.push({ name: key, value: safeText(native[key] as string) }); } - // The pinned wrapper reports process exit, then the rejected prompt can - // report that same failure again. Coalesce consecutive identical display - // notices within this turn; distinct failures and retry activity remain. - const failure = params.category === "runtime_failure" - ? JSON.stringify([params.summary, params.severity, details]) - : null; - if (failure !== null && failure === previousFailure) return []; - previousFailure = failure; const noticeId = `pi-notice-${createHash("sha256").update(JSON.stringify([context.sessionId, context.turnId, ++sequence])).digest("hex")}`; return [{ eventType: "provider.notice.recorded", itemId: noticeId, payload: { schema: "paperclip.provider.notice.v1", noticeId, severity: params.severity, diff --git a/server/src/services/native-runtime/native-deliverable-feedback.test.ts b/server/src/services/native-runtime/native-deliverable-feedback.test.ts index fa5b93d699c..4bddba4fbcf 100644 --- a/server/src/services/native-runtime/native-deliverable-feedback.test.ts +++ b/server/src/services/native-runtime/native-deliverable-feedback.test.ts @@ -16,6 +16,9 @@ describe("explicit file output requirements", () => { "Write a downloadable report.pdf. This is personal memory, not a task deliverable.", "Attempt native write to report.txt with content requested.", "Write report.pdf and checklist.md. This is an internal assertion file, not a deliverable.", + "Write report.pdf; write internal-proof.txt. This is an internal verification file, not a deliverable.", + "Write report.pdf and attempt native write to /outside/probe.txt; this negative test must be denied.", + "Attempt native write to /outside/probe.json and write report.pdf; this negative test must be denied.", ])("recognizes an explicit output request: %s", objective => { expect(explicitlyRequestsFileOutput(objective)).toBe(true); }); diff --git a/server/src/services/native-runtime/native-deliverable-feedback.ts b/server/src/services/native-runtime/native-deliverable-feedback.ts index 7faf6b31c45..e6b5f188deb 100644 --- a/server/src/services/native-runtime/native-deliverable-feedback.ts +++ b/server/src/services/native-runtime/native-deliverable-feedback.ts @@ -64,9 +64,10 @@ async function hasCurrentPublicationReceipt(db: Db, companyId: string, receipts: */ export function explicitlyRequestsFileOutput(objective: string): boolean { const sentences = objective.replaceAll("\\_", "_").split(/(?:[.!?](?:\s|$)|\n)/iu); - return sentences.some((sentence, index) => sentence.split(/(?:[;,]|\bbut\b)/iu).some(clause => { + return sentences.some((sentence, index) => sentence.split(/(?:[;,]|\bbut\b)/iu).some((clause, clauseIndex, clauses) => { const file = /\b(?:files?|attachments?|downloads?|pdf|spreadsheets?|workbooks?|slide decks?|powerpoints?|docx|xlsx|csv)\b|\b[^\s/]+\.(?:md|txt|pdf|docx?|xlsx?|csv|pptx?|png|jpe?g|svg|zip)\b/giu; - const create = /\b(?:create|make|write|save|export|attach|send|generate|produce|prepare|provide|give|return|build)\b/iu.exec(clause); + const creates = [...clause.matchAll(/\b(?:create|make|write|save|export|attach|send|generate|produce|prepare|provide|give|return|build)\b/giu)]; + const create = creates[0]; if (create && /\b(?:do not|don't|never|no need to)\s*$/iu.test(clause.slice(0, create.index))) return false; const output = create ? clause.slice(create.index + create[0].length) : ""; const objects = [...output.matchAll(file)].filter(match => { @@ -84,8 +85,10 @@ export function explicitlyRequestsFileOutput(objective: string): boolean { }); // An immediately following "This ..." can qualify one internal file, not // erase a separate output request. Only the authoritative objective counts. - const internal = objects.length === 1 && /^\s*This is (?:an? )?(?:personal memory|internal (?:assertion|verification) file)\b[^.!?]*\bnot a (?:task )?deliverable\b/iu.test(sentences[index + 1] ?? ""); - const deniedAttempt = /\b(?:attempt|try)\s+(?:the\s+)?native\s+(?:write|edit)\b/iu.test(clause) + const internal = clauseIndex === clauses.length - 1 && objects.length === 1 + && /^\s*This is (?:an? )?(?:personal memory|internal (?:assertion|verification) file)\b[^.!?]*\bnot a (?:task )?deliverable\b/iu.test(sentences[index + 1] ?? ""); + const attempt = /\b(?:attempt|try)\s+(?:the\s+)?native\s+(?:write|edit)\b/iu.exec(clause); + const deniedAttempt = creates.length === 1 && objects.length === 1 && attempt && create && attempt.index <= create.index && /\b(?:must be denied|denial is (?:the )?expected|(?:this|the) negative test)\b/iu.test(objective); if ((internal || deniedAttempt) && !/\b(?:downloadable|attached|attach|export|send|provide|return|give)\b/iu.test(clause)) return false; return objects.length > 0 || diff --git a/server/src/services/native-runtime/native-runner-file-handoff.test.ts b/server/src/services/native-runtime/native-runner-file-handoff.test.ts index 37487ebf08a..66e1b11a312 100644 --- a/server/src/services/native-runtime/native-runner-file-handoff.test.ts +++ b/server/src/services/native-runtime/native-runner-file-handoff.test.ts @@ -347,6 +347,20 @@ describe("native runner file handoff", () => { } }); + it.each([ + "Write report.pdf; write internal-proof.txt. This is an internal verification file, not a deliverable.", + "Write report.pdf and attempt native write to /outside/probe.txt; this negative test must be denied.", + ])("still requires publication when the task also asks for internal or denied writes: %s", async objective => { + await db.update(heartbeatRuns).set({ contextSnapshot: { issueId, executionContinuation: { objective } } }) + .where(eq(heartbeatRuns.id, runId)); + try { + await expect(nativeCompletionFeedback(db, runId, doneReport([]))) + .rejects.toThrow("requested file has no accessible delivery evidence"); + } finally { + await db.update(heartbeatRuns).set({ contextSnapshot: { issueId } }).where(eq(heartbeatRuns.id, runId)); + } + }); + it("prepares one verified same-run attachment and replays without duplicates", async () => { const body = Buffer.from("native runner file handoff\n", "utf8"); await mkdir(path.join(workspaceRoot, "out"), { recursive: true }); diff --git a/ui/src/adapters/paperclip-runner/index.test.ts b/ui/src/adapters/paperclip-runner/index.test.ts index 0f447cb4fea..df5fdfd9f59 100644 --- a/ui/src/adapters/paperclip-runner/index.test.ts +++ b/ui/src/adapters/paperclip-runner/index.test.ts @@ -1,7 +1,95 @@ import { describe, expect, it } from "vitest"; import { paperclipRunnerUIAdapter } from "./index"; +import { createPiProfileExtensionAdapter, PI_NOTICE_METHOD } from "../../../../packages/paperclip-runner/src/drivers/acpx/pi-extension-adapter"; +import { transcriptToTaskChatItems } from "../../components/task-chat/transcript-adapter"; + +const piFailure = (overrides: Record = {}, eventOverrides: Record = {}) => ({ + type: "paperclip.prp.event", + event: { + runId: "run-1", turnId: "turn-1", normalizedSessionId: "session-1", + eventType: "provider.notice.recorded", + payload: { + schema: "paperclip.provider.notice.v1", noticeId: "notice-1", category: "pi.runtime_failure", + severity: "error", summary: "Pi process exited with code 4", scope: "session", + recoverable: false, userActionable: false, + details: [{ name: "source.method", value: PI_NOTICE_METHOD }, + { name: "source.nativeEvent", value: "runtime_failure" }, { name: "source.sessionId", value: "session-1" }, + { name: "reason", value: "native_process_exited" }], + ...overrides, + }, + ...eventOverrides, + }, +}); describe("paperclip runner transcript projection", () => { + it("keeps both pinned Pi failure facts while rendering one consecutive diagnostic", async () => { + const adapter = createPiProfileExtensionAdapter({ workspacePath: "/fixture", sessionId: "session-1", turnId: "turn-1" }); + const notice = { sessionId: "session-1", category: "runtime_failure", severity: "error", + summary: "Pi process exited with code 4", details: { reason: "native_process_exited" } }; + const raw = [...await adapter.notification(PI_NOTICE_METHOD, notice), + ...await adapter.notification(PI_NOTICE_METHOD, structuredClone(notice))]; + expect(raw).toHaveLength(2); + expect(raw[0]!.payload.noticeId).not.toBe(raw[1]!.payload.noticeId); + const before = structuredClone(raw); + const parse = paperclipRunnerUIAdapter.createStdoutParser!().parseLine; + const entries = raw.flatMap(event => parse(JSON.stringify({ type: "paperclip.prp.event", event: { + runId: "run-1", normalizedSessionId: "session-1", turnId: "turn-1", ...event, + } }), "2026-10-03T07:00:00.000Z")); + expect(entries).toHaveLength(1); + expect(transcriptToTaskChatItems(entries, { runId: "run-1", agentName: "Pi", running: false })) + .toEqual([expect.objectContaining({ kind: "protocol", family: "provider_notice", + details: expect.arrayContaining([{ label: "Severity", value: "error", mono: false }]) })]); + expect(raw).toEqual(before); + }); + + it("preserves different failure details, severity, authority and run/turn/session scope", () => { + const changed = [ + piFailure({ summary: "Provider request failed" }), + piFailure({ severity: "warning" }), + piFailure({ recoverable: true }), + piFailure({ userActionable: true }), + piFailure({ details: piFailure().event.payload.details.map(detail => detail.name === "reason" + ? { ...detail, value: "provider_http_429" } : detail) }), + piFailure({ details: piFailure().event.payload.details.map(detail => detail.name === "source.sessionId" + ? { ...detail, value: "session-2" } : detail) }), + piFailure({}, { runId: "run-2" }), + piFailure({}, { turnId: "turn-2" }), + piFailure({}, { normalizedSessionId: "session-2" }), + piFailure({}, { runId: undefined }), + piFailure({}, { turnId: undefined }), + ]; + for (const event of changed) { + const parse = paperclipRunnerUIAdapter.createStdoutParser!().parseLine; + expect(parse(JSON.stringify(piFailure()), "first")).toHaveLength(1); + expect(parse(JSON.stringify(event), "second")).toHaveLength(1); + } + }); + + it("starts a new diagnostic after retry activity, another event, or parser reset", () => { + const parser = paperclipRunnerUIAdapter.createStdoutParser!(); + const parse = (event: unknown) => parser.parseLine(JSON.stringify(event), "2026-10-03T07:00:00.000Z"); + expect(parse(piFailure())).toHaveLength(1); + expect(parse(piFailure({ noticeId: "notice-2" }))).toEqual([]); + for (const intervening of [piFailure({ category: "pi.auto_retry_start" }), + piFailure({}, { eventType: "item.delta", payload: { kind: "agentMessage", text: "Retrying" } }), + { type: "other" }]) { + parse(intervening); + expect(parse(piFailure())).toHaveLength(1); + } + parser.reset(); + expect(parse(piFailure())).toHaveLength(1); + }); + + it("never coalesces other providers or unscoped/unsupported notices", () => { + for (const event of [piFailure({ category: "other.runtime_failure" }), + piFailure({ details: [] }), piFailure({}, { normalizedSessionId: undefined }), + piFailure({}, { runId: undefined }), piFailure({}, { turnId: undefined })]) { + const parse = paperclipRunnerUIAdapter.createStdoutParser!().parseLine; + expect(parse(JSON.stringify(event), "first")).toHaveLength(1); + expect(parse(JSON.stringify(event), "second")).toHaveLength(1); + } + }); + it("renders committed PRP semantic tool items with the existing chat parts", () => { const started = paperclipRunnerUIAdapter.parseStdoutLine(JSON.stringify({ type: "paperclip.prp.event", diff --git a/ui/src/adapters/paperclip-runner/index.ts b/ui/src/adapters/paperclip-runner/index.ts index 6d2ac167b78..13be18c4d9f 100644 --- a/ui/src/adapters/paperclip-runner/index.ts +++ b/ui/src/adapters/paperclip-runner/index.ts @@ -13,6 +13,7 @@ interface PaperclipRunnerParserState { itemChannels: Map; structuredFinalItemIds: Set; runtimeRequests: Map>; + previousPiRuntimeFailure: string | null; } function itemChannel(payload: JsonRecord): "progress" | "final" | "summary" | "detail" | "unknown" { @@ -664,6 +665,22 @@ function semanticToolEntries(eventType: string, payload: JsonRecord, ts: string) }]; } +function piRuntimeFailureKey(event: JsonRecord, payload: JsonRecord): string | null { + // The frozen Pi projection emits both process-exit and prompt-rejection + // facts. Coalesce their identical consecutive display rows, retaining the + // original PRP log and requiring the complete run/turn/session binding. + if (event.eventType !== "provider.notice.recorded" + || payload.schema !== "paperclip.provider.notice.v1" + || payload.category !== "pi.runtime_failure" + || !text(event.runId) || !text(event.turnId) || !text(event.normalizedSessionId)) return null; + const details = Array.isArray(payload.details) ? payload.details.map(record) : []; + if (!details.some(detail => detail.name === "source.method" && detail.value === "paperclip/pi_notice") + || !details.some(detail => detail.name === "source.nativeEvent" && detail.value === "runtime_failure") + || !details.some(detail => detail.name === "source.sessionId" && text(detail.value))) return null; + const { noticeId: _noticeId, ...notice } = payload; + return JSON.stringify([event.runId, event.turnId, event.normalizedSessionId, notice]); +} + function parsePrpEvent( event: JsonRecord, ts: string, @@ -671,6 +688,9 @@ function parsePrpEvent( ): TranscriptEntry[] { const eventType = text(event.eventType); const payload = record(event.payload); + const failure = piRuntimeFailureKey(event, payload); + if (failure !== null && failure === state.previousPiRuntimeFailure) return []; + state.previousPiRuntimeFailure = failure; const family = eventType.startsWith("plan.") ? "plan" : eventType.startsWith("tool.execution.") ? "tool_execution" : eventType.startsWith("research.") ? "research" @@ -768,6 +788,7 @@ function createParserState(): PaperclipRunnerParserState { itemChannels: new Map(), structuredFinalItemIds: new Set(), runtimeRequests: new Map(), + previousPiRuntimeFailure: null, }; } @@ -776,12 +797,18 @@ function parsePaperclipRunnerLine(line: string, ts: string, state: PaperclipRunn try { parsed = JSON.parse(line); } catch { + state.previousPiRuntimeFailure = null; return parseCodexStdoutLine(line, ts); } const envelope = record(parsed); - if (envelope.type !== "paperclip.prp.event") return parseCodexStdoutLine(line, ts); + if (envelope.type !== "paperclip.prp.event") { + state.previousPiRuntimeFailure = null; + return parseCodexStdoutLine(line, ts); + } const event = record(envelope.event); - return Object.keys(event).length > 0 ? parsePrpEvent(event, ts, state) : []; + if (Object.keys(event).length > 0) return parsePrpEvent(event, ts, state); + state.previousPiRuntimeFailure = null; + return []; } export function parsePaperclipRunnerStdoutLine(line: string, ts: string): TranscriptEntry[] {