Repository navigation
fix(embedded-runner): flush partial streaming output before run budget abort - #116253
Conversation
5028b8f to
f18f08e
Compare
|
Codex review: needs changes before merge. Reviewed August 20, 2026, 4:33 AM ET / 08:33 UTC. ClawSweeper reviewWhat this changesThe PR drains queued embedded-runner stream events after a run-budget timeout and preserves already-visible assistant text in the final result. Merge readinessKeep open: the exact PR head still retains salvaged partial text when a later authoritative terminal message is empty, and the prior comment-cleanup finding remains unresolved. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherThe embedded runner receives provider stream events, buffers visible assistant text, and settles the run into a final agent result for delivery. This change adds timeout-time queue draining and buffered-text reconciliation before that result is finalized. flowchart LR
A[Provider stream] --> B[Embedded runner]
B --> C[Serialized event queue]
C --> D[Assistant text buffer]
E[Run-budget timeout] --> F[Terminal settlement]
F --> C
F --> D
D --> G[Final assistant result]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +121, Tests +729. Total +850 across 18 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Make the existing reply-delivery reconciliation replace or clear the flushed segment for every authoritative message_end, add the empty-terminal regression, and remove review-priority wording from the durable test comments. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: flush a visible partial, then emit an authoritative empty message_end; the new nonempty-only reconciliation branch leaves the stale partial in assistantTexts. Is this the best way to solve the issue? No: the PR handles nonempty terminal replacement but not terminal retraction; the existing reply-delivery reconciliation should own both outcomes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 68ae235318c0. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
f18f08e to
497814e
Compare
72ef084 to
1d17bbe
Compare
1d17bbe to
cfa694d
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…t abort When an embedded-agent run hits its run-budget deadline mid-answer, the half-typed reply is no longer thrown away: the visible text already streamed is preserved, and any final text still waiting in the delivery queue behind the abort is drained and committed exactly once. - `attempt-timeout-prepare.ts`: no longer commits partial output before abort — it marks the run-budget terminal and aborts; the timeout callback never mutates `assistantTexts` (terminal ownership is not final yet). - `embedded-agent-subscribe.ts`: `flushPartialAssistantText` commits the buffered visible text; a committed segment (live block chunks and/or an earlier flush) is replaced by the refreshed cumulative visible text (exactly-once for multi-chunk streams, queued suffixes, sanitizer retractions); the raw buffer is retained so an unclosed hidden tag keeps hiding queued continuations; `message_end` replaces the flushed partial with the complete text; commentary-phase bytes are never committed. - `attempt-settle.ts`: for the run-budget timeout terminal the settle phase drains with `joinWithBoundedDeadline` (no abort-signal race) and re-reads the terminal AFTER the queue is quiescent: the salvage requires the terminal to be run-budget-owned AND failure-free, so an external abort or a provider failure attached while draining discards the buffered text. If the run-budget timer fires while the initial abort-aware join is still pending, the abort resolves that join without draining — the settle phase re-reads the terminal afterwards and runs the bounded drain before the salvage flush. The bounded timeout drain uses a queue-only drain (`waitForPendingEventChain`) — only the serialized event chain whose handlers can mutate the assistant text buffer — not the broad `waitForPendingEvents` join, which also awaits `pendingPartialReplyTasks` (asynchronous `onPartialReply` delivery callbacks that cannot change the buffered text). A stalled transport callback must not hold an already-aborted run in settlement for the 120s liveness deadline. Ordinary terminal delivery still uses the broad join. Both bounded-drain selection points (the initial entry check and the post-abort re-drain) are gated on a failure-free run-budget terminal via `isFailureFreeRunBudgetTimeout` (`timedOutByRunBudget && !failed`): a run-budget timeout terminal that already carries a provider failure settles immediately instead of waiting on the wedged serialized chain for the full liveness deadline, since partial output would be discarded by the flush gate anyway. - `attempt-finalize.ts` + `attempt-prompt-submit.ts`: the run-budget timeout's own abort is no longer classified as a provider failure. The timer aborts the run controller with a tagged timeout reason (`createTimeoutAbortReason`, marked with the `RUN_BUDGET_TIMEOUT_ABORT` symbol); `abortable()` wraps the rejected prompt as an `AbortError` whose `cause` is that reason. `handleEmbeddedAttemptPromptError` exempts such a timeout-owned abort wrapper (identified via `isOpenClawAbortableWrapper` + `isRunBudgetTimeoutAbortReason`) instead of attaching it as a `promptFailure` — otherwise the terminal would be `failed` and the failure-free salvage gate above would skip the drain and flush on the normal run-budget timeout path, silently dropping the buffered output the repair is meant to preserve. Real provider failures and external cancellations (non-timeout abort wrappers) still attach. - `abortable.ts`: `joinWithBoundedDeadline` — bounded join without the abort-signal short-circuit. - Tests: +30 regressions (aborted-signal drain ordering, cancellation- during-drain discard, queued-provider-failure discard, timeout- during-settlement re-drain, non-budget gating, live multi-chunk replacement, queued-suffix fold-in, hidden-tag context, sanitizer retraction, `message_end` replacement, commentary exclusion, timeout never commits before abort, bounded-deadline behavior, queue-only drain not blocked by a stalled partial-reply callback, failed-budget- terminal skipping the bounded drain when a provider failure is already attached before settlement chooses its join mode, run-budget timeout abort exempted from prompt-failure attachment, non-timeout abort wrappers still surfacing as prompt failures). ClawSweeper P1 fixes across six review rounds: terminal ownership, failure-free terminal gating (salvage flush and both bounded-drain selection points), timeout-during-settlement re-drain, queue-only drain separation, the pre-attached provider-failure entry-state regression, and the timeout-owned abort classification that keeps the normal run-budget timeout path failure-free so the salvage gate can run. Fixes openclaw#119935 Related to openclaw#113182
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
What Problem This Solves
Preserve visible assistant text when the generic embedded-agent run budget expires after streaming has begun.
Fixes #119935. Related: #113182 uses the separate Codex app-server path.
Root cause
The run-budget timer recorded a timeout and aborted the provider prompt before normal
message_endfinalization. Settlement raced the aborted signal while joining queued subscription events, so it could return before a queuedmessage_updatereached the assistant buffer. The final result therefore had no assistant text even though Telegram had already rendered a streaming preview.Fix
message_endwithout duplication.Production delta against current main:
+158/-38(net+120), reduced from the prior head's net+299.Evidence
Exact head:
5582959bf73f82021804c20d7ca5ff9922e10427Regression and local proof
QA streaming preview in progress; run-budget abort then produced an empty final assistant result and replaced the visible reply with the timeout error.drains queued events after a run-budget abort before re-flushing partial assistant textfail withreceived ["pending-event-chain"], expected["pending-event-chain", "flush-partial"].git diff --check origin/main...HEAD: passed.pnpm tsgo: passed.pnpm check:test-types: passed.Exact-head review and CI
gpt-5.6-terra, high): correct patch; 0 findings; 0 security concerns; no maintainer decision; 0 Rank-up moves.openclaw/ci-gatepassed.Telegram E2E
5582959bf73f82021804c20d7ca5ff9922e10427.$telegram-e2e-userbotDM recipe exercised partial streaming withagents.defaults.timeoutSeconds=1.QA streaming preview in progressbeforeembedded run timeout; terminalassistant_message_endcarried emptyrawText.