: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): shorten codex stream idle timeout in cloud sandboxes (#83749)
Andrew Maguiredcc7e1aa25fb
diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.test.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.test.tsindex a5784252d4f7..2786d27fe37d 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.test.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.test.ts@@ -1,7 +1,11 @@import { delimiter, dirname } from "node:path";import { describe, expect, it, vi } from "vitest";import type { Logger } from "../../utils/logger";-import { buildAppServerArgs, spawnCodexAppServerProcess } from "./spawn";+import {+ buildAppServerArgs,+ SANDBOX_STREAM_IDLE_TIMEOUT_MS,+ spawnCodexAppServerProcess,+} from "./spawn";const BINARY_PATH = "/bundle/codex";@@ -138,6 +142,19 @@ describe("buildAppServerArgs", () => {expect(args).toContain('model_verbosity="low"');});+ it("shortens the gateway stream idle timeout only in cloud sandboxes", () => {+ const idleTimeoutArg = `model_providers.posthog.stream_idle_timeout_ms=${SANDBOX_STREAM_IDLE_TIMEOUT_MS}`;+ const options = {+ binaryPath: "/bundle/codex",+ apiBaseUrl: "https://gateway.example/v1",+ };++ expect(buildAppServerArgs(options, { IS_SANDBOX: "1" })).toContain(+ idleTimeoutArg,+ );+ expect(buildAppServerArgs(options, {})).not.toContain(idleTimeoutArg);+ });+it("pins the cloud BASH_ENV into tool shells for secondary checkouts", () => {const args = buildAppServerArgs({ binaryPath: "/bundle/codex" },diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.tsindex 81deb7a4aab3..4362f6080a43 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/spawn.ts@@ -69,6 +69,9 @@ export interface CodexAppServerProcessOptions {processCallbacks?: ProcessSpawnedCallback;}+/** Idle time on a gateway SSE stream before codex abandons it and retries, in cloud sandboxes. */+export const SANDBOX_STREAM_IDLE_TIMEOUT_MS = 90_000;+export interface CodexAppServerProcess {process: ChildProcess;stdin: Writable;@@ -171,6 +174,19 @@ export function buildAppServerArgs(`model_providers.posthog.http_headers=${tomlInlineTable(options.httpHeaders)}`,);}++ // Gateway response streams occasionally go silent mid-generation and stay+ // open. Codex only retries once the stream has been idle for+ // stream_idle_timeout_ms (default 300000), so each stall costs a cloud run+ // five minutes of wall clock and sandbox occupancy. A shorter idle timeout+ // bounds that cost; the retry re-issues the request. Cloud-only because a+ // desktop user can see and interrupt a hung turn themselves.+ if (environment.IS_SANDBOX) {+ args.push(+ "-c",+ `model_providers.posthog.stream_idle_timeout_ms=${SANDBOX_STREAM_IDLE_TIMEOUT_MS}`,+ );+ }}// developer_instructions are set per-thread in thread/start (with the host's