{"record":{"id":"8de1c4964491b3fc","repo":"Hmbown/CodeWhale","slug":"compactruntimeerror-response-status-body-8de1c4","errorCode":null,"errorMessage":"${compactRuntimeError(response.status, body)}","messagePattern":"\\$\\{compactRuntimeError\\(response\\.status, body\\)\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/telegram-bridge/src/index.mjs","lineNumber":629,"sourceCode":"    }\n  };\n  const typingTimer = setInterval(() => {\n    void tickTyping();\n  }, TYPING_INTERVAL_MS);\n  typingTimer.unref?.();\n\n  try {\n    void tickTyping();\n    const response = await fetch(\n      `${config.runtimeUrl}/v1/threads/${encodeURIComponent(threadId)}/events?since_seq=${sinceSeq}`,\n      {\n        headers: authHeaders(),\n        signal: controller.signal\n      }\n    );\n    if (!response.ok) {\n      const body = await readJsonSafe(response);\n      throw new Error(compactRuntimeError(response.status, body));\n    }\n\n    for await (const event of readSse(response)) {\n      if (!event.data) continue;\n      const record = JSON.parse(event.data);\n      latestSeq = Math.max(latestSeq, Number(record.seq || 0));\n      await flushLastSeq(false);\n\n      if (turnId && record.turn_id && record.turn_id !== turnId) continue;\n      const lifecycleStatus =\n        record.event === \"turn.lifecycle\"\n          ? record.payload?.turn?.status || record.payload?.status\n          : null;\n      const stopTypingEvent =\n        record.event === \"turn.completed\" ||\n        [\"failed\", \"canceled\", \"interrupted\"].includes(lifecycleStatus);\n      if (typingPaused && record.event !== \"approval.required\" && !stopTypingEvent) {\n        typingPaused = false;","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/telegram-bridge/src/index.mjs#L611-L647","documentation":"streamTurnEvents opens an SSE connection to the runtime and throws when the HTTP response status is not OK. The message is produced by compactRuntimeError(status, body), which folds the status code and any error details from the JSON body into a single compact string. This surfaces runtime-side failures (auth, bad request, server error) at the point of streaming instead of producing confusing downstream parse failures.","triggerScenarios":"The fetch of the turn-events SSE endpoint resolves but response.ok is false — e.g. 401/403 from missing or stale auth headers, 404 from a wrong runtimeUrl, or 5xx from the runtime process.","commonSituations":"Runtime server not running or listening on a different port than configured, expired/incorrect API credentials, reverse proxy returning 502/503, or an API version mismatch changing the endpoint path.","solutions":["Read the status and body in the error message; fix the indicated cause (401/403 → fix credentials, 404 → fix runtimeUrl, 5xx → check the runtime server logs).","Verify the runtime service is running and the configured runtimeUrl/host/port is correct.","Regenerate or update the auth token used by authHeaders()."],"exampleFix":"// before\nTELEGRAM_BRIDGE_RUNTIME_URL=http://localhost:9000  # runtime actually on 8080\n// Error: 404 ...\n\n// after\nTELEGRAM_BRIDGE_RUNTIME_URL=http://localhost:8080","handlingStrategy":"try-catch","validationCode":"// Preflight the runtime before streaming:\nconst base = process.env.TELEGRAM_BRIDGE_RUNTIME_URL;\nconst res = await fetch(`${base}/health`);\nif (!res.ok) throw new Error(`Runtime not ready: HTTP ${res.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  for await (const event of streamTurnEvents(input)) {\n    handle(event);\n  }\n} catch (err) {\n  const m = /^(\\d{3})/.exec(err.message);\n  if (m && [\"401\", \"403\"].includes(m[1])) {\n    await reauthenticate(); // refresh token and retry once\n  } else if (m && m[1].startsWith(\"5\")) {\n    await delay(1000); // transient server error: retry with backoff\n  } else {\n    throw err;\n  }\n}","preventionTips":["Health-check the runtime before opening SSE streams.","Rotate auth tokens on a schedule shorter than their expiry.","Pin bridge and runtime versions so endpoint paths stay compatible.","Alert on 5xx rates from the runtime service."],"tags":["http","network","sse","runtime"],"backgroundTag":"http-error-response","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T10:30:35.592Z"}