Skip to content

Commit dfe5d27

Browse files
committed
chore(session): add debug traces and tidy retry path
- Trace retry trigger under OPENCODE_CURSOR_DEBUG - Log original resume failure when it cannot ride along as cause - Document that retry fires on any error class (Cursor's status:"error" carries no machine-readable class); bounded to one attempt - Drop unused resetSessionPoolMemory import in tests
1 parent 80e9f9e commit dfe5d27

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎src/provider/language-model.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,21 @@ export class CursorLanguageModel implements LanguageModelV3 {
237237
// replay the full transcript — self-healing, no context loss. The
238238
// fresh agent re-pools under the same session (overwriting the dead
239239
// agentId) via acquireAgent's existing pooling path.
240+
//
241+
// Deliberate tradeoff: the retry fires on ANY error class (including
242+
// rate-limit or network failures) because Cursor's status:"error"
243+
// carries no machine-readable class to discriminate on. Bounded to a
244+
// single attempt, so the worst case is one extra create.
240245
if (
241246
acquired.resumed &&
242247
!yielded &&
243248
!options.abortSignal?.aborted
244249
) {
250+
if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
251+
console.error(
252+
"[cursor:debug] resumed turn failed before emitting; retrying with a fresh agent",
253+
);
254+
}
245255
acquired.release();
246256
releasedOriginal = true;
247257
// A fresh create (no resumeAgentId) re-pools under the same
@@ -254,6 +264,14 @@ export class CursorLanguageModel implements LanguageModelV3 {
254264
} catch (retryErr) {
255265
if (retryErr instanceof Error && retryErr.cause === undefined) {
256266
retryErr.cause = err;
267+
} else if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
268+
// Non-Error throw or pre-existing cause: the original resume
269+
// failure can't ride along as `cause`, so log it instead of
270+
// dropping it silently.
271+
console.error(
272+
"[cursor:debug] original resume failure (not attachable as cause):",
273+
err,
274+
);
257275
}
258276
throw retryErr;
259277
}

‎test/language-model.test.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ vi.mock("../src/api-key.js", () => ({
2222
const { CursorLanguageModel } = await import(
2323
"../src/provider/language-model.js"
2424
);
25-
const {
26-
clearAgentPool,
27-
getPooledAgentId,
28-
resetSessionPoolMemory,
29-
} = await import("../src/provider/session-pool.js");
25+
const { clearAgentPool, getPooledAgentId } = await import(
26+
"../src/provider/session-pool.js"
27+
);
3028

3129
type OnDelta = (input: {
3230
update: Record<string, unknown> & { type: string };

0 commit comments

Comments
 (0)