fix(agents): detect truncated API responses to prevent silent session hang#89160
fix(agents): detect truncated API responses to prevent silent session hang#89160joelnishanth wants to merge 2 commits into
Conversation
|
Codex review: found issues before merge. Reviewed June 1, 2026, 7:49 PM ET / 23:49 UTC. Summary PR surface: Source +55, Tests +148, Config 0. Total +203 across 4 files. Reproducibility: Do we have a high-confidence way to reproduce the issue? Partly: the linked report and proof screenshot demonstrate an Ollama Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Preserve native provider length termination at the Ollama stream boundary, remove the committed proof image, keep the runner guard as a generic safety net, and land only after maintainer acceptance of the fail-closed liveness behavior. Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? Partly: the linked report and proof screenshot demonstrate an Ollama Is this the best way to solve the issue? Is this the best way to solve the issue? No; the runner guard is a useful safety net, but the best fix must also preserve the provider's native length terminal signal and get maintainer acceptance for the fail-closed lifecycle change. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 086274fd7e7a. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +55, Tests +148, Config 0. Total +203 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
… hang (openclaw#89051) Co-authored-by: Cursor <cursoragent@cursor.com>
a392986 to
5721545
Compare
Real Behavior Proof: Live Ollama Truncation DetectionTested against a real Ollama instance ( Screenshot: Live proof execution (real Ollama API)What was proven
Unit Tests (242 passing)
|

Summary
Fixes #89051 — embedded agent sessions silently hanging after a truncated API response with no error logging or recovery.
Root cause: When an API stream ends without a proper
finish_reason(or withstopReason: "length"), and the last assistant message contains incomplete/unsigned thinking blocks,resolveIncompleteTurnPayloadTextbails early at thepayloadCount > 0guard. This causes the run loop to treat the truncated turn as a successful completion, returninglivenessState: "working"with no further API calls, no error logs, and no recovery path.Fix: Adds a
isTruncatedTerminalAssistantTurndetector that identifies truncated responses (missing/length stopReason + incomplete-thinking assessment fromassessLastAssistantMessage). This detector:payloadCount > 0short-circuit inresolveIncompleteTurnPayloadText— truncated responses now surface the incomplete-turn error even when partial text was streamed (parallel to existingtoolUseTerminalguard from [Bug] Agent tool-chain final text segments silently dropped — invisible to user and next-turn context #76477)Changes
src/agents/embedded-agent-runner/run/incomplete-turn.ts: NewisTruncatedTerminalAssistantTurnexport + wired intoresolveIncompleteTurnPayloadTextas a bypass guardsrc/agents/embedded-agent-runner/run.ts: Import + log.warn when truncation is detected before the success exit pathsrc/agents/embedded-agent-runner/run.incomplete-turn.test.ts: 9 new tests (6 unit + 2 integration-level + 1 end-to-end viarunEmbeddedAgent)Test plan
payloadCount > 0+ truncated response = error surfaced (previously returned null)runEmbeddedAgent: truncated Ollama response with partial streamed text = error payload + warn log (previously silent success)pnpm tsgo)Real behavior proof (required for external PRs)
done_reason: "length") with no error, no log, and no recovery.npx tsx proof-89051.tswhich calls the real Ollama/api/chatendpoint withnum_predict: 3to force a truncated response (done_reason: "length"), then feeds the real API response through the patchedisTruncatedTerminalAssistantTurnandresolveIncompleteTurnPayloadTextfunctions.done_reason: "length", content: "The history of") andresolveIncompleteTurnPayloadTextreturns an error message instead ofnull. Before the fix, it returnednullcausing the session to hang silently. After the fix, it returns the error string andlog.warnfires with provider/model/stopReason details.stopReason: "length"behavior).stopReasonandassessLastAssistantMessageregardless of provider.Joel Nishanth | offlyn.AI