fix(core): preserve active Todo context across tool turns - #7915
fix(core): preserve active Todo context across tool turns#7915yiliang114 wants to merge 1 commit into
Conversation
|
Thanks for the PR! Template looks good ✓
Problem: the problem is real and observed — after several tool calls following a Direction: aligned. Keeping task context salient across tool turns is squarely within the agent's core mission. The approach (prompt-scoped reminder injected after function responses) is a standard context-management technique and doesn't change stop semantics. Size: 190 production lines (Session.ts 70, config.ts 40, coreToolScheduler.ts 27, todoWrite.ts 22, client.ts 22, nonInteractiveCli.ts 9), 275 test lines, 33 docs. Not applicable for escalation. Approach: the scope feels right — the feature needs to touch both loops (core + ACP), the config layer, the tool, and the scheduler. Good reuse of the existing
Risk: Flagging the base branch and the two design questions above before diving deeper. 中文说明感谢贡献! 模板完整 ✓
问题:问题是真实且可观察的——在 方向:对齐。在连续工具轮次中保持任务上下文显著性完全属于 agent 的核心使命。方案(按 prompt 隔离的 reminder 注入到 function response 之后)是标准的上下文管理技术,不改变停止语义。 规模:190 行生产代码(Session.ts 70、config.ts 40、coreToolScheduler.ts 27、todoWrite.ts 22、client.ts 22、nonInteractiveCli.ts 9),275 行测试,33 行文档。不需要升级。 方案:范围合理——功能需要触及两个循环(core + ACP)、config 层、工具和调度器。良好复用了现有的
风险: 先提出基础分支问题和上述两个设计问题,再深入看代码。 — Qwen Code · qwen3.8-max-preview Reviewed at |
Code ReviewIndependent proposal: I'd store unfinished todos in a session-scoped map keyed by prompt ID, inject the reminder after function responses in both loops (core + ACP), clear on completion or new work chain, transfer on retry/continue, and cap the payload. The PR's approach matches this closely. Assessment: the implementation is clean and well-structured. Good reuse of the existing Findings:
No critical blockers found in the code itself. Testing
No unit, build, or lint CI has run on this commit. The only workflow runs are Not verified: build, typecheck, unit tests, lint — no CI evidence available. The author reports local passes ( 中文说明代码审查独立方案: 我会将未完成 todo 存储在按 prompt ID 键控的会话级 Map 中,在两个循环(core + ACP)的 function response 之后注入 reminder,在完成或新工作链时清除,在 retry/continue 时转移,并限制载荷大小。PR 的方案与此高度一致。 评估: 实现干净、结构良好。良好复用了现有的 发现:
代码本身未发现关键阻塞问题。 测试没有 CI 运行。基础分支 未验证:构建、类型检查、单元测试、lint——无 CI 证据。作者报告本地通过( — Qwen Code · qwen3.8-max-preview Reviewed at |
|
Confidence: 3/5 — the code is clean and the approach is right, but the PR targets a non-existent base branch and has zero CI coverage, so it cannot be verified or merged as-is. Stepping back: the design is sound. Prompt-scoped todo reminders injected after function responses is the right mechanism — it preserves context without changing stop semantics, and the work-chain isolation prevents cross-contamination between concurrent turns. The implementation reuses existing infrastructure well ( What holds this back from approval:
Once the base is fixed and CI runs green, this should be straightforward to approve. The code itself has no critical blockers. ⏸️ Not approving — the base branch and CI gaps need resolution first. @yiliang114 could you retarget this to 中文说明置信度:3/5 —— 代码干净、方案正确,但 PR 的目标分支不存在且没有 CI 覆盖,无法验证或合入。 总体来看:设计合理。按 prompt 隔离的 todo reminder 注入到 function response 之后是正确的机制——保留上下文而不改变停止语义,工作链隔离防止了并发轮次之间的交叉污染。实现良好复用了现有基础设施( 阻止批准的原因:
基础分支修复并且 CI 绿色通过后,批准应该是顺理成章的。代码本身没有关键阻塞问题。 ⏸️ 暂不批准——需要先解决基础分支和 CI 问题。@yiliang114 能否将目标分支改为 — Qwen Code · qwen3.8-max-preview Reviewed at |
What this PR does
This change keeps the latest unfinished Todo list salient across tool turns. After a successful Todo update, Qwen Code retains a bounded prompt-scoped reminder and appends it after function responses in both the core and ACP loops. Mid-turn user input remains last so the user's newest direction keeps precedence.
Todo reminders are isolated by work-chain prompt ID, so cron jobs and background notifications cannot overwrite an ordinary user task. Retry, continue, and explicitly related automatic turns move the reminder to their new prompt ID, while session changes clear it. The existing experimental Todo Stop Guard remains unchanged and disabled by default.
Why it's needed
Today the complete Todo state is emphasized only in the immediate
todo_writeresult. After several other tool calls, that state loses salience and the model can naturally end the turn while Todo items are still pending. Re-reading the persisted Todo file is not safe because it can outlive the work chain that created it, and changing stop semantics would turn a planning aid into a completion oracle.This preserves the current task context before the stop decision without treating Todo state as proof that the task is complete or forcing an automatic retry.
Reviewer Test Plan
How to verify
Evidence (Before & After)
N/A — model-context behavior with no UI change. Focused regressions cover Todo persistence, prompt ownership, Core and ACP injection order, retry/continue transfer, and the Todo Stop Guard remaining off by default.
Tested on
Environment (optional)
Local Node.js 22 workspace.
npm run build,npm run typecheck, changed-file ESLint and Prettier, TodoWrite and Config tests, Core client and scheduler tests, non-interactive CLI tests, and focused ACP Session regressions all pass. A full ACP Session run reached 454 passing tests and one pre-existing 30-second mid-turn drain timeout; the affected ACP tests pass when run directly.Risk & Scope
todoStopGuard, and guaranteeing that every model will always follow the reminder.Linked Issues
Related to #6945 and #7821.
中文说明
这个 PR 做了什么
这个改动让最新的未完成 Todo 列表在连续工具轮次中保持显著。
todo_write成功后,Qwen Code 会保留一段有大小上限、按 prompt 隔离的 reminder,并在 Core 和 ACP 循环中把它追加到 function response 之后。轮次中途到达的用户输入仍然放在最后,因此用户最新指令保持最高优先级。Todo reminder 按工作链 prompt ID 隔离,因此 cron 任务和后台 notification 不会覆盖普通用户任务。retry、continue 和明确相关的自动轮次会把 reminder 转移到新的 prompt ID;session 切换会清理 reminder。现有实验性 Todo Stop Guard 不做修改,默认仍然关闭。
为什么需要
当前完整 Todo 状态只会在当次
todo_write结果中被重点提示。经过若干其他工具调用后,这段状态的显著性会降低,模型可能在仍有 pending Todo 时自然结束轮次。直接重新读取持久化 Todo 文件并不安全,因为文件可能比创建它的工作链存活更久;而修改 stop 语义则会把规划辅助误当成完成判定器。这个方案在模型做出停止决定之前持续保留当前任务上下文,但不会把 Todo 状态当作任务已经完成的证据,也不会强制自动重试。
Reviewer 测试计划
如何验证
证据(Before & After)
N/A —— 这是模型上下文行为变化,没有 UI 改动。聚焦回归覆盖 Todo 持久化、prompt ownership、Core 与 ACP 注入顺序、retry/continue 转移,以及 Todo Stop Guard 默认仍关闭。
测试平台
环境(可选)
本地 Node.js 22 workspace。
npm run build、npm run typecheck、变更文件 ESLint 与 Prettier、TodoWrite 与 Config 测试、Core client 与 scheduler 测试、non-interactive CLI 测试和 ACP Session 聚焦回归均通过。ACP Session 全量运行有 454 个测试通过,另有一个既有的 mid-turn drain 用例在 30 秒超时;本次影响到的 ACP 测试单独运行均通过。风险与范围
todoStopGuard,以及保证所有模型始终遵循 reminder。关联 Issue
与 #6945 和 #7821 相关。