{"record":{"id":"eae2bc9af1b525db","repo":"decolua/9router","slug":"kiro-mitm-request-processing-failed-error-mes","errorCode":null,"errorMessage":"[Kiro MITM] Request processing failed: ${error.message}","messagePattern":"\\[Kiro MITM\\] Request processing failed: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/mitm/handlers/kiro.js","lineNumber":522,"sourceCode":"    const tools = extractTools(body);\n\n    const openaiBody = {\n      model: mappedModel,\n      messages,\n      stream: true,\n      // Forward tools so Claude uses structured tool_calls instead of XML text fallback\n      ...(tools.length > 0 && { tools, tool_choice: \"auto\" }),\n    };\n\n    // 3: Forward to 9router\n    const routerRes = await fetchRouter(openaiBody, \"/v1/chat/completions\", req.headers);\n\n    // 4 + 5: Re-encode response as AWS EventStream binary using standard pipeline\n    const state = initKiroState(mappedModel);\n\n    await pipeTransformedEventStream(routerRes, res, convertOpenAIToKiro, state);\n  } catch (error) {\n    err(`[Kiro MITM] Request processing failed: ${error.message}`);\n    if (!res.headersSent) {\n      res.writeHead(500, { \"Content-Type\": \"application/json\" });\n    }\n    res.end(JSON.stringify({ \n      error: { \n        message: error.message, \n        type: \"mitm_error\",\n        handler: \"kiro\"\n      } \n    }));\n  }\n}\n\n// Detect AWS EventStream binary format\nfunction isBinaryEventStream(buffer) {\n  if (!buffer || buffer.length < 12) return false;\n  // AWS EventStream signature: \n  // - First 4 bytes: total frame length (big-endian)","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/mitm/handlers/kiro.js#L504-L540","documentation":"The Kiro MITM handler forwards requests to the router and re-encodes the OpenAI SSE response into AWS EventStream binary via pipeTransformedEventStream. Any failure (router fetch, OpenAI→Kiro conversion, EventStream encoding) is logged '[Kiro MITM] Request processing failed: <message>' and returned as a 500 JSON error to the Kiro client.","triggerScenarios":"intercept() throws during JSON parsing of the Kiro binary request, router call fails, or convertOpenAIToKiro/EventStream re-encoding encounters an unexpected chunk shape mid-stream.","commonSituations":"Kiro IDE pointed at the MITM host while the gateway is down; Kiro client updated its EventStream framing; a model mapping missing for the requested Kiro model.","solutions":["Confirm the 9Router gateway is running and reachable at the configured router port.","Read the logged failure message: encoding errors usually mean a Kiro client/protocol update — update 9Router.","Verify the requested model exists in the Kiro model map / provider config.","Retry; if it fails mid-stream repeatedly, capture the dump file and compare against a working request."],"exampleFix":"// before: protocol mismatch\nconvertOpenAIToKiro throws on unknown event shape → Request processing failed\n// after\nnpm update 9router  # pull updated Kiro EventStream translation","handlingStrategy":"try-catch","validationCode":"const health = await fetch('http://127.0.0.1:20128/dashboard').then(r => r.ok).catch(() => false);\nif (!health) throw new Error('Router gateway not reachable');\nif (!modelMap[kiroModel]) throw new Error(`No model mapping for ${kiroModel}`);","typeGuard":null,"tryCatchPattern":"try {\n  const state = initKiroState(mappedModel);\n  await pipeTransformedEventStream(routerRes, res, convertOpenAIToKiro, state);\n} catch (error) {\n  err(`[Kiro MITM] Request processing failed: ${error.message}`);\n  if (!res.headersSent) res.writeHead(500, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({ error: { message: error.message, type: 'mitm_error' } }));\n}","preventionTips":["Keep Kiro model mappings current with the Kiro IDE's requested model ids.","Update 9Router when Kiro changes its EventStream framing.","Validate gateway health before starting the MITM listener.","Retain dump files from failed requests for protocol debugging."],"tags":["mitm","kiro","eventstream","protocol"],"backgroundTag":"mitm-proxy-request-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}