Skip to content

fix(embedded-runner): flush partial streaming output before run budget abort - #116253

Merged
obviyus merged 5 commits into
openclaw:mainfrom
SunnyShu0925:fix/run-timeout-progress-grace-113182
Aug 20, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
SunnyShu0925:fix/run-timeout-progress-grace-113182

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

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_end finalization. Settlement raced the aborted signal while joining queued subscription events, so it could return before a queued message_update reached the assistant buffer. The final result therefore had no assistant text even though Telegram had already rendered a streaming preview.

Fix

  • Keep the hard run budget unchanged.
  • Let terminal settlement own timeout salvage: drain the serialized event queue with a bounded deadline, re-read canonical terminal ownership, then publish buffered visible text only for a failure-free run-budget timeout.
  • Exclude external partial-reply callbacks from the timeout-critical drain; they cannot mutate the assistant buffer and may be transport-stalled.
  • Reconcile cumulative buffered text with live chunks, commentary/reasoning filtering, queued suffixes, sanitizer retractions, and a later authoritative message_end without duplication.
  • Preserve provider failures and external cancellation as non-salvage terminals.
  • Use one deadline helper and one configurable pending-event drain. No timeout marker protocol or parallel drain implementation.

Production delta against current main: +158/-38 (net +120), reduced from the prior head's net +299.

Evidence

Exact head: 5582959bf73f82021804c20d7ca5ff9922e10427

Regression and local proof

  • Current-main real Telegram reproduction: streaming preview contained QA streaming preview in progress; run-budget abort then produced an empty final assistant result and replaced the visible reply with the timeout error.
  • Owner-boundary red proof: removing only settlement's final timeout publication call makes drains queued events after a run-budget abort before re-flushing partial assistant text fail with received ["pending-event-chain"], expected ["pending-event-chain", "flush-partial"].
  • Focused Vitest: 19 files, 285 tests passed.
  • git diff --check origin/main...HEAD: passed.
  • Oxfmt check on all changed TypeScript files: passed.
  • Type-aware Oxlint on all changed TypeScript files: passed with zero warnings.
  • pnpm tsgo: passed.
  • pnpm check:test-types: passed.

Exact-head review and CI

  • Local ClawSweeper (gpt-5.6-terra, high): correct patch; 0 findings; 0 security concerns; no maintainer decision; 0 Rank-up moves.
  • Hosted CI: 207 passed, 0 pending, 0 failing. openclaw/ci-gate passed.
  • Review threads: none.

Telegram E2E

  • Exact-head run: 5582959bf73f82021804c20d7ca5ff9922e10427.
  • Canonical $telegram-e2e-userbot DM recipe exercised partial streaming with agents.defaults.timeoutSeconds=1.
  • Raw stream emitted QA streaming preview in progress before embedded run timeout; terminal assistant_message_end carried empty rawText.
  • Telegram retained the streamed partial exactly once, then delivered the timeout guidance as a separate message.
  • Recording completed with 2 SUT messages, 2 typing events, and 3 mock-provider requests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 30, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/run-timeout-progress-grace-113182 branch from 5028b8f to f18f08e Compare July 30, 2026 05:39
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 30, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 20, 2026, 4:33 AM ET / 08:33 UTC.

ClawSweeper review

What this changes

The PR drains queued embedded-runner stream events after a run-budget timeout and preserves already-visible assistant text in the final result.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep 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
Reviewed head: 5582959bf73f82021804c20d7ca5ff9922e10427

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real behavior evidence is useful, but an empty-terminal correctness defect blocks merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides a real Telegram after-fix trace on a production-identical predecessor and records that the final exact-head Telegram gate was unavailable because the shared pool was exhausted.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides a real Telegram after-fix trace on a production-identical predecessor and records that the final exact-head Telegram gate was unavailable because the shared pool was exhausted.
Evidence reviewed 6 items Current main behavior: Current main joins pending events with the run abort signal and then settles without a partial-text flush, so the requested behavior is not already implemented.
Proposed timeout owner: The PR adds a queue-only bounded drain, re-reads terminal ownership, and calls the subscription flush only for a failure-free run-budget terminal.
Empty-terminal reconciliation defect: The new reconciliation branch only replaces the salvaged segment when terminal text is nonempty; an empty authoritative message_end leaves the prior partial segment in assistantTexts.
Findings 2 actionable findings [P2] Clear salvaged text on an empty terminal result
[P3] Remove review-priority prose from regression comments
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts

Result: FAIL (partial) — step 2 expect_output drains queued events after a run-budget abort before re-flushing partial assistant text: expected terminal output was not visible within 30 seconds: "drains queued events after a run-budget abort before re-flushing partial assistant text"

node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-116253-XMraYq/target$ node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.
test.ts
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts
[test] starting test/vitest/vitest.agents-embedded-agent-run.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-116253-XMraYq/target

 ✓  agents-embedded-agent-run  src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts (14 tests) 208ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  08:34:37
   Duration  15.95s (transform 12.59s, setup 989ms, import 14.40s, tests 208ms, environment 0ms)

[test] passed 1 Vitest shard in 21.89s
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-116253-XMraYq/target$ node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.
test.ts
[test] starting test/vitest/vitest.agents-embedded-agent-run.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-116253-XMraYq/target

 ✓  agents-embedded-agent-run  src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts (14 tests) 213ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  08:34:59
   Duration  7.35s (transform 4.06s, setup 453ms, import 6.45s, tests 213ms, environment 0ms)

[test] passed 1 Vitest shard in 13.20s
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-116253-XMraYq/target$




















Assertions:

  • FAIL expect_output: drains queued events after a run-budget abort before re-flushing partial assistant text

How this fits together

The 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]
Loading

Before merge

  • Clear salvaged text on an empty terminal result (P2) - When timeout salvage has set hasFlushedPartialText, an authoritative message_end with empty text skips this branch. Lifecycle cleanup then clears the flag but leaves the salvaged segment in assistantTexts, so a retracted/empty final result is reported as stale partial output. This was also visible on the prior review of this same head.
  • Remove review-priority prose from regression comments (P3) - P1 is review metadata rather than durable behavioral context. Remove it here and from the matching retraction comment at line 2088, as the previous review requested.
  • Resolve merge risk (P2) - An authoritative empty terminal message can leave timeout-salvaged text in the final assistant result, misrepresenting the provider’s final output.
  • Resolve merge risk (P2) - This bug fix adds production +158/-38 lines (net +120), so the reconciliation should remain centralized in the existing reply-delivery owner rather than adding another timeout-specific state path.

Findings

  • [P2] Clear salvaged text on an empty terminal result — src/agents/embedded-agent-subscribe.reply-delivery.ts:242-246
  • [P3] Remove review-priority prose from regression comments — src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.subscribeembeddedagentsession.test.ts:1989-1990
Agent review details

Security

None.

PR surface

Source +121, Tests +729. Total +850 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 12 159 38 +121
Tests 6 732 3 +729
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 891 41 +850

Review metrics

Metric Value Why it matters
Production versus test LOC production +158/-38 (net +120); tests/test support +730/-3 The bug fix materially expands the timeout and reply-delivery state path, so the canonical reconciliation boundary matters before merge.

Merge-risk options

Maintainer options:

  1. Repair terminal reconciliation before merge (recommended)
    Clear the salvaged segment when message_end is empty, cover that path with a regression test, and remove the remaining review-priority comments.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Update timeout-salvage reconciliation so an authoritative empty message_end clears the salvaged segment; add focused regression coverage and remove P1 review-priority prose from the two test comments.

Technical review

Best 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:

  • [P2] Clear salvaged text on an empty terminal result — src/agents/embedded-agent-subscribe.reply-delivery.ts:242-246
    When timeout salvage has set hasFlushedPartialText, an authoritative message_end with empty text skips this branch. Lifecycle cleanup then clears the flag but leaves the salvaged segment in assistantTexts, so a retracted/empty final result is reported as stale partial output. This was also visible on the prior review of this same head.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.
  • [P3] Remove review-priority prose from regression comments — src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.subscribeembeddedagentsession.test.ts:1989-1990
    P1 is review metadata rather than durable behavioral context. Remove it here and from the matching retraction comment at line 2088, as the previous review requested.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 68ae235318c0.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body provides a real Telegram after-fix trace on a production-identical predecessor and records that the final exact-head Telegram gate was unavailable because the shared pool was exhausted.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The PR addresses loss or corruption of visible assistant output during active agent runs.
  • merge-risk: 🚨 session-state: The patch changes the terminal commit and replacement rules for buffered assistant text.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body provides a real Telegram after-fix trace on a production-identical predecessor and records that the final exact-head Telegram gate was unavailable because the shared pool was exhausted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a real Telegram after-fix trace on a production-identical predecessor and records that the final exact-head Telegram gate was unavailable because the shared pool was exhausted.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.subscribeembeddedagentsession.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-finalize.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Authored the recent embedded subscription and block-state refactor that shaped this owner boundary. (role: embedded-subscription refactor author; confidence: high; commits: d54d0b4a8033; files: src/agents/embedded-agent-runner/run/attempt-settle.ts, src/agents/embedded-agent-subscribe.ts)
  • Vyctor H. Brzezowski: Current-main blame attributes the pending-event settlement and reply-delivery lines to the recent commit 916eef4. (role: recent current-main line carrier; confidence: medium; commits: 916eef4e9960; files: src/agents/embedded-agent-runner/run/attempt-settle.ts, src/agents/embedded-agent-subscribe.reply-delivery.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Clear salvaged text for an empty authoritative message_end and add the focused regression.
  • Remove the two review-priority references from regression comments.
  • After changing terminal behavior, capture a fresh redacted runtime trace covering the repaired empty-terminal path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-18T06:10:04.691Z sha 01c7210 :: needs changes before merge. :: [P2] Clear the flushed segment for an empty terminal result
  • reviewed 2026-08-18T06:30:54.935Z sha 01c7210 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-20T07:48:49.062Z sha 2fff8a7 :: needs changes before merge. :: [P3] Remove review-cycle prose from regression comments
  • reviewed 2026-08-20T08:09:33.656Z sha 5582959 :: needs changes before merge. :: [P3] Remove review-priority prose from regression comments

@SunnyShu0925
SunnyShu0925 force-pushed the fix/run-timeout-progress-grace-113182 branch from f18f08e to 497814e Compare July 30, 2026 06:55
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 30, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/run-timeout-progress-grace-113182 branch from 72ef084 to 1d17bbe Compare July 30, 2026 07:52
@SunnyShu0925 SunnyShu0925 changed the title fix(embedded-runner): slide run budget deadline on progress, bounded by proportional grace fix(embedded-runner): grant streaming grace to in-flight model output before run budget abort Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 30, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/run-timeout-progress-grace-113182 branch from 1d17bbe to cfa694d Compare July 30, 2026 10:37
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

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
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: run-budget timeout discards buffered visible assistant text on the generic embedded runner

3 participants