@@ -1089,8 +1089,8 @@ func TestProcessModel_ContextCancelledDuringDispatch(t *testing.T) {
10891089
10901090// TestProcessModel_SIGTERMCancelsAllDispatched verifies that when SIGTERM arrives after all
10911091// requests have been dispatched as goroutines, processModel returns errShutdown so the job
1092- // is re-enqueued . This covers the case where undispatched is empty but in-flight requests
1093- // were cancelled by context propagation.
1092+ // is left for the orphan reconciler . This covers the case where undispatched is empty but
1093+ // in-flight requests were cancelled by context propagation.
10941094func TestProcessModel_SIGTERMCancelsAllDispatched (t * testing.T ) {
10951095 cfg := config .NewConfig ()
10961096 cfg .WorkDir = t .TempDir ()
@@ -1142,8 +1142,8 @@ func TestProcessModel_SIGTERMCancelsAllDispatched(t *testing.T) {
11421142//
11431143// P1c regression: Before the fix, the drain-switch default checked ctx.Err() (which is
11441144// requestAbortCtx), so a sibling abort looked like a pod shutdown and returned errShutdown.
1145- // executeJob would then route the job to re-enqueue instead of failed-with-partial, breaking
1146- // retry safety for batches with partial results. After the fix, the default checks mainCtx
1145+ // executeJob would then route the job to the errShutdown path instead of failed-with-partial,
1146+ // breaking retry safety for batches with partial results. After the fix, the default checks mainCtx
11471147// (the main processor context), which is only cancelled on SIGTERM.
11481148func TestProcessModel_SiblingAbort_ReturnsNil (t * testing.T ) {
11491149 cfg := config .NewConfig ()
@@ -1422,7 +1422,7 @@ func TestExecuteJob_CancelAfterAllRequestsComplete(t *testing.T) {
14221422// TestExecuteJob_SIGTERMAfterAllComplete verifies that when all requests finish successfully
14231423// and SIGTERM arrives before executeJob returns, the function returns nil (not errShutdown).
14241424// This ensures the caller proceeds to finalizeJob (which uses a detached context) rather than
1425- // re-enqueueing a fully-complete job.
1425+ // taking the errShutdown path (which leaves the job for the orphan reconciler) .
14261426func TestExecuteJob_SIGTERMAfterAllComplete (t * testing.T ) {
14271427 cfg := config .NewConfig ()
14281428 cfg .WorkDir = t .TempDir ()
@@ -2105,7 +2105,7 @@ func TestHandleJobError_errCancelled(t *testing.T) {
21052105 }
21062106}
21072107
2108- func TestHandleJobError_Shutdown_ReEnqueues (t * testing.T ) {
2108+ func TestHandleJobError_Shutdown_LeavesJobForReconciler (t * testing.T ) {
21092109 cfg := config .NewConfig ()
21102110 cfg .WorkDir = t .TempDir ()
21112111
@@ -2118,8 +2118,6 @@ func TestHandleJobError_Shutdown_ReEnqueues(t *testing.T) {
21182118 BatchJob : & openai.Batch {BatchSpec : openai.BatchSpec {CreatedAt : time .Now ().Add (- 10 * time .Second ).Unix ()}},
21192119 }
21202120
2121- beforeFailed := gatherHistogramSampleCount (t , "batch_job_e2e_latency_seconds" , map [string ]string {"status" : "failed" })
2122-
21232121 ctx := testLoggerCtx (t )
21242122 env .p .handleJobError (ctx , & jobExecutionParams {
21252123 updater : env .updater ,
@@ -2128,17 +2126,26 @@ func TestHandleJobError_Shutdown_ReEnqueues(t *testing.T) {
21282126 jobInfo : ji ,
21292127 }, errShutdown )
21302128
2131- afterFailed := gatherHistogramSampleCount (t , "batch_job_e2e_latency_seconds" , map [string ]string {"status" : "failed" })
2132- if delta := afterFailed - beforeFailed ; delta != 0 {
2133- t .Fatalf ("E2E latency failed: delta=%d, want 0 (re-enqueue succeeded, not terminal)" , delta )
2134- }
2135-
2129+ // Job must NOT be re-enqueued — reconciler handles recovery.
21362130 tasks , err := env .pqClient .PQDequeue (ctx , 0 , 10 )
21372131 if err != nil {
21382132 t .Fatalf ("PQDequeue: %v" , err )
21392133 }
2140- if len (tasks ) == 0 {
2141- t .Fatalf ("expected re-enqueued task, got none" )
2134+ if len (tasks ) != 0 {
2135+ t .Fatalf ("expected no re-enqueued tasks, got %d" , len (tasks ))
2136+ }
2137+
2138+ // Job status must remain in_progress (not transitioned by the processor).
2139+ items , _ , _ , err := env .dbClient .DBGet (ctx , & db.BatchQuery {BaseQuery : db.BaseQuery {IDs : []string {"job-ctx" }}}, true , 0 , 1 )
2140+ if err != nil || len (items ) != 1 {
2141+ t .Fatalf ("DBGet: err=%v len=%d" , err , len (items ))
2142+ }
2143+ var got openai.BatchStatusInfo
2144+ if err := json .Unmarshal (items [0 ].Status , & got ); err != nil {
2145+ t .Fatalf ("unmarshal status: %v" , err )
2146+ }
2147+ if got .Status != openai .BatchStatusInProgress {
2148+ t .Fatalf ("status = %s, want %s (unchanged, left for reconciler)" , got .Status , openai .BatchStatusInProgress )
21422149 }
21432150}
21442151
0 commit comments