@@ -272,7 +272,43 @@ describe("CursorAdapterV2", () => {
272272 } ) ,
273273 failure : { class : "transport_error" , message : "Provider turn failed." } ,
274274 } ,
275- ] ) ( "fails the turn with $reason" , ( { updates = [ ] , wait, failure } ) =>
275+ {
276+ reason : "an error Cursor's run ended with after the turn ended" ,
277+ updates : [
278+ { type : "text-delta" , text : "The answer." } ,
279+ { type : "turn-ended" } ,
280+ ] satisfies ReadonlyArray < InteractionUpdate > ,
281+ wait : Effect . succeed ( {
282+ id : "native-cursor-run" ,
283+ requestId : "native-request" ,
284+ status : "error" as const ,
285+ error : { message : "Checkpoint persistence failed" } ,
286+ model : { id : "claude-fable-5" } ,
287+ durationMs : 1 ,
288+ } ) ,
289+ failure : { class : "provider_error" , message : "Checkpoint persistence failed" } ,
290+ } ,
291+ {
292+ reason : "no failure when Cursor's resume after the turn ended made no progress" ,
293+ // Cursor's SDK resumed from an older checkpoint after the answer was
294+ // delivered, regenerated the closing, then gave up on the run.
295+ updates : [
296+ { type : "text-delta" , text : "The answer." } ,
297+ { type : "turn-ended" } ,
298+ { type : "text-delta" , text : "A regenerated closing." } ,
299+ { type : "turn-ended" } ,
300+ ] satisfies ReadonlyArray < InteractionUpdate > ,
301+ wait : Effect . succeed ( {
302+ id : "native-cursor-run" ,
303+ requestId : "native-request" ,
304+ status : "error" as const ,
305+ error : { message : "Agent turn stopped after repeated resume attempts made no progress" } ,
306+ model : { id : "claude-fable-5" } ,
307+ durationMs : 1 ,
308+ } ) ,
309+ failure : null ,
310+ } ,
311+ ] ) ( "ends the turn with $reason" , ( { updates = [ ] , wait, failure } ) =>
276312 Effect . gen ( function * ( ) {
277313 const fileSystem = yield * FileSystem . FileSystem ;
278314 const workspace = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "cursor-v2-failure-" } ) ;
@@ -371,9 +407,9 @@ describe("CursorAdapterV2", () => {
371407 ) ;
372408 assert . isTrue ( Option . isSome ( terminal ) ) ;
373409 if ( Option . isSome ( terminal ) ) {
374- assert . equal ( terminal . value . status , "failed" ) ;
375- assert . equal ( terminal . value . failure ?. class , failure . class ) ;
376- assert . equal ( terminal . value . failure ?. message , failure . message ) ;
410+ assert . equal ( terminal . value . status , failure === null ? "completed" : "failed" ) ;
411+ assert . equal ( terminal . value . failure ?. class , failure ? .class ) ;
412+ assert . equal ( terminal . value . failure ?. message , failure ? .message ) ;
377413 }
378414 } ) . pipe (
379415 Effect . scoped ,
@@ -383,149 +419,6 @@ describe("CursorAdapterV2", () => {
383419 ) ,
384420 ) ;
385421
386- it . effect ( "keeps a delivered answer when the SDK's resume after turn-ended fails" , ( ) =>
387- Effect . gen ( function * ( ) {
388- const fileSystem = yield * FileSystem . FileSystem ;
389- const workspace = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "cursor-v2-resume-" } ) ;
390- const instanceId = ProviderInstanceId . make ( "cursor" ) ;
391- const threadId = ThreadId . make ( "cursor-resume-thread" ) ;
392- const modelSelection = { instanceId, model : "claude-opus-5-5" } ;
393- const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
394- runtimeMode : "full-access" ,
395- interactionMode : "default" ,
396- cwd : workspace ,
397- } ) ;
398- const usage = { inputTokens : 1 , outputTokens : 1 , cacheReadTokens : 0 , cacheWriteTokens : 0 } ;
399- // Cursor's SDK resumes from an older checkpoint after the turn ended,
400- // regenerates the closing twice, then gives up on the run.
401- const updates : ReadonlyArray < InteractionUpdate > = [
402- { type : "text-delta" , text : "The answer." } ,
403- { type : "turn-ended" , usage } ,
404- { type : "thinking-delta" , text : "Resuming." } ,
405- { type : "text-delta" , text : "A second closing." } ,
406- { type : "turn-ended" , usage } ,
407- { type : "text-delta" , text : "A third closing." } ,
408- { type : "turn-ended" , usage } ,
409- ] ;
410- const adapter = yield * makeCursorAdapterV2 ( {
411- instanceId,
412- settings : yield * decodeCursorSettings ( { } ) ,
413- environment : { HOME : workspace } ,
414- } ) . pipe (
415- Effect . provideService ( CursorAgentSdk . CursorAgentSdkRunner , {
416- assertComplete : Effect . void ,
417- open : ( ) =>
418- Effect . succeed ( {
419- agentId : "native-cursor-resume" ,
420- listMessages : Effect . succeed ( [ ] ) ,
421- close : Effect . void ,
422- send : ( input ) =>
423- Effect . gen ( function * ( ) {
424- for ( const update of updates ) {
425- yield * input . onDelta ! ( update ) . pipe ( Effect . orDie ) ;
426- }
427- return {
428- agentId : "native-cursor-resume" ,
429- runId : "native-cursor-run" ,
430- wait : Effect . succeed ( {
431- id : "native-cursor-run" ,
432- requestId : "native-request" ,
433- status : "error" as const ,
434- error : {
435- message :
436- "Agent turn stopped after repeated resume attempts made no progress" ,
437- } ,
438- model : { id : "claude-opus-5-5" } ,
439- durationMs : 1 ,
440- } ) ,
441- cancel : Effect . void ,
442- } ;
443- } ) ,
444- } ) ,
445- } ) ,
446- Effect . provide ( TestProviderHost . layer ( { cwd : workspace } ) ) ,
447- ) ;
448- const runtime = yield * adapter . openSession ( {
449- threadId,
450- providerSessionId : ProviderSessionId . make ( "cursor-resume-session" ) ,
451- modelSelection,
452- runtimePolicy,
453- } ) ;
454- const providerThread = yield * runtime . ensureThread ( {
455- threadId,
456- modelSelection,
457- runtimePolicy,
458- } ) ;
459- const now = yield * DateTime . now ;
460- yield * runtime . startTurn ( {
461- threadId,
462- providerThread,
463- modelSelection,
464- runtimePolicy,
465- runId : RunId . make ( "cursor-resume-run" ) ,
466- runOrdinal : 1 ,
467- providerTurnOrdinal : 1 ,
468- attemptId : RunAttemptId . make ( "cursor-resume-attempt" ) ,
469- rootNodeId : NodeId . make ( "cursor-resume-root" ) ,
470- appThread : {
471- id : threadId ,
472- projectId : ProjectId . make ( "cursor-resume-project" ) ,
473- createdBy : "user" ,
474- creationSource : "web" ,
475- title : "Cursor resume" ,
476- providerInstanceId : instanceId ,
477- modelSelection,
478- runtimeMode : "full-access" ,
479- interactionMode : "default" ,
480- branch : null ,
481- worktreePath : null ,
482- activeProviderThreadId : providerThread . id ,
483- lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
484- forkedFrom : null ,
485- createdAt : now ,
486- updatedAt : now ,
487- archivedAt : null ,
488- settledOverride : null ,
489- settledAt : null ,
490- lastVisitedAt : null ,
491- deletedAt : null ,
492- } ,
493- message : {
494- messageId : MessageId . make ( "cursor-resume-message" ) ,
495- createdBy : "user" ,
496- creationSource : "web" ,
497- text : "hi" ,
498- attachments : [ ] ,
499- } ,
500- } ) ;
501- const events = yield * runtime . events . pipe (
502- Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
503- Stream . runCollect ,
504- ) ;
505- const terminal = events . find ( ( event ) => event . type === "turn.terminal" ) ;
506- assert . equal ( terminal ?. status , "completed" ) ;
507- assert . isNull ( terminal ?. failure ) ;
508- const items = events . flatMap ( ( event ) =>
509- event . type === "turn_item.updated" ? [ event . turnItem ] : [ ] ,
510- ) ;
511- assert . deepEqual (
512- [
513- ...new Set (
514- items . flatMap ( ( item ) =>
515- item . type === "assistant_message" || item . type === "reasoning" ? [ item . text ] : [ ] ,
516- ) ,
517- ) ,
518- ] ,
519- [ "The answer." ] ,
520- ) ;
521- } ) . pipe (
522- Effect . scoped ,
523- Effect . provide (
524- Layer . mergeAll ( NodeServices . layer , IdAllocator . layer , McpProviderSessions . layer ) ,
525- ) ,
526- ) ,
527- ) ;
528-
529422 it . effect ( "fails standalone SDK transport diagnostics and sends compaction as /compress" , ( ) =>
530423 Effect . gen ( function * ( ) {
531424 const fileSystem = yield * FileSystem . FileSystem ;
0 commit comments