Skip to content

fix: stream thinking output immediately#145

Closed
Huarong wants to merge 1 commit intoopenclaw:mainfrom
Huarong:codex/stream-thinking-output
Closed

fix: stream thinking output immediately#145
Huarong wants to merge 1 commit intoopenclaw:mainfrom
Huarong:codex/stream-thinking-output

Conversation

@Huarong
Copy link
Copy Markdown
Contributor

@Huarong Huarong commented Mar 16, 2026

Summary

This change makes text-mode thinking output render as soon as each agent_thought_chunk arrives, instead of buffering until the next non-thought update.

Problem

The text formatter currently accumulates thought chunks in thoughtBuffer and only flushes them when a later non-thought update or prompt result arrives. In practice this means thinking output appears blocked, even when the agent is streaming it incrementally.

Changes

  • render each incoming agent_thought_chunk immediately in text mode
  • remove the behavioral dependency on a later non-thought update before thought becomes visible
  • add a regression test proving that thought text is visible after the first chunk arrives

Why this should be separate

This PR only changes the output timing. It does not change thought formatting or whitespace handling.

Testing

  • ./node_modules/.bin/tsc -p tsconfig.test.json
  • node --test dist-test/test/output.test.js

@dutifulbob
Copy link
Copy Markdown
Collaborator

Triage result

Quick read

  • Solves the right problem: 🛑 Localized, bad, or unclear fix
  • Close PR: 🛑 Yes
  • Recommendation: 🏁 close PR

Intent

This PR is trying to make text-mode CLI output show agent thinking as soon as each agent_thought_chunk arrives, instead of waiting for a later non-thought update before anything becomes visible.

Why

The underlying problem is real, but this fix is too localized. It removes the delay by changing the rendered text behavior so each transport chunk becomes its own [thinking] entry. That means the visible UX now depends on arbitrary ACP chunk boundaries rather than on one coherent thought stream.

Codex review

Not run in this read-only triage step. Local diff inspection indicates the fix changes the output contract in the wrong place:

  • src/output.ts:555-663 stops buffering and calls writeThoughtChunk() for every agent_thought_chunk, and beginSection() adds section spacing before each chunk.
  • collapseWhitespace() and truncate() now run per chunk instead of on the combined thought, so chunk boundaries can change grouping, spacing, and truncation behavior.
  • test/output.test.ts:60-71 now expects two separate [thinking] lines for two chunks, which codifies chunk-boundary leakage as the intended behavior.

CI/CD

Not run in this step. This was a read-only triage pass only; no installs, tests, CI checks, or review automation were started here.

Recommendation

Close this PR. A right-shaped fix should make thinking output visible promptly without making the text formatter's public output depend on how the upstream agent happens to split agent_thought_chunk messages.

@dutifulbob
Copy link
Copy Markdown
Collaborator

Closed by automated triage.

@dutifulbob dutifulbob closed this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants