Repository navigation
[Bug][0.2.0-rc.2] A cancelled step's reasoning is replayed as plain assistant text (pi-ai route), bypassing pi-ai's aborted-message skip #9095
avpanasyuk
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
When a turn is cancelled while the model is still reasoning, the partial step's reasoning is replayed on the next request. On the pi-ai route it comes back as plain assistant text, as if the model had said it. pi-ai has a guard that skips aborted assistant messages, and the dsh adapter defeats it by labelling the interrupted message
stopReason: "stop".Keeping the delivered prefix is documented. The
dsh-agent-loopREADME says a cancelled stream appends aninterrupted: trueanchor "with the delivered prefix so the next request contains what the user saw". This report is narrower: the reasoning part of that prefix changes role on replay.Environment
dsh-agent-loop,dsh-llm,dsh-llm-pi-ai@earendil-works/pi-ai0.87.1dsh-llm-pi-ai(seen with OpenRouter,deepseek/deepseek-v4.1-flash, reasoning on)The chain
The partial is kept with its reasoning.
dsh-agent-looplib/index.js:1081-1100: on abort,content = live.interruptedBlocks(), thenassistant/messageis appended withinterrupted: trueandsurfaceOp: "append".dsh-llmlib/types/assembler.js:155-165,interruptedBlocks(), keeps every non-blanktextandreasoningblock.It has no replay state.
assembler.js:77-80sets_replayStateonly on thefinishchunk, which a cancelled stream does not reach, sosource.replayStateis absent.So the adapter treats it as foreign.
dsh-llm-pi-ailib/index.js,toPiAssistant:if (source.replayState === void 0) return foreignAssistant(message);.foreignAssistantmapsreasoningto{type: "thinking"}and setsapi: "dsh-foreign"andstopReason: "stop"(it is"toolUse"only when there is a tool call).pi-ai converts foreign thinking into text.
pi-aidist/api/transform-messages.js:66-90:isSameModelcomparesapi, so"dsh-foreign"is never the same model. A non-redacted thinking block from a different model becomes{ type: "text", text: block.thinking }.pi-ai's own guard is bypassed.
transform-messages.js:159-167skips assistant messages whosestopReasonis"error"or"aborted". Its comment says: "These are incomplete turns that shouldn't be replayed … reasoning without message". The interrupted message reaches it as"stop", so it is kept.Why it matters
One reason to cancel a turn is that its reasoning has gone wrong, for example a model stuck in a repetition loop in its reasoning channel (see #6711, #8425). After the cancel, the next prompt carries that looping text back as the model's own visible answer, which is a strong way to re-seed the same loop.
A text-only partial (the user-visible prefix) is unaffected. Only reasoning changes role.
Suggestion
Any one of these:
interruptedinto the replayed message, and haveforeignAssistantemitstopReason: "aborted"for it. pi-ai then drops it, as its comment intends. The cost is that the visible text prefix is dropped too.interruptedBlocks()(or the adapter) dropreasoningblocks from an interrupted message and keep the deliveredtext. This matches the documented intent, "what the user saw".textblock.Found and verified against the installed 0.2.0-rc.2 and pi-ai 0.87.1 sources with the help of an AI coding agent.
All reactions