Repository navigation
fix(plugin): retry a turn whose only visible output was a stripped tag echo (#870) - #871
Conversation
88fcb52 to
8d0a089
Compare
|
Filed note on the Gemini half, deliberately not in this branch. The commit that teaches the gate the Gemini terminal spelling ( Branch head is now The other half of the same stall is a separate problem and a separate PR: a render tag wrapped around the model's whole turn now leaves an empty turn instead of orphan markup (#872), which is the shape this retry exists to re-ask. |
|
Live verification in the reporter's own session, on the locally installed build of this change, after the proxy was restarted onto it at 18:04:48Z. Counted per hour in that machine's
Before this went upstream, both shapes were re-proved against the installed bundle with a mock upstream: two upstream requests, the second carrying the continuation nudge, and a readable tool call reaching the client. |
…anxianglei#870, PR ranxianglei#871) The retry gate read only the Anthropic (message_delta stop_reason) and OpenAI (choices[].finish_reason) terminals, so an echo-only Gemini turn — whose terminal is the candidate that closes the stream, finishReason STOP — was never re-asked and still reached the host empty. The gate now reads that spelling as well, and appendTrailingUserText carries the nudge on the Google wire's own turn shape (a text part appended to the last user content) instead of reporting an unusable body.
14ec41c to
817a8cf
Compare
|
Adding the third pipe. The Responses passthrough had no gate at all, so an echo-only codex subagent turn still reached the host empty: 8 of one day's degenerate turns in a single session, 56 across all sessions. One design note, because this pipe's terminal is not the chat wires' terminal. A Responses turn ends on a FAMILY — Wired at all three Responses passthrough sites: plugin mode, the native-compact tee, and proxy mode without injection. Tests: five in |
Reviewed the rebased head ( Verification (local, on rebased head)
Constraint-by-constraint check (#870 OP)
Non-blocking observations
Diff hygiene: 8 files, every line on-purpose, no lockfile churn, 中文摘要:修复了插件透传模式下模型整轮只吐出被剥离的 render tag、导致客户端拿到空回合而中断的问题(干净终止且零可见文本/零工具调用时,用 agent 自己的 body 追加一次续写 nudge 重发,严格限一次重试并保住两种 wire 的帧结构);已逐条核对 #870 的全部约束并在 rebase 后的分支上验证 typecheck/测试/构建(唯一失败项在 master 上同样失败,属既有问题),可以合并。 |
Review follow-ups on ranxianglei#871. The retry swaps in a new reader while the first attempt's stream is already terminal and drained; the old one is now closed explicitly in both pipes instead of being left for the garbage collector to release. Two tests the reviewer asked for: a chunk that coalesces content with the finish reason counts its own text (and, when that coalesced content is an echo, still retries exactly once — the ordering the gate depends on), and a retry stream that is cut still raises the ranxianglei#721 truncation signal, because takeover resets the terminal flag.
Review follow-ups on ranxianglei#871. The retry swaps in a new reader while the first attempt's stream is already terminal and drained; the old one is now closed explicitly in both pipes instead of being left for the garbage collector to release. Two tests the reviewer asked for: a chunk that coalesces content with the finish reason counts its own text (and, when that coalesced content is an echo, still retries exactly once — the ordering the gate depends on), and a retry stream that is cut still raises the ranxianglei#721 truncation signal, because takeover resets the terminal flag.
|
Three things: the head moved, your five observations answered, and two of them acted on. The head moved since your reviewYou reviewed Its terminal is a family rather than one event, so the retry holds Your five observations
What I would look at on the re-reviewThe third pipe is the part you have not seen, so that is where a second pass earns its keep: the id rewriting, the drop-on-takeover of the held family, and the framing parity with your points about Nothing else is pending on our side; merge stays human-side per the repo rules. Thanks for the constraint-by-constraint trace — the coalesced-chunk ordering is exactly the kind of thing that looks correct in code and fails in production. |
|
One more commit on the branch, and it is a bug this PR's own third pipe introduced — found by proving the pipe against the installed bundle rather than the build. A Responses turn whose only output is an echoed render tag now reaches the retry correctly, but the retry's
How it surfaced is the part I would keep: the chat pipe's prover cannot see this path, so I wrote the Responses twin ( |
Gap found in production: a turn that ends in visible orphan markup does not retryThe gate counts Two production occurrences on 2026-09-16, both on the OpenAI wire with DeepSeek:
The second occurrence is the first one again: the model opens a render tag and writes the whole turn inside it with the attributes still open, so no close is ever written and no tag regex can match the span. Proposed condition, in the shape of the existing one: treat the turn as empty when everything the client received was markup the filter declined to swallow. Second condition: surface the failure instead of ending emptyBoth occurrences shared a worse property than the missing retry: the turn stalled rather than failing, so nothing reached the client until the user interrupted by hand. An empty turn is indistinguishable from a model that simply produced nothing, and the session looks idle while it is dead. After the retry has been spent, a turn that ends in orphan markup with no tool call should raise an in-band error. The channel exists: Not implemented in this branch yet. The wire bytes of the second occurrence are gone — the proxy log records events rather than bodies, and the payload store keeps only the proxy's own transformed view — but the client-visible residue survives in that session's transcript, so a fixture has to be reconstructed from the client's view rather than recorded off the stream. The |
Third occurrence, 2026-09-16T20:46:05Z: per call, not per turnSame session as the second occurrence ( Two properties this adds:
In all three cases the client showed a stalled session rather than an error, which is the second condition above. Where the bytes are not, for anyone chasing a fourth: |
…xianglei#870, PR ranxianglei#871) A render tag whose close never arrives is dropped by the filter while its interior survives as the turn's only visible text: the host receives orphan markup, finds no tool call in it, and stalls. The gate measured that interior as visible output, so the degenerate-turn retry never fired. Count the text a dropped tag leaves behind as markup instead, at both the chat wire's rewrite sites, and re-issue the turn. The recorded architect-session turn is the fixture, reconstructed from the client-visible residue because the wire bytes are not kept anywhere.
|
Implemented in a008628. The gate now counts the text a dropped tag leaves behind as markup rather than as visible output, at both of the chat wire's rewrite sites, so a turn whose only visible content is a surviving tag interior is re-issued. Measured behaviour: that interior has already reached the client by the time the terminal arrives, so the retry cannot erase it — what the fix guarantees is that the turn carries content the host can act on, which is what the stall was missing. Fixture Still open, unchanged: the in-band error when the retry is also degenerate, and the same gate on the Responses pipe, whose |
Evidence for the second condition, from the session that hit it five timesReported by
That last point locates the cause away from this repository. The marker is DeepSeek's own envelope vocabulary — fullwidth vertical bars, |
|
|
Checked the sequencing question above, and it is not redundant: the wire branch has no |
…nxianglei#870, PR ranxianglei#871) A turn the host never sees any content from is indistinguishable from a model that produced nothing, and the client reports neither, so a dead session reads as an idle one. The degenerate-turn gate already retried once; when that retry degenerates as well, the client now gets the in-band stream error the host would never surface, and the retry's own terminal is dropped so the error closes the turn. Observed on 2026-09-16 by the session that hit the corruption five times: no parse error, no warning, the residue as ordinary assistant text.
The Responses pipe has the same hole; the measurements for whoever takes itTested rather than assumed: an unclosed render tag on the Responses wire does not retry. The probe is the chat one's shape on that wire ( Four attempts to mirror the chat fix failed, and the measurements say why that pipe's accounting is not symmetric:
Net: a correct fix must measure the attempt's text once, across the delta, the flush tail and the held family. Left out rather than half-done. The chat wire, which every observed failure was on, has both halves working. |
Resolved: the gate keeps the released-markup measure and drops the `degenerateRetried ||` guard (that guard made the spent-retry error branch unreachable) while taking integration's newer CLEAN_TURN_REASONS object form; the changelog keeps integration's ranxianglei#872/ranxianglei#868 bullets and the branch's copy of the ranxianglei#871 bullet, which carries the sentences this change added.
|
ci失败 |
|
继续 |
…g echo Plugin-mode turns that end with no visible text and no tool call reach the host as an empty completed turn, which it then aborts (ranxianglei#673 logs them as degenerate). The trigger is the render-tag echo: the model imitates the annotation line it saw in its prompt, the tag filter strips it, and where the echo was the whole turn nothing is left to send. The filter's own rules are not negotiable — ranxianglei#463 pins that an all-echo turn is dropped, ranxianglei#673 pins that a typo'd tag never leaks and that the emptiness is reported — so the turn is recovered rather than redefined. The pipe re-issues the agent's own request once, with the continuation nudge ranxianglei#732/ranxianglei#821 already uses for the compress loop, when a turn reaches its terminal (openai finish_reason chunk, anthropic message_delta) with zero visible text, no tool call and a clean completion reason. The retry's content is spliced into the same client turn: the first attempt's terminal event is dropped, its message is never re-opened, and the retry's anthropic content blocks are offset past the ones the client already saw. A retry that also comes back empty, or cannot be issued at all, leaves today's behaviour exactly as it was: the empty turn passes through and [degenerate-turn] warns. injectFakeCompletionHint's per-wire body mutation moves to wire-body.ts so both post-hoc mutations share one implementation, and the retry nudge text moves to degenerate-retry.ts so the loop and the pipe quote one string.
…ianglei#870, ranxianglei#732/ranxianglei#821) The chat pipes re-issue the agent's own body once when a turn reaches its terminal with nothing visible — the render-tag echo case the filter empties. The Responses pipe had no such gate, so an echo-only codex subagent turn still reached the host empty: 8 of one day's degenerate turns in a single session and 56 across all sessions. Its terminal is a family rather than one event, so the retry HOLDS response.output_text.done / response.content_part.done / response.output_item.done until response.completed decides the turn. On a degenerate completion the held events and that completion are dropped, the body is re-issued with the same continuation nudge, and the retry is reframed onto the ids the client already holds: its response.created and added events are dropped, and item_id, output_index and the completed output ids are rewritten to the first attempt's. A healthy turn releases the held events in place, so holding never reorders a turn. Wired at all three Responses passthrough sites (plugin mode, the native-compact tee, and proxy mode without injection); the plugin chat pipes' refetch already carries the URL and headers this needs.
Review follow-ups on ranxianglei#871. The retry swaps in a new reader while the first attempt's stream is already terminal and drained; the old one is now closed explicitly in both pipes instead of being left for the garbage collector to release. Two tests the reviewer asked for: a chunk that coalesces content with the finish reason counts its own text (and, when that coalesced content is an echo, still retries exactly once — the ordering the gate depends on), and a retry stream that is cut still raises the ranxianglei#721 truncation signal, because takeover resets the terminal flag.
The retry reframed the response id, the completed output ids and the `item_id` on deltas, but `response.output_item.*` carries the item's identity nested as `item.id`. That frame is released to the client, so without this the client watched the item it held be replaced by the retry's mid-turn. Found by proving the pipe against the installed bundle rather than the build: a Responses turn whose only output is an echoed render tag, driven through the real CLI, reached the client with `item.id = msg_second` while every other id carried the first attempt's. The regression pin now emits that frame from the retry.
…xianglei#870, PR ranxianglei#871) A render tag whose close never arrives is dropped by the filter while its interior survives as the turn's only visible text: the host receives orphan markup, finds no tool call in it, and stalls. The gate measured that interior as visible output, so the degenerate-turn retry never fired. Count the text a dropped tag leaves behind as markup instead, at both the chat wire's rewrite sites, and re-issue the turn. The recorded architect-session turn is the fixture, reconstructed from the client-visible residue because the wire bytes are not kept anywhere.
…nxianglei#870, PR ranxianglei#871) A turn the host never sees any content from is indistinguishable from a model that produced nothing, and the client reports neither, so a dead session reads as an idle one. The degenerate-turn gate already retried once; when that retry degenerates as well, the client now gets the in-band stream error the host would never surface, and the retry's own terminal is dropped so the error closes the turn. Observed on 2026-09-16 by the session that hit the corruption five times: no parse error, no warning, the residue as ordinary assistant text.
…lei#870, PR ranxianglei#871) Two CI regressions found while reviewing ranxianglei#871's red test jobs: 1. The degenerate-turn re-issue fired on the native-compaction trigger request (the resetAfterSuccess passthrough), appending the continuation nudge AFTER compaction_trigger and breaking the wire shape (ranxianglei#283: the trigger must stay the last input item). makeContinuationRefetch now refuses to re-issue a body whose final input item is a trigger. 2. The new gates retried turns the model left genuinely bare — zero output of any kind — double-billing an upstream empty completion. Both plugin pipes now require proof of invisible-but-real output (a stripped render-tag/marker echo, released markup, or thought/reasoning), matching the boundary the compress loop has kept since ranxianglei#732/ranxianglei#821.
cffedd1 to
86abe3a
Compare
CI failure — root-caused, fixed, re-pushed. All jobs green on Reproduced all three red test jobs locally with an A/B against base 1. 2. 3. What changed: rebased onto current master Ready for merge whenever. 修了什么问题:PR 新增的空轮重试有两个回归——(1) 会对 native-compaction 触发请求重发、把 nudge 追加到 |
A model imitating the render tag can write its whole turn — tool call included — where the opening's attributes are still open, so the attribute list never terminates and no close tag is ever written (recorded shape: `<acp tokens="1" text="text` immediately followed by the turn's own markup, architect session 01a0a0cb, 2026-09-16T17:29:09). Every tag pattern misses the span at once: attribute classes stop at `<`, and the value opened with a quote is never closed. The filter dropped the opening and released the payload, and the agent received a completed turn of orphan parameter/invoke/calls closers with no tool call in it, stalling until nudged. The stripper now recognises the wrapped shape by form — the attribute list runs into a `<` (BROKEN_ATTRS), or carries an odd number of quotes — and swallows the span whole to a loose close tag or to the end of the turn, in stripAcpTags and in the streaming filter alike, with a budget of its own so the #644 rule for a plain opening's over-long tail stays intact. The turn reaches the client empty, which the degenerate-turn retry (#870/#871) re-asks for.
Problem
The plugin path strips render tags from every forwarded chunk. When the model echoes a ref annotation as the entire visible content of a turn, the tag is removed, the emptied chunk is suppressed, and the client receives a turn with neither text nor a tool call, which the harness aborts. Releasing the echo is not an option: #463 deliberately swallows a pure tag echo, and #674 plus the degenerate-turn warning exist so that imitated tags never reach the client.
The adapter path (proxy mode with the compress tool injected) already answers this with a one-shot re-fetch; the plugin's direct pipe had no equivalent, so the defect only bit plugin-mode sessions.
Fix
On a turn that ends cleanly (
stop,end_turn,stop_sequence) with zero visible text, zero tool calls and no error finish reason, the pipe now re-issues the same request once with a continuation nudge and relays the retry in the original framing.src/degenerate-retry.ts(new):DEGENERATE_RETRY_NUDGE,injectContinuationNudge(protocol, body)andmakeContinuationRefetch(opts), moved out ofsrc/loop/core.tsso both paths share one nudge and one body builder.src/wire-body.ts(new):appendTrailingUserText(protocol, body, text), extracted from the fake-completion hint, which now delegates to it.src/plugin.ts:pipePluginChatWithStriptakes arefetchcallback, tracksdegenerateRetried/inRetry/retryIndexOffset/blocksForwarded, and gates on a clean terminal reason set.Two details the tests forced, both about not corrupting the client's view of the turn: the openai terminal is the
choices[].finish_reasonchunk rather than[DONE](using[DONE]let the first attempt's terminal reach the client twice), and the gate runs after the event is processed, because a coalesced chunk can carry both content and the finish reason and would otherwise be judged empty and dropped. An anthropic retry lands at"index":1with a singlemessage_start/message_stop, and an unissuable retry presents the original terminal with valid JSON.If the retry is also empty, the original empty turn is passed through and the existing
[degenerate-turn]warning fires, so the contract that keeps the annotation away from the client is unchanged.Tests
tests/plugin-empty-turn-retry.test.ts(8, against the pipe with a fake response and a fake refetch): retries once on an echo-only turn and the client sees the retry's prose with exactly one[DONE]and onefinish_reason; no retry when visible text, a tool call orcontent_filterends the turn; an empty retry passes the empty turn through and warns; an unissuable retry presents the original terminal as valid JSON; anthropic keeps onemessage_start/message_stopwith the retry at index 1; and the nudge-body shapes per wire.Verification
Full proxy suite on the branch: 1669 tests, 1661 passing, the same six environmental failures upstream shows.
npm run buildclean (dist 2.89 MB),npx tsc --noEmit -p tsconfig.build.jsonclean. The branch is deliberately not part of the local installation, which carries the wire and the fold budget; the reproduction it answers was a live plugin-mode session whose turn ended with no text and no tool call.