Hmbown/CodeWhale · error
${compactRuntimeError(response.status, body)}
Error message
${compactRuntimeError(response.status, body)} What it means
streamTurnEvents opens an SSE connection to the runtime and throws when the HTTP response status is not OK. The message is produced by compactRuntimeError(status, body), which folds the status code and any error details from the JSON body into a single compact string. This surfaces runtime-side failures (auth, bad request, server error) at the point of streaming instead of producing confusing downstream parse failures.
Solutions
- Read the status and body in the error message; fix the indicated cause (401/403 → fix credentials, 404 → fix runtimeUrl, 5xx → check the runtime server logs).
- Verify the runtime service is running and the configured runtimeUrl/host/port is correct.
- Regenerate or update the auth token used by authHeaders().
Example fix
// before TELEGRAM_BRIDGE_RUNTIME_URL=http://localhost:9000 # runtime actually on 8080 // Error: 404 ... // after TELEGRAM_BRIDGE_RUNTIME_URL=http://localhost:8080
Defensive patterns
Strategy: try-catch
Validate before calling
// Preflight the runtime before streaming:
const base = process.env.TELEGRAM_BRIDGE_RUNTIME_URL;
const res = await fetch(`${base}/health`);
if (!res.ok) throw new Error(`Runtime not ready: HTTP ${res.status}`); Try / catch
try {
for await (const event of streamTurnEvents(input)) {
handle(event);
}
} catch (err) {
const m = /^(\d{3})/.exec(err.message);
if (m && ["401", "403"].includes(m[1])) {
await reauthenticate(); // refresh token and retry once
} else if (m && m[1].startsWith("5")) {
await delay(1000); // transient server error: retry with backoff
} else {
throw err;
}
} Prevention
- Health-check the runtime before opening SSE streams.
- Rotate auth tokens on a schedule shorter than their expiry.
- Pin bridge and runtime versions so endpoint paths stay compatible.
- Alert on 5xx rates from the runtime service.
When it happens
Trigger: The fetch of the turn-events SSE endpoint resolves but response.ok is false — e.g. 401/403 from missing or stale auth headers, 404 from a wrong runtimeUrl, or 5xx from the runtime process.
Common situations: Runtime server not running or listening on a different port than configured, expired/incorrect API credentials, reverse proxy returning 502/503, or an API version mismatch changing the endpoint path.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- ${compactRuntimeError(response.status, body)}
- ${compactRuntimeError(response.status, body)}
- ${compactRuntimeError(response.status, body)}
- ${compactRuntimeError(response.status, result)}
- Stream read error
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/8de1c4964491b3fc.
Report an issue: GitHub.
Appendix: source
Thrown at integrations/telegram-bridge/src/index.mjs:629
}
};
const typingTimer = setInterval(() => {
void tickTyping();
}, TYPING_INTERVAL_MS);
typingTimer.unref?.();
try {
void tickTyping();
const response = await fetch(
`${config.runtimeUrl}/v1/threads/${encodeURIComponent(threadId)}/events?since_seq=${sinceSeq}`,
{
headers: authHeaders(),
signal: controller.signal
}
);
if (!response.ok) {
const body = await readJsonSafe(response);
throw new Error(compactRuntimeError(response.status, body));
}
for await (const event of readSse(response)) {
if (!event.data) continue;
const record = JSON.parse(event.data);
latestSeq = Math.max(latestSeq, Number(record.seq || 0));
await flushLastSeq(false);
if (turnId && record.turn_id && record.turn_id !== turnId) continue;
const lifecycleStatus =
record.event === "turn.lifecycle"
? record.payload?.turn?.status || record.payload?.status
: null;
const stopTypingEvent =
record.event === "turn.completed" ||
["failed", "canceled", "interrupted"].includes(lifecycleStatus);
if (typingPaused && record.event !== "approval.required" && !stopTypingEvent) {
typingPaused = false;View on GitHub (pinned to 433685b202)