{"record":{"id":"0f969b06f65276f7","repo":"diegosouzapw/OmniRoute","slug":"failed-to-parse-stage-response-as-json","errorCode":null,"errorMessage":"Failed to parse stage response as JSON","messagePattern":"Failed to parse stage response as JSON","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"open-sse/services/autoCombo/pipelineRouter.ts","lineNumber":174,"sourceCode":"\n    // Intermediate stage: buffer and extract text\n    if (!response.ok) {\n      const errorText = await response.text().catch(() => \"unknown error\");\n      log.warn(\"PIPELINE\", `Stage returned ${response.status}: ${errorText.slice(0, 200)}`);\n      return { text: \"\" };\n    }\n\n    try {\n      const json = await response.json();\n      // OpenAI chat completions format: choices[0].message.content\n      const content = json?.choices?.[0]?.message?.content;\n      if (typeof content === \"string\") {\n        return { text: content };\n      }\n      // Fallback: try to extract any text field\n      return { text: JSON.stringify(json) };\n    } catch {\n      log.warn(\"PIPELINE\", \"Failed to parse stage response as JSON\");\n      return { text: \"\" };\n    }\n  };\n}\n\n// ---------------------------------------------------------------------------\n// Token estimation\n// ---------------------------------------------------------------------------\n\n/**\n * Rough token estimate from message content (4 chars ≈ 1 token).\n */\nfunction estimateTokens(messages: Array<{ role: string; content: unknown }>): number {\n  let total = 0;\n  for (const msg of messages) {\n    if (typeof msg.content === \"string\") {\n      total += Math.ceil(msg.content.length / 4);\n    } else if (Array.isArray(msg.content)) {","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/open-sse/services/autoCombo/pipelineRouter.ts#L156-L192","documentation":"Error \"Failed to parse stage response as JSON\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at open-sse/services/autoCombo/pipelineRouter.ts:174 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}