{"record":{"id":"729a40b4df71b433","repo":"Hmbown/CodeWhale","slug":"compactruntimeerror-response-status-body-729a40","errorCode":null,"errorMessage":"${compactRuntimeError(response.status, body)}","messagePattern":"\\$\\{compactRuntimeError\\(response\\.status, body\\)\\}","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/weixin-bridge/src/index.mjs","lineNumber":420,"sourceCode":"  const timeout = setTimeout(\n    () => controller.abort(),\n    config.turnTimeoutMs\n  );\n  let responseText = \"\";\n  let latestSeq = sinceSeq;\n  let sentProgressAt = Date.now();\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      const record = JSON.parse(event.data);\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 (\n        record.event === \"item.delta\" &&\n        record.payload?.kind === \"agent_message\"\n      ) {\n        responseText += record.payload.delta || \"\";\n        const now = Date.now();\n        if (\n          responseText.length > config.maxReplyChars &&","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/weixin-bridge/src/index.mjs#L402-L438","documentation":"The Weixin bridge's streamTurnEvents throws compactRuntimeError(response.status, body) when the SSE endpoint responds with a non-OK status, before consuming any events. The error carries the HTTP status and any error details from the JSON body, turning runtime-side rejections into an explicit failure instead of an empty or broken event stream.","triggerScenarios":"fetch of the turn-events SSE endpoint resolves with response.ok false: 401/403 (bad auth headers), 404 (wrong runtimeUrl or path), 429 (rate limiting), or 5xx (runtime fault).","commonSituations":"Wrong port/host in runtime configuration, expired credentials, runtime restart invalidating tokens, or a proxy/load balancer returning 502/503 while the runtime is down.","solutions":["Address the status shown in the message: fix auth for 401/403, fix runtimeUrl for 404, back off for 429, check runtime logs for 5xx.","Confirm the runtime service is running and reachable at the configured address.","Update the token/secret used by authHeaders()."],"exampleFix":"// before\nWEIXIN_BRIDGE_RUNTIME_URL=http://localhost:7000  # runtime on 8080\n// Error: 404 ...\n\n// after\nWEIXIN_BRIDGE_RUNTIME_URL=http://localhost:8080","handlingStrategy":"retry","validationCode":"const base = process.env.WEIXIN_BRIDGE_RUNTIME_URL;\nconst res = await fetch(`${base}/health`);\nif (!res.ok) throw new Error(`Runtime not ready: HTTP ${res.status}`);","typeGuard":null,"tryCatchPattern":"async function streamWithRetry(input, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try {\n      for await (const event of streamTurnEvents(input)) handle(event);\n      return;\n    } catch (err) {\n      if (/^(429|5\\d\\d)/.test(err.message) && i < attempts - 1) {\n        await delay(1000 * 2 ** i);\n        continue;\n      }\n      throw err;\n    }\n  }\n}","preventionTips":["Health-check the runtime before opening SSE connections.","Use exponential backoff for 429/5xx instead of tight reconnect loops.","Rotate auth tokens before expiry so streams are not rejected mid-operation.","Confirm the runtime URL/port in configuration matches the deployed runtime."],"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"}