mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
Preserve exact remote bootstrap read evidence in provider-death qualification
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
5e790deff5
commit
05daf995d1
3 files changed
+20
-5
No files matched your search
@@ -126,7 +126,7 @@ export async function runNativeActiveStopFlow(input: {
|
||||
const state = await load();
|
||||
if (providerDeath) {
|
||||
if (!deathPending || !deathSettlement) throw new Error("Missing provider-death settlement");
|
||||
return assertCopilotProviderDeath({ ...state, pending: deathPending });
|
||||
return assertCopilotProviderDeath({ ...state, pending: deathPending, bootstrap: bootstrap() });
|
||||
}
|
||||
if (!completed) throw new Error("Missing active Stop settlement");
|
||||
return readActiveStopSettlement({ ...state, ...completed, bootstrap: bootstrap() });
|
||||
@@ -208,7 +208,7 @@ export async function runNativeActiveStopFlow(input: {
|
||||
deathSettlement = await pollUntil({ label: "expired callback after owned Copilot death", deadlineAt: input.deadlineAt, intervalMs: 200, load: async () => {
|
||||
const state = await load();
|
||||
if (["succeeded", "cancelled", "timed_out"].includes(state.run.status)) throw new Error("Provider death produced an unexpected terminal run");
|
||||
return assertCopilotProviderDeath({ ...state, pending: deathPending! });
|
||||
return assertCopilotProviderDeath({ ...state, pending: deathPending!, bootstrap: bootstrap() });
|
||||
}, accept: Boolean });
|
||||
check("provider-death-expires-pending", true, "The owned provider died and its unanswered callback expired without completing the task");
|
||||
await input.evidence("copilot-provider-death-settlement.json", deathSettlement);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { bootstrapReadExecutionId } from "./native-bootstrap-read-proof.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { canonicalRemoteCopilotCommand, copilotDeathArguments, selectOwnedCopilotProcess } from "./copilot-provider-death.js";
|
||||
|
||||
@@ -46,6 +48,17 @@ describe("provider-death independent evidence", () => {
|
||||
it("accepts callback expiry and an unfinished failed task with no replay", () => {
|
||||
expect(assertCopilotProviderDeath(facts())).toMatchObject({ expired: true, mutationReplay: false });
|
||||
});
|
||||
it("exempts only an exactly attested completed remote instruction-file read", () => {
|
||||
const actionFile = `.paperclip-eval-action-${"a".repeat(36)}.txt`, toolCallId = "instruction-read";
|
||||
const native = (seq: number, status: string) => row(seq, "provider.notice.recorded", { schema: "paperclip.provider.notice.v1", scope: "turn", category: "copilot_tool_evidence_v1", provenance: { sessionId: "native-session", turnId: "turn", eventType: "tool", method: "session/update" }, details: Object.entries({ stage: "tool", toolCallId, operation: "read", status, readTargetSha256: `sha256:${createHash("sha256").update(actionFile).digest("hex")}` }).map(([name, value]) => ({ name, value })) });
|
||||
const canonical = (seq: number, eventType: string, status: string) => row(seq, eventType, { schema: "paperclip.tool.execution.v1", transport: "builtin", operation: "read", target: actionFile, executionId: bootstrapReadExecutionId(toolCallId), status });
|
||||
const state = facts();
|
||||
const edit = row(5, "provider.notice.recorded", { schema: "paperclip.provider.notice.v1", scope: "turn", category: "copilot_tool_evidence_v1", provenance: { sessionId: "native-session", turnId: "turn", eventType: "tool", method: "session/update" }, details: Object.entries({ stage: "tool", toolCallId: pending.toolCallId, operation: "edit", status: "pending" }).map(([name, value]) => ({ name, value })) });
|
||||
state.events = [native(1, "pending"), canonical(2, "tool.execution.started", "running"), native(3, "completed"), canonical(4, "tool.execution.completed", "completed"), edit, row(6, notice.eventType, notice.payload.prpEvent.payload), row(7, "runtime_request.expired", { requestId: "request", turnId: "turn", requestKind: "permission_approval", reason: "provider_exit" }), row(8, "turn.failed", { error: { code: "AGENT_DISCONNECTED", message: "Provider exited" } })];
|
||||
expect(assertCopilotProviderDeath({ ...state, bootstrap: { actionFile, events: state.events } })).toMatchObject({ expired: true });
|
||||
expect(() => assertCopilotProviderDeath(state)).toThrow(/operation/);
|
||||
expect(() => assertCopilotProviderDeath({ ...state, bootstrap: { actionFile: actionFile.replace("a", "b"), events: state.events } })).toThrow(/bootstrap read/);
|
||||
});
|
||||
it.each(["execute", "read", "edit"])("refuses an additional %s operation after provider death", operation => {
|
||||
const replay = facts();
|
||||
const extra = row(4, "provider.notice.recorded", { schema: "paperclip.provider.notice.v1", scope: "turn", category: "copilot_tool_evidence_v1", provenance: { sessionId: "native-session", turnId: "turn", eventType: "tool", method: "session/update" }, details: Object.entries({ stage: "tool", toolCallId: "extra-tool", operation, status: "completed" }).map(([name, value]) => ({ name, value })) });
|
||||
|
||||
@@ -3,6 +3,8 @@ import { COPILOT_LAUNCH_ARGUMENTS } from "../../packages/paperclip-runner/src/dr
|
||||
import { isValidNativePrpEnvelope } from "./native-event-envelope.js";
|
||||
import { copilotEditOriginForPermission, readCopilotToolEvidence } from "./copilot-evidence.js";
|
||||
import { readCopilotContextRead } from "./copilot-context-evidence.js";
|
||||
import { copilotActionNotices } from "./copilot-protection-evidence.js";
|
||||
import type { BootstrapReadProof } from "./native-bootstrap-read-proof.js";
|
||||
import type { ActiveStopPending } from "./copilot-active-stop-evidence.js";
|
||||
|
||||
/** Closed selector shared by local and remote observers. It accepts no caller PID.
|
||||
@@ -48,7 +50,7 @@ export function copilotDeathCommandDigest(argv: readonly string[]) {
|
||||
|
||||
/** A failed run alone is insufficient: the pending callback must expire and its
|
||||
* native operation must never complete or appear again after the stale answer. */
|
||||
export function assertCopilotProviderDeath(input: { pending: ActiveStopPending; run: Record<string, any>; issue: Record<string, any>; events: readonly any[] }) {
|
||||
export function assertCopilotProviderDeath(input: { pending: ActiveStopPending; run: Record<string, any>; issue: Record<string, any>; events: readonly any[]; bootstrap?: BootstrapReadProof }) {
|
||||
const { pending, run, issue } = input;
|
||||
if (run.id !== pending.scope.runId || run.companyId !== pending.scope.companyId || issue.id !== pending.scope.issueId || issue.status !== "blocked" || run.nativeIssueId !== pending.scope.issueId || run.runtimeMode !== "native" || run.status !== "failed") throw new Error("Provider death requires one failed unfinished run");
|
||||
const rows = input.events.filter(row => row.payload?.prpEvent);
|
||||
@@ -60,8 +62,8 @@ export function assertCopilotProviderDeath(input: { pending: ActiveStopPending;
|
||||
const target = copilotEditOriginForPermission(allNotices, pending.scope.target, pending.toolCallId);
|
||||
if (pending.scope.requireContextRead && !target) throw new Error("Provider death lacks the exact mutation origin");
|
||||
const context = target ? readCopilotContextRead(input.events, target, pending.scope.requireContextRead) : undefined;
|
||||
const notices = context ? allNotices.filter(n => ![context.toolCallId, ...context.discoveries.map(d => d.toolCallId)].includes(n.toolCallId)) : allNotices;
|
||||
if (notices.filter(n => n.stage === "permission_requested").length !== 1 || notices.some(n => n.stage === "permission_delivered" && ["allow_once", "allow_always"].includes(n.outcome ?? "")) || notices.some(n => n.stage === "tool" && (n.toolCallId !== pending.toolCallId || n.operation !== "edit" || n.status === "completed"))) throw new Error("Provider death replayed or completed an operation");
|
||||
const notices = target ? copilotActionNotices(allNotices, target, input.bootstrap, context ? input.events : undefined) : allNotices;
|
||||
if (notices.filter(n => n.stage === "permission_requested").length !== 1 || notices.some(n => n.stage === "permission_delivered" && ["allow_once", "allow_always"].includes(n.outcome ?? "")) || notices.some(n => n.stage === "tool" && (n.toolCallId !== pending.toolCallId || (n.operation !== undefined && n.operation !== "edit") || n.status === "completed"))) throw new Error("Provider death replayed or completed an operation");
|
||||
const expirySeq = rows.find(row => row.payload.prpEvent === expiry[0])!.seq;
|
||||
if (allNotices.some(n => n.stage === "tool" && n.seq >= expirySeq && !(n.toolCallId === pending.toolCallId && n.operation === "edit" && n.status === "failed"))) throw new Error("Provider death executed an operation after callback expiry");
|
||||
if (!events.some(event => ["turn.failed", "turn.interrupted"].includes(event.eventType) && event.turnId === pending.turnId)) throw new Error("Provider death lacks a failed provider turn");
|
||||
|
||||
Reference in new issue
Block a user