Repository navigation
fix(schedule): 静默定时任务在 CLI 收下提示词前不再被当作已完成关闭 - #2334
Merged
Merged
Conversation
静默定时任务(新话题 / 任务专属话题)跑在隐藏会话里,回合首次空闲即回收。 OpenCode 的首条提示词经 --prompt 传入,TUI 加载期间可能静默超过首条静默 窗口(4 秒),worker 把这段静默当成回合结束,daemon 随即关闭隐藏会话, CLI 还没提交提示词就被结束,任务静默不执行(#1607)。 - worker:隐藏运行的 argv 首条提示词,若 CLI 自带会话库可确认提交 (OpenCode / MiMo Code),首次空闲等会话库记录到这条提示词再放行; 沿用 Pi 同款 90 秒兜底。范围判断抽成 hiddenRunSubmissionEvidence, 普通会话保持原来的首次空闲行为。 - 兜底到期仍未记录:worker 以失败终态上报 schedule_prompt_undelivered, daemon 回收会话时把这次运行的执行记录改为错误,并在任务所在群发一条说明。 - 隐藏运行记下所属调度 runId,任务专属话题再次触发时随回合一起交接。 Closes #1607 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 25, 2026 10:09
Owner
Author
|
已合并 → 8901859(squash)。
后续事项(不阻断):
|
90 秒兜底到期时,原来只读一次 OpenCode 库就判定提示词没送达:读库失败 (库被删、打不开、查询出错)也被当成「库里没有这一行」,会在群里误报 「本次没有执行」并把执行记录改成 error,而这次运行可能正在正常执行。 - adapter 契约:findInitialPromptArgSubmission 读不了库时带 unreadable, OpenCode 的 detectNewSubmit 不再把读失败压成 found:false。 - worker:到期时按三态判断(已记录 / 读到了但没有 / 读不了),只有 「读到了但没有」才上报 schedule_prompt_undelivered;读不了只记一条日志, 照常放行空闲,不改执行记录、不发群提示。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…recondition-dispose
This was referenced Oct 25, 2026
deepcoldy
pushed a commit
that referenced
this pull request
Oct 25, 2026
deepcoldy
pushed a commit
that referenced
this pull request
Oct 25, 2026
|
🚀 Released in v3.52.0 |
baicaicc
added a commit
that referenced
this pull request
Oct 27, 2026
rebase 到 master 66c8eab 后的整合提交: - 计数归一:runStats.consecutiveFailures 为唯一计数;删除顶层 task.consecutiveFailures。nextFailureTracking 改为读写账本, crossedFailureThreshold 由结算前后推导(after≥阈值 且 before<阈值), 每段失败串恰好越线一次。 - 迁移吸收:absorbLegacyFailureStats 把 #2334 已落盘的顶层计数折叠进 账本(max 胜出,不回退在途失败串),JSON store migrate 与 authority store parseTask(SQLite task_json)都过一遍。 - 两个水印各自保留:管理员 DM 的顶层 failureAlertSent 落盘即记账 (#2334 原语义,投递 fire-and-forget);owner @ 的 runStats.failingNotifiedAt 投递成功才写。不合并。 - 阈值统一:SCHEDULE_FAILURE_ALERT_THRESHOLD 保留为 SCHEDULE_FAILING_THRESHOLD 的兼容别名,两套通知共用一段失败串。 - 触发面:管理员 DM 对所有周期任务无条件(#2334 照旧);owner @ 仅 notify:['failing'] opt-in(本 PR 设计)。正交并存。 - 日历 error 计入共享计数(本 PR 口径),三连 error 同时触发管理员 DM (刻意更一致);legacy markCalendarBlocked 同步,calendar 结算点新增 emitFailureAlertIfNeeded。 - markRun 的追踪推进提前到 until-done 早退之前,closing/until-done 结算也推进同一计数;daemon 两个注册(setScheduleFailureAlert / setScheduleNotifier)并存,emit 点核对含 closing 路径。 测试:#2334 用例适配新签名并保留全部行为覆盖;新增顶层计数吸收 (JSON + authority)、未 opt-in 只走管理员 DM、opt-in 双通道同一次 越线且水印互不代写、投递失败不回滚管理员水印、日历 error 双路径 管理员告警、planCronRealign 窗口门纯函数 + restart 断言 (realign 后 nextRunAt 仍等于 finalRetryAt,P3 加固)。
baicaicc
added a commit
that referenced
this pull request
Oct 27, 2026
rebase 到 master 66c8eab 后的整合提交: - 计数归一:runStats.consecutiveFailures 为唯一计数;删除顶层 task.consecutiveFailures。nextFailureTracking 改为读写账本, crossedFailureThreshold 由结算前后推导(after≥阈值 且 before<阈值), 每段失败串恰好越线一次。 - 迁移吸收:absorbLegacyFailureStats 把 #2334 已落盘的顶层计数折叠进 账本(max 胜出,不回退在途失败串),JSON store migrate 与 authority store parseTask(SQLite task_json)都过一遍。 - 两个水印各自保留:管理员 DM 的顶层 failureAlertSent 落盘即记账 (#2334 原语义,投递 fire-and-forget);owner @ 的 runStats.failingNotifiedAt 投递成功才写。不合并。 - 阈值统一:SCHEDULE_FAILURE_ALERT_THRESHOLD 保留为 SCHEDULE_FAILING_THRESHOLD 的兼容别名,两套通知共用一段失败串。 - 触发面:管理员 DM 对所有周期任务无条件(#2334 照旧);owner @ 仅 notify:['failing'] opt-in(本 PR 设计)。正交并存。 - 日历 error 计入共享计数(本 PR 口径),三连 error 同时触发管理员 DM (刻意更一致);legacy markCalendarBlocked 同步,calendar 结算点新增 emitFailureAlertIfNeeded。 - markRun 的追踪推进提前到 until-done 早退之前,closing/until-done 结算也推进同一计数;daemon 两个注册(setScheduleFailureAlert / setScheduleNotifier)并存,emit 点核对含 closing 路径。 测试:#2334 用例适配新签名并保留全部行为覆盖;新增顶层计数吸收 (JSON + authority)、未 opt-in 只走管理员 DM、opt-in 双通道同一次 越线且水印互不代写、投递失败不回滚管理员水印、日历 error 双路径 管理员告警、planCronRealign 窗口门纯函数 + restart 断言 (realign 后 nextRunAt 仍等于 finalRetryAt,P3 加固)。
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.
Closes #1607
现象
带 Bash 前置条件的静默定时任务(
new-topic/task位置,跑在隐藏会话里):调度记录显示model_dispatched, precondition=passed,CLI(OpenCode)也起来了,但提示词从没提交,约 3–4 秒后会话被关闭,任务静默不执行,只留一条无关的 WARN。根因
隐藏会话的回收时机是「这一回合第一次空闲」:worker 报空闲 → daemon 去抖 1.5 秒(
scheduleDeferredScheduleSettlement→settleDeferredScheduleRun)→ 没有botmux send就关会话。OpenCode 的首条提示词经
--prompt传入,没有可靠的就绪提示符,worker 只能靠「输出静默 4 秒」判断空闲(adapter 的首条静默窗口),而且把这类 CLI 的第一次空闲直接当成回合结束。所以 OpenCode 的 TUI 在加载期只要画完一帧后静默超过 4 秒,worker 就报空闲,daemon 关掉会话,此时 OpenCode 还没提交提示词。用户日志里init之后约 4 秒disposing instance、库里没有这次的 session 行,与此一致。复现(控制变量)
1. issue 里的变量:前置条件耗时。 前置条件只决定「是否、何时」调用
execute:printf '1\n'与sleep 2; printf '1\n'给execute的参数完全相同(stdout 都是1、没有附加 prompt),之后建会话、发给 worker 的 init 也完全相同(src/services/schedule-precondition-gate.ts等脚本完全结束才调execute,executeScheduledTask里没有依赖触发时刻的逻辑)。所以在隔离环境里单改前置条件耗时不会改变投递结果,这一点按代码核对过,也没能单靠它复现。真正决定成败的变量是 CLI 加载期的静默时长是否超过 4 秒。用户环境里慢前置条件和失败同时出现,推测是同一时刻 OpenCode 冷启动变慢(macOS 冷启动、同一时间点触发的其它任务同时拉起 CLI 等),这一点无法在本机验证,如实说明。2. 真实 OpenCode 复现(隔离 HOME,provider 指向本机关闭端口,不出网)。 真实 worker(
src/worker.ts)驱动真实 opencode 1.19.3,按静默定时任务的 init(带deferredScheduleRun、schedule:回合)启动;opencode 经一个启动器拉起:先画一帧,再静默 N 秒后exec opencode。记录 worker 报这一回合空闲的时间与 opencode 把提示词写进自己库的时间:3. 确定性用例(进 CI):
test/schedule-hidden-run-first-idle.integration.test.ts。真实 worker + 一个假 opencode:画一帧、静默 6.5 秒、再把提示词写进 opencode 库并跑一个短回合。修复前这条用例红(expected <空闲时间> to be greater than <提示词落库时间>)。修法
deferredScheduleRun)、首条提示词经 argv 传入、CLI 能从自己的库确认提交(OpenCode / MiMo Code 已有的findInitialPromptArgSubmission,按文本匹配)、启动前能读到库的基线。等待复用 Pi 已有的 90 秒兜底;其余会话保持原来的第一次空闲行为。schedule_prompt_undelivered),再照常放行空闲;daemon 把这个结论记在会话上(失败终态之后紧跟着的空闲会重新排一次结算),关会话时:markScheduleRunLogFailed;多群任务只改出问题的那个群);schedule_prompt_undelivered;读不了只记一条 WARN 日志并照常放行空闲,不改执行记录、不发群提示——一次读失败不能证明这次运行没执行。为此 adapter 契约findInitialPromptArgSubmission增加unreadable标记,OpenCode 的detectNewSubmit不再把读失败压成「没有这一行」(写入时的提交确认只读found,不受影响)。runId随deferredScheduleRun一起保存,task位置的隐藏会话再次触发时随回合交接,执行记录改的是正确的那一次。老用户行为
属于修错误行为:以前提示词没送到就被当成执行完成、静默关掉,现在等真正送达再结束回合;真没送达时,执行记录和群里都看得到。群提示只在「这次运行确实没有执行」时发一次,不新增配置;正常运行(提示词送达)不多发任何消息。持久化只多一个可选字段
deferredScheduleRun.runId,老数据没有它时照常运行(只是不改执行记录,群提示照发)。影响面
new-topic/task位置的隐藏运行 + OpenCode / MiMo Code + 启动前能读到它的库」生效。普通会话、非静默任务、续接(resume,提示词走输入队列)不受影响;这道范围条件抽成了hiddenRunSubmissionEvidence并有用例锁住。验证
那 1 例是
worker-argv-reaction-status.integration的「90 秒兜底时 PTY 仍在输出不放行空闲」(Pi 专属分支,本 PR 未改其逻辑):它要在真实 90 秒计时后 100 秒内等到一行日志,当时整机负载约 77,worker 启动慢了十几秒超时;单独重跑通过(Tests 1 passed)。新增 / 改动的测试:
schedule-hidden-run-first-idle.integration:真实 worker + 假 opencode(静默 6.5 秒后才提交),空闲必须晚于提示词落库。schedule-hidden-run-argv-gate:worker 的真实闸门函数——等库、库读失败当未记录、90 秒到期先报未送达再放行、哪些 spawn 才启用这道等待(普通会话不启用)。schedule-hidden-run-terminal-settle/-undelivered-report:daemon 真实结算调度:失败终态之后的空闲仍按未送达结算,执行记录改为 error、群里发一条说明,两步互不影响。deferred-schedule-settlement/schedule-run-log-store/scheduler-silent-execute:结算结论、执行记录改写(多群只改出问题的群)、runId 保存与再次触发时交接。变异证据(每处单独改回、只跑相关用例、每枪 timeout 300 秒,跑完 worktree 干净)
unreadable标记found:falseunreadableN1–N5 是合前追加的「读不了库不下结论」修复的变异(同时复跑 M3 仍红)。追加修复后在同步了最新 master(含 #2327)的树上:
bun run build通过;schedule-hidden-run-*、deferred-schedule-settlement、schedule-run-log-store、scheduler-silent-execute、opencode-resume、opencode-first-prompt-quiescence、native-print-process、minimax-long-entry、test-hygiene共 12 文件 184 例全过。已知限制
XDG_DATA_HOME指到别处时,worker 读到的是另一个能正常打开的库(不属于「读不了」):会多等 90 秒后误报「未送达」。OpenCode 的续接目标探测等现有功能有同样的前提(worker 与 CLI 读同一个库)。🤖 Generated with Claude Code