{"record":{"id":"44be079bf4bb39fd","repo":"Hmbown/CodeWhale","slug":"compactruntimeerror-response-status-body-44be07","errorCode":null,"errorMessage":"${compactRuntimeError(response.status, body)}","messagePattern":"\\$\\{compactRuntimeError\\(response\\.status, body\\)\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/wecom-bridge/src/index.mjs","lineNumber":317,"sourceCode":"\nasync function streamTurnEvents(chatId, frame, threadId, turnId, sinceSeq) {\n  const controller = new AbortController();\n  const timeout = setTimeout(() => controller.abort(), config.turnTimeoutMs);\n  const streamId = generateReqId(\"stream\");\n  let responseText = \"\";\n  let latestSeq = sinceSeq;\n\n  try {\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      let record;\n      try {\n        record = JSON.parse(event.data);\n      } catch (error) {\n        console.warn(\"Skipping malformed runtime SSE event:\", publicBridgeError(error));\n        continue;\n      }\n      latestSeq = Math.max(latestSeq, Number(record.seq || 0));\n      await threadStore.patchChat(chatId, { lastSeq: latestSeq });\n\n      if (turnId && record.turn_id && record.turn_id !== turnId) continue;\n\n      if (record.event === \"item.delta\" && record.payload?.kind === \"agent_message\") {\n        responseText += record.payload.delta || \"\";","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/wecom-bridge/src/index.mjs#L299-L335","documentation":"In the WeCom bridge's streamTurnEvents, a non-OK HTTP response from the runtime's SSE endpoint triggers compactRuntimeError(response.status, body), which merges the status code and JSON error details into the thrown message. This converts transport-level failures (auth rejection, bad URL, server errors) into an explicit, diagnosable error before any SSE parsing begins.","triggerScenarios":"fetch to the turn-events endpoint resolves with response.ok false — 401/403 for bad auth headers, 404 for a wrong runtime URL/path, or 5xx when the runtime crashes or a proxy fails.","commonSituations":"WeCom bridge pointed at the wrong runtime port, missing/expired credentials, runtime under load returning 502/503 through a proxy, or version skew between bridge and runtime endpoints.","solutions":["Decode the status in the message and address it: fix credentials for 401/403, fix runtimeUrl for 404, inspect runtime logs for 5xx.","Confirm the runtime service is up and reachable at the configured URL.","Refresh the token/secret feeding authHeaders()."],"exampleFix":"// before\nWECOM_BRIDGE_RUNTIME_URL=http://127.0.0.1:9999  # nothing listening / wrong path\n// Error: 404 ...\n\n// after\nWECOM_BRIDGE_RUNTIME_URL=http://127.0.0.1:8080  # actual runtime address","handlingStrategy":"try-catch","validationCode":"const base = process.env.WECOM_BRIDGE_RUNTIME_URL;\nconst res = await fetch(`${base}/health`);\nif (!res.ok) throw new Error(`Runtime unavailable: HTTP ${res.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  for await (const event of streamTurnEvents(input)) {\n    handle(event);\n  }\n} catch (err) {\n  if (/^40[13]/.test(err.message)) {\n    await reauthenticate();\n  } else if (/^5\\d\\d/.test(err.message)) {\n    scheduleRetry();\n  } else {\n    throw err;\n  }\n}","preventionTips":["Verify runtimeUrl/host/port against the runtime's actual listen address before deploying.","Refresh credentials proactively; treat 401 as a signal to rotate tokens.","Add proxy/load-balancer health checks so 502/503 is caught upstream of the bridge.","Keep bridge and runtime endpoint versions aligned."],"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"}