mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
fix(cursor): preserve Stop precedence and explicit denied-task recovery
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
c45cf9f418
commit
c48d0fba50
6 files changed
+27
-11
No files matched your search
@@ -250,7 +250,7 @@ full single-path shape update before execution progress. Every attested notice
|
||||
retains that same digest; late, changed, multi-path, and unsafe input stays
|
||||
unproven. This changes passive evidence, not provider permissions or file access.
|
||||
Committed Cursor permission declines followed by a completed turn without a
|
||||
semantic result now fail the run once, keep the task open, and assign recovery to
|
||||
semantic result now fail the run once, block the unfinished task, and assign recovery to
|
||||
the operator with no automatic wake. Other missing-result recovery remains intact.
|
||||
The decision proof binds company, agent, run, turn, normalized session, source,
|
||||
request, and strict event order. It does not assert response delivery or absence
|
||||
@@ -260,3 +260,15 @@ Focused verification passed: 534 controller tests, 43 Cursor runtime tests, and
|
||||
43 fixture evidence tests, plus affected typechecks. The provider CLI pin,
|
||||
native patch, and command/profile digest remain unchanged; the candidate source
|
||||
and Node pack identities must be rebuilt before repeating affected qualification.
|
||||
|
||||
The first local repeat at `c45cf9` confirmed the named permission-declined failure
|
||||
without another provider attempt. It remains failed because the fixture expected
|
||||
In Progress while canonical failure recovery projected Blocked. The release
|
||||
contract now requires Blocked for the new explicit permission-declined failure;
|
||||
historical generic missing-result evidence retains its prior status contract.
|
||||
Exact delivery, a single terminal, absent effects and process retirement remain
|
||||
mandatory. A reproduced Stop-precedence race is also repaired: acknowledged
|
||||
operator and reassignment cancellation wins over the new typed decline error.
|
||||
The frozen v11 runtime packs and image remain at `c45cf9`; these follow-up changes
|
||||
touch the controller and harness only, and their distinct source identity is
|
||||
recorded with subsequent results.
|
||||
@@ -7375,21 +7375,25 @@ describe("native warm session supervision", () => {
|
||||
});
|
||||
|
||||
describe("native session bounded recovery", () => {
|
||||
it("leaves a denied Cursor task open and gives recovery to the operator without another provider attempt", async () => {
|
||||
it("blocks a denied Cursor task and gives recovery to the operator without another provider attempt", async () => {
|
||||
const updates: Array<{ table: unknown; values: Record<string, unknown> }> = [];
|
||||
const failure = new NativeCursorPermissionDeclinedError();
|
||||
state.execute.mockReset().mockRejectedValueOnce(failure);
|
||||
state.upsertRecoveryAction.mockReset().mockResolvedValue({});
|
||||
const updateIssue = vi.fn(async () => ({ status: "blocked", statusVersion: 7 }));
|
||||
const service = vi.spyOn(issueServiceModule, "issueService").mockReturnValue({ update: updateIssue } as unknown as ReturnType<typeof issueServiceModule.issueService>);
|
||||
try {
|
||||
await expect(executePaperclipNativeSession({ db: leaseDb(execution, {}, {}, updates), execution, runnerInstanceId: "runner" })).rejects.toBe(failure);
|
||||
expect(updates.find(update => update.table === nativeRunFinalizations && update.values.phase === "terminal_failure")?.values).toMatchObject({
|
||||
failureCode: "native_permission_declined", nextAttemptAt: null,
|
||||
failureDetail: { recoverable: false, nextAction: expect.stringContaining("Automatic recovery is stopped") },
|
||||
});
|
||||
expect(updates.some(update => update.table === issues && update.values.status === "blocked")).toBe(false);
|
||||
expect(updateIssue).toHaveBeenCalledWith(execution.binding.issueId, { status: "blocked" }, expect.anything());
|
||||
expect(state.upsertRecoveryAction).toHaveBeenCalledWith(expect.objectContaining({ cause: "native_permission_declined", ownerType: "board", wakePolicy: null }));
|
||||
expect(state.execute).toHaveBeenCalledTimes(1);
|
||||
} finally { service.mockRestore(); }
|
||||
});
|
||||
it.each(["operator", "reassignment"])("does not turn an acknowledged %s Stop before completion into a failure or a retry", async (source) => {
|
||||
it.each([["operator", "missing-result"], ["reassignment", "missing-result"], ["operator", "permission-declined"], ["reassignment", "permission-declined"]])("does not turn an acknowledged %s Stop before %s completion into a failure or a retry", async (source, failureKind) => {
|
||||
const updates: Array<{ table: unknown; values: Record<string, unknown> }> = [];
|
||||
const stop: Record<string, unknown> = {};
|
||||
state.execute.mockReset().mockImplementationOnce(async () => {
|
||||
@@ -7399,7 +7403,7 @@ describe("native session bounded recovery", () => {
|
||||
schema: "paperclip.native-cancellation.v1", ...execution.binding, scope: "run", reasonCode: "cancellation_run_only",
|
||||
dispatched: true, dispatchState: "acknowledged", intentAuditId: "intent", acknowledgementAuditId: "ack",
|
||||
} });
|
||||
throw new Error("native_finalization_missing: session returned no semantic result");
|
||||
throw failureKind === "permission-declined" ? new NativeCursorPermissionDeclinedError() : new Error("native_finalization_missing: session returned no semantic result");
|
||||
});
|
||||
state.upsertRecoveryAction.mockClear();
|
||||
await expect(executePaperclipNativeSession({
|
||||
|
||||
@@ -6074,7 +6074,6 @@ export function nativeSessionRecoveryProjection(input: {
|
||||
exhausted,
|
||||
issueStatus:
|
||||
exhausted &&
|
||||
input.failureCode !== "native_permission_declined" &&
|
||||
input.failureCode !== NATIVE_ADOPTED_RUNNER_AUTHENTICATION_TIMEOUT
|
||||
? ("blocked" as const)
|
||||
: null,
|
||||
@@ -8742,7 +8741,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
// another turn to perform completion bookkeeping.
|
||||
const stoppedBeforeFirstTurn = error instanceof Error && error.message === "native_session_cancelled";
|
||||
if (protocolIntegrityFailure === null && error instanceof Error &&
|
||||
(stoppedBeforeFirstTurn || error.message === "native_finalization_missing: session returned no semantic result")) {
|
||||
(stoppedBeforeFirstTurn || error instanceof NativeCursorPermissionDeclinedError || error.message === "native_finalization_missing: session returned no semantic result")) {
|
||||
const [stoppedRun] = await input.db.select().from(heartbeatRuns).where(and(
|
||||
eq(heartbeatRuns.id, input.execution.binding.runId),
|
||||
eq(heartbeatRuns.companyId, input.execution.binding.companyId),
|
||||
|
||||
@@ -126,7 +126,7 @@ it("requires a correlated failed semantic finalization after the delivered denia
|
||||
const input = { runId: "run", turnId: "turn", requestId: "request", issue: { id: "issue", status: "in_progress" },
|
||||
run: { id: "run", nativeIssueId: "issue", runtimeMode: "native", status: "failed", errorCode: "native_session_interrupted", error: "native_finalization_missing: session returned no semantic result" }, events: [evidence, terminal] };
|
||||
expect(hasCursorDeniedTurnTerminal(input)).toBe(true);
|
||||
const declined = { ...input, run: { ...input.run, errorCode: "native_permission_declined", error: "native_finalization_missing: session returned no semantic result; Cursor permission was declined; explicit direction is required" } };
|
||||
const declined = { ...input, issue: { ...input.issue, status: "blocked" }, run: { ...input.run, errorCode: "native_permission_declined", error: "native_finalization_missing: session returned no semantic result; Cursor permission was declined; explicit direction is required" } };
|
||||
expect(hasCursorDeniedTurnTerminal(declined)).toBe(true);
|
||||
expect(hasCursorDeniedTurnTerminal({ ...declined, events: [terminal] })).toBe(false);
|
||||
for (const status of ["succeeded", "cancelled", "timed_out", "running"]) expect(hasCursorDeniedTurnTerminal({ ...input, run: { ...input.run, status } })).toBe(false);
|
||||
|
||||
@@ -76,7 +76,7 @@ export function hasCursorDeniedTurnTerminal(input: {
|
||||
const missingResult = run.errorCode === "native_session_interrupted" && run.error === "native_finalization_missing: session returned no semantic result";
|
||||
const declined = run.errorCode === "native_permission_declined" && run.error === "native_finalization_missing: session returned no semantic result; Cursor permission was declined; explicit direction is required";
|
||||
if (!id(input.runId) || !id(input.turnId) || !id(input.requestId) || run.id !== input.runId || run.nativeIssueId !== issue.id
|
||||
|| run.status !== "failed" || run.runtimeMode !== "native" || issue.status !== "in_progress"
|
||||
|| run.status !== "failed" || run.runtimeMode !== "native" || issue.status !== (declined ? "blocked" : "in_progress")
|
||||
|| (!missingResult && !declined)) return false;
|
||||
const terminals = input.events.map(rec).map(row => ({ row, event: rec(rec(row.payload).prpEvent) }))
|
||||
.filter(({ event }) => ["turn.completed", "turn.failed", "turn.cancelled", "turn.interrupted"].includes(event.eventType));
|
||||
|
||||
@@ -343,7 +343,8 @@ export async function runCursorNativeFlow(input: {
|
||||
check("browser-exact-denial", posted.turnId === event.turnId && posted.requestKind === "permission_approval" && posted.resolution?.action === "decline", "Browser denied the exact native run/request/turn");
|
||||
const identity = { runId: native.runId, turnId: event.turnId, requestId: request.requestId, method: "session/request_permission" as const, action: "decline" as const };
|
||||
const rejectDenial = (state: Awaited<ReturnType<typeof load>>) => state.runs.length !== 1
|
||||
|| ["succeeded", "cancelled", "timed_out"].includes(state.runs[0]?.status) || state.issue.status !== "in_progress"
|
||||
|| ["succeeded", "cancelled", "timed_out"].includes(state.runs[0]?.status)
|
||||
|| (state.issue.status !== "in_progress" && !(state.issue.status === "blocked" && state.runs[0]?.status === "failed" && state.runs[0]?.errorCode === "native_permission_declined"))
|
||||
? "Denied Cursor operation claimed success, changed task disposition, or created another run" : undefined;
|
||||
await pollUntil({ label: "exact native denial delivery and settled call", deadlineAt: input.deadlineAt, load, reject: rejectDenial,
|
||||
accept: state => hasDeliveredCursorNativeRequest({ ...identity, events: state.runEvents })
|
||||
@@ -356,7 +357,7 @@ export async function runCursorNativeFlow(input: {
|
||||
await sampleDenied("after-terminal", remoteFinal ?? undefined);
|
||||
check("negative-task-unfinished", hasCursorDeniedTurnTerminal({ run: terminal.runs[0], issue: terminal.issue, events: terminal.runEvents, ...identity }), "Denied native turn supplied no semantic completion; its failed run does not falsely complete the task");
|
||||
await page.reload();
|
||||
await expect(page.getByTestId("issue-detail-header").getByRole("button", { name: "Change status (current: In Progress)", exact: true })).toBeVisible();
|
||||
await expect(page.getByTestId("issue-detail-header").getByRole("button", { name: `Change status (current: ${terminal.issue.status === "blocked" ? "Blocked" : "In Progress"})`, exact: true })).toBeVisible();
|
||||
const comments = await api.get<Row[]>(`/api/issues/${issue.id}/comments`);
|
||||
await input.evidence("api-state.json", { ...terminal, run: runs[0], comments, checks, notices: denialNotices, commandSha256: deniedCommand!.commandSha256, denialTerminalProven, runEventsByRun: [{ runId: native.runId, events: terminal.runEvents }] });
|
||||
await input.capture("final-state", "Cursor denied command ended without completing the task", "final-state.png");
|
||||
|
||||
Reference in new issue
Block a user