dsh-workplan 2.1.3 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/README.en.md +5 -2
  3. package/README.md +5 -2
  4. package/README.zh.md +5 -2
  5. package/client.js +143 -3
  6. package/docs/dsh-workplan_T4_runtime.patch +508 -0
  7. package/docs/release-records/_release_notes_2.1.2_20261106.md +44 -0
  8. package/docs/release-records/_t2_version_determination_20261106.md +39 -0
  9. package/docs/release-records/_t5_external_reverify_20261106.md +18 -0
  10. package/docs/release-records/release-dryrun-report-20261106.md +74 -0
  11. package/docs/release-records/release-notes-2.2.6-T3.md +128 -0
  12. package/docs/release-records/release-record-2.1.3-20261106.md +82 -0
  13. package/docs/release-records/release-steps-20261106.md +129 -0
  14. package/docs/release-records/version-freeze-20261109-T2.md +37 -0
  15. package/lib/client.js +143 -3
  16. package/lib/comm-format.js +17 -0
  17. package/lib/departments.js +19 -0
  18. package/lib/host.js +95 -17
  19. package/lib/notice-channel.js +290 -0
  20. package/lib/plan.js +541 -32
  21. package/lib/replan.js +4 -0
  22. package/lib/runtime.js +1481 -85
  23. package/lib/supersede.js +2 -2
  24. package/lib/understanding.js +8 -2
  25. package/lib/watchdog.js +52 -1
  26. package/package.json +3 -2
  27. package/scripts/repair-malformed-user-messages.mjs +312 -0
  28. package/src/client.ts +150 -2
  29. package/src/comm-format.ts +17 -0
  30. package/src/departments.ts +22 -0
  31. package/src/host.ts +90 -12
  32. package/src/notice-channel.ts +328 -0
  33. package/src/plan.ts +575 -24
  34. package/src/replan.ts +4 -0
  35. package/src/runtime.ts +1500 -86
  36. package/src/supersede.ts +2 -1
  37. package/src/understanding.ts +10 -2
  38. package/src/watchdog.ts +80 -1
@@ -0,0 +1,508 @@
1
+ # T4 波次补丁(柔性时长协商·运行时改造)
2
+ # 仅 src/runtime.ts、仅 T4 hunk;不含 14:32 预存 WIP hunk(WIP 不动、不回滚、不重排)。
3
+ # 归属标签:[2.2.0][T4/O-3b](A/B/C/E/F)/[2.2.0][T4/O-3b][O-4c/O-4d](D);
4
+ # 两处纯措辞行 hunk 无标签行,属 C 项(消息不再写「强制结束」)。
5
+ diff --git a/src/runtime.ts b/src/runtime.ts
6
+ index 96b7042..2445227 100644
7
+ --- a/src/runtime.ts
8
+ +++ b/src/runtime.ts
9
+ @@ -34,6 +34,8 @@ import {
10
+ createStatuses,
11
+ deliveryReadiness,
12
+ derivePlanSnapshot,
13
+ + // [2.2.0][T4/O-3b] O-3b 消费接线:缺省协商上限由预估派生(plan.ts 纯函数,T3 已定稿)。
14
+ + deriveSubtaskTimeoutMs,
15
+ extractJson,
16
+ flattenSubtasks,
17
+ isRecord,
18
+ @@ -191,6 +209,13 @@ export const PLANNER_IDLE_TIMEOUT_MS = 90000
19
+ * plan became terminal at the first slow subtask. The ceiling is now a
20
+ * settlement guarantee, while the no-progress window below is what normally
21
+ * ends an attempt.
22
+ + *
23
+ + * [2.2.0][T4/O-3b] 语义更新(柔性时长协商,方案 §1③/§2.2):这不是固定交付
24
+ + * 期限,而是「协商上限+L4 安全兜底」——单次执行时限协商而来(subtask.timeoutMs
25
+ + * 显式值优先,缺省 deriveSubtaskTimeoutMs(estimateMinutes)=clamp(预估分钟×
26
+ + * 2.0×60000, MIN, MAX)),本常量只在无预估、无显式值时兜底(③C2 零回归)。
27
+ + * 时间是协商出来的安全兜底,不是固定交付期限:到点走 L4 安全兜底结算+
28
+ + * 「待裁决」标记(延期 / 重试 / 接受),不表述为「强制结束」式固定期限误杀。
29
+ */
30
+ export const CHILD_TIMEOUT_MS = 900000
31
+ /** No-progress window: the child's own session log stopped growing. */
32
+ @@ -202,7 +227,14 @@ export const CHILD_IDLE_TIMEOUT_MS = 300000
33
+ * minutes.
34
+ */
35
+ export const MIN_CHILD_TIMEOUT_MS = 1000
36
+ -export const MAX_CHILD_TIMEOUT_MS = 1800000
37
+ +/*
38
+ + * [2.2.0][T4/O-3b] 单次绝对上限 1800000 → 7200000(120 分钟):用户 2026-11-07
39
+ + * 决断(方案 §6 未知第 4 条)。协商上限 = clamp(预估分钟 × 2.0, 全局下限,
40
+ + * 单次绝对上限)(方案 §1③),2h 让「预告 60 分钟的子任务,其单次执行上限
41
+ + * ≥ 60 分钟」(方案 C1)成立;tests/time-estimate-negotiation.test.ts 的
42
+ + * expected 公式直接引用本常量,数值不同步会红灯。
43
+ + */
44
+ +export const MAX_CHILD_TIMEOUT_MS = 7200000
45
+ export const MIN_CHILD_IDLE_MS = 1000
46
+ export const MAX_CHILD_IDLE_MS = 900000
47
+ export const CHILD_POLL_MS = 2000
48
+ @@ -230,6 +262,9 @@ export const INSTRUCTION_ACK_DEADLINE_MS = 180000
49
+ * 会话读取次数控制在可接受范围(每个等指示的行每 5s 一次只读查询)。
50
+ */
51
+ export const INSTRUCTION_POLL_MS = 5000
52
+ +// [2.2.0][T4/O-3b] 本轮总预算(数值不变):与单次协商上限(见 CHILD_TIMEOUT_MS)
53
+ +// 区分——单次到点走 L4 安全兜底结算+待裁决,不是固定交付期限;本值仍是调度
54
+ +// 阶段的总预算兜底(方案 §2.5 剩余轮预算参与重试预算钳制)。
55
+ export const TOTAL_TIMEOUT_MS = 1200000
56
+ export const DISPOSE_TIMEOUT_MS = 5000
57
+ export const STALE_PENDING_MS = 10 * 60 * 1000
58
+ @@ -1105,11 +1400,24 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
59
+ let interruptedFlag = false
60
+ let interruptedEvidence: { artifacts: any[]; missingArtifacts: string[] } | null = null
61
+ try {
62
+ + // [2.2.0][T4/O-3b] 尝试起点与协商截止同一时钟读数(C3 契约:deadlineAt −
63
+ + // startedAt 严格等于协商窗口)。deadlineAt 走 StatusEntry 未知字段保留通道
64
+ + // 直写:applyStatus(src/plan.ts,T3 领地)无路由分支,patch 会静默丢弃。
65
+ + const attemptStartMs = Date.now()
66
+ + const attemptWindowMs = Number(options.attemptTimeoutMs ?? 0)
67
+ if (!writeSubtaskStatus(record, subtask.id, {
68
+ status: 'in_progress',
69
+ progress: 5,
70
+ - startedAt: Date.now(),
71
+ + startedAt: attemptStartMs,
72
+ }, guard)) return
73
+ + if (Number.isFinite(attemptWindowMs) && attemptWindowMs > 0) {
74
+ + const attemptRow = record.statuses.find((item: any) => item?.subtaskId === subtask.id)
75
+ + if (attemptRow) attemptRow.deadlineAt = attemptStartMs + attemptWindowMs
76
+ + if (options.attemptHandle) {
77
+ + options.attemptHandle.startedAt = attemptStartMs
78
+ + options.attemptHandle.deadlineAt = attemptStartMs + attemptWindowMs
79
+ + }
80
+ + }
81
+
82
+ for (let attempt = firstAttempt; attempt <= 2; attempt += 1) {
83
+ if (guard.timedOut) return
84
+ @@ -1269,8 +1577,55 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
85
+ deadlineTimer.unref?.()
86
+ ackTimers.push(deadlineTimer)
87
+ const idleTimeoutMs = normaliseIdleTimeout(options.idleTimeoutMs)
88
+ - const hardTimeoutMs = normaliseChildTimeout(options.childTimeoutMs)
89
+ + // [2.2.0][T4/O-3b][O-4d] 双计时同源(方案 §2.5):看门狗 hardMs 与本次尝试的
90
+ + // 协商执行时限同值(options.attemptTimeoutMs,缺省回落旧路径);两者必须同步
91
+ + // 推移——延期时 rearmApproachingDeadline 传「自尝试起点计的新完整窗口」。
92
+ + const hardTimeoutMs = Number.isFinite(Number(options.attemptTimeoutMs)) && Number(options.attemptTimeoutMs) > 0
93
+ + ? Math.min(MAX_CHILD_TIMEOUT_MS, Math.max(MIN_CHILD_TIMEOUT_MS, Number(options.attemptTimeoutMs)))
94
+ + : normaliseChildTimeout(options.childTimeoutMs)
95
+ const watchdog = createProgressWatchdog({
96
+ + // [2.2.0][T4/O-3b][O-4b] 到点预警接线(T7 watchdog.ts 契约,原样消费):
97
+ + // 剩余 ≤ max(timeoutMs×0.2, 120000) 触发一次、同一武装周期幂等、extend 后
98
+ + // rearm 可再触发。最小处理器:时间链留档 timeWarning+本轮记录 notice+会话
99
+ + // 消息通知主 Agent(格式朴素,T6 波次统一润色)。
100
+ + subtaskId: String(subtask.id),
101
+ + onApproachingDeadline: (info: any) => {
102
+ + if (guard.timedOut) return
103
+ + try {
104
+ + const warnRow = Array.isArray(record.statuses)
105
+ + ? record.statuses.find((item: any) => item?.subtaskId === subtask.id)
106
+ + : null
107
+ + if (warnRow) {
108
+ + // timeWarning 走未知字段通道直写(applyStatus 白名单属 T3 领地)。
109
+ + warnRow.timeWarning = {
110
+ + at: Date.now(),
111
+ + remainingMs: Math.max(0, Number(info?.remainingMs ?? 0)),
112
+ + newEstimateMinutes: null,
113
+ + channel: 'watchdog',
114
+ + }
115
+ + }
116
+ + const text = `子任务 ${subtask.id} 即将到点:剩余 ${Math.max(0, Math.round(Number(info?.remainingMs ?? 0) / 1000))}s(协商上限 ${Number(info?.timeoutMs ?? 0)}ms);如需继续请尽快决定延期(extendMs),否则到点将按安全兜底结算(待裁决)`
117
+ + record.notices = [...(record.notices ?? []), text].slice(-20)
118
+ + record.updatedAt = Date.now()
119
+ + /*
120
+ + * 会话消息只对「有决策余量」的窗口推送:窗口 < 120000ms(=触发规则
121
+ + * max(timeoutMs×0.2, 120000) 里的预警下限,生产最小派生窗口恰好
122
+ + * 120000ms)只出现在测试小窗场景,预警本身没有可执行的延期决策余量,
123
+ + * 此时只留档(record.notices+timeWarning),不推送会话消息——也不与
124
+ + * tests/workplan-stuck-recovery.test.ts「session.events 只计持久消息」
125
+ + * 的既有断言冲突。T6 波次统一润色通知渠道时再定稿推送策略。
126
+ + */
127
+ + if (Number(info?.timeoutMs ?? 0) >= 120000) {
128
+ + options.agent?.session?.append?.('notice', {
129
+ + at: Date.now(),
130
+ + subtaskId: String(subtask.id),
131
+ + text,
132
+ + })
133
+ + }
134
+ + } catch {
135
+ + // 预警只做提示不得影响执行:写档失败静默忽略(T6 波次统一润色)。
136
+ + }
137
+ + },
138
+ getSeq: () => {
139
+ try {
140
+ const childSession = ctx.sessions?.get?.(activation.childId)
141
+ @@ -1317,6 +1672,9 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
142
+ { subtaskId: subtask.id },
143
+ ),
144
+ })
145
+ + // [2.2.0][T4/O-3b][O-4d] 看门狗挂到计时句柄:extendDeadline 延期成功后经
146
+ + // watchdog.rearmApproachingDeadline(传新完整窗口)同步推移两处计时。
147
+ + options.attemptHandle?.attachWatchdog?.(watchdog)
148
+ let result: any
149
+ try {
150
+ const waiter = waitForActivation(activation, child.controller.signal)
151
+ @@ -1469,6 +1827,109 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
152
+ }
153
+ }
154
+
155
+ +/*
156
+ + * [2.2.0][T4/O-3b] 本次执行时限(柔性时长协商消费序;T3b 待决点③裁决:消费侧钳位)。
157
+ + *
158
+ + * 消费序:① subtask.timeoutMs 显式协商上限(O-3c 原样透传)→ ② 缺省
159
+ + * deriveSubtaskTimeoutMs(estimateMinutes)=clamp(预估分钟×2.0×60000, 1000,
160
+ + * 7200000) 派生(方案 §1③)→ ③ 两者皆无回落 normaliseChildTimeout(全局兜底
161
+ + * CHILD_TIMEOUT_MS,方案 ③C2 零回归)。结果统一钳 [MIN_CHILD_TIMEOUT_MS,
162
+ + * MAX_CHILD_TIMEOUT_MS](方案 ③C3)。
163
+ + *
164
+ + * 显式注入的 childTimeoutMs(测试小窗 / DSH_WORKPLAN_CHILD_TIMEOUT_MS 旋钮)
165
+ + * 语义是「兜底上限」而非「固定值」(方案 §5.2「协商的默认基准/兜底上限」):
166
+ + * 它对上面三步的结果取 min。必须区分「显式注入」与「缺省」——验收合同
167
+ + * tests/no-fixed-deadline-semantics.test.ts E4 注入 1000ms 小窗必须压过
168
+ + * estimateMinutes:10 派生的 1200000ms;而 tests/time-estimate-negotiation
169
+ + * .test.ts C3(无注入)派生值必须严格生效(deadlineAt − startedAt === 派生值)。
170
+ + * 因此 dispatchPlan 三处调用点改传 options.childTimeoutMs 原始值(未配置=
171
+ + * undefined),不再传 normalise 后的 limits.childTimeoutMs(后者恒为 900000,
172
+ + * 无法区分显式与缺省)。
173
+ + */
174
+ +function resolveSubtaskTimeoutMs(subtask: any, configuredChildTimeoutMs: any) {
175
+ + const clampWindow = (value: number) =>
176
+ + Math.min(MAX_CHILD_TIMEOUT_MS, Math.max(MIN_CHILD_TIMEOUT_MS, value))
177
+ + const explicit = Number(subtask?.timeoutMs)
178
+ + const derived = deriveSubtaskTimeoutMs(subtask?.estimateMinutes, MIN_CHILD_TIMEOUT_MS, MAX_CHILD_TIMEOUT_MS)
179
+ + let window: number
180
+ + if (Number.isFinite(explicit) && explicit > 0) window = clampWindow(explicit)
181
+ + else if (derived !== undefined) window = clampWindow(derived)
182
+ + else window = normaliseChildTimeout(configuredChildTimeoutMs)
183
+ + // 显式注入=兜底上限(对协商结果取 min);未配置不封顶。
184
+ + const cap = Number(configuredChildTimeoutMs)
185
+ + if (Number.isFinite(cap) && cap > 0) window = Math.min(window, clampWindow(cap))
186
+ + return window
187
+ +}
188
+ +
189
+ +/*
190
+ + * [2.2.0][T4/O-3b][O-4c/O-4d] 延期接口(D 项;T5 extendMs 事务的计时侧承接)。
191
+ + *
192
+ + * 调用契约(T5 按此接线):
193
+ + * extendDeadline(record, subtaskId, extendMs, { by?, reason? })
194
+ + * → 成功 { ok: true, deadlineAt, timerRearmed: true, watchdogRearmed }
195
+ + * → 拒绝 { ok: false, code: 'INVALID_EXTEND' | 'NO_ACTIVE_ATTEMPT', error, hint }
196
+ + *
197
+ + * 语义与边界:
198
+ + * - extendMs 须为正有限数(毫秒,向下取整),否则 INVALID_EXTEND。
199
+ + * - 只对「有活跃尝试」的子任务生效(runSubtaskAttempt 已注册计时句柄且未收束);
200
+ + * 已到点收束 / 已结束的尝试一律 NO_ACTIVE_ATTEMPT(不能复活已结算的行)。
201
+ + * - 累计放宽预算校验(≤初始协商上限×1,超限 EXTEND_BUDGET_EXHAUSTED→转新轮
202
+ + * 续跑或转 escalate)属 T5 事务层职责,本函数不重复校验:调用方先校验再调用。
203
+ + * - 线程/并发语义:Node 单线程;本函数「校验→改 deadlineAt→重置计时器→
204
+ + * watchdog.rearmApproachingDeadline→行内直写」在一个同步段完成,天然原子;
205
+ + * 并发调用按到达顺序串行,每次追加独立 timeJournal 条目(action:'extend')。
206
+ + * - 延期成功后 deadlineAt 同步更新(行上字段=句柄 deadlineAt),runSubtaskAttempt
207
+ + * 的一次性计时器重置为「新截止点 − now」,原截止点不再触发(O-4d:任务不被
208
+ + * 原截止点杀死)。
209
+ + * - 与 watchdog 的配合(F 项):watchdog.rearmApproachingDeadline(newTimeoutMs)
210
+ + * 传入「自尝试起点计的新完整窗口」=deadlineAt − 尝试起点(T7 watchdog.ts
211
+ + * 契约,不是剩余量);两处计时同步推移(方案 §2.5),先触发者仍会杀任务。
212
+ + * - 行字段直写原因:applyStatus(src/plan.ts,T3 领地)无 deadlineAt/timeJournal
213
+ + * 路由分支,patch 会静默丢弃;这里走 StatusEntry 未知字段保留通道直写,
214
+ + * 回放/重建白名单在 reconstructFromSession 同名直写(本文件 2931 一带)。
215
+ + */
216
+ +export function extendDeadline(record: any, subtaskId: any, extendMs: any, meta: any = {}) {
217
+ + const id = String(subtaskId ?? '')
218
+ + const amount = Number(extendMs)
219
+ + if (!Number.isFinite(amount) || amount < 1) {
220
+ + return {
221
+ + ok: false,
222
+ + code: 'INVALID_EXTEND',
223
+ + error: `extendMs 必须是正有限数(毫秒):${String(extendMs)}`,
224
+ + hint: '请传入 1 以上的毫秒数;需要更长时限请转新轮续跑或转 escalate',
225
+ + }
226
+ + }
227
+ + const delta = Math.floor(amount)
228
+ + const handle = record?.attemptHandles?.[id]
229
+ + if (!handle || handle.settled) {
230
+ + return {
231
+ + ok: false,
232
+ + code: 'NO_ACTIVE_ATTEMPT',
233
+ + error: `子任务 ${id} 当前没有可延期的执行中尝试`,
234
+ + hint: '已收束的尝试不能复活:请转新轮续跑或人工裁决(escalate)',
235
+ + }
236
+ + }
237
+ + const deadlineAt = handle.extend(delta)
238
+ + const row = Array.isArray(record?.statuses)
239
+ + ? record.statuses.find((item: any) => item?.subtaskId === id)
240
+ + : null
241
+ + if (row) {
242
+ + // deadlineAt/timeJournal 走未知字段通道直写(applyStatus 白名单属 T3 领地)。
243
+ + row.deadlineAt = deadlineAt
244
+ + const journal = Array.isArray(row.timeJournal) ? row.timeJournal : []
245
+ + journal.push({
246
+ + at: Date.now(),
247
+ + action: 'extend',
248
+ + extendMs: delta,
249
+ + by: ['agent', 'child', 'system'].includes(meta?.by) ? meta.by : 'agent',
250
+ + reason: truncate(String(meta?.reason ?? ''), 300),
251
+ + })
252
+ + row.timeJournal = journal.slice(-20)
253
+ + }
254
+ + record.updatedAt = Date.now()
255
+ + return { ok: true, deadlineAt, timerRearmed: true, watchdogRearmed: Boolean(handle.watchdog) }
256
+ +}
257
+ +
258
+ /*
259
+ * One attempt under a deadline that belongs to that attempt alone.
260
+ *
261
+ @@ -1508,14 +1969,45 @@ async function runSubtaskAttempt(
262
+ */
263
+ let ceilingFingerprint: any[] = []
264
+ const stat = typeof options.artifactStat === 'function' ? options.artifactStat : statSync
265
+ + /*
266
+ + * [2.2.0][T4/O-3b][O-4d] 可延期计时句柄(D 项延期接口的运行时锚点,方案 §2.2/§2.5)。
267
+ + * 本次尝试的协商截止只属于这次尝试:extend() 重置一次性计时器并同步 watchdog
268
+ + * (rearmApproachingDeadline 传「自尝试起点计的新完整窗口」);settled 后不得
269
+ + * 复活(extendDeadline 一律 NO_ACTIVE_ATTEMPT)。行上 deadlineAt 由 executeSubtask
270
+ + * 以同一时钟读数写入(C3 契约),句柄权威值随写同步。
271
+ + */
272
+ + const attemptStart = Date.now()
273
+ + const attemptHandle = {
274
+ + subtaskId: String(subtask.id),
275
+ + startedAt: attemptStart,
276
+ + deadlineAt: attemptStart + timeoutMs,
277
+ + settled: false,
278
+ + watchdog: null as any,
279
+ + arm: (_ms: number) => {},
280
+ + extend(ms: number) {
281
+ + if (this.settled) return this.deadlineAt
282
+ + this.deadlineAt += ms
283
+ + this.arm(this.deadlineAt - Date.now())
284
+ + this.watchdog?.rearmApproachingDeadline(this.deadlineAt - this.startedAt)
285
+ + return this.deadlineAt
286
+ + },
287
+ + attachWatchdog(watchdog: any) {
288
+ + this.watchdog = watchdog
289
+ + },
290
+ + }
291
+ + record.attemptHandles = { ...(record.attemptHandles ?? {}), [String(subtask.id)]: attemptHandle }
292
+ const deadlinePromise = new Promise<void>((resolve) => {
293
+ - timer = setTimeout(() => {
294
+ + const fire = () => {
295
+ ceilingFired = true
296
+ guard.timedOut = true
297
+ - // Reached only when the child ignored both its idle window and its
298
+ - // abort signal; the message says so, otherwise the cause looks like a
299
+ - // plain "too slow" and the next investigation goes down the wrong path.
300
+ - const message = `子任务 ${subtask.id} 达到执行上限(${timeoutMs}ms),已强制结束`
301
+ + attemptHandle.settled = true
302
+ + // [2.2.0][T4/O-3b][O-4d] L4 安全兜底结算+「待裁决」标记(E4 契约):时间是
303
+ + // 协商出来的安全兜底,不是固定交付期限——到点不表述为「强制结束」式固定期限
304
+ + // 误杀,而是安全兜底结算落盘,供主 Agent 决定延期 / 重试 / 接受(或转新轮
305
+ + // 续跑、人工裁决)。Reached only when the child ignored both its idle window
306
+ + // and its abort signal; the message says so, otherwise the cause looks like
307
+ + // a plain "too slow" and the next investigation goes down the wrong path.
308
+ + const message = `子任务 ${subtask.id} 达到协商执行上限(${timeoutMs}ms),已按安全兜底结算(待裁决:请主 Agent 决定延期 / 重试 / 接受,或转新轮续跑、人工裁决)`
309
+ try {
310
+ // [1.8.19] Keep the evidence of what already landed on disk.
311
+ const { patch, landed } = timeoutBlockedPatch(subtask, options.cwd, message, options.artifactExists)
312
+ @@ -1539,6 +2031,13 @@ async function runSubtaskAttempt(
313
+ record.statuses = applyStatus(record.statuses, subtask.id, patch)
314
+ record.errors = [...(record.errors ?? []), `${subtask.id}: ${patch.error}`].slice(-20)
315
+ }
316
+ + /*
317
+ + * [2.2.0][T4/O-3b][C/E] 「待裁决」结构化标记(E4 契约):结算文案已含
318
+ + * 「待裁决」,这里再落机器可读标记供裁决/回放白名单透传(pendingAdjudication)。
319
+ + * 走 StatusEntry 未知字段通道直写(applyStatus 白名单属 T3 领地)。
320
+ + */
321
+ + const settleRow = record.statuses.find((item: any) => item?.subtaskId === subtask.id)
322
+ + if (settleRow) settleRow.pendingAdjudication = true
323
+ record.updatedAt = Date.now()
324
+ } catch (error: any) {
325
+ record.errors = [
326
+ @@ -1552,8 +2051,16 @@ async function runSubtaskAttempt(
327
+ child.disposeListener()
328
+ resolve()
329
+ }
330
+ - }, timeoutMs)
331
+ - timer.unref?.()
332
+ + }
333
+ + // [2.2.0][T4/O-3b][O-4d] 可延期计时(D 项):arm() 重置一次性计时器,extend()
334
+ + // 经 attemptHandle 调用它把截止点推移到新协商截止;原截止点不再触发。
335
+ + const arm = (ms: number) => {
336
+ + if (timer) clearTimeout(timer)
337
+ + timer = setTimeout(fire, Math.max(1, ms))
338
+ + timer.unref?.()
339
+ + }
340
+ + attemptHandle.arm = arm
341
+ + arm(timeoutMs)
342
+ })
343
+ try {
344
+ // [1.8.6] The outcome (`{interrupted:true}`) has to reach the dispatcher;
345
+ @@ -1563,11 +2070,18 @@ async function runSubtaskAttempt(
346
+ ...options,
347
+ child,
348
+ guard,
349
+ + // [2.2.0][T4/O-3b] 本次尝试的协商执行时限与计时句柄(deadlineAt 写入同源、
350
+ + // 看门狗 hardMs 同值、延期接口锚点)。
351
+ + attemptTimeoutMs: timeoutMs,
352
+ + attemptHandle,
353
+ }),
354
+ deadlinePromise,
355
+ ])
356
+ return { outcome, ceilingFired, ceilingLanded, ceilingFingerprint }
357
+ } finally {
358
+ + // [2.2.0][T4/O-3b] 收束即注销句柄:已收束的尝试不得再被 extendDeadline 复活。
359
+ + attemptHandle.settled = true
360
+ + if (record.attemptHandles) delete record.attemptHandles[String(subtask.id)]
361
+ if (timer) {
362
+ clearTimeout(timer)
363
+ timer = null
364
+ @@ -1592,7 +2106,10 @@ async function runSubtaskAttempt(
365
+ * skipped and the row is marked `artifactConflict` instead of overwriting it.
366
+ */
367
+ async function runSubtask(ctx: any, record: any, stage: any, subtask: any, options: any) {
368
+ - const childTimeoutMs = normaliseChildTimeout(options.childTimeoutMs)
369
+ + // [2.2.0][T4/O-3b] 本次执行时限=柔性时长协商消费序(见 resolveSubtaskTimeoutMs):
370
+ + // ① subtask.timeoutMs 显式值 → ② deriveSubtaskTimeoutMs(estimateMinutes) 派生 →
371
+ + // ③ 缺省回落 CHILD_TIMEOUT_MS;显式注入的 childTimeoutMs 作兜底上限取 min。
372
+ + const childTimeoutMs = resolveSubtaskTimeoutMs(subtask, options.childTimeoutMs)
373
+ const first = await runSubtaskAttempt(ctx, record, stage, subtask, options, childTimeoutMs)
374
+ if (!first.ceilingFired) return first.outcome
375
+
376
+ @@ -1600,7 +2117,7 @@ async function runSubtask(ctx: any, record: any, stage: any, subtask: any, optio
377
+ const now = Date.now()
378
+ const deadline = Number.isFinite(options.deadline) ? Number(options.deadline) : now + childTimeoutMs
379
+ const remaining = deadline - now
380
+ - const message = `子任务 ${subtask.id} 达到执行上限(${childTimeoutMs}ms)`
381
+ + const message = `子任务 ${subtask.id} 达到协商执行上限(${childTimeoutMs}ms)`
382
+ /*
383
+ * [1.8.6] A parent abort outranks a retry: the round is being stopped on
384
+ * purpose, and a second child would only be aborted on arrival.
385
+ @@ -1654,7 +2171,7 @@ async function runSubtask(ctx: any, record: any, stage: any, subtask: any, optio
386
+ const second = await runSubtaskAttempt(ctx, record, stage, subtask, {
387
+ ...options,
388
+ attemptOffset: 2,
389
+ - priorFailure: { attempt: 1, code: 'CHILD_TIMEOUT', message: `${message},已强制结束` },
390
+ + priorFailure: { attempt: 1, code: 'CHILD_TIMEOUT', message: `${message},已按安全兜底结算(待裁决)` },
391
+ }, retryTimeoutMs)
392
+ return second.outcome
393
+ }
394
+ @@ -1739,6 +2256,21 @@ export function modelStatusLines(statuses: any) {
395
+ status: handoff.status,
396
+ })),
397
+ reportedAt: item.reportedAt ?? null,
398
+ + /*
399
+ + * [2.2.0][T4/O-3b][O-2.4] 柔性时长协商字段进入模型可读面(纯展示):
400
+ + * 协商截止 deadlineAt、尝试起点 startedAt、剩余协商时间、预警标记 timeWarning、
401
+ + * 待裁决标记 pendingAdjudication 与时间链审计 timeJournal。验收合同
402
+ + * tests/time-estimate-negotiation.test.ts C3 直接从 statusTool 输出读
403
+ + * deadlineAt/startedAt(字段名/单位照合同原文)。
404
+ + */
405
+ + startedAt: item.startedAt ?? null,
406
+ + deadlineAt: item.deadlineAt ?? null,
407
+ + deadlineRemainingMs: Number.isFinite(Number(item.deadlineAt))
408
+ + ? Math.max(0, Number(item.deadlineAt) - Date.now())
409
+ + : null,
410
+ + timeWarning: item.timeWarning ?? null,
411
+ + timeJournal: Array.isArray(item.timeJournal) ? item.timeJournal.slice(-10) : [],
412
+ + pendingAdjudication: item.pendingAdjudication === true,
413
+ }))
414
+ }
415
+
416
+ @@ -2618,6 +3150,20 @@ export function reconstructFromSession(session: any, targetPlanId?: string) {
417
+ const snap = snapshots.get(result.planId)
418
+ if (snap) {
419
+ snap.statuses = applyResultStatuses(snap.statuses, result)
420
+ + /*
421
+ + * [2.2.0][T4/O-3b][E] 重建白名单(E 项,runtime 侧):applyResultStatuses
422
+ + * (src/plan.ts,T3 领地)逐字段重建不含柔性时长协商新字段,会把
423
+ + * deadlineAt/timeNotice/timeWarning/timeJournal/待裁决标记洗掉;结果消息
424
+ + * 整包透传行对象(字段在 entry 上),按 T3b plan.ts:2966-2971 同名修复
425
+ + * 口径补直写回放。
426
+ + */
427
+ + for (const entry of (Array.isArray(result.statuses) ? result.statuses : [])) {
428
+ + const rebuiltRow = snap.statuses.find((item: any) => item?.subtaskId === entry?.subtaskId)
429
+ + if (!rebuiltRow || !isRecord(entry)) continue
430
+ + for (const field of ['deadlineAt', 'timeNotice', 'timeWarning', 'timeJournal', 'pendingAdjudication']) {
431
+ + if (entry[field] !== undefined) rebuiltRow[field] = entry[field]
432
+ + }
433
+ + }
434
+ // Resume bookkeeping must survive a page refresh, otherwise the budget
435
+ // silently resets and a never-succeeding subtask can loop forever.
436
+ snap.resumeCount = Number(result.resumeCount ?? snap.resumeCount) || 0
437
+ @@ -2668,8 +3214,41 @@ export function reconstructFromSession(session: any, targetPlanId?: string) {
438
+ missingArtifacts: update.missingArtifacts,
439
+ handoffs: update.handoffs,
440
+ revision: Number.isInteger(update.revision) ? update.revision : undefined,
441
+ + // [2.2.0][T4/O-3b][E] 回放白名单(T3b TODO#2):O-3b/O-2c 留档字段随
442
+ + // update 记录回放;timeoutMs 有 applyStatus 分支,走 patch 即可。
443
+ + timeoutMs: update.timeoutMs,
444
+ updatedBy: 'agent',
445
+ })
446
+ + /*
447
+ + * [2.2.0][T4/O-3b][E] 柔性时长协商新字段回放(E 项,runtime.ts 2931 一带)。
448
+ + *
449
+ + * deadlineAt/timeNotice/timeWarning/timeJournal/待裁决标记在 applyStatus
450
+ + * (src/plan.ts,T3 领地)无路由分支,走 patch 会被静默丢弃;按 T3b
451
+ + * plan.ts:2966-2971 同名修复口径在此直写重建行。extendMs 走累加语义
452
+ + * (与线上 extendDeadline 一致:deadlineAt += extendMs 并追加 timeJournal),
453
+ + * 仅当记录未自带 timeJournal 时合成,避免同一条 journal 被回放两次。
454
+ + */
455
+ + const replayRow = snap.statuses.find((item: any) => item?.subtaskId === update.subtaskId)
456
+ + if (replayRow) {
457
+ + for (const field of ['deadlineAt', 'timeNotice', 'timeWarning', 'timeJournal', 'pendingAdjudication']) {
458
+ + if (update[field] !== undefined) replayRow[field] = update[field]
459
+ + }
460
+ + const replayExtend = Number(update.extendMs)
461
+ + if (update.timeJournal === undefined && Number.isFinite(replayExtend) && replayExtend > 0
462
+ + && Number.isFinite(Number(replayRow.deadlineAt))) {
463
+ + replayRow.deadlineAt = Number(replayRow.deadlineAt) + Math.floor(replayExtend)
464
+ + replayRow.timeJournal = [
465
+ + ...(Array.isArray(replayRow.timeJournal) ? replayRow.timeJournal : []),
466
+ + {
467
+ + at: Date.now(),
468
+ + action: 'extend',
469
+ + extendMs: Math.floor(replayExtend),
470
+ + by: 'agent',
471
+ + reason: truncate(String(update.reason ?? ''), 300),
472
+ + },
473
+ + ].slice(-20)
474
+ + }
475
+ + }
476
+ appliedUpdates.set(updateKey(update.planId, update.subtaskId), {
477
+ seq: Number(event.seq ?? 0),
478
+ status: String(update.status ?? ''),
479
+ @@ -3133,7 +3726,8 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
480
+ record.dispatchPromise = dispatchPlan(ctx, record, {
481
+ ...roundOptions,
482
+ signal: controller.signal,
483
+ - childTimeoutMs: limits.childTimeoutMs,
484
+ + // [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
485
+ + childTimeoutMs: options.childTimeoutMs,
486
+ idleTimeoutMs: limits.idleTimeoutMs,
487
+ totalTimeoutMs: limits.totalTimeoutMs,
488
+ maxResumes: limits.maxResumes,
489
+ @@ -3949,7 +4543,8 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
490
+ record.dispatchPromise = dispatchPlan(ctx, record, {
491
+ ...base,
492
+ signal: controller.signal,
493
+ - childTimeoutMs: limits.childTimeoutMs,
494
+ + // [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
495
+ + childTimeoutMs: options.childTimeoutMs,
496
+ idleTimeoutMs: limits.idleTimeoutMs,
497
+ totalTimeoutMs: limits.totalTimeoutMs,
498
+ maxResumes: limits.maxResumes,
499
+ @@ -5037,7 +5632,8 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
500
+ record.dispatchPromise = dispatchPlan(ctx, record, {
501
+ ...roundOptions,
502
+ signal: dispatchController.signal,
503
+ - childTimeoutMs: limits.childTimeoutMs,
504
+ + // [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
505
+ + childTimeoutMs: options.childTimeoutMs,
506
+ idleTimeoutMs: limits.idleTimeoutMs,
507
+ totalTimeoutMs: limits.totalTimeoutMs,
508
+ maxResumes: limits.maxResumes,
@@ -0,0 +1,44 @@
1
+ # dsh-workplan 2.1.2 发布说明(Release Notes)
2
+
3
+ 发布日期:2026-11-06 | 版本号:2.1.2 | 升级类型:patch(bug 修复)
4
+
5
+ ---
6
+
7
+ ## 一句话说明
8
+
9
+ 修复自动任务拆分「稳定超时被误报成意外中断」的问题:把规划器的思考时间上限从 2 分钟放宽到 5 分钟,并让真正超时时报出明确原因。
10
+
11
+ ## 一、问题是什么(通俗版)
12
+
13
+ 插件在接到一个复杂任务时,会先花一段时间自动把它「拆分」成几个子任务,再分派给各部门去执行。这一步是有时间上限的:
14
+
15
+ 1. 之前的上限只有 **2 分钟(120 秒)**。当任务描述特别长、要求特别多时,拆分还没做完,就被定时器强制打断了;
16
+ 2. 更糟的是,底层的大模型接口把「超时被打断」这件事,**误报成了「请求意外中断」**(`DeepSeek Messages request aborted`),看起来像网络偶发故障,根本看不出真正原因是「时间到了」。
17
+
18
+ 结果就是:复杂任务每次都会稳定失败,但日志却让人以为是「偶发中断」,排查方向被带偏。
19
+
20
+ ## 二、改了什么(只有这两处)
21
+
22
+ 1. 把拆分的时间上限从 **2 分钟(120 秒)放宽到 5 分钟(300 秒)**,给复杂任务留足拆分时间。
23
+ 2. 当确实是「超时」被打断时,不再被误报成「意外中断」,而是明确抛出「规划器超时:任务分解未在时限内完成」的清晰报错。
24
+
25
+ 改动只涉及 `lib/runtime.js` 与 `src/runtime.ts` 两个文件(+14/−2),没有改其它任何功能。
26
+
27
+ ## 三、安装
28
+
29
+ ```bash
30
+ npm install dsh-workplan@2.1.2
31
+ ```
32
+
33
+ (版本号 2.1.2 为 patch 升级,属 bug 修复级别。)
34
+
35
+ ---
36
+
37
+ ## 四、版本号与内容一致性核对清单
38
+
39
+ | # | 核对项 | 结果 | 证据 |
40
+ |---|---|---|---|
41
+ | C1 | 发布说明标题与正文版本号均为 **2.1.2**,与 T2 目标版本号一致 | ✅ 一致 | 本文档标题与正文、`CHANGELOG.md` 顶部 `## 2.1.2 — 2026-11-06`;T2 结论 `2.1.2`(patch,远端 404 未占用) |
42
+ | C2 | 只陈述已验证的两处修正(120000→300000、新增 PLANNER_TIMEOUT 明确报错),无虚构事实 | ✅ 一致 | `git diff`:`lib/runtime.js` 与 `src/runtime.ts` 各 +7/−1(共 +14/−2);`PLANNER_TIMEOUT_MS` 两文件均为 `300000`;新增 `throw new PlanError('规划器超时…','PLANNER_TIMEOUT')` |
43
+ | C3 | 改动范围陈述准确(仅 2 文件、+14/−2) | ✅ 一致 | `git diff --stat`:`lib/runtime.js` 与 `src/runtime.ts` 各 8 行改动(+7/−1)→ 合计 14 insertions / 2 deletions |
44
+ | C4 | 对外语句通俗易懂、无内部术语堆砌 | ✅ 通过 | 全文用「拆分」「时间上限」「意外中断」等白话表述,无 `runPlanner`/`abortError`/`PlanError` 等内部标识符直接出现在正文(仅作为代码引用保留必要的字段名说明) |
@@ -0,0 +1,39 @@
1
+ # T2 版本确定与发布渠道核对记录(2026-11-06)
2
+
3
+ 本文件为可复现证据记录,供 T4(运维发布)接手。
4
+
5
+ ## 一、包信息(读取 package.json)
6
+
7
+ | 字段 | 值 |
8
+ |---|---|
9
+ | name | `dsh-workplan` |
10
+ | 当前 version | `2.1.1` |
11
+ | publishConfig.access | `public` |
12
+ | main | `lib/host.js` |
13
+ | repository | git+https://github.com/abbaababa/dsh-workplan.git |
14
+
15
+ ## 二、版本冲突结论(A2)
16
+
17
+ - 远端 registry 已发布版本共 28 个,其中已含 `2.1.1`,且 `latest` dist-tag 指向 `2.1.1`。
18
+ - 本地 `package.json` 版本仍为 `2.1.1`,与远端冲突,**不可重复发布**(npm 拒绝覆盖已发布版本)。
19
+ - 「修正后的最新源代码」= `PLANNER_TIMEOUT_MS` 120000 → 300000 的超时修复,属于**未提交的工作区改动**(`git status`:`M lib/runtime.js`、`M src/runtime.ts`)。
20
+ - 远端 2.1.1 tarball 内 `PLANNER_TIMEOUT_MS = 120000`(旧值),本地为 `300000`,证明该修复**确为 2.1.1 之后的新改动**,尚未对外发布。
21
+ - **目标发布版本号:`2.1.2`**(patch 升级,属 bug 修复级别,符合 semver 递增规则)。`2.1.2` 远端返回 HTTP 404,未被占用。
22
+
23
+ ## 三、版本号规范性(A1)
24
+
25
+ - `2.1.2` 符合 semver `MAJOR.MINOR.PATCH` 规范(严格正则通过)。
26
+
27
+ ## 四、发布渠道与凭证(A3)
28
+
29
+ - 发布渠道:`https://registry.npmjs.org/`
30
+ - 发行 tag:`latest`(默认;package.json 无自定义 dist-tag,publishConfig 仅 access=public)
31
+ - 凭证:`~/.npmrc` 已配置 `//registry.npmjs.org/:_authToken`(40 字符,前缀 `npm_`,值已脱敏不落盘)。
32
+ - 凭证可用性验证(可复现):
33
+ - `npm whoami --cache /tmp/t2-npmcache` → `open-dsh`(通过)
34
+ - 直连 `GET https://registry.npmjs.org/-/whoami`(Authorization: Bearer <token>)→ `{"username":"open-dsh"}`(通过)
35
+
36
+ ## 五、已知环境风险(需转达 T4)
37
+
38
+ - 默认 npm 缓存目录 `/Users/open/.npm/_cacache/tmp` 存在 root 属主文件,导致 `npm whoami`(不带 --cache)报 `EPERM`。
39
+ - **规避方式**:发布时使用 `npm publish --cache /tmp/<可写目录>`,或先 `sudo chown -R 501:20 /Users/open/.npm`(需提权,子 Agent 无此权限)。
@@ -0,0 +1,18 @@
1
+ # T5 外部渠道回验结果(2026-11-06)
2
+
3
+ ## A1 外部渠道可检索到目标版本号
4
+ - `GET https://registry.npmjs.org/dsh-workplan/2.1.2` → HTTP 200
5
+ - 返回 version=2.1.2, name=dsh-workplan
6
+ - `GET https://registry.npmjs.org/dsh-workplan` → dist-tags = {"latest":"2.1.2"}
7
+
8
+ ## A2 远端内容与本地修正后代码关键点一致
9
+ - 远端 tarball 本地计算 shasum = ac65faefcd1065386bf66f7533e9295cffaecd5b
10
+ (与 registry dist.shasum 完全一致)
11
+ - 远端 package/package.json version = 2.1.2(本地 package.json 同为 2.1.2)
12
+ - 远端 package/lib/runtime.js:97 = `export const PLANNER_TIMEOUT_MS = 300000;`
13
+ 本地 lib/runtime.js:97 = `export const PLANNER_TIMEOUT_MS = 300000;` → 一致
14
+ - 远端 package/src/runtime.ts:175 = `export const PLANNER_TIMEOUT_MS = 300000`
15
+ 本地 src/runtime.ts:175 = `export const PLANNER_TIMEOUT_MS = 300000` → 一致
16
+
17
+ ## A3 超时迹象
18
+ - 无。全程命令均在数秒内返回,未触发任何 step 超时。