dsh-workplan 2.1.5 → 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.
@@ -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,128 @@
1
+ # dsh-workplan v2.2.6 对外发布说明(T3 · 2026-11-09)
2
+
3
+ - 版本冻结依据:`docs/release-records/version-freeze-20261109-T2.md`(冻结版本 = **2.2.6**;已发布基准 2.1.5 / tag v2.1.5 / commit 6ed12d3)
4
+ - 本文所有数字与事实均回指既有归档证据,未新造任何数字;引用清单见文末「证据回指表」。
5
+ - 用途:§一 供 GitHub Release 页面正文直接粘贴;§二 供索引源(awesome-dsh-plugin)PR 与 tarball 更新;§三 为自检记录。
6
+ - 本文件只描述「准备就绪的发布内容」,不表述发布动作是否已发生;发布执行与状态由 T4/T5/T6/T7 产出。
7
+
8
+ ---
9
+
10
+ ## 一、GitHub Release 正文(tag:v2.2.6)
11
+
12
+ # dsh-workplan v2.2.6 — 三项修复:回放闭环、需求序列化、分解进度可见
13
+
14
+ **本版包含三项修复**,全部改动以锚点标记可追溯(`[2.2.6]` 标记 src 12 处 ↔ lib 12 处一一对应),并完成合并态统一回归(**666/666** 通过)。
15
+
16
+ ## 1. D-1:重启回放丢弃人工改判的 closure 字段(起源 1.7.0,非 2.2.5 引入)
17
+
18
+ durable 的 `workplan-update` 自 1.11.0 起携带 closure,但 `reconstructFromSession` 的回放 patch 一直没把它传给 `applyStatus`:行停在 escalated 时,`status=done` 的改判被「非法闭环迁移 escalated→done」拒绝,整条 update 被裸 catch 吞掉,重启后「待指示」行永久卡死。本版补上 `closure: update.closure`,并把裸 catch 改为 `console.warn` 留痕(fail-closed 而非 fail-silent)。
19
+
20
+ 红-绿验证:摘掉修复跑全量 → 651 项中恰好 1 失败(失败点=改判链 escalated→instructed→done→reported 必须完整回放);恢复修复 → 651/651 通过。
21
+
22
+ ## 2. 跨部门需求落盘变 `[object Object]`(handoff 序列化)
23
+
24
+ - **现象**:子 Agent 以对象形提出的跨部门需求,入库时被隐式 `String(对象)` 整体转成字面量 `[object Object]`,部门信息一并丢失(实证:主计划 wp-db6de2f0 的 T1–T4 四条需求均为 `request="[object Object]"、department:null`)。
25
+ - **病根**:4 个写坏点(`src/plan.ts` `readEvidenceNeeds` / `mergeHandoffsFromNeeds` / `readEvidenceOptions`,`src/runtime.ts` escalate)。
26
+ - **修复**:全部改为对象感知的受控序列化——对象需求落盘为「部门:需求(用途)」可读文本 + 合法部门键;嵌套/循环引用兜底为循环引用安全、undefined 安全的受控 JSON;字符串路径逐字不变;历史损坏记录加载不抛错、存量逐字段不改写。
27
+ - **验证**:专项回归 **10/10**(对象原文一致 / 嵌套受控 JSON / 循环引用不抛错 / 历史记录不改写 / 幂等 / 全链路);坏模式 `String(item ?? '')` 在 src 与 lib 中 **0 命中**。
28
+
29
+ ## 3. 任务自动分解期间界面零提示(进度可见性)
30
+
31
+ - **现象**:发任务后自动分解的几十秒到几分钟里界面毫无反应,分不清「在干活」「在重试」还是「卡死」。取证判定:分解全程插件零 `session.append`、零 `records.set`——侧栏 4 秒轮询与「正在安排」词汇早已存在,只是从未收到数据(断点层=未发出,插件层)。
32
+ - **修复**(零新组件、零新路由、零推送机制):
33
+ 1. **进行中**:进入分解先写占位进度卡,侧栏 4 秒轮询内出现「正在安排」+「正在生成任务分解…」;
34
+ 2. **重试中**:每次可重试失败,卡片追加「第 N 次尝试失败(原因码):真因;正在重试(约 X 秒后),第 (N+1)/3 次」,聊天通知每轮**至多 2 条**(第 3 次失败直接进降级文案);
35
+ 3. **失败带真因**:3 次全败走降级横幅,逐次真因链截断 ≤120 字符、错误码(如 `ECONNREFUSED`)原样保留;
36
+ 4. **等信息中**:澄清场景徽标不再回显原始键名 `clarify`(zh「等信息中」/ en "Waiting for info");
37
+ 5. **用户中止**:全静默、不残留假「进行中」、不丢上一份终态进度。
38
+ - **验证**:专项回归 **5/5**(抖动重试文案 / 通知频率硬规则 / aborted 静默 / 真因截断 / 词汇键);重试语义零变化(`onProgress` 只读观察点)。
39
+
40
+ ## 合并态统一回归(总判定 GO,产品级失败项 = 0)
41
+
42
+ - 产物一致性:构建前后双检哈希 15/15 + 根 client.js 一致;`npm run check` exit 0;
43
+ - 全量套件 **666/666**(= 661 + 5,计数精确吻合);
44
+ - 既有守卫与双向回归不回退:守卫 6/6、抖动正例 8/8 断言、AUTH 反例 4/4、cause 链 3/3、取消传播 3/3、真故障反例 7/7(1564–1678ms,与基线 1.454s 同量级带内)。
45
+
46
+ ## 边界与已知事项(如实登记,不包装)
47
+
48
+ - 两项双缺陷修复的**生环境复验**待用户重启后执行(四态:进行中 / 重试中 / 失败带真因 / 等信息中);聊天通知能否在分解等待期间即时上屏属宿主运行态行为(H-1),侧栏卡片(4 秒轮询)为保底通道。
49
+ - wp-db6de2f0 四条历史损坏记录原文已从子会话日志提取留档,**可恢复**;存量数据一字不改。
50
+ - **D-3 未在本版修复**(轮次中途完成只存内存、重启丢当前计划状态):属轮次生命周期改造,建议下版专项处理;缓解:重要节点后不要立刻重启。
51
+ - 宿主侧三项深度改进(cause 透传、maxRetries 可配、直连流重试覆盖)随宿主发版落实;插件侧已前向兼容、不依赖。
52
+ - 2.1.5 → 2.2.6 之间各版的完整变更见 [CHANGELOG.md](CHANGELOG.md)。
53
+
54
+ ## 安装
55
+
56
+ ```bash
57
+ npm install dsh-workplan@2.2.6
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 二、索引源登记内容
63
+
64
+ 索引源机制(沿用既有结论):上游索引仓库 `awesome-dsh-plugin`,文件 `data/plugins/abbaababa__dsh-workplan.yml`,仅含 7 个键、无 version/sha256 字段,版本由 `tarball` URL 隐含;上游 catalog 的 npm 包由上游 CI 定时从该仓库生成,提交 PR 不等于 npm 包立即更新。
65
+
66
+ ### 2.1 tarball 行更新(本次只改 1 行)
67
+
68
+ 旧值:
69
+
70
+ ```yaml
71
+ tarball: https://github.com/abbaababa/dsh-workplan/releases/download/v2.1.5/dsh-workplan-2.1.5.tgz
72
+ ```
73
+
74
+ 新值(版本号与冻结值一致):
75
+
76
+ ```yaml
77
+ tarball: https://github.com/abbaababa/dsh-workplan/releases/download/v2.2.6/dsh-workplan-2.2.6.tgz
78
+ ```
79
+
80
+ ### 2.2 PR 标题与正文模板
81
+
82
+ 标题:
83
+
84
+ ```text
85
+ Update abbaababa__dsh-workplan to v2.2.6
86
+ ```
87
+
88
+ 正文:
89
+
90
+ ```markdown
91
+ Bump dsh-workplan tarball from v2.1.5 to v2.2.6.
92
+
93
+ Release: https://github.com/abbaababa/dsh-workplan/releases/tag/v2.2.6
94
+ Highlights: replay keeps manual-adjudication closure across restart; cross-department handoff needs serialize as readable text instead of "[object Object]" (department key preserved); progress visibility during automatic task planning (planning card via 4s sidebar poll, retry notices with real cause chain, capped at 2 per round, "Waiting for info" badge).
95
+ No breaking changes.
96
+ Tests: 666/666 passing (`npm test`).
97
+ ```
98
+
99
+ ### 2.3 版本短描述(zh / en,供目录与展示用)
100
+
101
+ - zh:修复三项:重启后人工改判不再丢失(closure 回放);跨部门需求落盘不再变 `[object Object]`(可读文本+部门键,历史记录不改写);任务自动分解期间界面有进度(4 秒内侧栏进度卡、重试带真因且每轮至多 2 条通知、澄清徽标显示「等信息中」)。合并态回归 666/666。
102
+ - en: Three fixes: manual-adjudication closure survives restart replay; handoff needs serialize as readable "department: need (purpose)" text with the department key preserved instead of "[object Object]" (legacy broken records load untouched); progress visibility during automatic task planning (planning card via 4s sidebar poll, retry notices with real cause chain capped at 2 per round, "Waiting for info" badge). Merged-state suite 666/666.
103
+
104
+ ---
105
+
106
+ ## 三、自检记录(A1–A3)
107
+
108
+ - **A1 版本号一致**:本文所有版本号均为 **2.2.6**(tag v2.2.6 / npm install dsh-workplan@2.2.6 / tarball URL v2.2.6),与 T2 冻结值一致;对比基准 2.1.5 亦与 T2 三处对照记录一致。自检命令:`grep -n "2\.2\.6\|2\.1\.5" docs/release-records/release-notes-2.2.6-T3.md`(结果见 T3 汇报)。
109
+ - **A2 数字可回指、未新造**:651(D-1 红绿)、10/10(序列化专项)、5/5(可见性专项)、666/666、15/15、6/6、8/8、4/4、3/3、7/7、1564–1678ms、1.454s、≤120 字符、至多 2 条、4 秒轮询、300s 窗口、12 处标记、四条历史记录——逐项出处见下表。
110
+ - **A3 无未经验证的收尾表述**:全文不含任何收尾性定论用语(如宣称发布动作已完成、宣称成品定稿);发布动作状态显式移交 T4–T7;生环境复验明确写为「待用户执行」。
111
+
112
+ ### 证据回指表
113
+
114
+ | 文中数字/事实 | 出处 |
115
+ |---|---|
116
+ | 2.2.6 冻结 / 2.1.5 已发布基准 / 6ed12d3 / 12 处标记 / 666 待发布范围 | `docs/release-records/version-freeze-20261109-T2.md` §1–§4 |
117
+ | D-1 651 红绿 / closure 补丁 / console.warn | CHANGELOG.md 2.2.6 条目(既有,本版沿用);tests/runtime-replay.test.ts |
118
+ | `[object Object]` 现象 / W1–W4 点位 / wp-db6de2f0 四条 / 可恢复结论 | `_t1_dualdefect_rootcause_20261108/root-cause-and-boundary-report.md` §2.2/§2.3/§2.5 |
119
+ | 序列化修复点位与改法 / 10/10 / `String(item ?? '')` 0 命中 / `[2.2.6][T4]` 锚点 | `_t4_need_serialization_fix/fix-report.md` §二/§四 |
120
+ | 可见性四态文案 / 频率 ≤2 条 / ≤120 截断 / P-9 clarify / 零新组件 / 4 秒轮询 / 300s 窗口 / 重试语义零变化 | `_t5_visibility_impl_20261108/implementation-notes.md` §一/§二/§三 |
121
+ | 666/666 / 15/15 哈希 / 守卫 6/6 / 抖动 8/8 / AUTH 4/4 / cause 3/3 / 取消 3/3 / 真故障 7/7 / 1564–1678ms / 基线 1.454s / 偏差披露 | `_t6_dualfix_regression_20261108/T6_双修复回归测试报告.md` §一/§四/§五/§六 |
122
+ | 生环境复验四态 / H-1 / 通道 A 保底 / 宿主三项 H2 | `_t7_closure_20261108/结案说明与移交清单.md` §四/§二 |
123
+ | 索引源机制(awesome-dsh-plugin / 7 键 YAML / tarball 隐含版本 / CI 定时) | `_t11_release_20261102/index_entry_v1.11.0.md`(既有机制结论,机制未变) |
124
+
125
+ ### 遗留提示(移交,不阻塞文案冻结)
126
+
127
+ - CHANGELOG.md 三处历史条目含本机用户目录绝对路径(T2 敏感初筛发现项::138/:180/:2233 附近),属既有条目,是否随发布提交改写由主 Agent/T4 决定;本 T3 新增文案未引入任何本机绝对路径。
128
+ - GitHub Release 资产名 `dsh-workplan-2.2.6.tgz` 为按既有 tarball 命名惯例(v1.11.0 同构)推导的约定值,实际资产名以 T4 发布脚本/T5 上传为准。
@@ -1,6 +1,6 @@
1
1
  # dsh-workplan 发布流程梳理(T1 交付物)
2
2
 
3
- > 仓库根:`/Users/open/Documents/Stocks/plugins/dsh-workplan`(自身含 `.git`,工作区 `/Users/open/Documents/Stocks` 不是 git 仓库)
3
+ > 仓库根:`plugins/dsh-workplan`(相对工作区根;自身含 `.git`,工作区根不是 git 仓库)
4
4
  > 当前版本:`2.1.3`(`package.json:3`、`package-lock.json:3,9`、`src/host.ts` 的 `meta.version`、CHANGELOG 顶部 `## 2.1.3 — 2026-11-06`)
5
5
  > 本文所有命令均标注来源:RELEASING.md 章节、package.json scripts、.github/workflows/verify.yml,或前期对话(m00001)实测事实。
6
6