diff --git a/internal/engine/lost_cli_session_test.go b/internal/engine/lost_cli_session_test.go new file mode 100644 index 000000000..9411d7969 --- /dev/null +++ b/internal/engine/lost_cli_session_test.go @@ -0,0 +1,41 @@ +package engine + +import ( + "errors" + "testing" +) + +// TestLostCLISession covers the phrasings the CLIs print when the session a +// node wants to resume no longer exists on the execution machine. Every one of +// them must drop the stored session and restart the node, not park it on a +// human gate. +func TestLostCLISession(t *testing.T) { + lost := []string{ + "no conversation found", + "Session not found", + "no such session", + "conversation does not exist", + // Codex JSON-RPC reply after the sandbox recreated .agentflow. + "Error: thread/resume: thread/resume failed: no rollout found for thread id 01a1f321-9110-7af0-8a19-2b32b06025d4 (code -32600)", + "thread/resume failed", + "code -32600", + } + for _, msg := range lost { + if !lostCLISession(msg, nil) { + t.Errorf("lostCLISession(%q) = false, want true", msg) + } + if !lostCLISession("", errors.New(msg)) { + t.Errorf("lostCLISession(err=%q) = false, want true", msg) + } + } + for _, msg := range []string{ + "", + "unexpected status 503 Service Unavailable", + "exit status 1", + "REJECT: 独立评审未通过", + } { + if lostCLISession(msg, nil) { + t.Errorf("lostCLISession(%q) = true, want false", msg) + } + } +} diff --git a/internal/engine/node_execute.go b/internal/engine/node_execute.go index 0651e783e..a5d200288 100644 --- a/internal/engine/node_execute.go +++ b/internal/engine/node_execute.go @@ -1151,7 +1151,15 @@ func lostCLISession(output string, err error) bool { return strings.Contains(msg, "no conversation found") || strings.Contains(msg, "session not found") || strings.Contains(msg, "no such session") || - strings.Contains(msg, "conversation does not exist") + strings.Contains(msg, "conversation does not exist") || + // Codex answers `exec resume ` with a JSON-RPC error when the + // thread's rollout file is gone, which happens when the sandbox is + // recreated or re-prepared and .agentflow is reset. The session is + // equally unrecoverable, so the node must restart instead of parking + // on a human gate. + strings.Contains(msg, "no rollout found") || + strings.Contains(msg, "thread/resume failed") || + strings.Contains(msg, "code -32600") } func clipHumanGateDetail(detail string) string {