Skip to content

fix: keep long replies streaming after tool traces and code fences - #172832

Merged
steipete merged 7 commits into
mainfrom
fix/streaming-visible-text-incremental
Oct 15, 2026
Merged

steipete merged 7 commits into
mainfrom
fix/streaming-visible-text-incremental

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #172629

What Problem This Solves

Fixes: long streamed replies containing an actual tool trace or fenced code repeatedly sanitize accumulated text, occupying the Gateway thread and delaying other sessions.

User Impact

Long trace-bearing and fenced-code replies reuse settled output while preserving the exact visible text at each stream boundary. No configuration changes or migration are required.

Why This Change Was Made

The earlier trace-head fix stopped activation on ordinary prose, but a real trace head still enabled whole-reply scrubbing. The plain-tool filter also repeatedly parsed growing fenced answers when payload markers appeared.

The existing text projection owner now retains only unresolved source and reuses settled output. Canonical line and tool-call scanners report source/output settlement boundaries. Proven open fences carry their opener without retaining their body; canonical Markdown ownership handles ambiguous syntax, reference definitions, and unfinished titles. Tool calls stay provisional while another suffix can change their output. Replacement/reset behavior stays with the existing projector, and the superseded block-marker latch path is removed.

Late image definitions can revoke inline-code protection, so their unresolved descriptions remain available. Unrelated citations or image references plus external inline code can settle. This is synchronous text projection: no detached effects, captured authority, schema changes, or new SDK contracts.

Evidence

  • Source/history confirmation on main 55147a0e6972: a real trace head permanently activates whole-reply sanitization, and the plain-tool activation path reparses accumulated code regions. Merged fix: streaming a reply that mentions tool calls no longer stalls the Gateway event loop #172631 and fix: avoid repeated scans while streaming citation replies #172470 leave these residuals documented.
  • bounds canonical work after $name counts regex input characters for real trace heads, repeated fenced payload markers, indented fences, earlier definitions, and completed citation/image paragraphs with unrelated inline code. The protected-payload scanner also has an indexed-character work bound. No timing assertions.
  • projects %s in token-sized chunks and matches the canonical strip while streaming %# compare every prefix at sizes 1, 3, and 7. Cases cover opening/closing fences, traces inside code, multiline inline code, CRLF, provisional JSON/XML suffixes, reference definitions before and after images, nested/escaped/code-owned brackets, unfinished link/definition titles, and replacement/reset behavior. Parser tests protect settlement offsets.
  • Changed-file oxfmt, oxlint --config .oxlintrc.json --tsconfig config/tsconfig/oxlint.core.json, and git diff --check pass. Deslop removed the superseded activation path; no unrelated cleanup or weakened checks. Isolated Codex autoreview through P2 resolved findings about reference context, protected-payload ordering, and nested image descriptions. The cloud P1 about unrelated references pinning output is fixed with deterministic regressions. Final committed-branch autoreview is scoped-clean through P2, with no accepted/actionable findings. Current main was merged without rebase before pushing; the reviewed patch stayed identical by stable patch ID, and all ten changed TypeScript files passed lint/format again.
  • First-head CI 38689513464 passed its streaming, type, lint, and UI lanes. Its sole failing execution lane, checks-node-compact-small-1, exposed missing wrapper inventory dependencies; the inventory now includes both imported Markdown helpers. The aggregate CI gate reflected that failure. Exact-head CI 38691084644 on 73aafb6c8f49029a188671d85ab7640bd9e7430a completed with 53 successful jobs. Its only failed execution lane is checks-node-compact-small-5-2: unchanged ci-node-test-plan.test.ts expects one planConcurrency === 2 job and receives zero. Baseline classification remains unconfirmed. The latest scheduled main run initially failed before tests on the known setup-go codeload 404. After the URL returned 200, a single main lane was retried (job 116279219483) and then cancelled after more than 20 minutes. Its completed log showed different packed runtime shards, not the planner test, so it is not inherited-failure evidence. Source inspection confirms this streaming diff does not affect the planner test's five fixed target inputs, but no matching scheduled-main failure is claimed. No PR test retry was used. The CI-planner failure requires separate triage before treating the aggregate gate as green.
  • Exact-head test logs confirm assistant-visible-text: 76/76 passed (runner wall time 3.64 s); plain-tool-call-text: 42/42 (4.57 s); tool-call-repair payload: 24/24 (1.82 s). Both original work bounds and the citation/image retention bounds passed. Types, lint, UI, and wrapper inventory checks passed.
  • PR CI is the test gate and covers the new regressions, sibling suites, types, lint, and selected integration lanes. Local tests/typechecks, production negative controls, and live Gateway/Crabbox/Testbox proof were intentionally skipped per maintainer policy. No leases or Gateway processes were started; no local test wall times are claimed.
  • Production +317/−79 (net +238); tests +221/−1 (net +220); wrapper inventory +2/−0; docs +0/−0. Production growth funds explicit canonical settlement, reference/fence context, and image-code ownership; unrelated deletions were not used to meet a line-count target.

Reuse settled visible text in the existing projection owner. Keep provisional tool calls and mutable Markdown with their canonical parsers, carrying fence and reference-definition context across stable boundaries. Add chunk parity and deterministic work-bound regressions for the remaining streaming rescans behind #172629.
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 15, 2026 05:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T06:14:05.820784Z 73aafb6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7de11989e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses settled visible text so tool traces and fenced code do not repeatedly trigger whole-reply sanitization.

Example: A reply starts with tool call: hidden, followed by 256 explanation lines streamed in four-character chunks.

  • Before: The trace activates repeated sanitization of the accumulated reply.
  • After: Settled output is reused while the trace remains hidden and explanation text remains visible.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with meaningful production-code harness coverage and no concrete finding; supplied proof does not establish end-to-end Gateway performance.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored exemption applies to the ordinary live-proof gate; evidence consists of CI regressions exercising the real projection and parser owners, with no shipped-entry-point performance capture claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Long replies containing tool traces or repeated fenced payload markers consume growing synchronous processing work and delay streaming.
Reason: The source-backed performance gap merits repair, and the supplied maintainer-authored status establishes direction without another product decision.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it addresses documented streaming-performance residuals still present on main, with no concrete introduced defect found; the failed CI gate needs classification before landing.

Priority: P2
Reviewed head: 73aafb6c8f49029a188671d85ab7640bd9e7430a

Before merge

  • Complete next step - Resolve the planner-capacity CI gate through a demonstrated repair or the repository's evidence-backed inherited-failure landing path.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Gateway streaming run or demonstrated base-failing negative control is supplied for the changed trace-bearing and fenced-code paths.
Agent review details

How this fits together

The shared text projector receives assistant text deltas, applies canonical visibility filters, and returns visible snapshots and append deltas to streaming consumers.

flowchart LR
  A[Assistant text deltas] --> B[Shared text projection]
  B --> C[Markdown ownership]
  C --> D[Canonical visibility filters]
  D --> E[Settled output and unresolved suffix]
  E --> F[Streaming reply consumers]
Loading

Technical review

Best possible solution:

Retain canonical filtering and mutable Markdown ownership while settling reusable output in the existing projection owner.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes repeated accumulated-text transforms after trace activation; no target code or benchmark was executed during this read-only review.

Is this the best way to solve the issue?

The approach fits the existing projection owner, preserves canonical scanners, and adds focused settlement and prefix-parity coverage without creating a competing sanitizer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 37e45ded12fc.

Provenance checked

  • Incremental text projection keeps the original intent (6c1dde5: Reuse incremental reply projections while retaining canonical transforms for activated syntax and replacements.)
  • Trace-head activation keeps the original intent (55147a0: Avoid prose-triggered rescans while preserving canonical trace grammar and code protection; activated-stream rescans were explicitly deferred.)
  • Protected block-marker activation changes intended behavior with a stated reason (59a60de: Retire payload tokens inside settled block code to avoid persistent sanitizer activation.)
  • Tool-call stripping and code protection keeps the original intent (a1c689e: Preserve literal code examples through an explicit canonical protected-range resolver while continuing to strip genuine leaked calls.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6c1dde5 adds src/shared/text/text-projection.ts:67 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6c1dde5291ad; files: src/shared/text/text-projection.ts)
  • Jason Cat: Raw commit 55147a0 adds src/shared/text/assistant-visible-text.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 55147a0e6972; files: src/shared/text/assistant-visible-text.ts)

PR surface

Source +238, Tests +220, Other +2. Total +460 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 317 79 +238
Tests 3 221 1 +220
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 11 540 80 +460

Review metrics

Metric Value Why it matters
Production versus test growth Production +317/-79; tests +221/-1 Production growth implements settlement boundaries and carried Markdown context; test growth covers output parity and bounded work.

Labels

Label changes:

  • add P2: The patch addresses deterministic excess streaming work for triggered long replies, without evidence of a current production outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The patch addresses deterministic excess streaming work for triggered long replies, without evidence of a current production outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 15, 2026, 2:59 AM ET / 06:59 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…penclaw#172832)

* fix: keep trace-bearing and fenced replies incremental

Reuse settled visible text in the existing projection owner. Keep provisional tool calls and mutable Markdown with their canonical parsers, carrying fence and reference-definition context across stable boundaries. Add chunk parity and deterministic work-bound regressions for the remaining streaming rescans behind openclaw#172629.

* fix: protect literal code before scanning tool payloads

* fix: retain ambiguous image and reference label prefixes

* fix: retain unfinished Markdown link and definition titles

* fix: settle unrelated references in streaming replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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]: streaming a reply that mentions a tool call in prose blocks the Gateway event loop for seconds (quadratic per-delta trace scrub)

1 participant