: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): avoid session restarts on oversized requests (#98785)
Peter Kirkham4ee4c7052ed6
diff --git a/products/desktop/docs/TROUBLESHOOTING.md b/products/desktop/docs/TROUBLESHOOTING.mdindex c9e425a529c0..352f3bf3b47a 100644--- a/products/desktop/docs/TROUBLESHOOTING.md+++ b/products/desktop/docs/TROUBLESHOOTING.md@@ -1,5 +1,14 @@# Troubleshooting+## Conversation is too large to continue++A request can exceed the size limit when a conversation contains large images or tool output.+The app keeps the session connected and reports the size error instead of restarting the agent and sending the same request again.+Restarting the session does not reduce the request size.++Start a new task with a short text summary of the work.+Do not copy the old images or full tool output into the new task.+## Codex asks for the same permissions againCodex Auto keeps approvals for actions outside its allowed scope.diff --git a/products/desktop/packages/core/src/sessions/sessionServicePromptRecovery.test.ts b/products/desktop/packages/core/src/sessions/sessionServicePromptRecovery.test.tsindex e6897c7f939a..26f868dc0eeb 100644--- a/products/desktop/packages/core/src/sessions/sessionServicePromptRecovery.test.ts+++ b/products/desktop/packages/core/src/sessions/sessionServicePromptRecovery.test.ts@@ -113,6 +113,51 @@ describe("SessionService prompt recovery on fatal session errors", () => {);});+ it.each(+ [+ "This conversation is too large to continue.",+ "Prompt is too long",+ "exceeded this model context window limit",+ 'API Error: 413 {"error":{"message":"Request rejected"}}',+ ].flatMap((message) =>+ (["message", "details"] as const).map((location) => ({+ message,+ location,+ })),+ ),+ )(+ "keeps the session connected for $message in $location",+ async ({ message, location }) => {+ const { service, sessions, promptMutate, recoverSpy, usageLimitShow } =+ createHarness();+ const error =+ location === "message"+ ? new Error(`Internal error: ${message}`)+ : Object.assign(new Error("Internal error"), {+ data: { details: message },+ });+ promptMutate.mockImplementation(async () => {+ sessions[TASK_RUN_ID].isCompacting = true;+ throw error;+ });+ recoverSpy.mockResolvedValue(true);++ await expect(service.sendPrompt(TASK_ID, "/compact")).rejects.toThrow(+ error,+ );++ expect(promptMutate).toHaveBeenCalledTimes(1);+ expect(recoverSpy).not.toHaveBeenCalled();+ expect(usageLimitShow).not.toHaveBeenCalled();+ expect(sessions[TASK_RUN_ID]).toMatchObject({+ status: "connected",+ isPromptPending: false,+ isCompacting: false,+ promptStartedAt: null,+ });+ },+ );+it.each([{case: "recovery fails",diff --git a/products/desktop/packages/shared/src/errors.test.ts b/products/desktop/packages/shared/src/errors.test.tsindex 3f59c8ba0d7e..fcd2a16804d0 100644--- a/products/desktop/packages/shared/src/errors.test.ts+++ b/products/desktop/packages/shared/src/errors.test.ts@@ -179,6 +179,12 @@ describe("classifyPromptFailure", () => {],["Authentication required", undefined, "authentication", true],["process exited", undefined, "fatal_session", true],+ [+ "Internal error: This conversation is too large to continue.",+ undefined,+ "unknown",+ false,+ ],["invalid model", undefined, "unknown", false],] as const)("classifies %j as %s", (message, errorType, kind, retryable) => {expect(@@ -216,6 +222,19 @@ describe("isFatalSessionError", () => {expect(isFatalSessionError("temporary network blip")).toBe(false);});+ it.each([+ "This conversation is too large to continue.",+ "API Error: 413 Payload Too Large",+ "Request body too large",+ "Prompt is too long",+ "exceeded this model context window limit",+ 'API Error: 413 {"error":{"message":"Request rejected"}}',+ "api error:413",+ ])("does not treat the request size error %j as fatal", (message) => {+ expect(isFatalSessionError(`Internal error: ${message}`)).toBe(false);+ expect(isFatalSessionError("Internal error", message)).toBe(false);+ });+it.each(["Internal error: API Error: the operation timed out","Internal error: API Error: Request timeout",diff --git a/products/desktop/packages/shared/src/errors.ts b/products/desktop/packages/shared/src/errors.tsindex 7b4d7e798533..ec9665eb89e8 100644--- a/products/desktop/packages/shared/src/errors.ts+++ b/products/desktop/packages/shared/src/errors.ts@@ -109,6 +109,16 @@ const FATAL_SESSION_ERROR_PATTERNS = ["session not found",] as const;+const REQUEST_SIZE_ERROR_PATTERNS = [+ "this conversation is too large to continue",+ "request body too large",+ "payload too large",+ "prompt is too long",+ "exceeded this model context window limit",+] as const;++const REQUEST_SIZE_ERROR_REGEX = /API Error:\s*413\b/i;+/*** Transient upstream provider failures, as surfaced by agent adapters in* "API Error: …" result strings (kept in sync with classifyAgentError in@@ -275,6 +285,14 @@ export function isFatalSessionError(errorMessage: string,errorDetails?: string,): boolean {+ if (+ includesAny(errorMessage, REQUEST_SIZE_ERROR_PATTERNS) ||+ includesAny(errorDetails, REQUEST_SIZE_ERROR_PATTERNS) ||+ REQUEST_SIZE_ERROR_REGEX.test(errorMessage) ||+ REQUEST_SIZE_ERROR_REGEX.test(errorDetails ?? "")+ ) {+ return false;+ }if (isRateLimitError(errorMessage, errorDetails)) return false;if (isTurnEndedWithoutResponseError(errorMessage, errorDetails)) return false;if (isTransientUpstreamError(errorMessage, errorDetails)) return false;