Repository navigation
Description
Verified against
988c0355bb05631e9c6c1785e443937ff2a88c0e (main, CLI v0.14.0), rechecked October 16, 2026. Reproduced with Node.js v22.22.2 on macOS.
What is broken
A connection reset after HTTP success headers is reported as malformed JSON (INTERNAL, exit 1). GET requests and writes carrying an idempotency key also skip their existing transport retry budget.
The shared HTTP client catches failures from readBoundedText() and JSON.parse() together at src/lib/http.ts:944-962. A native fetch body error such as TypeError: terminated therefore reaches malformedResponseError(), which incorrectly advises checking the API endpoint or a captive portal.
Reproduction
After npm ci and npm run build, run this from the repository root. It uses native fetch with an in-memory dispatcher: no external network, server, account, or real API key is required. The first response fails during body reading; the second is healthy.
node --input-type=module <<'NODE'
import { HttpClient } from './dist/lib/http.js';
let calls = 0;
const dispatcher = {
dispatch(_options, handler) {
calls += 1;
handler.onConnect(() => {});
handler.onHeaders(200, ['content-type', 'application/json'], () => {});
if (calls === 1) {
handler.onData(Buffer.from('{"ok":'));
setImmediate(() => handler.onError(
Object.assign(new Error('other side closed'), { code: 'UND_ERR_SOCKET' }),
));
} else {
handler.onData(Buffer.from('{"ok":true}'));
handler.onComplete([]);
}
return true;
},
};
const client = new HttpClient({
baseUrl: 'http://example.test/api/cli/v1',
apiKey: 'sk-user-repro',
sleep: async () => {},
fetchImpl: (url, options) => fetch(url, { ...options, dispatcher }),
});
try {
console.log(await client.get('/projects'));
} catch (error) {
console.log(JSON.stringify({
calls, code: error.code, exitCode: error.exitCode,
parseError: error.details?.parseError,
}));
}
NODEObserved:
{"calls":1,"code":"INTERNAL","exitCode":1,"parseError":"terminated"}The healthy second response is never requested. Moving the same socket failure before receipt of the headers uses the existing transport retry policy instead.
Expected behavior and impact
This GET should use its bounded transport retries, request the healthy second response, and return {"ok":true}. Exhausted transport retries should report UNAVAILABLE/exit 10. Recoverable response-body resets should not immediately fail commands with an unrelated endpoint-configuration diagnosis.
Writes with an idempotency key should retain the same safe retry policy. Keyless writes and retry: false must remain non-retriable. Genuine malformed JSON must retain its existing no-retry behavior.
Proposed scope
Separate body-read failures from JSON syntax failures and reuse the existing transport retry policy. Add mocked regression tests for recovery and retry exhaustion on GET/keyed writes, no retries on keyless writes or retry: false, and preservation of timeout, interruption, response-size, and malformed-JSON behavior. No new flags or runtime dependencies are needed.
This is separate from the genuine malformed-JSON handling in merged PR #166 and the presigned upload error-body timeout in #404.
Season 4 / contact
Intended for the Season 4 CLI Improvement Bonus. GitHub: @Davidson3556; please contact me on GitHub for coordination. I searched existing issues and PRs for this failure mode before filing.
Activity
Davidson3556 commentedon Oct 16, 2026
/assign
testsprite-hob commentedon Oct 16, 2026
Thanks for the interest, @Davidson3556! This issue hasn't been accepted for implementation yet — see the triage comment (a maintainer will label it
acceptedonce it is). Feel free to check back, or ping us on Discord if it's been quiet.Davidson3556 commentedon Oct 16, 2026
Superseded by #431 — same report, refiled through the Hackathon Improvement form so it carries the template labels. Please track it there.