Skip to content

Commit 07110e2

Browse files
Refactor container state checking to fail fast
Co-authored-by: victorgelias <[email protected]>
1 parent 8c149d4 commit 07110e2

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

ai/worker/docker.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -785,18 +785,12 @@ tickerLoop:
785785
break tickerLoop
786786
}
787787

788-
// Detect terminal/non-recoverable states early and fail fast instead of
789-
// waiting for the full timeout. This covers cases where the container
790-
// was stopped or killed immediately after startup (e.g., by another
791-
// orchestrator cleaning up), leaving it in a non-running state that
792-
// will never transition to running.
788+
// Fail fast on states that won't become running after startup.
793789
if json.State != nil {
794790
status := strings.ToLower(json.State.Status)
795-
// Docker statuses can be: "created", "restarting", "running",
796-
// "removing", "paused", "exited", or "dead".
797-
// Treat exited/dead/removing as terminal. If not running and not
798-
// restarting, and we have a non-zero exit code or an error, also fail.
799-
if status == "exited" || status == "dead" || status == "removing" {
791+
// Consider exited/dead as terminal. "removing" will surface via
792+
// inspect error or transition to exited/dead shortly.
793+
if status == "exited" || status == "dead" {
800794
return fmt.Errorf("container entered terminal state before running: %s (exitCode=%d)", json.State.Status, json.State.ExitCode)
801795
}
802796
if !json.State.Restarting && json.State.ExitCode != 0 {

0 commit comments

Comments
 (0)