Skip to content

fix(tui): render delta-only assistant streams - #83000

Merged
steipete merged 3 commits into
openclaw:mainfrom
flashosophy:codex/delta-only-chat-projection
Jul 5, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
flashosophy:codex/delta-only-chat-projection

Conversation

@flashosophy

@flashosophy flashosophy commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #82988

What Problem This Solves

Fixes an issue where Gateway-backed and embedded TUI sessions could drop live assistant output when a runtime emitted incremental delta frames without also repeating the cumulative text snapshot. Users saw no progress until the final response, despite the runtime streaming correctly.

Why This Change Was Made

A shared live-chat input normalizer now accepts snapshot-only, delta-only, and combined assistant events before both TUI backends enter the existing sanitization, merge, suppression, and projection pipeline. The branch was rebased and rewritten on current main; unrelated dependency override and lockfile changes were removed.

User Impact

Streaming text appears incrementally in both normal Gateway TUI sessions and tui --local, including runtimes that emit canonical delta-only events. Commentary suppression, abort handling, buffer caps, and final-message behavior are unchanged.

Evidence

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server-chat.agent-events.test.ts src/gateway/server-chat.stream-text-merge.test.ts — 109 tests passed.
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.tui.config.ts src/tui/embedded-backend.test.ts — 43 tests passed.
  • Testbox-through-Crabbox tbx_01kwrjhsjn8geh91q5w6rnh5j3: real Gateway + real tmux TUI showed the first DELTA_ frame before the second frame arrived, then rendered DELTA_ONLY_VISIBLE while still streaming.
  • Testbox-through-Crabbox tbx_01kwrjhsjn8geh91q5w6rnh5j3: pnpm check:changed passed, including typechecks, lint, guards, and import-cycle checks.
  • .agents/skills/autoreview/scripts/autoreview --mode local --stream-engine-output — clean, no accepted/actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head e71d36c8820d073f43087d18976fb421915c81d6, but the PR head is now 69f985a06e2fe629fb2c8f9a33c7f85e2e59cfe5. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (8 earlier review cycles)
  • reviewed 2026-07-01T04:27:28.889Z sha 0429b7c9957fedaacb4d4b77f13090d411fbd4fd :: needs real behavior proof before merge. :: [P1] Revert the unrelated Pi dependency override
  • reviewed 2026-07-05T08:02:24.022Z sha c6a83a04f6c674f169992d8ff4c1a411f9b4b1c0 :: needs changes before merge. :: [P1] Sanitize delta streams after raw merge | [P3] Remove the release-owned changelog edit
  • reviewed 2026-07-05T08:08:55.934Z sha c6a83a04f6c674f169992d8ff4c1a411f9b4b1c0 :: needs changes before merge. :: [P1] Sanitize delta streams after raw merge | [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T11:07:07.058Z sha 005f0eef60f4e69840a3e1c44982b98a399ef9ca :: needs changes before merge. :: [P1] Sanitize delta streams after raw merge | [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T11:17:38.585Z sha ad94fc731e06047eb155b92160fb11f873e9df4c :: needs changes before merge. :: [P1] Sanitize delta streams after raw merge | [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T11:32:57.505Z sha fd5934e34e609183a47611ccaeedf204ee8ce1b1 :: needs changes before merge. :: [P1] Sanitize delta fragments after raw merge | [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T12:17:59.749Z sha 89858472524401f5a1e901cf089fa941038ccaec :: needs changes before merge. :: [P1] Merge delta-only chunks before display sanitizing | [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T13:04:23.959Z sha bc2c6d82a8112e7c50b7fd8945062dc27753551a :: needs changes before merge. :: [P1] Preserve protected block openers before raw capping | [P3] Remove the release-owned changelog entry

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels May 17, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels Jun 14, 2026
@steipete
steipete force-pushed the codex/delta-only-chat-projection branch from 0429b7c to c6a83a0 Compare July 5, 2026 07:46
@steipete steipete changed the title [codex] Fix delta-only assistant chat projection fix(tui): render delta-only assistant streams Jul 5, 2026
@steipete
steipete marked this pull request as ready for review July 5, 2026 07:46
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: XS and removed size: S labels Jul 5, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

💡 Codex Review

https://github.com/openclaw/openclaw/blob/c6a83a04f6c674f169992d8ff4c1a411f9b4b1c0/src/gateway/live-chat-projector.ts#L29-L31
P2 Badge Sanitize delta-only streams after merging fragments

When an assistant runtime emits only delta strings and the model echoes a protected runtime-context/directive block split across frames, this helper turns the missing snapshot into "", so both live chat callers sanitize each fragment before appending it. stripInternalRuntimeContext needs the begin/end markers in the same string; after a first fragment containing the begin marker is dropped, later fragments containing the secret body/end marker are appended to chatRunState.buffers/run.buffer and can be rendered in the TUI/final output. Please merge raw delta text first, or carry sanitizer state, before projecting delta-only streams.

ℹ️ 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".

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling extensions: anthropic channel: qa-channel Channel integration: qa-channel extensions: qa-lab extensions: memory-wiki extensions: codex size: XL labels Jul 5, 2026
@steipete
steipete force-pushed the codex/delta-only-chat-projection branch 2 times, most recently from ad94fc7 to fd5934e Compare July 5, 2026 11:24
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 5, 2026

@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: fd5934e34e

ℹ️ 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".

Comment on lines +29 to +31
return {
text: typeof record.text === "string" ? record.text : "",
delta: typeof record.delta === "string" ? record.delta : "",

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.

P2 Badge Sanitize delta-only chunks after merging

For delta-only streams, this returns each fragment with text: "", and both new callers run normalizeLiveAssistantEventText on that single fragment before appending it to the live buffer. When the model emits an inline directive or runtime-context delimiter split across deltas (for example [[reply_to_ then current]] hello, or split <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>> blocks), the stripping regexes never see the complete marker, so the TUI can render those raw control tokens during live streaming (and embedded local mode can keep them through final projection). Please preserve/merge the raw delta-only buffer first, then apply the existing display sanitizer to the merged text.

Useful? React with 👍 / 👎.

@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: f61fd39b8e

ℹ️ 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".

Comment thread CHANGELOG.md Outdated
@@ -43,6 +43,7 @@ Docs: https://docs.openclaw.ai
- **Control UI terminal tabs:** vertically center the new-session button in the terminal tab strip.
- **Control UI composer scrollbar:** show the message-field scrollbar only when the draft actually overflows its autosized height.
- **Control UI terminal cursor:** hide the browser-native contenteditable caret so the integrated terminal shows only its canvas-rendered cursor.
- **TUI streaming:** render delta-only assistant events in live Gateway and embedded TUI sessions instead of waiting for the final response. Thanks @flashosophy.

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.

P2 Badge Remove the manual changelog entry

This fix is not release-generation work, but the root AGENTS.md says CHANGELOG.md is release-only and must not be edited for normal PRs or direct fixes; release generation derives entries from merged PRs and direct commits. Leaving this hand-written entry can duplicate or conflict with the generated release notes, so move the release-note context to the PR/squash/direct-commit text and leave the changelog unchanged.

Useful? React with 👍 / 👎.

@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: 31aa4e25b1

ℹ️ 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".

Comment on lines 761 to 765
const mergedRawText = resolveMergedAssistantText({
previousText: previousRawText,
nextText: cleaned.text,
nextDelta: cleaned.delta,
nextText: text,
nextDelta: typeof delta === "string" ? delta : "",
});

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.

P1 Badge Preserve protected block openers before capping deltas

When a delta-only assistant stream opens an internal runtime-context block and that block grows past MAX_LIVE_CHAT_BUFFER_CHARS before the closing delimiter arrives, this now feeds the unsanitized raw delta into the capped merge buffer. resolveMergedAssistantText keeps only the tail, so the opening delimiter can be discarded before normalizeLiveAssistantBufferedText runs; after that the stripper no longer recognizes the protected block and can broadcast the private tail as chat text. This affects live Gateway streaming here and the same raw-buffer pattern in embedded TUI; keep unmatched protected blocks/cap after sanitizing visible text so large private blocks cannot leak mid-stream.

Useful? React with 👍 / 👎.

@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: 8161186730

ℹ️ 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".

Comment on lines +774 to +775
const normalizedText = normalizeLiveAssistantBufferedText(mergedRawText);
const projected = projectLiveAssistantBufferedText(normalizedText);

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.

P2 Badge Hold incomplete control markers before broadcasting

In a delta-only stream where a frame ends with an unfinished control marker such as [[reply_to_ or the first half of <<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>, this normalizes the incomplete buffer to the same text and the later delta path broadcasts it before the sanitizer can ever see the completed tag. The next frame may eventually replace the text, but live Gateway clients can still see raw directive/runtime-context marker fragments; this is fresh evidence after the merge-buffer change because the first unmatched fragment is sent before merge completion. Please keep unmatched directive/runtime-context prefixes pending until they either complete or are known to be normal text.

Useful? React with 👍 / 👎.

@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: 69f985a06e

ℹ️ 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".

Comment on lines 1098 to 1102
run.buffer = resolveMergedAssistantText({
previousText: run.buffer,
nextText: cleaned.text,
nextDelta: cleaned.delta,
nextText: assistantLiveChatInput.text,
nextDelta: assistantLiveChatInput.delta,
});

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.

P2 Badge Preserve final payload when raw deltas sanitize away

When local mode receives a delta-only assistant event that is entirely stripped from display (for example a runtime-context block or directive tag) and the command later resolves with the actual answer only in result.payloads, this assignment makes run.buffer truthy even though its normalized visible text is empty. The completion path only copies payloadText(result?.payloads) when !run.buffer, so emitChatFinal() normalizes the raw control-only buffer to empty and emits a final without the answer; before accepting delta-only events, that fallback still displayed the non-streamed final payload. Track visible text separately or fall back when the normalized buffer is empty.

Useful? React with 👍 / 👎.

@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway and embedded TUI ignore delta-only assistant events for live chat projection

2 participants