Skip to content

Fetch timeout after 5 minutes: "TypeError: terminated" in auth-proxy #1484

@littlekirkycode

Description

@littlekirkycode

Streaming responses terminated after ~5 minutes with "TypeError: terminated" in auth-proxy

Nodes built in fetch has a default bodyTimeout of 5 minutes, when streaming SSE response that takes longer to fully receive undici kills the tls socket and gives error 'TypeError: terminated.'

PR 1362 Didn't create this but may have made it worse as:
Before: fetch(url,options) was called immediately with a synchonouse token injection so full 5 min was availiable but still limited to 5 min timeout.
After: authenticatedFetch does await getvalidAccessToken() before each fetch calling ensureValidSession(), potentially triggers refreshSession() eating into the 5 minute window so it isn't always exactly the same window.

Also, the shared refreshPromise singleton means if any concurrent request triggers a token refresh all pending autheticatedFetch calls block on it.

Potential Fix (untested):

In auth-proxy/service.ts's forwardRequest, the fetch needs bodyTimeout: 0 to disable the timeout for streaming.

// Pass a custom undici dispatcher or signal with no timeout
const controller = new AbortController();
const fetchOpts = { ...options, signal: controller.signal };

Or if undici options can be passed directly: bodyTimeout: 0.

Files to look at

  • apps/code/src/main/services/auth-proxy/service.ts — forwardRequest method
  • apps/code/src/main/services/auth/service.ts — authenticatedFetch and getValidAccessToken

Steps to reproduce

  1. Start a new session
  2. Send a prompt that requires a long streaming response (e.g. "Write me a 5000 word essay on the history of Blizzard and Activision")
  3. Wait ~4-5 minutes
  4. Session crashes with proxy forward error

Full Logs

[2026-04-03 15:00:38.626] [info]  (agent:AcpConnection)        Created claude agent
[2026-04-03 15:00:39.110] [info]  (process-tracking)           Registered process: pid=30358 category=agent label=agent:2536c4e5-af39-4bee-9831-ee9b5333269c taskId=585d9a05-2f5e-4301-8397-01476e3f69ca
[2026-04-03 15:00:42.370] [info]  (agent-service)              Sending prompt to agent {
  sessionId: '2536c4e5-af39-4bee-9831-ee9b5333269c',
  blockCount: 1,
  blocks: '[{"type":"text","text":"Write me a 5000 word essay after some research on the history of the company blizzard and activision."}]',
  totalSize: 128
}
[2026-04-03 15:00:42.223] [info]  (terminal-manager)           Creating terminal instance: shell-1775224842222-1c2w6i3
[2026-04-03 15:00:42.445] [info]  (shell)                      Creating shell session shell-1775224842222-1c2w6i3: shell=/bin/zsh, cwd=/Users/jameskirkham/Desktop/selfquestall
[2026-04-03 15:00:42.447] [info]  (process-tracking)           Registered process: pid=30447 category=shell label=shell:shell-1775224842222-1c2w6i3 taskId=585d9a05-2f5e-4301-8397-01476e3f69ca
[2026-04-03 15:00:42.447] [info]  (terminal-manager)           Shell session ready: shell-1775224842222-1c2w6i3
[2026-04-03 15:00:43.286] [info]  (mcp-apps-service)           Discovery complete {
  serverNames: [ 'codebase-memory-mcp', 'posthog' ],
  toolKeys: [
    'mcp__posthog__experiment-get-all',
    'mcp__posthog__experiment-create',
    'mcp__posthog__experiment-update',
    'mcp__posthog__experiment-get',
    'mcp__posthog__experiment-results-get',
    'mcp__posthog__insight-query',
    'mcp__posthog__get-llm-total-costs-for-project',
    'mcp__posthog__survey-create',
    'mcp__posthog__survey-get',
    'mcp__posthog__surveys-get-all',
    'mcp__posthog__survey-update',
    'mcp__posthog__surveys-global-stats',
    'mcp__posthog__survey-stats',
    'mcp__posthog__debug-mcp-ui-apps',
    'mcp__posthog__actions-get-all',
    'mcp__posthog__action-create',
    'mcp__posthog__action-get',
    'mcp__posthog__action-update',
    'mcp__posthog__error-tracking-issues-list',
    'mcp__posthog__error-tracking-issues-retrieve',
    'mcp__posthog__error-tracking-issues-partial-update',
    'mcp__posthog__query-error-tracking-issues',
    'mcp__posthog__query-trends',
    'mcp__posthog__query-funnel',
    'mcp__posthog__query-retention',
    'mcp__posthog__query-stickiness',
    'mcp__posthog__query-paths',
    'mcp__posthog__query-lifecycle'
  ],
  associationCount: 28
}
[2026-04-03 15:03:10.759] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:10.759] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:10.760] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:10.760] [info]  (session-connection)         Reconnecting to existing task session {
  taskId: '99b54c92-b247-44bf-b298-46a131a1fb01',
  hasLatestRun: true,
  sessionStatus: 'none'
}
[2026-04-03 15:03:10.760] [info]  (session-service)            Connecting to task { taskId: '99b54c92-b247-44bf-b298-46a131a1fb01' }
[2026-04-03 15:03:11.752] [info]  (agent)                      Configured LLM gateway { adapter: 'claude' }
[2026-04-03 15:03:11.753] [info]  (agent:SessionLogWriter)     Session registered {
  taskId: '99b54c92-b247-44bf-b298-46a131a1fb01',
  runId: 'e6f0960e-7c19-42ef-b36b-af3a421a72d3'
}
[2026-04-03 15:03:11.753] [info]  (agent:AcpConnection)        Created claude agent
[2026-04-03 15:03:11.966] [info]  (agent-service)              Local JSONL exists, skipping S3 hydration { sessionId: '019d539d-c5c5-703c-9c75-2ed4364fc624' }
[2026-04-03 15:03:11.968] [info]  (process-tracking)           Registered process: pid=31393 category=agent label=agent:e6f0960e-7c19-42ef-b36b-af3a421a72d3 taskId=99b54c92-b247-44bf-b298-46a131a1fb01
[2026-04-03 15:03:14.318] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:14.318] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:14.318] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:15.478] [info]  (session-service)            Session adapter updated {
  taskRunId: 'e6f0960e-7c19-42ef-b36b-af3a421a72d3',
  adapter: 'claude'
}
[2026-04-03 15:03:15.493] [info]  (agent-service)              Session config option updated {
  sessionId: 'e6f0960e-7c19-42ef-b36b-af3a421a72d3',
  configId: 'effort',
  value: 'high'
}
[2026-04-03 15:03:15.493] [info]  (agent-service)              Session config option updated {
  sessionId: 'e6f0960e-7c19-42ef-b36b-af3a421a72d3',
  configId: 'model',
  value: 'claude-opus-4-6'
}
[2026-04-03 15:03:15.493] [info]  (agent-service)              Session config option updated {
  sessionId: 'e6f0960e-7c19-42ef-b36b-af3a421a72d3',
  configId: 'mode',
  value: 'plan'
}
[2026-04-03 15:03:15.938] [info]  (mcp-apps-service)           Discovery complete {
  serverNames: [ 'codebase-memory-mcp', 'posthog' ],
  toolKeys: [
    'mcp__posthog__experiment-get-all',
    'mcp__posthog__experiment-create',
    'mcp__posthog__experiment-update',
    'mcp__posthog__experiment-get',
    'mcp__posthog__experiment-results-get',
    'mcp__posthog__insight-query',
    'mcp__posthog__get-llm-total-costs-for-project',
    'mcp__posthog__survey-create',
    'mcp__posthog__survey-get',
    'mcp__posthog__surveys-get-all',
    'mcp__posthog__survey-update',
    'mcp__posthog__surveys-global-stats',
    'mcp__posthog__survey-stats',
    'mcp__posthog__debug-mcp-ui-apps',
    'mcp__posthog__actions-get-all',
    'mcp__posthog__action-create',
    'mcp__posthog__action-get',
    'mcp__posthog__action-update',
    'mcp__posthog__error-tracking-issues-list',
    'mcp__posthog__error-tracking-issues-retrieve',
    'mcp__posthog__error-tracking-issues-partial-update',
    'mcp__posthog__query-error-tracking-issues',
    'mcp__posthog__query-trends',
    'mcp__posthog__query-funnel',
    'mcp__posthog__query-retention',
    'mcp__posthog__query-stickiness',
    'mcp__posthog__query-paths',
    'mcp__posthog__query-lifecycle'
  ],
  associationCount: 28
}
[2026-04-03 15:03:18.250] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:18.250] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:18.250] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:18.251] [info]  (terminal-manager)           Creating terminal instance: shell-1775224346892-2s0n0r1
[2026-04-03 15:03:19.210] [info]  (shell)                      Creating shell session shell-1775224346892-2s0n0r1: shell=/bin/zsh, cwd=/Users/jameskirkham/Desktop/selfquestall
[2026-04-03 15:03:19.211] [info]  (process-tracking)           Registered process: pid=31581 category=shell label=shell:shell-1775224346892-2s0n0r1 taskId=99b54c92-b247-44bf-b298-46a131a1fb01
[2026-04-03 15:03:19.504] [info]  (terminal-manager)           Shell session ready: shell-1775224346892-2s0n0r1
[2026-04-03 15:03:21.059] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:21.060] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:21.060] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:21.060] [info]  (session-connection)         Reconnecting to existing task session {
  taskId: 'aaaacf06-b1f9-43ac-8aa5-c82f78384ce4',
  hasLatestRun: true,
  sessionStatus: 'none'
}
[2026-04-03 15:03:21.060] [info]  (session-service)            Connecting to task { taskId: 'aaaacf06-b1f9-43ac-8aa5-c82f78384ce4' }
[2026-04-03 15:03:22.057] [info]  (agent)                      Configured LLM gateway { adapter: 'claude' }
[2026-04-03 15:03:22.057] [info]  (agent:SessionLogWriter)     Session registered {
  taskId: 'aaaacf06-b1f9-43ac-8aa5-c82f78384ce4',
  runId: '6ee462a8-93be-498b-bddd-3b335d46dbef'
}
[2026-04-03 15:03:22.058] [info]  (agent:AcpConnection)        Created claude agent
[2026-04-03 15:03:22.469] [info]  (agent-service)              Local JSONL exists, skipping S3 hydration { sessionId: '019d538e-1db3-7429-845c-5dfa0c72d859' }
[2026-04-03 15:03:22.471] [info]  (process-tracking)           Registered process: pid=31671 category=agent label=agent:6ee462a8-93be-498b-bddd-3b335d46dbef taskId=aaaacf06-b1f9-43ac-8aa5-c82f78384ce4
[2026-04-03 15:03:25.291] [info]  (session-service)            Session adapter updated {
  taskRunId: '6ee462a8-93be-498b-bddd-3b335d46dbef',
  adapter: 'claude'
}
[2026-04-03 15:03:25.309] [info]  (agent-service)              Session config option updated {
  sessionId: '6ee462a8-93be-498b-bddd-3b335d46dbef',
  configId: 'effort',
  value: 'high'
}
[2026-04-03 15:03:25.310] [info]  (agent-service)              Session config option updated {
  sessionId: '6ee462a8-93be-498b-bddd-3b335d46dbef',
  configId: 'model',
  value: 'claude-opus-4-6'
}
[2026-04-03 15:03:25.310] [info]  (agent-service)              Session config option updated {
  sessionId: '6ee462a8-93be-498b-bddd-3b335d46dbef',
  configId: 'mode',
  value: 'default'
}
[2026-04-03 15:03:25.311] [info]  (terminal-manager)           Creating terminal instance: shell-1775223320863-6o2z1i2
[2026-04-03 15:03:25.527] [info]  (shell)                      Creating shell session shell-1775223320863-6o2z1i2: shell=/bin/zsh, cwd=/Users/jameskirkham/Desktop/selfquestall
[2026-04-03 15:03:25.529] [info]  (process-tracking)           Registered process: pid=31733 category=shell label=shell:shell-1775223320863-6o2z1i2 taskId=aaaacf06-b1f9-43ac-8aa5-c82f78384ce4
[2026-04-03 15:03:25.530] [info]  (terminal-manager)           Shell session ready: shell-1775223320863-6o2z1i2
[2026-04-03 15:03:25.549] [info]  (mcp-apps-service)           Discovery complete {
  serverNames: [ 'codebase-memory-mcp', 'posthog' ],
  toolKeys: [
    'mcp__posthog__experiment-get-all',
    'mcp__posthog__experiment-create',
    'mcp__posthog__experiment-update',
    'mcp__posthog__experiment-get',
    'mcp__posthog__experiment-results-get',
    'mcp__posthog__insight-query',
    'mcp__posthog__get-llm-total-costs-for-project',
    'mcp__posthog__survey-create',
    'mcp__posthog__survey-get',
    'mcp__posthog__surveys-get-all',
    'mcp__posthog__survey-update',
    'mcp__posthog__surveys-global-stats',
    'mcp__posthog__survey-stats',
    'mcp__posthog__debug-mcp-ui-apps',
    'mcp__posthog__actions-get-all',
    'mcp__posthog__action-create',
    'mcp__posthog__action-get',
    'mcp__posthog__action-update',
    'mcp__posthog__error-tracking-issues-list',
    'mcp__posthog__error-tracking-issues-retrieve',
    'mcp__posthog__error-tracking-issues-partial-update',
    'mcp__posthog__query-error-tracking-issues',
    'mcp__posthog__query-trends',
    'mcp__posthog__query-funnel',
    'mcp__posthog__query-retention',
    'mcp__posthog__query-stickiness',
    'mcp__posthog__query-paths',
    'mcp__posthog__query-lifecycle'
  ],
  associationCount: 28
}
[2026-04-03 15:03:28.050] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:28.050] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:03:28.050] [info]  (focus-saga)                 Starting saga { sagaName: 'FocusRestoreSaga' }
[2026-04-03 15:05:09.460] [error] (auth-proxy)                 Proxy forward error {
  url: 'https://gateway.us.posthog.com/posthog_code/v1/messages?beta=true',
  err: 'TypeError: terminated\n' +
    '    at Fetch.onAborted (node:internal/deps/undici/undici:12826:53)\n' +
    '    at Fetch.emit (node:events:508:28)\n' +
    '    at Fetch.terminate (node:internal/deps/undici/undici:11963:14)\n' +
    '    at Object.onError (node:internal/deps/undici/undici:12950:38)\n' +
    '    at Request.onError (node:internal/deps/undici/undici:3015:31)\n' +
    '    at Object.errorRequest (node:internal/deps/undici/undici:1887:17)\n' +
    '    at TLSSocket.onHttpSocketClose (node:internal/deps/undici/undici:7661:14)\n' +   '    at TLSSocket.emit (node:events:520:35)\n' +
    '    at node:net:346:12\n' +
    '    at TCP.done (node:internal/tls/wrap:667:7)'
}

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingOpen BetaWe should probably take care of this before the open beta

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions