Repository navigation
fix: truncated OpenCode Go completions stream after tools reports a generic agent failure - #140367
Conversation
… failure OpenCode Go openai-completions can close an SSE after settled tools without finish_reason. Classify that as an incomplete assistant stream and keep pre-tool commentary from blocking settled-turn recovery.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 3:38 PM ET / 19:38 UTC. ClawSweeper reviewWhat this changesRecognizes truncated completions streams as retryable failures and allows existing tool-free summary recovery when completed tools were preceded only by commentary. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and v2026.9.2 still miss the completions-stream classification. The earlier finalization-gate finding is addressed, and no new blocking defect was found. Priority: P1 Review scores
Verification
How this fits togetherThe embedded agent runner turns provider responses and completed tool results into a final reply. Its recovery gates distinguish an unfinished answer from already-delivered output before requesting a tool-free summary. flowchart TD
A[Provider stream ends early] --> B[Classify incomplete response]
B --> C{Tools completed?}
C -->|No| D[Existing replay-safe retry policy]
C -->|Yes| E[Check answer and settlement guards]
E --> F[Tool-free finalization]
F --> G[Summary or honest fallback]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +71, Tests +178. Total +249 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep incomplete-stream handling in the shared classifier and reuse bounded, tool-free finalization while preserving existing settlement and delivery guards. Do we have a high-confidence way to reproduce the issue? Yes, from source: an incomplete completions response emits an error that main does not classify, and pre-tool commentary independently blocks recovery context. No runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes. The patch repairs the existing classification and both recovery gates without replaying completed tools, adding settings, or changing the transport's terminal contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 62fca0de772f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review Addressed the downstream finalization-gate finding in af5690c. Shared current-turn, exact-message commentary classification now reaches terminal preparation/finalization. Four full-path regressions and two attribution edge cases were reproduced failing before repair; 774 focused tests pass, targeted lint is clean, and fresh complete-candidate autoreview is scoped-clean through P2. PR Evidence now records commands, scope, production/test delta, and the remaining hosted-CI/environment limitations. Please review only; do not merge. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]>
…eneric agent failure (openclaw#140367) * fix: truncated completions streams after tools report a generic agent failure OpenCode Go openai-completions can close an SSE after settled tools without finish_reason. Classify that as an incomplete assistant stream and keep pre-tool commentary from blocking settled-turn recovery. * fix(agents): complete post-tool recovery after commentary * test(agents): narrow optional finalization fixture entry Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: VACInc <[email protected]> Co-authored-by: roboclaw-bot <[email protected]>
Related: #128368, #127538, #137887, #126404, #138645, #124176, #138204
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where users sending a follow-up in a Telegram topic session would see a generic
⚠️ Agent run failed (model: opencode-go/glm-5.3).after the model had already run tools and delivered pre-tool commentary, when OpenCode Go's openai-completions SSE closed withoutfinish_reasonor[DONE].The sibling user-visible copy
The tool run finished, but no final summary was produced. I did not repeat any completed actions.is the intentional host fallback after settled tools when isolated finalization is empty. This incident never reached that path: the truncated stream was unclassified, and pre-tool commentary was treated as if the turn had already composed a final answer.Why This Change Was Made
Classify the completions-transport producer string
Stream ended without finish_reasonas the same incomplete assistant-stream timeout already used for Mistral/Bedrock/Anthropic/Google/OpenAI Responses. After tools have settled, capture settled-turn finalization context for that failure even when commentary was delivered before the last tool result. Do not treat that commentary as a composed final answer. Do not classify the plugin lifecycle stringopencode-go stream ended without a terminal event(different owner, corpus forbids it).Without prior tools, the timeout classification lets replay-safe failover/retry use the same path as the sibling incomplete-stream producers. After tools (replay-unsafe), the host can attempt a tool-free summary instead of unclassified "Agent run failed". If that summary is also empty, the existing honest fallback remains.
User Impact
timeout) instead of an unclassified failure.opencode-go stream ended without a terminal eventbehavior is unchanged.Evidence
Live incident (redacted, 2026-09-06 UTC)
Telegram group topic session (chat IDs, user IDs, usernames, hostnames, and personal content omitted).
opencode-go/glm-5.3disabled configured fallbacks.openai-completions. Endpoint:https://opencode.ai/zen/go/v1/chat/completions.finish_reasonand no[DONE].Stream ended without finish_reason.failoverReason: null,providerRuntimeFailureKind: unclassified.⚠️ Agent run failed (model: opencode-go/glm-5.3).stopReason: error, 0 tokens.Why settled-turn recovery did not run:
resolveSettledTurnFinalizationContextonly treatedisTransientNetworkErroras eligible. Incomplete-stream text is not a network errno.assistantTextsomitted context. Pre-tool commentary ("checking post-reboot state…") filled that list even though no post-tool answer existed.Same-topic observations (not claimed as the same root cause)
glm-5.3cloud route returned HTTP 429 session usage limit (you have reached your session usage limit; account identifier redacted). Retries 1–9 then rate-limit user copy. Provider name was already log-redacted.Reply operation aborted by user).restart recovery claim changed before agent adoptionon the same topic (operational noise).Session transcript keyed user is outside the current turnonopenai/gpt-5.6-sol(separate defect).Classification contract
Producer in
packages/ai/src/transports/openai-completions-stream.tsstill throwsStream ended without finish_reason(tests already expect that string). Classification is the owner fix.Pre-fix
INCOMPLETE_ASSISTANT_STREAM_REmatch results:Stream ended without finish_reasontimeout)Mistral stream ended without a terminal finish reasonBedrock stream ended before messageStopopencode-go stream ended without a terminal eventLocal proof
attempt-result, settled-turn context (includingincomplete-completions-streamcapture), failover corpus (639), retry freeze. Exit 0.node scripts/check-changed.mjson the six touched files: exit 0 (core + coreTests), including tsgo and oxlint.git diff --check: clean.--mode local --base origin/main --max-priority P1) reported three P1s insrc/cli/update-cli/*andsrc/commands/doctor-update.ts. Those files are not in this diff. Rejected as out of scope / wrong-patch hallucination.Review follow-up (2026-09-06)
Runtime repair:
af5690cec24d51b189229d7d5f086265eed3c67f; final head:43b605dc99d6ba5520922a25f5d3ceb2ba666c44.Addressed ClawSweeper’s P2: context capture and the synthetic terminal-provider-error gate now use the same commentary-aware classifier. Matching is restricted to the current user turn and exact whole commentary messages; prior-turn text and substring collisions cannot hide a composed answer. The tool-warning gate remains blank-text-only; settlement, cancellation, async work, delivered replies/media, explicit silence, refusals, and structured errors retain their existing guards.
Regression proof uses real attempt-result projection through terminal preparation and isolated finalization. Four cases failed before repair with
not-attemptedand pass afterward: thrown versus assistant-reported truncated streams, each with a returned summary or empty-finalizer honest fallback. Separate historical-text and current-commentary-substring regressions also failed before their repairs. Finalization requests keep tools disabled and retain the settled attempt.Validation:
node scripts/run-vitest.mjson those six files; final affected scopes rerun after refinements.node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json: 0 warnings/errors; formatting andgit diff --checkclean.Proof limitations: no new live Telegram/provider run. Testbox warmup was blocked by missing host authentication. Local full changed checks hit the pinned pnpm package-age restriction; standalone typechecking rejected shared dependency links. Neither safeguard was changed. Exact-head hosted CI subsequently passed on
43b605dc99d6ba5520922a25f5d3ceb2ba666c44: run 34055207990, including the requiredopenclaw/ci-gate.Related work (do not close as duplicates)
These overlap recovery, GLM, or truncated streams, but they do not own this completions
finish_reasonclassification gap:finalizeSettledTurn→ host fallback. Overlaps the fallback copy, not the unclassified completions throw.sessions_yield.<tool_call>shadow text still reaches chat. GLM-related, different defect.finish_reason(closed; different owner).NO_REPLYissues that mention the same fallback sentence ([Bug]: 2026.8.2 delivers the synthesized "no final summary was produced" fallback for cron jobs that deliberately end with NO_REPLY after tool calls (2026.8.1 stayed silent) #135658, [Bug]: NO_REPLY silence is defeated by settled-turn fallback — agentTurn cron announces a placeholder on every healthy run #137024, [Bug]: Failed cron command followed by NO_REPLY announces a fallback and records succeeded on 2026.9.1 #139253) are heartbeat/cron silence, not this truncated-stream path.No existing open PR classifies
Stream ended without finish_reason.Test plan
Stream ended without finish_reasonastimeoutand still leavesopencode-go stream ended without a terminal eventunclassified43b605dc99d6ba5520922a25f5d3ceb2ba666c44(run 34055207990; requiredopenclaw/ci-gatepassed)CI and review follow-up
ClawSweeper refreshed again at 19:38 UTC on September 6, 2026 for exact final head
43b605dc99d6ba5520922a25f5d3ceb2ba666c44: ready for maintainer review, no actionable findings, no before-merge items. The test-only optional-entry narrowing correction (toolAssistant?.role) fixes the TypeScript failure in earlier CI run 34054819853, job 101544853652. Its 26-test file passes after correction. Final-head CI run 34055207990 completed successfully, including requiredopenclaw/ci-gatejob 101546748326. PR remains open and unmerged for the maintainer.Worked on by: