@@ -503,6 +503,26 @@ test("task --resume-last resumes the latest persisted task thread", () => {
503503 assert . equal ( result . stdout , "Resumed the prior run.\nFollow-up prompt accepted.\n" ) ;
504504} ) ;
505505
506+ test ( "task --resume-last ignores a stale current-session worker and resumes the prior completed thread" , ( ) => {
507+ const repo = makeTempDir ( ) ;
508+ const binDir = makeTempDir ( ) ;
509+ installFakeCodex ( binDir ) ;
510+ initGitRepo ( repo ) ;
511+ fs . writeFileSync ( path . join ( repo , "README.md" ) , "hello\n" ) ;
512+ run ( "git" , [ "add" , "README.md" ] , { cwd : repo } ) ;
513+ run ( "git" , [ "commit" , "-m" , "init" ] , { cwd : repo } ) ;
514+ const env = { ...buildEnv ( binDir ) , CODEX_COMPANION_SESSION_ID : "sess-current" } ;
515+ const first = run ( "node" , [ SCRIPT , "task" , "initial task" ] , { cwd : repo , env } ) ;
516+ assert . equal ( first . status , 0 , first . stderr ) ;
517+ const statePath = path . join ( resolveStateDir ( repo ) , "state.json" ) ;
518+ const state = JSON . parse ( fs . readFileSync ( statePath , "utf8" ) ) ;
519+ state . jobs . push ( { id : "task-stale" , status : "running" , title : "Codex Task" , jobClass : "task" , sessionId : "sess-current" , pid : 999999 , updatedAt : "2099-01-01T00:00:00.000Z" } ) ;
520+ fs . writeFileSync ( statePath , `${ JSON . stringify ( state , null , 2 ) } \n` , "utf8" ) ;
521+ const resumed = run ( "node" , [ SCRIPT , "task" , "--resume-last" , "follow up" ] , { cwd : repo , env } ) ;
522+ assert . equal ( resumed . status , 0 , resumed . stderr ) ;
523+ assert . equal ( resumed . stdout , "Resumed the prior run.\nFollow-up prompt accepted.\n" ) ;
524+ } ) ;
525+
506526test ( "task-resume-candidate returns the latest rescue thread from the current session" , ( ) => {
507527 const workspace = makeTempDir ( ) ;
508528 const stateDir = resolveStateDir ( workspace ) ;
@@ -2036,6 +2056,25 @@ test("stop hook logs running tasks to stderr without blocking when the review ga
20362056 assert . match ( blocked . stderr , / \/ c o d e x : c a n c e l t a s k - l i v e / i) ;
20372057} ) ;
20382058
2059+ test ( "stop hook ignores a stale current-session worker when the review gate is disabled" , ( ) => {
2060+ const repo = makeTempDir ( ) ;
2061+ initGitRepo ( repo ) ;
2062+ fs . writeFileSync ( path . join ( repo , "README.md" ) , "hello\n" ) ;
2063+ run ( "git" , [ "add" , "README.md" ] , { cwd : repo } ) ;
2064+ run ( "git" , [ "commit" , "-m" , "init" ] , { cwd : repo } ) ;
2065+ const stateDir = resolveStateDir ( repo ) ;
2066+ fs . mkdirSync ( path . join ( stateDir , "jobs" ) , { recursive : true } ) ;
2067+ fs . writeFileSync ( path . join ( stateDir , "state.json" ) , `${ JSON . stringify ( { version : 1 , config : { stopReviewGate : false } , jobs : [ { id : "task-stale" , status : "running" , title : "Codex Task" , jobClass : "task" , sessionId : "sess-current" , pid : 999999 , updatedAt : "2099-01-01T00:00:00.000Z" } ] } , null , 2 ) } \n` , "utf8" ) ;
2068+ const result = run ( "node" , [ STOP_HOOK ] , {
2069+ cwd : repo ,
2070+ env : { ...process . env , CODEX_COMPANION_SESSION_ID : "sess-current" } ,
2071+ input : JSON . stringify ( { cwd : repo } )
2072+ } ) ;
2073+ assert . equal ( result . status , 0 , result . stderr ) ;
2074+ assert . equal ( result . stdout . trim ( ) , "" ) ;
2075+ assert . doesNotMatch ( result . stderr , / t a s k - s t a l e i s s t i l l r u n n i n g / i) ;
2076+ } ) ;
2077+
20392078test ( "stop hook allows the stop when the review gate is enabled and the stop-time review task is clean" , ( ) => {
20402079 const repo = makeTempDir ( ) ;
20412080 const binDir = makeTempDir ( ) ;
0 commit comments