Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/adapters/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export function createCursorAdapter(provider: OcxProviderConfig, deps: CursorAda
coveredMessageCount,
prefixDigest: cursorCoveredPrefixDigest(_parsed, coveredMessageCount),
systemDigest: cursorInstructionDigest(_parsed),
toolSuspended: toolSuspendedCommit,
});
if (!checkpointRef) return;
if (previousRef && previousRef !== checkpointRef) invalidateCursorCheckpoint(previousRef);
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/cursor/checkpoint-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface CursorCheckpointSnapshot {
coveredMessageCount?: number;
prefixDigest?: string;
systemDigest?: string;
toolSuspended?: boolean;
}

interface CursorCheckpointStore {
Expand Down Expand Up @@ -187,6 +188,7 @@ export function commitCursorCheckpoint(input: {
coveredMessageCount?: number;
prefixDigest?: string;
systemDigest?: string;
toolSuspended?: boolean;
}): string | undefined {
if (!input.conversationId || !input.modelId || input.checkpointBytes.byteLength === 0) return undefined;
if (input.checkpointBytes.byteLength > CURSOR_CHECKPOINT_MAX_TOTAL_BYTES) return undefined;
Expand Down Expand Up @@ -216,6 +218,7 @@ export function commitCursorCheckpoint(input: {
...(input.coveredMessageCount !== undefined ? { coveredMessageCount: input.coveredMessageCount } : {}),
...(input.prefixDigest ? { prefixDigest: input.prefixDigest } : {}),
...(input.systemDigest ? { systemDigest: input.systemDigest } : {}),
...(input.toolSuspended ? { toolSuspended: true } : {}),
};
const blobIds = collectCheckpointBlobIds(input.checkpointBytes);
if (blobIds === undefined) return undefined;
Expand Down
5 changes: 4 additions & 1 deletion src/adapters/cursor/request-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ function resolveCursorCheckpoint(
if (cursorCheckpointModelAffinityId(snapshot.modelId) !== cursorCheckpointModelAffinityId(request.modelId)) {
return { reason: "model_changed" };
}
if (parsed.context.messages.at(-1)?.role !== "toolResult" && cursorState?.checkpointUsable === false) {
if (
parsed.context.messages.at(-1)?.role !== "toolResult"
&& (snapshot.toolSuspended === true || cursorState?.checkpointUsable === false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retire rejected suspended snapshots after full replay

When provider-continuation metadata is absent and the same ordinary request is retried, this guard rejects the prefix-selected suspended snapshot but discards its ref. The adapter then completes a full replay and commits another snapshot for the identical prefix, while inheritedCheckpointRef remains undefined, so the rejected snapshot is never invalidated; getCursorCheckpointForPrefix subsequently sees multiple matching refs and returns undefined. Every later ref-less continuation from that prefix therefore falls back to full replay until the stale snapshot expires. Preserve the selected ref and invalidate it after a successful replay, or supersede matching lineage when committing the replacement snapshot.

AGENTS.md reference: src/AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

) {
return { reason: "trailing_tool_result" };
}
const lineage = lineageMismatch(parsed, snapshot);
Expand Down
18 changes: 17 additions & 1 deletion tests/cursor-tool-suspended-checkpoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from "bun:test";
import { createCursorAdapter as createCursorAdapterProduction } from "../src/adapters/cursor";
import { clearCursorCheckpointsForTests, getCursorCheckpoint } from "../src/adapters/cursor/checkpoint-store";
import { createCursorRequest } from "../src/adapters/cursor/request-builder";
import { create, toBinary } from "@bufbuild/protobuf";
import { ConversationStateStructureSchema } from "../src/adapters/cursor/gen/agent_pb";
import type { AdapterEvent, OcxParsedRequest, OcxProviderConfig } from "../src/types";
Expand Down Expand Up @@ -55,7 +56,22 @@ describe("tool-suspended checkpoint commit (devlog 260826 050)", () => {
if (done?.type !== "done") throw new Error("expected done");
expect(done.providerState?.cursor?.checkpointRef).toBeDefined();
expect(done.providerState?.cursor?.checkpointUsable).toBe(false);
expect(getCursorCheckpoint(done.providerState?.cursor?.checkpointRef)).toBeDefined();
expect(getCursorCheckpoint(done.providerState?.cursor?.checkpointRef)?.toolSuspended).toBe(true);

const retry = createCursorRequest(body("cursor/grok-4.6"));
expect(retry.continuationMode).toBe("full-replay");
expect(retry.checkpointInvalidationReason).toBe("trailing_tool_result");

const continuation = body("cursor/grok-4.6");
continuation.context.messages.push({
role: "toolResult",
toolCallId: "call_x",
content: "sunny",
timestamp: 2,
});
const resumed = createCursorRequest(continuation);
expect(resumed.continuationMode).toBe("checkpoint");
expect(resumed.checkpointBytes).toEqual(checkpointBytes);
clearCursorCheckpointsForTests();
});

Expand Down
Loading