decolua/9router · error
AWS EventStream payload is not valid JSON (${error.message})
Error message
AWS EventStream payload is not valid JSON (${error.message}) What it means
After the header section, an EventStream frame's remaining bytes are the payload. parseEventFrame() decodes them as UTF-8 and expects JSON; if JSON.parse throws, it wraps the parse error message in this error. The frame arrived structurally intact (CRC checks passed) but its payload is not the JSON the Kiro executor expects.
Source
Thrown at open-sse/executors/kiro.js:1278
const bytes = data.subarray(offset, offset + valueLength);
headers[name] = type === 7 ? decoder.decode(bytes) : bytes;
offset += valueLength;
} else if (type === 9) {
requireBytes(16);
offset += 16;
} else {
throw new Error(`AWS EventStream header ${name} has unknown type ${type}`);
}
}
const payloadBytes = data.subarray(headerEnd, totalLength - 4);
if (payloadBytes.byteLength === 0) return { headers, payload: null };
const payloadText = decoder.decode(payloadBytes);
if (!payloadText.trim()) return { headers, payload: null };
try {
return { headers, payload: JSON.parse(payloadText) };
} catch (error) {
throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);
}
}
export default KiroExecutor;
View on GitHub (pinned to 90b52e06ff)
Solutions
- Log payloadText (not just error.message) to see what the upstream actually sent — it usually names the real problem (quota, auth, HTML error page)
- Retry the request; transient upstream error frames often contain non-JSON bodies
- Check account quota/auth state if the payload mentions throttling or credentials
- Update 9router in case Kiro changed its payload encoding and the parser was adapted
- Bypass intermediaries that could rewrite response bodies
Example fix
// before
try { return { headers, payload: JSON.parse(payloadText) }; }
catch (error) { throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`); }
// after (surface upstream text for diagnosis)
catch (error) {
console.error('eventstream payload:', payloadText.slice(0, 500));
throw new Error(`AWS EventStream payload is not valid JSON (${error.message})`);
} Defensive patterns
Strategy: try-catch
Try / catch
try {
await executor.execute(req);
} catch (e) {
if (String(e.message).includes('payload is not valid JSON')) {
// upstream sent a non-JSON frame payload; inspect and retry/fallback
return retryOnceThenFallback(req);
}
throw e;
} Prevention
- Log the decoded payload text on failure to identify the upstream's real message
- Monitor account quota/auth state — upstream error frames are often the root cause
- Keep the executor updated for payload-encoding changes
When it happens
Trigger: A Kiro EventStream frame whose payload bytes are not JSON — e.g. the upstream serializing an error/rate-limit notice as plain text inside a frame, an HTML error page fragment, or a binary payload variant.
Common situations: Kiro returns an internal error or throttle message as plain text; a proxy rewrites the payload bytes; a Kiro API change alters payload encoding.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- Cursor AgentService endpoint is not configured
- Kiro toolUseEvent is empty
- Kiro toolUseEvent is missing a tool name
- Kiro toolUseEvent has an invalid toolUseId
- Kiro tool name changed between fragments
AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30).
Data as JSON: /api/errors/50f14fd7a95f30c2.
Report an issue: GitHub.