Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agents): stop resuming a session that can't resolve its provider auth (MUL-5803) (#6482)

qiushihao279-cloud5a618e09255c
diff --git a/server/cmd/server/rerun_session_test.go b/server/cmd/server/rerun_session_test.go
index 47974d072f..7af6642910 100644
--- a/server/cmd/server/rerun_session_test.go
+++ b/server/cmd/server/rerun_session_test.go
@@ -246,6 +246,76 @@ func TestGetLastTaskSessionKeepsToolEmptinessError(t *testing.T) {
}
}
+// TestGetLastTaskSessionExcludesAuthResolutionFailure is the SQL half of the
+// auth-resolution resume fix: a provider that cannot resolve its own
+// authentication method (no api_key / auth_token / header) fails deterministically
+// on resume, so the (agent_id, issue_id) lookup must not hand the same dead
+// session to the next task. The row carries agent_error.unknown — what every
+// daemon version writes for this text — so only the ILIKE guard drops it, which
+// is what un-wedges an issue stuck before the fix deployed without a daemon
+// upgrade.
+func TestGetLastTaskSessionExcludesAuthResolutionFailure(t *testing.T) {
+ if testPool == nil {
+ t.Skip("no database connection")
+ }
+
+ issueID, agentID, runtimeID := setupRerunTestFixture(t)
+ t.Cleanup(func() { cleanupRerunFixture(t, issueID) })
+
+ ctx := context.Background()
+
+ if _, err := testPool.Exec(ctx, `
+ INSERT INTO agent_task_queue (agent_id, runtime_id, issue_id, status, priority, started_at, completed_at, session_id, work_dir, failure_reason, error)
+ VALUES ($1, $2, $3, 'failed', 0, now() - interval '1 minute', now() - interval '1 minute', 'POISONED-AUTH', '/tmp/poisoned', 'agent_error.unknown',
+ 'hermes provider error: "Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted"')
+ `, agentID, runtimeID, issueID); err != nil {
+ t.Fatalf("insert poisoned task: %v", err)
+ }
+
+ queries := db.New(testPool)
+ prior, err := queries.GetLastTaskSession(ctx, db.GetLastTaskSessionParams{
+ AgentID: pgtype.UUID{Bytes: parseUUIDBytes(agentID), Valid: true},
+ IssueID: pgtype.UUID{Bytes: parseUUIDBytes(issueID), Valid: true},
+ })
+ requireSessionExcluded(t, prior.SessionID, err)
+}
+
+// TestGetLastTaskSessionKeepsSessionOnAuthAdjacentError is the narrowness half:
+// the ILIKE guard must match the exact provider phrase, not any error that
+// merely talks about authentication. A false positive silently drops
+// conversation context on every follow-up, which is worse than the bug it
+// guards against.
+func TestGetLastTaskSessionKeepsSessionOnAuthAdjacentError(t *testing.T) {
+ if testPool == nil {
+ t.Skip("no database connection")
+ }
+
+ issueID, agentID, runtimeID := setupRerunTestFixture(t)
+ t.Cleanup(func() { cleanupRerunFixture(t, issueID) })
+
+ ctx := context.Background()
+
+ if _, err := testPool.Exec(ctx, `
+ INSERT INTO agent_task_queue (agent_id, runtime_id, issue_id, status, priority, started_at, completed_at, session_id, work_dir, failure_reason, error)
+ VALUES ($1, $2, $3, 'failed', 0, now() - interval '1 minute', now() - interval '1 minute', 'HEALTHY-AUTH', '/tmp/healthy', 'agent_error.unknown',
+ 'hermes provider error: could not resolve an authentication method for this model')
+ `, agentID, runtimeID, issueID); err != nil {
+ t.Fatalf("insert task: %v", err)
+ }
+
+ queries := db.New(testPool)
+ prior, err := queries.GetLastTaskSession(ctx, db.GetLastTaskSessionParams{
+ AgentID: pgtype.UUID{Bytes: parseUUIDBytes(agentID), Valid: true},
+ IssueID: pgtype.UUID{Bytes: parseUUIDBytes(issueID), Valid: true},
+ })
+ if err != nil {
+ t.Fatalf("GetLastTaskSession failed: %v", err)
+ }
+ if !prior.SessionID.Valid || prior.SessionID.String != "HEALTHY-AUTH" {
+ t.Fatalf("an auth-adjacent but non-matching error must not retire the session, got %+v", prior.SessionID)
+ }
+}
+
// TestCompletedTaskRolloutMissingWithholdsAndDisclosesGap is the cross-layer
// regression for MUL-5305 Must-fix 1: a COMPLETED follow-up whose Codex rollout
// is missing (the #5934 case — the user waits for each turn to finish) must (1)
diff --git a/server/cmd/server/retired_session_test.go b/server/cmd/server/retired_session_test.go
index 3a80029e5b..3606418c52 100644
--- a/server/cmd/server/retired_session_test.go
+++ b/server/cmd/server/retired_session_test.go
@@ -101,6 +101,64 @@ func TestGetLastChatTaskSessionKeepsHealthyDistinctSession(t *testing.T) {
}
}
+// TestGetLastChatTaskSessionExcludesAuthResolutionFailure is the chat half of
+// the auth-resolution resume fix, mirroring GetLastTaskSession: a provider that
+// cannot resolve its own authentication method must not be handed back to the
+// next task on the same chat. The row carries agent_error.unknown — what every
+// daemon version writes for this text — so only the ILIKE guard drops it.
+func TestGetLastChatTaskSessionExcludesAuthResolutionFailure(t *testing.T) {
+ if testPool == nil {
+ t.Skip("no database connection")
+ }
+
+ _, agentID, runtimeID := setupRerunTestFixture(t)
+ chatSessionID := newPoisonTestChatSession(t, agentID, runtimeID, "poison-auth-resolve")
+ ctx := context.Background()
+
+ if _, err := testPool.Exec(ctx, `
+ INSERT INTO agent_task_queue (agent_id, runtime_id, chat_session_id, status, priority, started_at, completed_at, session_id, work_dir, failure_reason, error)
+ VALUES ($1, $2, $3, 'failed', 0, now() - interval '1 minute', now() - interval '1 minute', 'POISONED-CHAT-AUTH', '/tmp/chat', 'agent_error.unknown',
+ 'hermes provider error: "Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted"')
+ `, agentID, runtimeID, chatSessionID); err != nil {
+ t.Fatalf("insert poisoned task: %v", err)
+ }
+
+ queries := db.New(testPool)
+ prior, err := queries.GetLastChatTaskSession(ctx, pgtype.UUID{Bytes: parseUUIDBytes(chatSessionID), Valid: true})
+ requireSessionExcluded(t, prior.SessionID, err)
+}
+
+// TestGetLastChatTaskSessionKeepsSessionOnAuthAdjacentError is the chat
+// narrowness half: the ILIKE guard must match the exact provider phrase, not an
+// error that merely resembles it, or a healthy conversation loses its resume
+// context on every follow-up.
+func TestGetLastChatTaskSessionKeepsSessionOnAuthAdjacentError(t *testing.T) {
+ if testPool == nil {
+ t.Skip("no database connection")
+ }
+
+ _, agentID, runtimeID := setupRerunTestFixture(t)
+ chatSessionID := newPoisonTestChatSession(t, agentID, runtimeID, "poison-auth-adjacent")
+ ctx := context.Background()
+
+ if _, err := testPool.Exec(ctx, `
+ INSERT INTO agent_task_queue (agent_id, runtime_id, chat_session_id, status, priority, started_at, completed_at, session_id, work_dir, failure_reason, error)
+ VALUES ($1, $2, $3, 'failed', 0, now() - interval '1 minute', now() - interval '1 minute', 'CHAT-HEALTHY-AUTH', '/tmp/chat', 'agent_error.unknown',
+ 'hermes provider error: could not resolve an authentication method for this model')
+ `, agentID, runtimeID, chatSessionID); err != nil {
+ t.Fatalf("insert task: %v", err)
+ }
+
+ queries := db.New(testPool)
+ prior, err := queries.GetLastChatTaskSession(ctx, pgtype.UUID{Bytes: parseUUIDBytes(chatSessionID), Valid: true})
+ if err != nil {
+ t.Fatalf("GetLastChatTaskSession failed: %v", err)
+ }
+ if !prior.SessionID.Valid || prior.SessionID.String != "CHAT-HEALTHY-AUTH" {
+ t.Fatalf("an auth-adjacent but non-matching error must not retire the session, got %+v", prior.SessionID)
+ }
+}
+
// TestRetiredSessionExcludedFromIssueResume covers the case the poison filters
// structurally cannot see (GH #6066): a fresh-session retry that SUCCEEDS. The
// recovered task is 'completed' and carries no failure to classify, so the only
diff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.go
index 3d5ad1804d..be34e46aed 100644
--- a/server/internal/daemon/daemon_test.go
+++ b/server/internal/daemon/daemon_test.go
@@ -4995,3 +4995,21 @@ func TestExecuteAndDrain_RedactsNestedToolInputBeforeSending(t *testing.T) {
t.Fatalf("redaction destroyed the change metadata: %s", blob)
}
}
+
+// TestFreshSessionMayHelp pins the verdict for the Hermes auth-resolution
+// failure this PR treats as session poison, so the "fresh session is the
+// answer" gate can't be flipped by a future classifier change. The error is
+// session-shaped (a fresh session resolves it), yet it must NOT count as one
+// of the "fresh session is not the answer" buckets — in particular not
+// missing-config — or the in-turn fresh-session retry on the five
+// ResumeRejectionUndetectable backends (antigravity, copilot, cursor, deveco,
+// opencode) would silently stop firing and the dead session would be resumed
+// into the same provider error forever.
+func TestFreshSessionMayHelp(t *testing.T) {
+ t.Parallel()
+
+ const hermesAuth = "hermes provider error: \"Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted\""
+ if !freshSessionMayHelp(hermesAuth) {
+ t.Fatalf("freshSessionMayHelp(auth-resolution error) = false; a fresh session cures this failure, it must report session-fixable")
+ }
+}
diff --git a/server/internal/service/resume_unsafe_test.go b/server/internal/service/resume_unsafe_test.go
index 9a107e7648..e3c1d9d39c 100644
--- a/server/internal/service/resume_unsafe_test.go
+++ b/server/internal/service/resume_unsafe_test.go
@@ -44,6 +44,28 @@ func TestResumeUnsafeFailureEmptyHistoryMessage(t *testing.T) {
errorText: gh5760,
want: true,
},
+ {
+ // A provider that cannot resolve its own authentication method is
+ // deterministic on resume: the missing api_key / auth_token / header is
+ // baked into the session's provider state, so a rerun must start fresh
+ // instead of replaying the same auth error. Every daemon version
+ // classifies this text as agent_error.unknown (resume-safe), so the text
+ // guard here is the only thing that un-wedges an issue stuck before (or
+ // after) this fix deployed.
+ name: "auth-resolution text flips resume even when the reason is unknown",
+ failureReason: "agent_error.unknown",
+ errorText: "hermes provider error: \"Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted\"",
+ want: true,
+ },
+ {
+ // The guard is the load-bearing layer, deliberately reason-independent:
+ // it must fire no matter what failure_reason a row happens to carry, so
+ // it is not coupled to a classification that could drift.
+ name: "text guard is reason-independent",
+ failureReason: "agent_error.missing_config",
+ errorText: "hermes provider error: \"Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the X-Api-Key or Authorization headers to be explicitly omitted\"",
+ want: true,
+ },
{
// Transient failures must stay resumable: the whole point of
// reusing the session on retry is to keep the conversation.
diff --git a/server/internal/service/task.go b/server/internal/service/task.go
index 818fc2dde8..76e3e4cadb 100644
--- a/server/internal/service/task.go
+++ b/server/internal/service/task.go
@@ -4076,6 +4076,17 @@ func ResumeUnsafeFailure(failureReason, errorText string) bool {
if strings.Contains(lower, "400") && strings.Contains(lower, "invalid_request_error") {
return true
}
+ // Provider credential-resolution failures are deterministic on resume: the
+ // missing api_key / auth_token / auth header is baked into the session's
+ // provider state, so a rerun must start fresh instead of replaying the same
+ // auth error on the recorded (agent, issue) session. taskfailure.Classify
+ // deliberately leaves this error as agent_error.unknown, so this
+ // reason-independent text guard is the load-bearing protection for both new
+ // and already persisted rows. Keep it in sync with the GetLastTaskSession /
+ // GetLastChatTaskSession resume queries.
+ if strings.Contains(lower, "could not resolve authentication method") {
+ return true
+ }
// Same defense-in-depth for the provider-agnostic empty-message shape:
// a daemon too old to carry classifyPoisonedError's new branch reports
// agent_error.unknown, and without this the manual-retry path would
diff --git a/server/pkg/db/generated/agent.sql.go b/server/pkg/db/generated/agent.sql.go
index 5b1a94cd20..257d171dab 100644
--- a/server/pkg/db/generated/agent.sql.go
+++ b/server/pkg/db/generated/agent.sql.go
@@ -3361,6 +3361,15 @@ WHERE session_id NOT IN (SELECT session_id FROM retired_sessions)
AND COALESCE(failure_reason, '') NOT IN ('iteration_limit', 'agent_fallback_message', 'api_invalid_request', 'codex_semantic_inactivity', 'agent_error.context_overflow', 'codex_resume_oversized')
AND NOT (COALESCE(error, '') ILIKE '%400%' AND COALESCE(error, '') ILIKE '%invalid_request_error%')
AND NOT (COALESCE(error, '') ILIKE '%image dimensions exceed max allowed size%' AND COALESCE(error, '') ILIKE '%image.source.base64.data%')
+ -- A provider credential-resolution failure ("Could not resolve
+ -- authentication method...") is deterministic on resume: the missing
+ -- api_key / auth_token / header is baked into the session's provider
+ -- state, so replaying it reproduces the same provider error forever. It
+ -- is classified agent_error.unknown (resume-safe), so this text guard is
+ -- the only thing that keeps a wedged issue from resuming the same dead
+ -- session on its next trigger — there is no daemon upgrade to wait for.
+ -- Keep in sync with ResumeUnsafeFailure and GetLastChatTaskSession.
+ AND NOT (COALESCE(error, '') ILIKE '%could not resolve authentication method%')
AND NOT (COALESCE(error, '') ~* 'must not be empty|must be non-?empty|must have non-?empty|non-?empty content|cannot be empty|should not be empty'
AND COALESCE(error, '') ~* 'role[^a-z0-9]{0,2}assistant|assistant message|message at position|messages\.[0-9]|messages\[[0-9]')
)
diff --git a/server/pkg/db/generated/chat.sql.go b/server/pkg/db/generated/chat.sql.go
index 9a3eb852eb..aab3e7fe8a 100644
--- a/server/pkg/db/generated/chat.sql.go
+++ b/server/pkg/db/generated/chat.sql.go
@@ -780,6 +780,13 @@ WHERE session_id NOT IN (SELECT session_id FROM retired_sessions)
status = 'failed'
AND COALESCE(failure_reason, '') NOT IN ('iteration_limit', 'agent_fallback_message', 'api_invalid_request', 'codex_semantic_inactivity', 'agent_error.context_overflow', 'codex_resume_oversized')
AND NOT (COALESCE(error, '') ILIKE '%400%' AND COALESCE(error, '') ILIKE '%invalid_request_error%')
+ -- Mirrors the GetLastTaskSession auth-resolution guard: a provider that
+ -- cannot resolve its auth method fails deterministically on resume, and
+ -- the classification is agent_error.unknown (resume-safe), so only this
+ -- text guard keeps the dead session from being replayed. This and
+ -- GetLastTaskSession must move together.
+ -- Keep in sync with ResumeUnsafeFailure and GetLastTaskSession.
+ AND NOT (COALESCE(error, '') ILIKE '%could not resolve authentication method%')
AND NOT (COALESCE(error, '') ~* 'must not be empty|must be non-?empty|must have non-?empty|non-?empty content|cannot be empty|should not be empty'
AND COALESCE(error, '') ~* 'role[^a-z0-9]{0,2}assistant|assistant message|message at position|messages\.[0-9]|messages\[[0-9]')
)
diff --git a/server/pkg/db/queries/agent.sql b/server/pkg/db/queries/agent.sql
index 6723ed0ca7..8be0518225 100644
--- a/server/pkg/db/queries/agent.sql
+++ b/server/pkg/db/queries/agent.sql
@@ -926,6 +926,15 @@ WHERE session_id NOT IN (SELECT session_id FROM retired_sessions)
AND COALESCE(failure_reason, '') NOT IN ('iteration_limit', 'agent_fallback_message', 'api_invalid_request', 'codex_semantic_inactivity', 'agent_error.context_overflow', 'codex_resume_oversized')
AND NOT (COALESCE(error, '') ILIKE '%400%' AND COALESCE(error, '') ILIKE '%invalid_request_error%')
AND NOT (COALESCE(error, '') ILIKE '%image dimensions exceed max allowed size%' AND COALESCE(error, '') ILIKE '%image.source.base64.data%')
+ -- A provider credential-resolution failure ("Could not resolve
+ -- authentication method...") is deterministic on resume: the missing
+ -- api_key / auth_token / header is baked into the session's provider
+ -- state, so replaying it reproduces the same provider error forever. It
+ -- is classified agent_error.unknown (resume-safe), so this text guard is
+ -- the only thing that keeps a wedged issue from resuming the same dead
+ -- session on its next trigger — there is no daemon upgrade to wait for.
+ -- Keep in sync with ResumeUnsafeFailure and GetLastChatTaskSession.
+ AND NOT (COALESCE(error, '') ILIKE '%could not resolve authentication method%')
AND NOT (COALESCE(error, '') ~* 'must not be empty|must be non-?empty|must have non-?empty|non-?empty content|cannot be empty|should not be empty'
AND COALESCE(error, '') ~* 'role[^a-z0-9]{0,2}assistant|assistant message|message at position|messages\.[0-9]|messages\[[0-9]')
)
diff --git a/server/pkg/db/queries/chat.sql b/server/pkg/db/queries/chat.sql
index 85715d172d..3cf7b2cabc 100644
--- a/server/pkg/db/queries/chat.sql
+++ b/server/pkg/db/queries/chat.sql
@@ -834,6 +834,13 @@ WHERE session_id NOT IN (SELECT session_id FROM retired_sessions)
status = 'failed'
AND COALESCE(failure_reason, '') NOT IN ('iteration_limit', 'agent_fallback_message', 'api_invalid_request', 'codex_semantic_inactivity', 'agent_error.context_overflow', 'codex_resume_oversized')
AND NOT (COALESCE(error, '') ILIKE '%400%' AND COALESCE(error, '') ILIKE '%invalid_request_error%')
+ -- Mirrors the GetLastTaskSession auth-resolution guard: a provider that
+ -- cannot resolve its auth method fails deterministically on resume, and
+ -- the classification is agent_error.unknown (resume-safe), so only this
+ -- text guard keeps the dead session from being replayed. This and
+ -- GetLastTaskSession must move together.
+ -- Keep in sync with ResumeUnsafeFailure and GetLastTaskSession.
+ AND NOT (COALESCE(error, '') ILIKE '%could not resolve authentication method%')
AND NOT (COALESCE(error, '') ~* 'must not be empty|must be non-?empty|must have non-?empty|non-?empty content|cannot be empty|should not be empty'
AND COALESCE(error, '') ~* 'role[^a-z0-9]{0,2}assistant|assistant message|message at position|messages\.[0-9]|messages\[[0-9]')
)