Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(tasks): retry codex turns when the model is at capacity (#123637)

Charles Vien359f8f6ef105
diff --git a/packages/agent/packages/agent/src/adapters/error-classification.test.ts b/packages/agent/packages/agent/src/adapters/error-classification.test.ts
index a51a9153d81b..21ead363352f 100644
--- a/packages/agent/packages/agent/src/adapters/error-classification.test.ts
+++ b/packages/agent/packages/agent/src/adapters/error-classification.test.ts
@@ -48,6 +48,10 @@ describe("classifyAgentError", () => {
["unexpected status 403 Forbidden: needs a paid plan", "agent_error"],
["Flex capacity unavailable.", "upstream_provider_failure"],
["Internal error: Flex capacity unavailable.", "upstream_provider_failure"],
+ [
+ "Selected model is at capacity. Please try a different model.",
+ "upstream_provider_failure",
+ ],
[
"[ede_diagnostic] result_type=user last_content_type=n/a stop_reason=null",
"turn_ended_without_response",
diff --git a/packages/agent/packages/agent/src/adapters/error-classification.ts b/packages/agent/packages/agent/src/adapters/error-classification.ts
index 01fa7b281b72..3dbadc8b0e0f 100644
--- a/packages/agent/packages/agent/src/adapters/error-classification.ts
+++ b/packages/agent/packages/agent/src/adapters/error-classification.ts
@@ -37,6 +37,7 @@ const CODEX_PROVIDER_ERROR_STATUS_PATTERN =
// OpenAI refuses a flex-tier request when it has no flex capacity. The
// refusal carries no HTTP status in the text, but it is transient.
const UPSTREAM_CAPACITY_UNAVAILABLE_PATTERN = /\bcapacity unavailable\b/i;
+const CODEX_SERVER_OVERLOADED_PATTERN = /\bSelected model is at capacity\b/i;
const SANDBOX_TASK_SPEND_LIMIT_PATTERN =
/This agent run reached its spend limit/i;
const TURN_ENDED_WITHOUT_RESPONSE_PATTERN =
@@ -91,6 +92,7 @@ export function classifyAgentError(
if (
UPSTREAM_PROVIDER_ERROR_STATUS_PATTERN.test(text) ||
CODEX_PROVIDER_ERROR_STATUS_PATTERN.test(text) ||
+ CODEX_SERVER_OVERLOADED_PATTERN.test(text) ||
UPSTREAM_CAPACITY_UNAVAILABLE_PATTERN.test(text)
) {
return "upstream_provider_failure";