Skip to content

fix(agent-runtime): release an unclosed think-tag open as text at flush - #1173

Open
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:oss/think-tag-unclosed-open-1155
Open

fix(agent-runtime): release an unclosed think-tag open as text at flush#1173
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:oss/think-tag-unclosed-open-1155

Conversation

@nordicnode

Copy link
Copy Markdown

Summary

  • an explicit <think> open in the content stream no longer commits the rest of the step to the thinking box unconditionally: the hold is released as text at flush() when no close ever arrives
  • give the explicit open the same hold machinery the implicit head already uses (holdingForOpen): a close settles the held content as reasoning, a native reasoning chunk disarms it, and a step that ends without a close releases it as text
  • the IMPLICIT_OPEN_BUDGET_CHARS give-up stays implicit-head-only — a genuine think block can legitimately run long, and only its close (or the end of the step) settles it
  • add regression tests for the prose-quoted open (Write <think> like this in your docs), the hold-until-close streaming shape, the native-reasoning disarm, and the flush release

This addresses the answer-swallowing part of #1155 (the unclosed-think-tag bug): whenever a model emits the tag as prose — writing docs, quoting a template, or a lane whose chat template is broken — the visible answer landed in the thinking box and the user saw an empty or short reply. History still stores the raw text, so this is a display/reclassification fix, not context loss.

Validation

Re-run on the new main after the history rewrite:

  • bun test packages/agent-runtime/src/util/__tests__/think-tag-stream.test.ts — 24 pass, 0 fail

Refs #1155


Replaces #1161 — auto-closed when the repo history was force-pushed (the original commits no longer exist in the new history). Rebased onto the new main per the maintainer's request; picking the review up here.

An explicit <think> open committed the rest of the step to the thinking
box unconditionally, so when a model wrote the tag as prose (docs,
quoted templates, a broken chat template) the visible answer landed in
the thinking box and the user saw an empty or short reply.

Give the explicit open the same treatment the implicit head already
has: hold until a close settles the block as reasoning, and release the
hold as text when the step ends without one — an answer is delayed,
never swallowed. The budget stays implicit-head-only: a genuine think
block can legitimately run long, and only its close (or flush) settles
it.

Refs CodebuffAI#1155
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.

1 participant