Repository navigation
fix(aimux): read openai-codex text-block thinking tags as thinking - #2322
yyhhyyyyyy wants to merge 2 commits into
Conversation
The managed openai-codex provider writes its reasoning into the text stream itself, wrapped in `<thinking>`…`</thinking>`, where every other consumer of the account sees it as reasoning; Dim streamed it as assistant text, so the tags and the reasoning reached the reply and the reasoning entered the next request as signed-off text. Convert at the provider boundary the issue names, scoped to the openai-codex preset the driver already gates on: when a text block's first non-whitespace content opens the tag, the block converts to thinking until the close tag, and what follows is text again. Both tags complete across deltas: a strict prefix of the open tag buffers undecided, and the tail of the thinking holds back the longest suffix that may still complete the close tag, so a split the provider fragments never leaks half a tag. A block that turns out not to open the tag replays its buffer verbatim, bytes neither lost nor repeated; a block that never closes the tag keeps its content as thinking; a reply of nothing but its tagged thinking answers the turn instead of failing as an empty response. The converted part carries no continuation metadata, so the existing replay rule for unsigned thinking keeps it out of the next request, while the item's metadata lands on the trailing text part. End-to-end tests drive the conversion through a scripted local Responses stream into a Session: thinking precedes text on the Timeline, the next request carries neither the tags nor the unsigned thinking, a tag inside the text stays verbatim, and a connection without the preset streams the same bytes untouched. Fixes #2300
Keep the open-tag strip in the shape clippy reads as a strip_prefix, and expect the conversion's one-argument-per-handle signature the way the crate's other host-assembled functions do. Refs #2300
eric8810
left a comment
There was a problem hiding this comment.
The preset scope and provider-side placement match #2300, and the Session fixture is useful evidence for the normal path and next-request filtering. Two acceptance gaps remain:
- Flush an open tag scan when a valid length finish arrives without TextEnd. The new scan is drained only in TextEnd, but Finish intentionally accepts active blocks on MaxTokens. The existing truncated-block contract test pins that path. A Codex text block truncated at a near-opening like
<thinloses the buffered text; an open thinking section truncated during a potential closing tag loses its held suffix and never emits ThinkingEnd from the scan. Drain pending scans before reporting the length stop, preserving the existing MaxTokens partial-output policy. Add scoped tests for both pending states with no TextEnd; ordinary Stop still must reject incomplete upstream blocks. - Provide the terminal evidence in #2300. Timeline and second-request assertions establish the adapter output, not that Dim's TUI renders the normalized section as a foldable thinking row next to the answer. No production OAuth override is needed for that part: use the normalized Timeline events from the local fixture as TUI replay input, or provide a sanitized terminal capture of the real path. Please show the answer without tags and the thinking row collapsed and expanded. Keep the existing provider fixture for the next-request assertion.
Static review and fixture inspection; no live provider call. CI for this head was still running.
eric8810
left a comment
There was a problem hiding this comment.
Scope correction from the maintainer: this is a rendering-only change. This supersedes my previous review’s acceptance criteria and the wording in #2300 about removing the tagged content from the next request.
Hide the <thinking> delimiters in the rendered transcript. If the view presents the enclosed text in a collapsible thinking row, that grouping is for display only. Keep the provider stream, stored Timeline facts, and next-turn assistant input unchanged from the base, including the original tags, text, and continuation metadata. Do not replace a persisted text part with unsigned thinking or change replay policy for this fix.
Acceptance: exercise the same tagged reply in the rendered terminal (including a literal mention of the tag in normal text), and assert the stored text and next-turn request still carry the original bytes. The previous request to flush the provider-side tag scanner on MaxTokens is superseded if that scanner is removed; the display should still preserve incomplete literal text rather than drop it.
zerob13
left a comment
There was a problem hiding this comment.
The fragment handling and literal-tag cases look good on the normal path. Two correctness issues remain in the adapter implementation currently in this PR:
- A length-limited finish can drop buffered output. Finish handling accepts an open block on
MaxTokens, but the tag scan only drains atTextEnd. With noTextEnd, an undecided text prefix can disappear, and a normalized block can lose its buffered tail and completion. If the scanner stays, verify that both pending states preserve the expected partial output and still report the length limit. Ordinary stop should still reject an incomplete upstream block. - Replay behavior changes across providers. Same-provider filtering does not establish that converted parts stay out of a later request after switching providers. Source tracing shows that a destination serializer can include unsigned parts. If adapter normalization is the chosen scope, verify with synthetic content that the ordinary answer survives and converted content stays out of the next request even after a switch.
#2300 describes adapter normalization, while the latest scope review proposes display only. These are alternative contracts. If display-only is confirmed, the adapter findings do not require new adapter logic: keep the original stream, Timeline and replay unchanged, and verify the rendered behavior with synthetic content. Source and fixture inspection only; no live provider calls. Exact CI was still running Linux workspace tests.
What
The managed openai-codex provider writes its reasoning into the text stream itself, wrapped in
<thinking>…</thinking>. Dim streamed it as assistant text, so the tags reached the reply and the reasoning entered the next request as ordinary assistant text. This change converts the tags at the provider boundary the issue names, scoped to the openai-codex preset: the conversion runs only when the driver's connection carriespreset == "openai-codex", whichstream::convertreceives as its newscan_thinking_tagsparameter atcrates/dim-agent-aimux/src/driver.rs:953.When a text block's first non-whitespace content is the open tag, the block converts to thinking until the close tag, and what follows the close tag is text again. Both tags complete across deltas: a strict prefix of the open tag buffers undecided, and the tail of the thinking holds back the longest suffix that may still complete the close tag, so no fragmentation of the provider's deltas leaks half a tag. A block that never closes the tag keeps its content as thinking. A reply of nothing but tagged thinking answers the turn instead of failing as an empty response. The tags never enter
step/textand never enter the next request: the converted thinking part carries no continuation metadata, so the existing replay rule for unsigned thinking incrates/dim-agent-aimux/src/request.rskeeps it out, while the item's continuation metadata lands on the trailing text part.Boundary behavior
Each behavior is pinned by a test in
crates/dim-agent-aimux/src/stream/tests.rsunless noted otherwise.thinking_tags_inside_text_stay_verbatim).<thin,< thinking>,<thinkingx,<think>) replay their buffered bytes verbatim, nothing lost or repeated (thinking_tags_almost_openings_are_buffered_verbatim).thinking_tags_scoped_blocks_scan_independently).thinking_tags_other_providers_stream_them_verbatim, and end-to-end incrates/dim-agent-aimux/tests/model_flow.rsresponses_without_the_codex_preset_streams_tags_verbatim).<thinking></thinking>has no visible output and commits nostep/thinking: exactly like empty native reasoning, the reply fails asMalformedResponseand goes through the single empty-reply retry (thinking_tags_empty_section_answers_nothing).step/thinking, which is not replay-safe, so the turn fails directly without a retry, like non-empty native reasoning.thinking_tags_leading_whitespace_before_the_open_tag); text on the same line right after the close tag is streamed as text (thinking_tags_close_followed_by_text_on_the_same_line); a tag unclosed at the block end keeps its content as thinking (thinking_tags_unclosed_at_the_block_end_stay_thinking).Acceptance criteria of the issue
<thinking>converts until</thinking>, then text again; both tags may complete across deltas, down to one byte per delta:thinking_tags_convert_a_codex_block_into_thinking_then_textandthinking_tags_split_across_deltas_convert_identically(which covers<thin+king>,</think+ing>, and a per-byte splitting).step/textor the next request's assistant body, and the converted thinking carries no continuation metadata: end-to-endcodex_thinking_tags_leave_text_as_thinking_and_the_next_requestdrives a scripted local Responses stream through the real driver into a Session and asserts the second request body contains neither the tags nor the thinking text;thinking_tags_continuation_metadata_reaches_only_the_text_partasserts the metadata lands only on the trailing text part.thinking_tags_inside_text_stay_verbatimandthinking_tags_almost_openings_are_buffered_verbatim.</thinking>keeps its content as thinking:thinking_tags_unclosed_at_the_block_end_stay_thinking.EventKind::ThinkingbeforeEventKind::Text, no tag characters anywhere), and the TUI's rendering of thinking (the streamed block, its settledThoughtrow and its rewrap across resizes) is the same render path already covered by the tmux scenariosresize_during_thinking_rewraps_multiline_historyandcomposer_borders_match_in_scrollback_and_fullscreeninscripts/tui-tmux/scenarios.mjs. A reply of nothing but tagged thinking completes the turn without an empty-reply retry:thinking_tags_only_reply_answers_the_turnand end-to-endcodex_thinking_tags_only_reply_completes_the_turn(which also asserts exactly one request was issued).Existing tests
crates/dim-agent-aimux/src/stream/tests.rsgained onefalseargument at each of the four existingstream::convertcall sites in the fixture helpers, becauseconvertgained thescan_thinking_tagsparameter. No existing assertion changed.Verification
Run locally on this head:
cargo fmt --all -- --check --config error_on_line_overflow=truecargo clippy --workspace --all-targets --locked -- -D warningscargo test --locked -p dim-agent-aimuxcargo test --locked -p dim-agent-typescargo test --locked -p dim-app-server --test app_server_flowcargo test --locked -p dim-agent-capabilities --test capabilities_flowcargo test --locked -p dim-agent-integration-tests --test integration_flowcargo test --locked -p dim-app-server --test transport_flowcargo check --locked -p dim-agent-aimux --target x86_64-pc-windows-gnucargo run --locked -p xtask -- checktransport_flow node_andapp_server_flow mcp_http_flow::node_ignored tests through the repository'sscripts/run-rust-test.mjsrunnerFixes #2300