Skip to content

fix(scheduler): 定时任务在活跃人工轮次后排队 - #2474

Merged
deepcoldy merged 1 commit into
deepcoldy:masterfrom
yousay123:fix/schedule-creator-turn-queue
Oct 29, 2026
Merged

deepcoldy merged 1 commit into
deepcoldy:masterfrom
yousay123:fix/schedule-creator-turn-queue

Conversation

@yousay123

Copy link
Copy Markdown
Contributor

改动内容

  • 对可信来源为 schedule_creator 的定时任务输入强制设置 queueAfterActiveTurn,避免会话繁忙时作为 type-ahead 写入当前人工轮次。
  • 增加会话生命周期回归测试,校验定时任务在活跃交互轮次之后排队,且保留原 trusted caller。

为什么改

定时任务触发时如果目标会话正在处理人工输入,任务 Prompt 可能被复用到当前交互轮次,导致 schedule:<taskId>:<turn> 的可信来源丢失。依赖调度身份的工具随后会按安全门禁拒绝请求。

本改动让人工轮次先完整结束,再以独立调度轮次执行任务,保留 task/app/owner provenance。

影响范围

  • 修改公共 sendWorkerInput 路径,但仅影响 trustedCaller.source === "schedule_creator" 且非 recovery dispatch 的输入。
  • 普通人工消息、已有串行群输入和带 dispatchAttempt 的恢复路径保持原行为。
  • 该路径为多 CLI / 多后端共用;本次通过公共层单测验证,live 验证覆盖 Codex PTY 会话。
  • 不修改模型选择、Prompt 内容、权限规则、数据查询或生产配置。

验证

  • bun run build:通过(本地 Bun 1.4.2,项目钉定/CI 为 1.4.3,命令仅产生版本告警)。
  • bun run test -- test/session-lifecycle-start.test.ts test/active-turn-authority.test.ts test/scheduled-turn-provenance.test.ts test/worker-queue-merge.test.ts:4 个文件通过,399 passed、7 skipped。
  • live 验证:定时任务在繁忙交互轮次后排队并独立执行,任务身份未再落入人工 turn。

@yousay123

Copy link
Copy Markdown
Contributor Author

本次提交修复定时任务在目标会话繁忙时被 type-ahead 到人工轮次、从而丢失 schedule_creator provenance 的问题。

增量改动:sendWorkerInput 对 scheduled creator 强制 queueAfterActiveTurn,并新增回归测试校验排队及 trusted caller 保留。

验证:

  • bun run build:通过(本地 Bun 1.4.2,项目/CI 钉定 1.4.3,仅版本告警)
  • bun run test -- test/session-lifecycle-start.test.ts test/active-turn-authority.test.ts test/scheduled-turn-provenance.test.ts test/worker-queue-merge.test.ts:399 passed、7 skipped
  • live:繁忙人工轮次结束后定时任务独立执行,调度身份保留

已核验 head:4ce57df540cd4c6b5509445276e4a929f6986eba。当前 CI:已触发,除 assign 成功外其余 build/test/network checks 正在排队或运行。

@deepcoldy

Copy link
Copy Markdown
Owner

你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改:
https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=b3ek5fce-e3dc-488a-a9f7-77e114ae0764

另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

(本条为自动流程发出的提示消息)

@deepcoldy
deepcoldy merged commit 58e4e82 into deepcoldy:master Oct 29, 2026
12 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并,感谢贡献!这个修复让定时任务在会话繁忙时不再被并入当前人工轮次,调度身份(schedule 任务创建者)得以完整保留。

以下 3 条非阻塞 follow-up 供后续参考(不影响本次合入):

  1. 补一条 durable 重投不带 queueAfterActiveTurn 的回归测试。 当前 opts.dispatchAttempt === undefined 这个排除条件只靠代码读出、没有行为测试钉住;把整个 guard 去掉后现有测试仍全绿。建议补一条:trustedCaller.source === 'schedule_creator' 且带 dispatchAttempt(如恢复重投)时,消息上不应带 queueAfterActiveTurn,防止以后误改恢复路径语义。

  2. failed-turn-recovery 的 at-most-once 路径行为增量建议补描述与用例。 该路径(failed-turn-recovery 中 atMostOnce: true 的投递)不传 dispatchAttempt,当 caller 是 schedule_creator 时现在也会带上排队标记:从「type-ahead 并进当前轮」变为「等当前轮结束后独立执行」。方向与本修复一致(该路径本就使用 schedule:<taskId>:<uuid> 且不可抢占),但属于 PR 描述未提及的增量,建议在描述里补一句并加对应用例。

  3. adopt 会话不经过此标记(记录现状)。 adopt 模式的消息项不携带 queueAfterActiveTurn(与既有的群串行输入同形),它由独立的串行写队列保证不被 steer/合并,身份不会丢失,属既有行为、无需在本 PR 处理。

另:作为附带效果,定时任务输入现在也不会再清除 TUI 阻塞选项卡状态、不会抢占正在运行的轮次——这对内部调度流量是正确行为,后续改动描述时可一并说明。

(以上为自动评审整理,最终以维护者审阅为准。)

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.55.0

deepcoldy pushed a commit to uestcwangci/botmux that referenced this pull request Oct 29, 2026
…ity-recovery-20261028

二次同步 master(875bb2dfc..d6e6cb8,含 deepcoldy#2468/deepcoldy#2474/deepcoldy#2481/deepcoldy#2491/deepcoldy#2493/deepcoldy#2499 等)。
仅 src/core/worker-pool.ts 与本分支有交集,git 自动合并干净、无冲突标记;
已重新 build 并跑 codex-app-runner.integration / 容量恢复两文件 /
codex-app-engine-identity / worker-codex-app-engine-root /
daemon-deployment-continuation / ordinary-turn-recovery 共 261 项全绿。

Co-Authored-By: Claude Code <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants