From 87560e9a6d5977f5f4abdda4c3e92d89c8dcae16 Mon Sep 17 00:00:00 2001 From: jieli Date: Fri, 20 Nov 2026 13:58:20 +0800 Subject: [PATCH] fix(engine): treat Codex no-rollout resume errors as lost CLI sessions When a node is retried after its sandbox was recreated, .agentflow is re-prepared and the Codex thread's rollout file is gone. The runtime still passes the stored session id and Codex answers thread/resume: thread/resume failed: no rollout found for thread id ... (code -32600) lostCLISession() did not recognise that phrasing, so dropLostCLISession() never fired and the node was parked on a human gate even though its code had already been committed and pushed. Match the Codex phrasings so the node restarts in a fresh session instead. --- internal/engine/lost_cli_session_test.go | 41 ++++++++++++++++++++++++ internal/engine/node_execute.go | 10 +++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 internal/engine/lost_cli_session_test.go 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 {