@@ -510,6 +510,35 @@ describe("Anthropic Agent SDK runtime ownership", () => {
510510 expect ( sdkOptions ( ) ) . not . toHaveProperty ( "sessionId" ) ;
511511 } ) ;
512512
513+ it ( "preserves cache, effort, and checkpoint-fork controls through SDK options" , async ( ) => {
514+ useSdkMessages ( ) ;
515+
516+ await collect (
517+ createContext ( {
518+ args : [
519+ "-p" ,
520+ "--cache-system-prompt" ,
521+ "--effort" ,
522+ "max" ,
523+ "--fork-session" ,
524+ "--resume-session-at" ,
525+ "assistant-before-stall" ,
526+ ] ,
527+ useResume : true ,
528+ } ) ,
529+ ) ;
530+
531+ expect ( sdkOptions ( ) ) . toEqual (
532+ expect . objectContaining ( {
533+ resume : SESSION_ID ,
534+ effort : "max" ,
535+ forkSession : true ,
536+ resumeSessionAt : "assistant-before-stall" ,
537+ extraArgs : { "cache-system-prompt" : null } ,
538+ } ) ,
539+ ) ;
540+ } ) ;
541+
513542 it ( "reuses one official SDK query and Claude process across compatible agent turns" , async ( ) => {
514543 const live = useLiveSdkStreams ( ) ;
515544 const capability = createLiveCapability ( ) ;
@@ -544,6 +573,39 @@ describe("Anthropic Agent SDK runtime ownership", () => {
544573 ] ) ;
545574 } ) ;
546575
576+ it ( "keeps a terminal error turn's warm query reusable for the next turn" , async ( ) => {
577+ const live = useLiveSdkStreams ( ) ;
578+ const capability = createLiveCapability ( ) ;
579+ const first = collect ( createContext ( { prompt : "Attempt the task." , liveSession : capability } ) ) ;
580+ await vi . waitFor ( ( ) => expect ( queryMock ) . toHaveBeenCalledOnce ( ) ) ;
581+ live . streams [ 0 ] ?. write ( {
582+ ...SUCCESS_RESULT ,
583+ subtype : "error_during_execution" ,
584+ is_error : true ,
585+ result : "The native tool failed." ,
586+ } ) ;
587+
588+ await expect ( first ) . resolves . toContainEqual (
589+ expect . objectContaining ( { is_error : true , result : "The native tool failed." } ) ,
590+ ) ;
591+ const firstHandle = capability . current ( ) ;
592+ expect ( firstHandle ?. isIdle ( ) ) . toBe ( true ) ;
593+
594+ const second = collect (
595+ createContext ( {
596+ prompt : "Continue without repeating the failed action." ,
597+ useResume : true ,
598+ liveSession : capability ,
599+ } ) ,
600+ ) ;
601+ await vi . waitFor ( ( ) => expect ( live . prompts [ 0 ] ) . toHaveLength ( 2 ) ) ;
602+ live . streams [ 0 ] ?. write ( { ...SUCCESS_RESULT , result : "continued" } ) ;
603+
604+ await expect ( second ) . resolves . toContainEqual ( expect . objectContaining ( { result : "continued" } ) ) ;
605+ expect ( queryMock ) . toHaveBeenCalledOnce ( ) ;
606+ expect ( capability . current ( ) ) . toBe ( firstHandle ) ;
607+ } ) ;
608+
547609 it ( "restarts the warm SDK query when its system prompt or execution fingerprint changes" , async ( ) => {
548610 const live = useLiveSdkStreams ( ) ;
549611 const shared : { current ?: CliBackendLiveSessionHandle } = { } ;
@@ -621,6 +683,21 @@ describe("Anthropic Agent SDK runtime ownership", () => {
621683 } ,
622684 ) ,
623685 ) . resolves . toEqual ( { behavior : "deny" , message : "The OpenClaw run is no longer active." } ) ;
686+
687+ const resumed = collect (
688+ createContext ( {
689+ prompt : "Resume after the interrupted turn." ,
690+ useResume : true ,
691+ liveSession : capability ,
692+ } ) ,
693+ ) ;
694+ await vi . waitFor ( ( ) => expect ( queryMock ) . toHaveBeenCalledTimes ( 2 ) ) ;
695+ live . streams [ 1 ] ?. write ( { ...SUCCESS_RESULT , result : "resumed" } ) ;
696+
697+ await expect ( resumed ) . resolves . toContainEqual ( expect . objectContaining ( { result : "resumed" } ) ) ;
698+ expect ( queryMock . mock . calls [ 1 ] ?. [ 0 ] ?. options ) . toEqual (
699+ expect . objectContaining ( { resume : SESSION_ID } ) ,
700+ ) ;
624701 } ) ;
625702
626703 it ( "rebinds a persistent SDK approval callback to only the active admitted turn" , async ( ) => {
0 commit comments