fix: detect mid-stream truncation and emit claude_truncated error code (FAR-95)

When Claude produces assistant content (output_tokens > 0) but the stream ends
without a result event, classify the run as truncated mid-stream rather than
falling through to the generic "did not produce a result — check API
credentials" message. The misleading hint pointed operators at auth/model
config when the real cause was pod termination, OOMKill, or CLI crash.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-26 01:54:35 +00:00
committed by Hugh Commit [agent]
parent 818aa0f1d6
commit a2874c0426
4 changed files with 104 additions and 0 deletions
+12
View File
@@ -1367,6 +1367,18 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
resultJson: { stdout },
};
}
if (parsedStream.truncatedMidStream) {
const exitHint = exitCode === null ? "no exit code" : `exit code ${exitCode}`;
const modelHint = parsedStream.model ? ` (model: ${parsedStream.model})` : "";
return {
exitCode,
signal: null,
timedOut: false,
errorMessage: `Claude run was truncated mid-stream${modelHint} — assistant produced content but no result event arrived (${exitHint}); pod may have been terminated, OOMKilled, or the CLI crashed`,
errorCode: "claude_truncated",
resultJson: { stdout },
};
}
return {
exitCode,
signal: null,