Repository navigation
fix(agent): read a reasoning block back while its run is still writing - #1702
Merged
Merged
Conversation
A lean lane sends a reasoning row's boundaries and not its body, and the row fetches the text when a reader opens it (`get_reasoning`). That read only ever looked at settled entries, and a reasoning block reaches the store with the entry that carries it — at the end of the run — so opening a thinking row mid-reasoning read back nothing and the phone said the reasoning was unreadable, while the desktop (which folds the run's own events) showed it. The text is not missing: it is in the run's live projection, the fold a streaming reply is drawn from. `get_reasoning` now answers from that projection when the stored block is missing, folding it the way the reply is rendered (start opens a block, deltas append to the block their id names or to the open one, end closes it) so a row's index means the same thing on both sides. The projection is read before `trim_projection`, which is what takes reasoning text out of a snapshot meant for a client, and only for the run this process is writing and whose projection covers the whole run: a finished run, an unknown one, or a projection that is a tail answers nothing, as before. A fragment that rode the wire as a content reference is a hole rather than a short thought, so that block is reported unreadable instead of truncated. Both clients keep such a body as a prefix: once the block settles, opening the row again reads the complete text instead of presenting what was on screen when the reader first opened it as the whole thought.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
移动端在推理还在流式输出时展开思考块,看到的是「这段推理暂时读不到」;等这一轮回复结束,同样的展开又能读到内容。桌面端一直正常。
原因
移动端为了省流量不接收推理正文的增量,展开时才按需向 agent 读一次文本(
get_reasoning)。而 agent 的这条读取路径此前只查已持久化的消息块——推理块跟随承载它的消息在轮次结束时才写入存储,所以流式期间读到text = null,前端落到thoughtUnavailable,轮次结束、块落库后自然就有内容了。桌面端不受影响,因为它自己就在消费流式增量。改动
agent/src/rpc/broadcaster/reasoning.rs(新增):reasoning_blocks从一次运行的 SSE 序列折叠出逐段推理正文,规则逐字对齐packages/thread-projection/src/liveApply.ts(thinking_start开启、thinking_delta/thinking_chunk追加、thinking_end关闭,兼顾匿名起始与孤立增量)。agent/src/rpc/broadcaster/replay.rs:SseBroadcaster::live_reasoning_blocks,仅在 run id 命中、投影完整、未超预算且尚未agent_end时返回;读的是trim_projection之前的内存投影,不改变快照既有的「清空推理正文」行为。agent/src/rpc/commands/mod.rs:get_reasoning改为先读存储、存储无文本时才用实时投影兜底。已结束的轮次仍然以存储为准,行为不变。content_refs形式传送的块(content_bytes > text.len())判定为不完整,返回null而不是截断的前缀;空块同样返回null。desktop/src/features/agent/ThinkingBlock.tsx与mobile/src/features/chat/messages/ThinkingRow.tsx给读回来的文本带上live标记,块平息后重读一次以替换成存储里的完整版本;已经展开的行保留原有文本,不跳变。desktop/src/features/remote-peer/remoteReasoning.ts里null的语义注释一并纠正。不涉及主机、远程协议或 capability(
reasoning_fetch_v1不变),也不需要重新生成 proto。验证
cargo fmt -p future-agent --check、cargo clippy -p future-agent --all-targets -- -D warnings通过;cargo test -p future-agent3129 个通过。整跑中 3 个与本改动无关的用例偶发失败(两个 session 删除用例、一个 Windows 沙箱探针),单独运行均通过。tsc --noEmit、eslint干净,vitest run src/features/agent src/features/remote-peer2420 个通过。tsc --noEmit干净,jest1394 个通过(MarkdownText.test.ts仅在临时工作树中因 node_modules junction 解析失败,主检出通过)。broadcaster/reasoning.rs单元测试 4 个、broadcaster/tests/live_reasoning.rs3 个、dispatcher_tests中「运行还在写时能读到那段推理」、ThinkingBlock.test.tsx与TimelineCard.test.ts中各一个「块平息后重读」用例。