dsh-workplan 2.1.5 → 2.2.7
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.
- package/CHANGELOG.md +408 -1
- package/README.en.md +5 -2
- package/README.md +5 -2
- package/client.js +148 -3
- package/docs/dsh-workplan_T4_runtime.patch +508 -0
- package/docs/release-record-2.2.6-20261109-T5.md +64 -0
- package/docs/release-records/release-notes-2.2.6-T3.md +128 -0
- package/docs/release-records/release-steps-20261106.md +1 -1
- package/docs/release-records/version-freeze-20261109-T2.md +37 -0
- package/lib/client.js +148 -3
- package/lib/comm-format.js +17 -0
- package/lib/host.js +95 -17
- package/lib/notice-channel.js +290 -0
- package/lib/plan.js +668 -39
- package/lib/replan.js +35 -4
- package/lib/runtime.js +1918 -116
- package/lib/supersede.js +2 -2
- package/lib/understanding.js +8 -2
- package/lib/watchdog.js +52 -1
- package/package.json +3 -2
- package/scripts/repair-malformed-user-messages.mjs +312 -0
- package/src/client.ts +155 -2
- package/src/comm-format.ts +17 -0
- package/src/host.ts +90 -12
- package/src/notice-channel.ts +328 -0
- package/src/plan.ts +699 -30
- package/src/replan.ts +32 -1
- package/src/runtime.ts +1966 -118
- package/src/supersede.ts +2 -1
- package/src/understanding.ts +10 -2
- package/src/watchdog.ts +80 -1
- package/README.zh.md +0 -239
package/lib/runtime.js
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
import { randomUUID } from 'node:crypto';
|
|
15
15
|
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
16
16
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
17
|
-
import {
|
|
17
|
+
import { createNoticeChannel, finaliseNoticeChannel, formatNoticeChannelLog, observeRelayedNotice, readLeadAgentId, resolveLeadAgentId, validateNoticeChannel, } from './notice-channel.js';
|
|
18
|
+
import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, appendUserMessage, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildClarifyMessage, createPlannerProgressReporter, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, DEFAULT_REASONING_EFFORT, deliveryReadiness, derivePlanSnapshot,
|
|
19
|
+
// [2.2.0][T4/O-3b] O-3b 消费接线:缺省协商上限由预估派生(plan.ts 纯函数,T3 已定稿)。
|
|
20
|
+
deriveSubtaskTimeoutMs, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, REASONING_EFFORTS, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, mergeHandoffEntriesByUpdatedAt, needEntryText, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, findSubtask, } from './plan.js';
|
|
18
21
|
import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js';
|
|
19
22
|
import { phaseGateFromErrors, phaseSummaryLine, validatePhaseEvidence } from './three-phase.js';
|
|
20
23
|
import { lessonStats, rankLessons, readLessons, recordLesson, renderLessonsBrief, resolveLessonsFile, } from './lessons.js';
|
|
@@ -80,13 +83,31 @@ function liveStatuses(statuses) {
|
|
|
80
83
|
* `changeRequest.pending`(执行中收到、尚未重规划的变更)与 `reportPending`
|
|
81
84
|
* (完成结果还没写进会话)只存在于 `record` 而不是 `statuses`,所以必须在
|
|
82
85
|
* 这一层显式传入;`plan.ts` 的 `deliveryReadiness` 因此仍是纯函数。
|
|
86
|
+
*
|
|
87
|
+
* [2.2.9][T3][M4.1] `reportPending` 不再读 `record.reportPending` 可变标志。
|
|
88
|
+
* 事故实证(wp-215ed52f 症状②):门禁读标志、看板读标志、消息冻结读标志,
|
|
89
|
+
* 而该标志在 finishRound/markReported/自愈/重建多处的写入时机互不同步,
|
|
90
|
+
* 判定结果随读取落在哪个时间窗口而翻转——「可交付↔未放行」来回震荡。
|
|
91
|
+
* 现在门禁、看板、stop-steer、消息冻结、自愈全部读同一个纯派生函数
|
|
92
|
+
* `deriveReportPending(record)`:事实只有 statuses(经 T2 单调闸的终态),
|
|
93
|
+
* 标志降级为审计镜像。blocked/pending 行不是 done,永不触发该阻塞。
|
|
83
94
|
*/
|
|
95
|
+
export function deriveReportPending(record) {
|
|
96
|
+
const statuses = Array.isArray(record?.statuses) ? record.statuses : [];
|
|
97
|
+
/*
|
|
98
|
+
* [1.11.0] 只把「本轮完成、还没回报」算作待回报:`closure:'done'` 是
|
|
99
|
+
* 1.11.0 的显式中间态。旧日志的 done 行没有 closure(null),它本来就
|
|
100
|
+
* 已经通过结果消息回报过,若用 `!== 'reported'` 判定,升级后每一份
|
|
101
|
+
* 1.10.6 的历史计划都会被判成「未回报」而永久不可交付。
|
|
102
|
+
*/
|
|
103
|
+
return statuses.some((item) => item?.status === 'done' && item?.closure === 'done');
|
|
104
|
+
}
|
|
84
105
|
function readinessOf(record, snapshot) {
|
|
85
106
|
const snap = snapshot ?? derivePlanSnapshot(record?.plan ? blockCancelledDependents(record.plan, record?.statuses) : record?.statuses, record?.plan ? definedSubtaskCount(record.plan) : undefined);
|
|
86
107
|
return deliveryReadiness(snap, {
|
|
87
108
|
phase: record?.phase,
|
|
88
109
|
changePending: record?.changeRequest?.status === 'pending',
|
|
89
|
-
reportPending: record
|
|
110
|
+
reportPending: deriveReportPending(record),
|
|
90
111
|
/*
|
|
91
112
|
* 计划定义的验收标准是交付门的另一半:状态行只回答「子 Agent 说通过
|
|
92
113
|
* 了几条」,这里回答「计划要求的几条有没有被逐条回应」。
|
|
@@ -96,14 +117,126 @@ function readinessOf(record, snapshot) {
|
|
|
96
117
|
}
|
|
97
118
|
export const PLANNER_TIMEOUT_MS = 300000;
|
|
98
119
|
/**
|
|
99
|
-
*
|
|
120
|
+
* 无进展窗口(默认 300s,DSH_WORKPLAN_PLANNER_TIMEOUT_MS,毫秒 >0)。
|
|
100
121
|
*
|
|
101
|
-
* 2.1.
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
122
|
+
* 2.1.6 起它的含义从「固定墙钟」改成「**没有新内容**的时长」:从上一个
|
|
123
|
+
* chunk 起算,首个 chunk 之前也按它计时。模型一直在正常输出时窗口不断
|
|
124
|
+
* 重置,慢而稳定的长任务不再被误杀。
|
|
125
|
+
*
|
|
126
|
+
* 历史:2.1.1 把 120s 提到 300s 只是推迟超时;2.1.3 把常量改成可配置,
|
|
127
|
+
* 默认值仍是 300s 的固定墙钟。于是 2026-11-07 10:05:19 → 10:10:19(实测
|
|
128
|
+
* 300.06s)规划器仍在工作却被 abort,自动分解直接降级——提高默认值或开放
|
|
129
|
+
* 配置都没有解决「按墙钟掐断一个正在产出的调用」这个结构问题。
|
|
105
130
|
*/
|
|
106
131
|
export const PLANNER_IDLE_TIMEOUT_MS = 90000;
|
|
132
|
+
/**
|
|
133
|
+
* 首个 chunk 之后的「完全静默」窗口(默认 90s,DSH_WORKPLAN_PLANNER_IDLE_
|
|
134
|
+
* TIMEOUT_MS,毫秒 >0):文本、推理、usage 一个 chunk 都没有这么久,判定为
|
|
135
|
+
* 连接卡死而不是模型还在思考。这个常量在 2.1.6 之前只声明、从未接线(死
|
|
136
|
+
* 代码),现在真正参与计时;设为不小于无进展窗口即等价于关闭。
|
|
137
|
+
*/
|
|
138
|
+
export const PLANNER_HARD_MULTIPLIER = 3;
|
|
139
|
+
/**
|
|
140
|
+
* 绝对上限 = 无进展窗口 × 该倍数(默认 900s)。慢可以,慢到没边不行:它给
|
|
141
|
+
* 单次规划器尝试一个终点,保证规划失败永远是「有限时间后给出可执行建议」,
|
|
142
|
+
* 而不是无限占用本轮预算。
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* [2.2.0][T13b/推理等级] 规划器默认推理档 = max(用户 2026-11-08 决策 5)。
|
|
146
|
+
*
|
|
147
|
+
* 用户规则(AGENTS.md 第 12 条)只说过「子 Agent 不得继承主 Agent 的等级」,
|
|
148
|
+
* 规划器同样是主 Agent 派出的子调用:任务里明确授权「规划器停止继承」。规划
|
|
149
|
+
* 本身属于「跨多个系统梳理根因并给出方案」——按五档规则(轻度=low/中等=
|
|
150
|
+
* medium或high/非常复杂=xhigh或max)属非常复杂 → 默认取 max(五档内的最高
|
|
151
|
+
* 档;xhigh 留给显式覆盖)。`DSH_WORKPLAN_PLANNER_REASONING_EFFORT` 仍可显式
|
|
152
|
+
* 覆盖(用户为降本/提速
|
|
153
|
+
* 主动选择低档时有效),未设或非法时才用本默认值;**绝不读取
|
|
154
|
+
* modelSelection.reasoningEffort**。旧行为(plannerEffort || 主 Agent 档位)会
|
|
155
|
+
* 让主 Agent 的 low/high 直接决定拆解质量,与「子 Agent 自决档位」同源、同错。
|
|
156
|
+
*/
|
|
157
|
+
export const DEFAULT_PLANNER_REASONING_EFFORT = 'max';
|
|
158
|
+
/*
|
|
159
|
+
* [2.2.7] 推理档位兼容性钳制(用户 2026-11-09 报告的 PLANNER_LLM_ERROR 根因修复)。
|
|
160
|
+
*
|
|
161
|
+
* 宿主 dsh-llm 会在发起网络请求之前,把请求的 reasoningEffort 与该模型声明的
|
|
162
|
+
* `reasoning.efforts` 清单逐一比对,不在清单内即抛 UNSUPPORTED_REASONING_EFFORT
|
|
163
|
+
* (本地失败、重试不会自愈)。规划器默认 max、子任务档位允许 low / medium /
|
|
164
|
+
* high / xhigh / max 五档——这些都假设主链路模型支持相应档位。一旦运行在
|
|
165
|
+
* qwen 这类只声明 low/medium/xhigh 的模型上,第一次规划调用就被宿主拒绝,
|
|
166
|
+
* 整个自动分解降级;
|
|
167
|
+
* 同一枚雷也埋在派发侧:计划里的 high/max/xhigh 行派给 qwen 子会话会同样即抛。
|
|
168
|
+
*
|
|
169
|
+
* 治本方案不是按模型名字猜档位(家族无穷、名单过时),而是在发送任何带档位的
|
|
170
|
+
* 请求前,用宿主公开能力面 `llm.resolveModelInfo` 读出目标模型**实际声明**的
|
|
171
|
+
* 档位清单,把请求档位钳制到清单内强度最接近的一档:
|
|
172
|
+
* - 清单包含请求档位 ⇒ 原样发送(模型声明支持五档时,low/medium/high/xhigh/max
|
|
173
|
+
* 全部原样透传,不钳制);
|
|
174
|
+
* - 否则取「不高于请求档」里最高的支持档(max→xhigh、high→medium…);
|
|
175
|
+
* [2.2.7][T4/五档] 五档请求落在三档清单(low/high/max)上的降级序按强度表
|
|
176
|
+
* 逐级下探:max 原样、xhigh→high、high 原样、medium→low、low 原样;落在
|
|
177
|
+
* qwen 型清单(low/medium/xhigh)上:max→xhigh、xhigh 原样、high→medium、
|
|
178
|
+
* medium 原样、low 原样。降级序即 EFFORT_STRENGTH_ORDER 中「不高于请求档」
|
|
179
|
+
* 的最近支持档,任何合法五档值都不会被拒绝或清空;
|
|
180
|
+
* - 全部支持档都强于请求档 ⇒ 取最弱支持档(宁可降质,不可失败);
|
|
181
|
+
* - 模型根本没有 reasoning 元数据(空清单)⇒ 不发送 reasoningEffort 字段,
|
|
182
|
+
* 与宿主 resolveCallWithInfo 的「reasoning===undefined 时任何档位都抛错」对齐;
|
|
183
|
+
* - 能力查询不可用(宿主不暴露 / 查询抛错)⇒ 保持旧行为,绝不因钳制引入新故障。
|
|
184
|
+
*/
|
|
185
|
+
const EFFORT_STRENGTH_ORDER = Object.freeze(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
|
|
186
|
+
/** 请求档位 → 模型支持清单内的等效钳制档;空清单返回 undefined(= 不发送该字段)。 */
|
|
187
|
+
export function clampEffortToSupported(effort, supported) {
|
|
188
|
+
if (!Array.isArray(supported) || supported.length === 0)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (supported.includes(effort))
|
|
191
|
+
return effort;
|
|
192
|
+
const rank = (id) => EFFORT_STRENGTH_ORDER.indexOf(id);
|
|
193
|
+
const ranked = [...supported].sort((a, b) => {
|
|
194
|
+
const ra = rank(a);
|
|
195
|
+
const rb = rank(b);
|
|
196
|
+
if (ra === rb)
|
|
197
|
+
return 0;
|
|
198
|
+
if (ra < 0)
|
|
199
|
+
return 1;
|
|
200
|
+
if (rb < 0)
|
|
201
|
+
return -1;
|
|
202
|
+
return ra - rb;
|
|
203
|
+
});
|
|
204
|
+
const target = rank(effort);
|
|
205
|
+
if (target < 0)
|
|
206
|
+
return ranked[ranked.length - 1];
|
|
207
|
+
const atOrBelow = ranked.filter((id) => rank(id) >= 0 && rank(id) <= target);
|
|
208
|
+
if (atOrBelow.length > 0)
|
|
209
|
+
return atOrBelow[atOrBelow.length - 1];
|
|
210
|
+
return ranked[0];
|
|
211
|
+
}
|
|
212
|
+
const supportedEffortsCache = new Map();
|
|
213
|
+
/**
|
|
214
|
+
* 读取 provider/model 声明的推理档位清单。
|
|
215
|
+
* @returns 档位 id 数组(可为空数组 = 模型不支持任何档位);null = 无从判定,调用方保持旧行为。
|
|
216
|
+
*/
|
|
217
|
+
export async function resolveSupportedEfforts(llm, provider, model, signal) {
|
|
218
|
+
if (!llm || typeof llm.resolveModelInfo !== 'function' || !provider || !model)
|
|
219
|
+
return null;
|
|
220
|
+
const key = `${provider}/${model}`;
|
|
221
|
+
const hit = supportedEffortsCache.get(key);
|
|
222
|
+
if (hit)
|
|
223
|
+
return hit;
|
|
224
|
+
if (signal?.aborted)
|
|
225
|
+
return null;
|
|
226
|
+
try {
|
|
227
|
+
const info = await llm.resolveModelInfo(provider, model, signal);
|
|
228
|
+
const efforts = info?.reasoning?.efforts;
|
|
229
|
+
const list = Array.isArray(efforts)
|
|
230
|
+
? efforts.map((item) => String(item?.id ?? '')).filter((id) => id !== '')
|
|
231
|
+
: [];
|
|
232
|
+
supportedEffortsCache.set(key, list);
|
|
233
|
+
return list;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// 查询失败 ⇒ 与「宿主不暴露该能力」同等处理:不钳制、不缓存、不阻断。
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
107
240
|
/**
|
|
108
241
|
* Absolute ceiling for one child execution.
|
|
109
242
|
*
|
|
@@ -113,6 +246,13 @@ export const PLANNER_IDLE_TIMEOUT_MS = 90000;
|
|
|
113
246
|
* plan became terminal at the first slow subtask. The ceiling is now a
|
|
114
247
|
* settlement guarantee, while the no-progress window below is what normally
|
|
115
248
|
* ends an attempt.
|
|
249
|
+
*
|
|
250
|
+
* [2.2.0][T4/O-3b] 语义更新(柔性时长协商,方案 §1③/§2.2):这不是固定交付
|
|
251
|
+
* 期限,而是「协商上限+L4 安全兜底」——单次执行时限协商而来(subtask.timeoutMs
|
|
252
|
+
* 显式值优先,缺省 deriveSubtaskTimeoutMs(estimateMinutes)=clamp(预估分钟×
|
|
253
|
+
* 2.0×60000, MIN, MAX)),本常量只在无预估、无显式值时兜底(③C2 零回归)。
|
|
254
|
+
* 时间是协商出来的安全兜底,不是固定交付期限:到点走 L4 安全兜底结算+
|
|
255
|
+
* 「待裁决」标记(延期 / 重试 / 接受),不表述为「强制结束」式固定期限误杀。
|
|
116
256
|
*/
|
|
117
257
|
export const CHILD_TIMEOUT_MS = 900000;
|
|
118
258
|
/** No-progress window: the child's own session log stopped growing. */
|
|
@@ -124,7 +264,14 @@ export const CHILD_IDLE_TIMEOUT_MS = 300000;
|
|
|
124
264
|
* minutes.
|
|
125
265
|
*/
|
|
126
266
|
export const MIN_CHILD_TIMEOUT_MS = 1000;
|
|
127
|
-
|
|
267
|
+
/*
|
|
268
|
+
* [2.2.0][T4/O-3b] 单次绝对上限 1800000 → 7200000(120 分钟):用户 2026-11-07
|
|
269
|
+
* 决断(方案 §6 未知第 4 条)。协商上限 = clamp(预估分钟 × 2.0, 全局下限,
|
|
270
|
+
* 单次绝对上限)(方案 §1③),2h 让「预告 60 分钟的子任务,其单次执行上限
|
|
271
|
+
* ≥ 60 分钟」(方案 C1)成立;tests/time-estimate-negotiation.test.ts 的
|
|
272
|
+
* expected 公式直接引用本常量,数值不同步会红灯。
|
|
273
|
+
*/
|
|
274
|
+
export const MAX_CHILD_TIMEOUT_MS = 7200000;
|
|
128
275
|
export const MIN_CHILD_IDLE_MS = 1000;
|
|
129
276
|
export const MAX_CHILD_IDLE_MS = 900000;
|
|
130
277
|
export const CHILD_POLL_MS = 2000;
|
|
@@ -152,7 +299,26 @@ export const INSTRUCTION_ACK_DEADLINE_MS = 180000;
|
|
|
152
299
|
* 会话读取次数控制在可接受范围(每个等指示的行每 5s 一次只读查询)。
|
|
153
300
|
*/
|
|
154
301
|
export const INSTRUCTION_POLL_MS = 5000;
|
|
155
|
-
|
|
302
|
+
// [2.2.5][RoundBudget] 轮次总预算默认关闭。
|
|
303
|
+
//
|
|
304
|
+
// 用户要求:对子任务的执行时间不做强制限制,只通过开工预告/预估/协商/延期
|
|
305
|
+
// 与到点预警来治理;旧版默认 20 分钟会在子任务自己的 30 分钟协商截止前
|
|
306
|
+
// 先切断整轮,界面上出现“本轮预算用尽”,与上述目标矛盾。
|
|
307
|
+
//
|
|
308
|
+
// 现在:
|
|
309
|
+
// - TOTAL_TIMEOUT_MS = 0 表示默认不设整轮硬预算;
|
|
310
|
+
// - 显式传正数(配置/DSH_WORKPLAN_TOTAL_TIMEOUT_MS)仍可启用安全兜底;
|
|
311
|
+
// - 子任务自己的 timeoutMs/deadlineAt/extendMs 不受影响。
|
|
312
|
+
// dispatchPlan 用 20 天哨兵值避免 Infinity 参与计时器/差值计算。
|
|
313
|
+
//
|
|
314
|
+
// [2.2.5][热修] 哨兵值不能超过 Node setTimeout 的上限:延时 > 2^31-1 毫秒
|
|
315
|
+
// (约 24.8 天)会被 Node 强制改成 1 毫秒并告警(TimeoutOverflowWarning)。
|
|
316
|
+
// 最初版本用 10 年,结果整轮定时器派发后 1ms 就触发,所有子任务瞬间被
|
|
317
|
+
// 「总执行超时」杀死(2026-11-08 17:36 / 18:01 两次现场实锤,38ms 与 8ms)。
|
|
318
|
+
// 20 天 = 1,728,000,000ms < 2^31-1,安全;且对单轮执行而言等价于“无预算”。
|
|
319
|
+
export const TOTAL_TIMEOUT_MS = 0;
|
|
320
|
+
export const NO_ROUND_BUDGET_MS = 20 * 24 * 60 * 60 * 1000;
|
|
321
|
+
export const ROUND_TIMER_MAX_MS = 2_000_000_000;
|
|
156
322
|
export const DISPOSE_TIMEOUT_MS = 5000;
|
|
157
323
|
export const STALE_PENDING_MS = 10 * 60 * 1000;
|
|
158
324
|
export const MAX_HISTORY_EVENTS = 2000;
|
|
@@ -329,7 +495,7 @@ function pushRecordError(record, error) {
|
|
|
329
495
|
const text = truncate(describeError(error), 1000);
|
|
330
496
|
record.errors = [...(record.errors ?? []), text].slice(-20);
|
|
331
497
|
}
|
|
332
|
-
async function collectStream(stream) {
|
|
498
|
+
async function collectStream(stream, onChunk, sink) {
|
|
333
499
|
let text = '';
|
|
334
500
|
let textDeltaSeen = false;
|
|
335
501
|
let finished = false;
|
|
@@ -337,19 +503,42 @@ async function collectStream(stream) {
|
|
|
337
503
|
for await (const chunk of stream) {
|
|
338
504
|
if (!chunk || typeof chunk !== 'object')
|
|
339
505
|
continue;
|
|
506
|
+
/*
|
|
507
|
+
* [2.1.6] 任何 chunk 都是「连接还活着」的证据——包括 reasoning-delta、
|
|
508
|
+
* block-start、usage 这些不进正文的类型。计时器只认这里,才不会把正在
|
|
509
|
+
* 推理的模型当成卡死。
|
|
510
|
+
*/
|
|
511
|
+
onChunk?.();
|
|
340
512
|
if (chunk.type === 'text-delta' && typeof chunk.text === 'string') {
|
|
341
513
|
text += chunk.text;
|
|
514
|
+
/*
|
|
515
|
+
* [2.1.7] 正文必须边流边落进 sink:定时器中止时 for-await 会直接抛错,
|
|
516
|
+
* 局部变量 text 连同 900 秒的产出一起蒸发,旧实现正是这样把「差一个
|
|
517
|
+
* 收尾 } 的完整计划」整体扔掉的。
|
|
518
|
+
*/
|
|
519
|
+
if (sink)
|
|
520
|
+
sink.text = text;
|
|
342
521
|
textDeltaSeen = true;
|
|
343
522
|
}
|
|
344
523
|
else if (chunk.type === 'block-end' && chunk.block?.type === 'text' && !textDeltaSeen) {
|
|
345
524
|
text += chunk.block.text ?? '';
|
|
525
|
+
if (sink)
|
|
526
|
+
sink.text = text;
|
|
346
527
|
}
|
|
347
528
|
else if (chunk.type === 'finish') {
|
|
348
529
|
finished = true;
|
|
349
530
|
finishKind = chunk.reason?.kind ?? 'unknown';
|
|
350
531
|
if (finishKind === 'error' || finishKind === 'aborted') {
|
|
351
532
|
const failure = chunk.reason?.failure;
|
|
352
|
-
|
|
533
|
+
/*
|
|
534
|
+
* [2.2.5][T4] 底层原因透传(T3 根因 P2):failure.message 只是包装文案
|
|
535
|
+
* (如 "Connection error."),真因可能挂在 failure.cause 上(宿主透传后
|
|
536
|
+
* 自动生效,未透传时保持原文、行为不变)。failure.code 记入 details,
|
|
537
|
+
* 供重试分级(P1)判定,不再从文案反解。
|
|
538
|
+
*/
|
|
539
|
+
const causeText = failure?.cause ? errorCauseChain(failure.cause) : '';
|
|
540
|
+
const failureCode = failure?.code != null ? String(failure.code) : '';
|
|
541
|
+
throw new PlanError(`模型调用结束:${finishKind}${failureCode ? ` ${failureCode}` : ''}${failure?.message ? `:${failure.message}` : ''}${causeText ? `(底层原因:${causeText})` : ''}`, finishKind === 'aborted' ? 'ABORTED' : 'PLANNER_LLM_ERROR', failureCode);
|
|
353
542
|
}
|
|
354
543
|
if (finishKind !== 'stop') {
|
|
355
544
|
throw new PlanError(`规划器输出未正常结束:${finishKind}`, 'PLANNER_INCOMPLETE');
|
|
@@ -374,21 +563,260 @@ function contextGuardStrict() {
|
|
|
374
563
|
const flag = String(process.env.DSH_WORKPLAN_CONTEXT_GUARD ?? '').trim().toLowerCase();
|
|
375
564
|
return flag !== 'off' && flag !== '0' && flag !== 'false';
|
|
376
565
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const
|
|
566
|
+
/** 规划器窗口取值:只接受有限正数,否则回落默认值(0/负数/NaN 都不许把计时器打成 1ms)。 */
|
|
567
|
+
export function normalisePlannerWindow(value, fallback) {
|
|
568
|
+
const numeric = Number(value);
|
|
569
|
+
return Number.isFinite(numeric) && numeric > 0 ? numeric : fallback;
|
|
570
|
+
}
|
|
571
|
+
function plannerDebugEnabled() {
|
|
572
|
+
const flag = String(process.env.DSH_WORKPLAN_DEBUG ?? '').trim().toLowerCase();
|
|
573
|
+
return flag !== '' && flag !== '0' && flag !== 'false' && flag !== 'off';
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* 把规划器遥测压成一行能直接给用户看的现场说明(降级消息的 detail)。
|
|
577
|
+
* 没有遥测时返回空串,调用方据此跳过,不制造「0 次尝试」之类的假事实。
|
|
578
|
+
*/
|
|
579
|
+
export function plannerTelemetryLine(telemetry) {
|
|
580
|
+
if (!telemetry || typeof telemetry !== 'object' || !telemetry.attempt)
|
|
581
|
+
return '';
|
|
582
|
+
const parts = [
|
|
583
|
+
telemetry.model ? `模型 ${telemetry.model}` : '',
|
|
584
|
+
Number(telemetry.elapsedMs) > 0 ? `耗时 ${(Number(telemetry.elapsedMs) / 1000).toFixed(1)}s` : '',
|
|
585
|
+
Number(telemetry.chunks) > 0 ? `收到 ${Number(telemetry.chunks)} 个输出块` : '未收到任何输出块',
|
|
586
|
+
Number(telemetry.promptChars) > 0 ? `提示词 ${Number(telemetry.promptChars)} 字` : '',
|
|
587
|
+
Number(telemetry.textChars) > 0 ? `输出 ${Number(telemetry.textChars)} 字` : '',
|
|
588
|
+
telemetry.outcome && telemetry.outcome !== 'ok' ? `判定 ${telemetry.outcome}` : '',
|
|
589
|
+
].filter(Boolean);
|
|
590
|
+
return `现场:${parts.join('|')}`;
|
|
591
|
+
}
|
|
592
|
+
const PLANNER_ABORT_CODES = ['PLANNER_TIMEOUT', 'PLANNER_IDLE', 'PLANNER_TIMEOUT_HARD'];
|
|
593
|
+
/*
|
|
594
|
+
* [2.2.5][T4] 规划器重试分级与退避(T3 根因 P1:规划器链路全层零重试零退避,
|
|
595
|
+
* 一次 ~1s 网络连接尖峰 × 0ms 间隔 = 1.2 秒内两连败直接降级)。
|
|
596
|
+
* - PLANNER_RETRYABLE_LLM_CODES:宿主 classifyPiAiError 的可自愈失败类
|
|
597
|
+
* (偶发传输错误 / 超时 / 服务端 5xx / 限流 429),重试前做指数退避;
|
|
598
|
+
* - 其余失败类(AUTH / INVALID_REQUEST / 配额 / 上下文溢出 / PI_AI_ERROR /
|
|
599
|
+
* ABORTED)重试不会自愈,立即终止,不再烧下一次调用;
|
|
600
|
+
* - 退避 500ms → 1s(±20% 抖动),期间 signal 一旦取消立即让路,绝不悬挂。
|
|
601
|
+
*/
|
|
602
|
+
const PLANNER_RETRYABLE_LLM_CODES = ['TRANSPORT', 'TIMEOUT', 'SERVER', 'RATE_LIMIT'];
|
|
603
|
+
const PLANNER_MAX_ATTEMPTS = 3;
|
|
604
|
+
const PLANNER_RETRY_BACKOFF_BASE_MS = 500;
|
|
605
|
+
/**
|
|
606
|
+
* [2.2.5][T4] 把 Error 的 cause 链展开成一行可读文本(T3 根因 P2 的插件侧落点)。
|
|
607
|
+
*
|
|
608
|
+
* 真实失败原因(ENOTFOUND / ECONNREFUSED / TLS alert 等)挂在 Error.cause 链上,
|
|
609
|
+
* 外层 message 往往只有包装文案("fetch failed"、"Connection error.")。
|
|
610
|
+
* 展开规则与宿主 dsh-llm 的 errorChain 一致:外层在前,每层 cause 以 ": " 追加,
|
|
611
|
+
* 重复文案只记一次;深度封顶 5 层防环。无 cause 时返回与 error.message 相同的
|
|
612
|
+
* 文本,不改变既有行为。
|
|
613
|
+
*/
|
|
614
|
+
function errorCauseChain(value) {
|
|
615
|
+
const parts = [];
|
|
616
|
+
let current = value;
|
|
617
|
+
for (let depth = 0; depth < 5 && current != null; depth += 1) {
|
|
618
|
+
const text = typeof current.message === 'string' && current.message !== ''
|
|
619
|
+
? current.message
|
|
620
|
+
: (typeof current.name === 'string' && current.name !== '' ? current.name : String(current));
|
|
621
|
+
if (!parts.includes(text))
|
|
622
|
+
parts.push(text);
|
|
623
|
+
current = current.cause;
|
|
624
|
+
}
|
|
625
|
+
return parts.join(': ');
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* [2.2.5][T4] 可被 signal 打断的退避等待:取消一到,Promise 立即 resolve,
|
|
629
|
+
* 调用方随后检查 signal.aborted 抛 ABORTED——真取消路径不吃退避延迟。
|
|
630
|
+
*/
|
|
631
|
+
function sleepAbortable(signal, ms) {
|
|
632
|
+
return new Promise((resolve) => {
|
|
633
|
+
let timer = null;
|
|
634
|
+
const finish = () => {
|
|
635
|
+
if (timer !== null)
|
|
636
|
+
clearTimeout(timer);
|
|
637
|
+
timer = null;
|
|
638
|
+
signal?.removeEventListener?.('abort', onAbort);
|
|
639
|
+
resolve();
|
|
640
|
+
};
|
|
641
|
+
const onAbort = () => finish();
|
|
642
|
+
if (signal?.aborted) {
|
|
643
|
+
resolve();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
timer = setTimeout(finish, ms);
|
|
647
|
+
signal?.addEventListener?.('abort', onAbort, { once: true });
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* [2.1.7] 定时器中止后的正文抢救。
|
|
652
|
+
*
|
|
653
|
+
* 事故里模型流式输出了 900 秒、11694 个块,却因为没等到 finish 信号被整体
|
|
654
|
+
* 丢弃——局部变量 text 连同它一起消失。只要正文末尾已闭合(`}`),就按与正常
|
|
655
|
+
* 路径完全一致的三道闸(extractJson → validatePlan → validatePlanContext)
|
|
656
|
+
* 重新验收;任何一道不过返回 null,照旧报超时。
|
|
657
|
+
*
|
|
658
|
+
* 只认「末尾已闭合」:被拦腰截断的 JSON 即使补上括号也可能丢掉尾部阶段,
|
|
659
|
+
* 静默交出残缺计划比降级更危险。
|
|
660
|
+
*/
|
|
661
|
+
function salvagePartialPlan(text, guardOptions) {
|
|
662
|
+
if (typeof text !== 'string')
|
|
663
|
+
return null;
|
|
664
|
+
const trimmed = text.trimEnd();
|
|
665
|
+
if (!trimmed.endsWith('}'))
|
|
666
|
+
return null;
|
|
667
|
+
try {
|
|
668
|
+
const raw = extractJson(trimmed);
|
|
669
|
+
const validated = validatePlan(raw);
|
|
670
|
+
if (!validated.ok)
|
|
671
|
+
return null;
|
|
672
|
+
const guard = validatePlanContext(validated.plan, guardOptions);
|
|
673
|
+
if (!guard.ok)
|
|
674
|
+
return null;
|
|
675
|
+
const plan = validated.plan;
|
|
676
|
+
plan.taskAnchor = guard.audit.anchor;
|
|
677
|
+
plan.understandingAudit = compactUnderstandingAudit(guard.audit);
|
|
678
|
+
return plan;
|
|
679
|
+
}
|
|
680
|
+
catch {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* [2.1.6] 单次规划器尝试的计时策略——判据是「有没有在产出」,不是「过了多久」。
|
|
686
|
+
*
|
|
687
|
+
* 三扇窗:
|
|
688
|
+
* 1. 无进展窗口(plannerTimeoutMs,默认 300s):自上一个 chunk 起算,首个
|
|
689
|
+
* chunk 之前同样适用。模型持续产出 ⇒ 窗口不断后移,慢而稳定的长任务不再
|
|
690
|
+
* 被固定墙钟掐断;
|
|
691
|
+
* 2. 静默窗口(plannerIdleTimeoutMs,默认 90s):首个 chunk 之后完全静默,
|
|
692
|
+
* 判定为卡死而非还在思考;不小于无进展窗口时等于关闭;
|
|
693
|
+
* 3. 绝对上限(无进展窗口 × PLANNER_HARD_MULTIPLIER,默认 900s):有无产出
|
|
694
|
+
* 都到此为止,规划失败因此永远是「有限时间 + 可执行建议」。
|
|
695
|
+
*
|
|
696
|
+
* 每次中止都携带真实旋钮(DSH_WORKPLAN_PLANNER_TIMEOUT_MS /
|
|
697
|
+
* DSH_WORKPLAN_PLANNER_IDLE_TIMEOUT_MS),而不是让用户去改源码常量。
|
|
698
|
+
*/
|
|
699
|
+
export async function runPlanner(ctx, options) {
|
|
700
|
+
const { taskText, cwd, sessionId, modelSelection, signal, conversationContext = '', budget = {}, sourceMessageIds = [], telemetry, onProgress, } = options;
|
|
701
|
+
const timeoutMs = normalisePlannerWindow(options.plannerTimeoutMs, PLANNER_TIMEOUT_MS);
|
|
702
|
+
const idleMs = normalisePlannerWindow(options.plannerIdleTimeoutMs, PLANNER_IDLE_TIMEOUT_MS);
|
|
703
|
+
const hardMs = timeoutMs * PLANNER_HARD_MULTIPLIER;
|
|
704
|
+
/*
|
|
705
|
+
* [2.1.7] 两个可选旋钮:
|
|
706
|
+
* - DSH_WORKPLAN_PLANNER_MAX_TOKENS:给单次生成封顶。无界生成是「流满 900 秒
|
|
707
|
+
* 撞绝对上限」的放大器——封顶后模型会正常 finish,截断可被抢救/回喂;
|
|
708
|
+
* - DSH_WORKPLAN_PLANNER_REASONING_EFFORT:规划专用推理档,只接受
|
|
709
|
+
* low / medium / high / xhigh / max 五档。非法值不传给模型,回落默认档(见下)。
|
|
710
|
+
*
|
|
711
|
+
* [2.2.0][T13b] 用户 2026-11-08 决策 5「规划器停止继承」:未设该旋钮时,规划器
|
|
712
|
+
* 不再沿用主 Agent 的推理档,而是取 DEFAULT_PLANNER_REASONING_EFFORT(max)。
|
|
713
|
+
* 校验白名单复用 plan.ts 的 REASONING_EFFORTS(五档:low / medium / high /
|
|
714
|
+
* xhigh / max;[2.2.7][T4] 由三档扩五档,medium/xhigh 现为合法值):把
|
|
715
|
+
* "ultra"/"minimal" 这类非法值原样发给模型,真实宿主会以 400 拒绝整次规划——
|
|
716
|
+
* 环境变量写错不应该让整个
|
|
717
|
+
* 任务降级,所以非法值按「未设置」处理。
|
|
718
|
+
*/
|
|
719
|
+
const plannerMaxTokens = normalisePlannerWindow(process.env.DSH_WORKPLAN_PLANNER_MAX_TOKENS, 0);
|
|
720
|
+
// 大小写归一:"LOW" 这类写法若因大小写被当成非法值回落 max,会静默抬高
|
|
721
|
+
// 用户的成本预期,所以先归一化再进白名单。
|
|
722
|
+
const plannerEffortRaw = String(process.env.DSH_WORKPLAN_PLANNER_REASONING_EFFORT ?? '').trim().toLowerCase();
|
|
723
|
+
const plannerEffort = REASONING_EFFORTS.includes(plannerEffortRaw) ? plannerEffortRaw : '';
|
|
724
|
+
const requestedPlannerEffort = plannerEffort || DEFAULT_PLANNER_REASONING_EFFORT;
|
|
725
|
+
/*
|
|
726
|
+
* [2.2.7] 发送前按模型能力钳制档位:宿主对不支持的档位会在网络调用前直接
|
|
727
|
+
* 抛 UNSUPPORTED_REASONING_EFFORT,重试不自愈(终态),整次规划因此降级。
|
|
728
|
+
* 查询不可用时保持旧行为;查询到清单后请求档钳制到清单内等效档,空清单
|
|
729
|
+
* (模型无 reasoning 元数据)则不发送档位字段。'' 在这里表示「不发送」。
|
|
730
|
+
*/
|
|
731
|
+
const plannerEffortSupport = await resolveSupportedEfforts(ctx.llm, modelSelection?.provider, modelSelection?.model, signal);
|
|
732
|
+
const effectivePlannerEffort = plannerEffortSupport === null
|
|
733
|
+
? requestedPlannerEffort
|
|
734
|
+
: (clampEffortToSupported(requestedPlannerEffort, plannerEffortSupport) ?? '');
|
|
735
|
+
if (plannerEffortSupport !== null && effectivePlannerEffort !== requestedPlannerEffort) {
|
|
736
|
+
console.warn('[dsh-workplan] planner reasoning effort clamped for model compatibility:', JSON.stringify({
|
|
737
|
+
provider: modelSelection?.provider,
|
|
738
|
+
model: modelSelection?.model,
|
|
739
|
+
requested: requestedPlannerEffort,
|
|
740
|
+
effective: effectivePlannerEffort || '(omitted)',
|
|
741
|
+
supported: plannerEffortSupport,
|
|
742
|
+
}));
|
|
743
|
+
}
|
|
744
|
+
const secs = (ms) => Math.max(1, Math.round(ms / 1000));
|
|
380
745
|
let lastErrors = [];
|
|
381
|
-
|
|
746
|
+
/*
|
|
747
|
+
* [2.1.6.1] 每次尝试的失败原因必须都留档:旧实现每轮 `lastErrors = ...` 整体
|
|
748
|
+
* 覆盖,最终报错里只剩最后一次,第一次为什么失败永远丢失——事后只能靠猜。
|
|
749
|
+
* [2.2.5][T4] 尝试次数由 2 提到 3(PLANNER_MAX_ATTEMPTS),可重试类失败
|
|
750
|
+
* (传输/超时/服务端/限流)在两次尝试之间做指数退避,吸收偶发网络抖动。
|
|
751
|
+
*/
|
|
752
|
+
const attemptReports = [];
|
|
753
|
+
let lastText = '';
|
|
754
|
+
for (let attempt = 1; attempt <= PLANNER_MAX_ATTEMPTS; attempt += 1) {
|
|
382
755
|
if (signal.aborted)
|
|
383
756
|
throw abortError();
|
|
384
757
|
const controller = new AbortController();
|
|
385
758
|
const onAbort = () => controller.abort(signal.reason ?? abortError());
|
|
386
759
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
760
|
+
const startedAt = Date.now();
|
|
761
|
+
let sawChunk = false;
|
|
762
|
+
let lastChunkAt = startedAt;
|
|
763
|
+
let chunks = 0;
|
|
764
|
+
let promptChars = 0;
|
|
765
|
+
let outcome = 'ok';
|
|
766
|
+
/*
|
|
767
|
+
* [2.1.7] 流式正文的落点:collectStream 边流边写,abort/缺 finish 时也
|
|
768
|
+
* 能留下全文,供抢救(salvagePartialPlan)与遥测复盘使用。
|
|
769
|
+
*/
|
|
770
|
+
const sink = { text: '' };
|
|
771
|
+
let progressTimer = null;
|
|
772
|
+
const clearProgress = () => {
|
|
773
|
+
if (progressTimer) {
|
|
774
|
+
clearTimeout(progressTimer);
|
|
775
|
+
progressTimer = null;
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
const idleActive = () => sawChunk && idleMs < timeoutMs;
|
|
779
|
+
const windowMs = () => (idleActive() ? idleMs : timeoutMs);
|
|
780
|
+
const stallError = () => (idleActive()
|
|
781
|
+
? new PlanError(`规划器停滞:输出开始后 ${secs(idleMs)} 秒没有任何新内容,判定为卡死(不是还在思考)。可用 DSH_WORKPLAN_PLANNER_IDLE_TIMEOUT_MS 调整,设为不小于 ${secs(timeoutMs)} 秒即关闭`, 'PLANNER_IDLE')
|
|
782
|
+
: new PlanError(`规划器超时:${secs(timeoutMs)} 秒内没有取得任何进展(任务过长或模型过慢)。请设置 DSH_WORKPLAN_PLANNER_TIMEOUT_MS(毫秒)放宽单次调用上限,或缩短任务文本`, 'PLANNER_TIMEOUT'));
|
|
783
|
+
const checkProgress = () => {
|
|
784
|
+
progressTimer = null;
|
|
785
|
+
// 到点时若其实还有进展(窗口刚被收紧或时钟抖动),按剩余时间重新武装。
|
|
786
|
+
if (Date.now() - lastChunkAt < windowMs()) {
|
|
787
|
+
scheduleCheck();
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
controller.abort(stallError());
|
|
791
|
+
};
|
|
792
|
+
const scheduleCheck = () => {
|
|
793
|
+
clearProgress();
|
|
794
|
+
const remaining = Math.max(1, windowMs() - (Date.now() - lastChunkAt));
|
|
795
|
+
progressTimer = setTimeout(checkProgress, remaining);
|
|
796
|
+
};
|
|
797
|
+
const hardTimer = setTimeout(() => {
|
|
798
|
+
controller.abort(new PlanError(`规划器超出绝对上限:${secs(hardMs)} 秒(= DSH_WORKPLAN_PLANNER_TIMEOUT_MS 的 ${PLANNER_HARD_MULTIPLIER} 倍)。请缩短任务文本,或提高 DSH_WORKPLAN_PLANNER_TIMEOUT_MS`, 'PLANNER_TIMEOUT_HARD'));
|
|
799
|
+
}, hardMs);
|
|
800
|
+
const onChunk = () => {
|
|
801
|
+
chunks += 1;
|
|
802
|
+
lastChunkAt = Date.now();
|
|
803
|
+
// 首个 chunk 到达时窗口可能由 300s 收紧为 90s,必须立刻按新窗口重排。
|
|
804
|
+
if (!sawChunk) {
|
|
805
|
+
sawChunk = true;
|
|
806
|
+
scheduleCheck();
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
scheduleCheck();
|
|
810
|
+
/*
|
|
811
|
+
* [2.2.5][T4] 本轮重试判定(catch 内赋值,finally 遥测之后执行):
|
|
812
|
+
* - terminalFailure:不可自愈的 LLM 失败类,本轮结束后立即跳出循环;
|
|
813
|
+
* - retryBackoffMs:可重试类失败的重试前退避毫秒数(0 = 不退避)。
|
|
814
|
+
*/
|
|
815
|
+
let terminalFailure = false;
|
|
816
|
+
let retryBackoffMs = 0;
|
|
390
817
|
try {
|
|
391
818
|
let prompt = buildPlannerPrompt(taskText, cwd, conversationContext, budget);
|
|
819
|
+
promptChars = prompt.length;
|
|
392
820
|
if (lastErrors.length > 0) {
|
|
393
821
|
prompt += [
|
|
394
822
|
'',
|
|
@@ -396,15 +824,27 @@ async function runPlanner(ctx, options) {
|
|
|
396
824
|
...lastErrors.slice(0, 12).map((error) => `- ${error}`),
|
|
397
825
|
].join('\n');
|
|
398
826
|
}
|
|
827
|
+
/*
|
|
828
|
+
* [2.2.0][T13b/推理等级] 规划器停止继承主 Agent 的档位(用户 2026-11-08
|
|
829
|
+
* 决策 5,选项 A):显式传 effectivePlannerEffort(旋钮合法值,否则 max)。
|
|
830
|
+
*
|
|
831
|
+
* 旧代码 `plannerEffort || modelSelection.reasoningEffort` 的第二个操作数是
|
|
832
|
+
* 主 Agent 的档位,等于让主 Agent 决定规划器:主 Agent 用 low 省成本时,
|
|
833
|
+
* 拆解也降档,复杂任务被拆得更浅,后续部门再努力也补不回来。现在没有任何
|
|
834
|
+
* 路径读 modelSelection.reasoningEffort 作为规划档位。
|
|
835
|
+
*/
|
|
399
836
|
const stream = ctx.llm.stream({
|
|
400
837
|
provider: modelSelection.provider,
|
|
401
838
|
model: modelSelection.model,
|
|
402
|
-
|
|
839
|
+
// [2.2.7] '' = 模型无 reasoning 元数据,不发送档位字段(发送必被宿主拒绝)。
|
|
840
|
+
...(effectivePlannerEffort ? { reasoningEffort: effectivePlannerEffort } : {}),
|
|
841
|
+
...(plannerMaxTokens > 0 ? { maxTokens: plannerMaxTokens } : {}),
|
|
403
842
|
messages: [{ role: 'user', content: [{ type: 'text', text: prompt }] }],
|
|
404
843
|
signal: controller.signal,
|
|
405
844
|
sessionId,
|
|
406
845
|
});
|
|
407
|
-
const text = await collectStream(stream);
|
|
846
|
+
const text = await collectStream(stream, onChunk, sink);
|
|
847
|
+
lastText = text;
|
|
408
848
|
const raw = extractJson(text);
|
|
409
849
|
const validated = validatePlan(raw);
|
|
410
850
|
if (validated.ok) {
|
|
@@ -426,32 +866,183 @@ async function runPlanner(ctx, options) {
|
|
|
426
866
|
plan.understandingAudit = compactUnderstandingAudit(guard.audit);
|
|
427
867
|
return plan;
|
|
428
868
|
}
|
|
869
|
+
outcome = 'CONTEXT_GUARD';
|
|
429
870
|
lastErrors = guard.errors.length > 0 ? guard.errors : guard.warnings;
|
|
430
871
|
continue;
|
|
431
872
|
}
|
|
873
|
+
outcome = 'INVALID_PLAN';
|
|
432
874
|
lastErrors = validated.errors ?? [];
|
|
433
875
|
}
|
|
434
876
|
catch (error) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
877
|
+
/*
|
|
878
|
+
* LLM 层会把 abort 掩码成泛化的 "DeepSeek Messages request aborted",丢失
|
|
879
|
+
* 真实原因。这里优先读我们自己写进 controller.signal.reason 的判定码,
|
|
880
|
+
* 再区分「用户/宿主主动取消」,最后才当作可重试的偶发错误。
|
|
881
|
+
*/
|
|
882
|
+
const reason = controller.signal.aborted ? controller.signal.reason : undefined;
|
|
883
|
+
if (reason && PLANNER_ABORT_CODES.includes(String(reason.code))) {
|
|
884
|
+
/*
|
|
885
|
+
* [2.1.7] 定时器中止 ≠ 产出作废。旧实现在此直接 throw,900 秒里流出来的
|
|
886
|
+
* 正文随局部变量一起蒸发(遥测 textChars=0 就是这么来的)。先尝试用
|
|
887
|
+
* 与正常路径一致的三道闸验收已产出的正文:能通过就照常返回计划;
|
|
888
|
+
* 通不过才按原判定中止,失败现场由 finally 的遥测留档。
|
|
889
|
+
*/
|
|
890
|
+
const salvaged = salvagePartialPlan(sink.text, {
|
|
891
|
+
taskText,
|
|
892
|
+
conversationContext,
|
|
893
|
+
sourceMessageIds,
|
|
894
|
+
strict: contextGuardStrict(),
|
|
895
|
+
});
|
|
896
|
+
if (salvaged && !signal.aborted) {
|
|
897
|
+
outcome = 'SALVAGED';
|
|
898
|
+
lastText = sink.text;
|
|
899
|
+
return salvaged;
|
|
900
|
+
}
|
|
901
|
+
outcome = String(reason.code);
|
|
902
|
+
throw reason;
|
|
440
903
|
}
|
|
441
|
-
|
|
904
|
+
/*
|
|
905
|
+
* [2.1.7] 同样地:模型写完了 JSON 却没送来 finish 信号(连接抖动、
|
|
906
|
+
* 层序错乱)时,正文若已完整可用就不要整轮作废。
|
|
907
|
+
*/
|
|
908
|
+
if (error instanceof PlanError && error.code === 'PLANNER_INCOMPLETE' && !signal.aborted) {
|
|
909
|
+
const salvaged = salvagePartialPlan(sink.text, {
|
|
910
|
+
taskText,
|
|
911
|
+
conversationContext,
|
|
912
|
+
sourceMessageIds,
|
|
913
|
+
strict: contextGuardStrict(),
|
|
914
|
+
});
|
|
915
|
+
if (salvaged) {
|
|
916
|
+
outcome = 'SALVAGED';
|
|
917
|
+
lastText = sink.text;
|
|
918
|
+
return salvaged;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (signal.aborted || (controller.signal.aborted && reason?.code === 'ABORTED')) {
|
|
922
|
+
outcome = 'ABORTED';
|
|
442
923
|
throw abortError();
|
|
443
924
|
}
|
|
444
|
-
if (error instanceof PlanError && error.code === 'ABORTED')
|
|
925
|
+
if (error instanceof PlanError && error.code === 'ABORTED') {
|
|
926
|
+
outcome = 'ABORTED';
|
|
445
927
|
throw error;
|
|
446
|
-
|
|
928
|
+
}
|
|
929
|
+
outcome = (error instanceof PlanError && error.code) || 'PLANNER_ERROR';
|
|
930
|
+
/*
|
|
931
|
+
* [2.2.5][T4] 失败原因整链透传(T3 根因 P2):error.message 只是外层包装
|
|
932
|
+
* (如 "fetch failed"),真因(ENOTFOUND / ECONNREFUSED / TLS alert)挂在
|
|
933
|
+
* cause 链上。展开后写入 lastErrors → attemptReports → 最终降级文案,
|
|
934
|
+
* 下次失败不再只看到一句 "TRANSPORT:Connection error"。
|
|
935
|
+
*/
|
|
936
|
+
const message = error instanceof Error ? errorCauseChain(error) : String(error);
|
|
937
|
+
lastErrors = [message];
|
|
938
|
+
/*
|
|
939
|
+
* [2.1.6.1] 只回一句「位置 6041」给模型毫无用处:它看不到自己断在哪。
|
|
940
|
+
* 把断点附近的原文与「截断 / 写错」的判据一并回喂,第二次尝试才有靶子;
|
|
941
|
+
* 同时把长度与尾部落进遥测,失败现场从此可复盘。
|
|
942
|
+
*/
|
|
943
|
+
if (error instanceof PlanError && error.code === 'INVALID_JSON' && lastText) {
|
|
944
|
+
const trimmed = lastText.trimEnd();
|
|
945
|
+
const tail = trimmed.slice(-120);
|
|
946
|
+
const closed = trimmed.endsWith('}');
|
|
947
|
+
lastErrors = [
|
|
948
|
+
message,
|
|
949
|
+
`输出共 ${lastText.length} 字符,末尾原文:${JSON.stringify(tail)}`,
|
|
950
|
+
closed
|
|
951
|
+
? '末尾已闭合 → 断点在正文中间,属语法写错(漏逗号/括号不匹配)'
|
|
952
|
+
: '末尾未闭合(没有结尾 })→ 疑似输出被截断,请给出更紧凑的完整 JSON',
|
|
953
|
+
];
|
|
954
|
+
}
|
|
955
|
+
/*
|
|
956
|
+
* [2.2.5][T4] 重试分级 + 退避(T3 根因 P1):旧实现 catch 后零退避立即
|
|
957
|
+
* 重试——一次 ~1s 网络连接尖峰 × 0ms 间隔 = 1.2 秒内两连败直接降级。
|
|
958
|
+
* 现在:可重试类(TRANSPORT/TIMEOUT/SERVER/RATE_LIMIT)按 500ms→1s
|
|
959
|
+
* 指数退避(±20% 抖动,可被 signal 打断)给抖动尾巴留出恢复窗口;
|
|
960
|
+
* 其余 LLM 失败类(AUTH/INVALID_REQUEST/配额/上下文溢出等)重试不会
|
|
961
|
+
* 自愈,置 terminal 标志本轮结束后立即跳出,不烧下一次调用。
|
|
962
|
+
*/
|
|
963
|
+
const llmCode = error instanceof PlanError && error.code === 'PLANNER_LLM_ERROR'
|
|
964
|
+
&& typeof error.details === 'string'
|
|
965
|
+
? error.details
|
|
966
|
+
: '';
|
|
967
|
+
if (llmCode !== '' && !PLANNER_RETRYABLE_LLM_CODES.includes(llmCode)) {
|
|
968
|
+
terminalFailure = true;
|
|
969
|
+
}
|
|
970
|
+
else if (attempt < PLANNER_MAX_ATTEMPTS && !signal.aborted) {
|
|
971
|
+
retryBackoffMs = Math.round(PLANNER_RETRY_BACKOFF_BASE_MS * 2 ** (attempt - 1) * (0.8 + Math.random() * 0.4));
|
|
972
|
+
}
|
|
447
973
|
}
|
|
448
974
|
finally {
|
|
449
|
-
|
|
975
|
+
clearProgress();
|
|
976
|
+
clearTimeout(hardTimer);
|
|
450
977
|
signal.removeEventListener('abort', onAbort);
|
|
978
|
+
/*
|
|
979
|
+
* [2.1.6] 规划器遥测:此前失败现场什么都不留,事后只能从会话 JSONL 反推
|
|
980
|
+
* 「恰好 300.06 秒」。现在每次尝试都留下模型、提示词规模、产出块数、耗时
|
|
981
|
+
* 与判定码,失败时随降级消息一起给到用户。
|
|
982
|
+
*/
|
|
983
|
+
if (outcome !== 'ok' && lastErrors.length > 0) {
|
|
984
|
+
attemptReports.push(`第 ${attempt} 次[${outcome}]:${lastErrors.join(';')}`);
|
|
985
|
+
/*
|
|
986
|
+
* [2.2.5][T5] 分解期间进度透出(T1 P-6 / T3 §5):每次失败尝试在遥测
|
|
987
|
+
* 留档之后向调用方回调一次(attempt / outcome / 真因链 / 退避毫秒 /
|
|
988
|
+
* 终态)。这里只是追加观察点——terminalFailure 与 retryBackoffMs 在
|
|
989
|
+
* catch 里已定值,本回调不读写循环控制变量,重试判定、退避与跳出
|
|
990
|
+
* 语义与旧实现逐字节一致。
|
|
991
|
+
*/
|
|
992
|
+
if (typeof onProgress === 'function') {
|
|
993
|
+
onProgress({
|
|
994
|
+
attempt,
|
|
995
|
+
outcome,
|
|
996
|
+
lastErrors: [...lastErrors],
|
|
997
|
+
retryBackoffMs,
|
|
998
|
+
terminal: terminalFailure,
|
|
999
|
+
aborted: signal.aborted,
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (telemetry && typeof telemetry === 'object') {
|
|
1004
|
+
Object.assign(telemetry, {
|
|
1005
|
+
// [2.1.7] 以 sink 为准:abort 时 lastText 恒为空,旧值让现场永远缺「输出 N 字」。
|
|
1006
|
+
textChars: Math.max(lastText.length, sink.text.length),
|
|
1007
|
+
provider: modelSelection.provider,
|
|
1008
|
+
model: modelSelection.model,
|
|
1009
|
+
// [2.2.0][T13b] 记录**实际发给模型**的档位:旧值记的是 modelSelection
|
|
1010
|
+
// (主 Agent 档位),规划器停止继承后它不再等于生效值,照抄会让事后
|
|
1011
|
+
// 复盘把「主 Agent=high」误读成「规划器=high」。
|
|
1012
|
+
// [2.2.7] 钳制发生时同样记录实际发出值('' = 未发送)。
|
|
1013
|
+
reasoningEffort: effectivePlannerEffort,
|
|
1014
|
+
reasoningEffortSource: (plannerEffort ? 'env' : 'default-max')
|
|
1015
|
+
+ (plannerEffortSupport !== null && effectivePlannerEffort !== requestedPlannerEffort
|
|
1016
|
+
? `→clamped(${requestedPlannerEffort})` : ''),
|
|
1017
|
+
attempt,
|
|
1018
|
+
taskChars: typeof taskText === 'string' ? taskText.length : 0,
|
|
1019
|
+
promptChars,
|
|
1020
|
+
chunks,
|
|
1021
|
+
elapsedMs: Date.now() - startedAt,
|
|
1022
|
+
outcome,
|
|
1023
|
+
at: Date.now(),
|
|
1024
|
+
});
|
|
1025
|
+
if (plannerDebugEnabled()) {
|
|
1026
|
+
console.warn('[dsh-workplan] planner attempt', JSON.stringify({ ...telemetry }));
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
/*
|
|
1031
|
+
* [2.2.5][T4] 退避在 finally(遥测计时)之后执行,不污染单次尝试的
|
|
1032
|
+
* elapsedMs;不可自愈失败在此直接跳出,最终报错仍走统一的聚合文案。
|
|
1033
|
+
* 校验类重试(CONTEXT_GUARD/INVALID_PLAN 的 continue)不经过这里,
|
|
1034
|
+
* 保持原有的零退避快重试。
|
|
1035
|
+
*/
|
|
1036
|
+
if (terminalFailure)
|
|
1037
|
+
break;
|
|
1038
|
+
if (retryBackoffMs > 0) {
|
|
1039
|
+
await sleepAbortable(signal, retryBackoffMs);
|
|
1040
|
+
if (signal.aborted)
|
|
1041
|
+
throw abortError();
|
|
451
1042
|
}
|
|
452
1043
|
}
|
|
453
1044
|
const deviation = lastErrors.some((error) => /^(?:DEVIATION|CLARIFY|CONTEXT):/.test(String(error)));
|
|
454
|
-
throw new PlanError(
|
|
1045
|
+
throw new PlanError(`规划器 ${attemptReports.length > 0 ? `全部 ${attemptReports.length} 次尝试` : '输出'}均未通过校验:${(attemptReports.length > 0 ? attemptReports : lastErrors).slice(0, 6).join(' | ')}`, deviation ? 'DEVIATION' : 'PLANNER_FAILED', lastErrors);
|
|
455
1046
|
}
|
|
456
1047
|
function createChildController(parentSignal) {
|
|
457
1048
|
const controller = new AbortController();
|
|
@@ -840,7 +1431,14 @@ export function budgetResetError(item, subtask, cwd, artifactExists = existsSync
|
|
|
840
1431
|
* the session replay cannot disagree. This wrapper only adds the two things
|
|
841
1432
|
* that need the environment: the strict/legacy switch and the file check.
|
|
842
1433
|
*/
|
|
843
|
-
function settleFromOutput(record, subtask, output, guard, options
|
|
1434
|
+
function settleFromOutput(record, subtask, output, guard, options,
|
|
1435
|
+
/*
|
|
1436
|
+
* [2.2.8][T7] 两个可选入参:`precomputedVerdict` 让调用方把已经裁决过的
|
|
1437
|
+
* 结果直接传入(unparsable 门在结算前判定过一次,纯函数重算是浪费也是
|
|
1438
|
+
* 双源);`extraEvidence` 只在「解析失败重试耗尽、按实受阻」时传入——
|
|
1439
|
+
* 它把 attempt 摘要/声明产物在盘上的事实随 blocked 行留档。
|
|
1440
|
+
*/
|
|
1441
|
+
precomputedVerdict, extraEvidence) {
|
|
844
1442
|
/*
|
|
845
1443
|
* [1.11.0] 已经升级的请示不能被收尾正文覆盖。
|
|
846
1444
|
*
|
|
@@ -852,7 +1450,7 @@ function settleFromOutput(record, subtask, output, guard, options) {
|
|
|
852
1450
|
const current = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
853
1451
|
if (current?.closure === 'escalated')
|
|
854
1452
|
return { status: 'blocked', escalated: true };
|
|
855
|
-
const verdict = adjudicateResult({
|
|
1453
|
+
const verdict = precomputedVerdict ?? adjudicateResult({
|
|
856
1454
|
output,
|
|
857
1455
|
strict: options.strictEvidence !== false,
|
|
858
1456
|
/*
|
|
@@ -867,6 +1465,26 @@ function settleFromOutput(record, subtask, output, guard, options) {
|
|
|
867
1465
|
const checked = checkArtifacts(verdict.artifacts, options.cwd, options.artifactExists);
|
|
868
1466
|
const escalated = verdict.status === 'blocked'
|
|
869
1467
|
&& typeof verdict.question === 'string' && verdict.question.trim() !== '';
|
|
1468
|
+
/*
|
|
1469
|
+
* [2.2.8][T7] 解析失败重试耗尽后的受阻,不得退化成「零产出失败」。
|
|
1470
|
+
*
|
|
1471
|
+
* T4 实证:子会话工作已完成、交付物已在盘上,只是结果块 JSON 写坏了;
|
|
1472
|
+
* 旧账本只留一句「结果块 JSON 非法」,主 Agent 无从知道产物存在,只能
|
|
1473
|
+
* 级联下游重做。现在把 attempt 摘要/声明产物中**确实在盘上**的清单随
|
|
1474
|
+
* blocked 行留档,并在 error 文案里给出「用 dsh_workplan_update 复核改判」
|
|
1475
|
+
* 的出口。语义不变:非法 JSON 依旧不计 done,这里只是把事实说全。
|
|
1476
|
+
*/
|
|
1477
|
+
const landedRefs = (extraEvidence?.artifacts ?? [])
|
|
1478
|
+
.filter((item) => item?.exists === true)
|
|
1479
|
+
.map((item) => String(item?.ref ?? ''))
|
|
1480
|
+
.filter((ref) => ref !== '');
|
|
1481
|
+
const reviewNote = landedRefs.length > 0
|
|
1482
|
+
? `;本次回报声明的产物清单已随本行留档(已在盘上:${landedRefs.slice(0, 6).join('、')})——产物已在盘上,`
|
|
1483
|
+
+ '请先用 dsh_workplan_update 复核改判,勿按零产出处理,也不要级联阻断下游'
|
|
1484
|
+
: '';
|
|
1485
|
+
const settleError = typeof verdict.error === 'string' && verdict.error !== ''
|
|
1486
|
+
? `${verdict.error}${reviewNote}`
|
|
1487
|
+
: verdict.error;
|
|
870
1488
|
/*
|
|
871
1489
|
* [2.0.0] 自我学习闭环的出口:完成且带复盘证据时,立刻写入永久记忆。
|
|
872
1490
|
*
|
|
@@ -901,11 +1519,15 @@ function settleFromOutput(record, subtask, output, guard, options) {
|
|
|
901
1519
|
progress: 100,
|
|
902
1520
|
finishedAt: Date.now(),
|
|
903
1521
|
summary: truncate(lessonNote ? `${output}\n[自我学习] ${lessonNote}` : output, 3000),
|
|
904
|
-
error:
|
|
1522
|
+
error: settleError,
|
|
905
1523
|
verification: verdict.verification,
|
|
906
1524
|
acceptance: verdict.acceptance,
|
|
907
|
-
artifacts: checked.artifacts.length > 0
|
|
908
|
-
|
|
1525
|
+
artifacts: checked.artifacts.length > 0
|
|
1526
|
+
? checked.artifacts
|
|
1527
|
+
: (extraEvidence && extraEvidence.artifacts.length > 0 ? extraEvidence.artifacts : undefined),
|
|
1528
|
+
missingArtifacts: checked.missingArtifacts.length > 0
|
|
1529
|
+
? checked.missingArtifacts
|
|
1530
|
+
: (extraEvidence && extraEvidence.missingArtifacts.length > 0 ? extraEvidence.missingArtifacts : undefined),
|
|
909
1531
|
needs: verdict.needs.length > 0 ? verdict.needs : undefined,
|
|
910
1532
|
/*
|
|
911
1533
|
* [1.11.0] 文本兜底:子会话拿不到 escalate 工具时,结果块里的
|
|
@@ -942,11 +1564,31 @@ function settleFromOutput(record, subtask, output, guard, options) {
|
|
|
942
1564
|
}),
|
|
943
1565
|
}, guard);
|
|
944
1566
|
if (verdict.status === 'blocked') {
|
|
945
|
-
recordSubtaskError(record, subtask.id, escalated ? `待指示:${verdict.question}` : (
|
|
1567
|
+
recordSubtaskError(record, subtask.id, escalated ? `待指示:${verdict.question}` : (settleError ?? '未完成'), guard);
|
|
946
1568
|
}
|
|
947
1569
|
else if (checked.missingArtifacts.length > 0) {
|
|
948
1570
|
recordSubtaskError(record, subtask.id, `声明产物缺失:${checked.missingArtifacts.join('、')}`, guard);
|
|
949
1571
|
}
|
|
1572
|
+
/*
|
|
1573
|
+
* [2.2.0][T6/O-1a] 完成即时通知(插件兜底通道,方案 §2.3)。
|
|
1574
|
+
*
|
|
1575
|
+
* 结算成功后立刻把「子任务 ID+摘要+验收计数+用时」交给主会话,不等待
|
|
1576
|
+
* 整轮结束;只有真正的 done 才通知(blocked/escalated 不产生「已完成」
|
|
1577
|
+
* 措辞,A4)。投递与幂等标记由 `onSubtaskDone` 处理器负责:先写通知、
|
|
1578
|
+
* 写成功才记 report.state='sent',绝不留无证据的已回报。
|
|
1579
|
+
*/
|
|
1580
|
+
if (verdict.status === 'done' && options.notifyCompletion === true
|
|
1581
|
+
&& typeof options.onSubtaskDone === 'function') {
|
|
1582
|
+
try {
|
|
1583
|
+
options.onSubtaskDone(record, subtask, verdict);
|
|
1584
|
+
}
|
|
1585
|
+
catch {
|
|
1586
|
+
/*
|
|
1587
|
+
* 通知是辅助通道:写失败不得回滚已经成立的完成判定,也不得让执行
|
|
1588
|
+
* 路径报错。失败由处理器记 reportPending,交 finishRound 批量补齐。
|
|
1589
|
+
*/
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
950
1592
|
return { ...verdict, escalated };
|
|
951
1593
|
}
|
|
952
1594
|
/**
|
|
@@ -993,10 +1635,62 @@ export function shouldRetryAttempt(error, attempt, remainingMs, idleTimeoutMs) {
|
|
|
993
1635
|
if (code === 'CHILD_NOT_COMPLETED') {
|
|
994
1636
|
return Number(remainingMs) > Number(idleTimeoutMs);
|
|
995
1637
|
}
|
|
1638
|
+
/*
|
|
1639
|
+
* [2.2.8][T7] 结果块解析失败与 CHILD_NOT_COMPLETED 走同一道闸(用户 2026-11-09
|
|
1640
|
+
* 报告 T4 事故:非法 JSON 一次即 blocked,并级联阻断下游;子会话其实已完成
|
|
1641
|
+
* 工作,只差一个合法回报)。回喂重报要有意义,必须还剩超过一个空闲窗口的
|
|
1642
|
+
* 预算;「最多两次」由函数开头的 attempt 上限统一把关,不会无限循环。
|
|
1643
|
+
*/
|
|
1644
|
+
if (code === 'EVIDENCE_UNPARSABLE') {
|
|
1645
|
+
return Number(remainingMs) > Number(idleTimeoutMs);
|
|
1646
|
+
}
|
|
1647
|
+
return true;
|
|
1648
|
+
}
|
|
1649
|
+
/*
|
|
1650
|
+
* [2.2.7] 执行中断即时通知(用户 2026-11-09 报告的第二个缺陷)。
|
|
1651
|
+
*
|
|
1652
|
+
* 缺陷现场:部门专家执行中被中断(子会话报错、重试、no-ack、预算耗尽)时,
|
|
1653
|
+
* 主会话直到整轮结束才随结果消息一并交代——期间用户只看到进度不动,无法区分
|
|
1654
|
+
* 「在慢慢做」与「已经失败」,只能干着急。既有即时通道只覆盖 done
|
|
1655
|
+
* (emitSubtaskDoneNotice)与到点预警;中断类事件全走 record.errors(只有
|
|
1656
|
+
* 主 Agent 下次读记录才可见)。
|
|
1657
|
+
*
|
|
1658
|
+
* 这里补上同构的「中断即报」:中断一发生就往主会话写一条纯文本 user/message,
|
|
1659
|
+
* 文案固定三段——发生什么(含错误码与真因摘录)、系统正在怎么处理(重试/收束/
|
|
1660
|
+
* 待裁决)、对用户意味着什么(不是任务失败终局)。频率纪律:每个子任务整轮
|
|
1661
|
+
* 至多 INTERRUPT_NOTICE_CAP 条,写失败只留档到 record.errors,绝不影响执行。
|
|
1662
|
+
* 消息不带 workplan 标记,回放解析器按未知消息跳过(与完成通知同一纪律)。
|
|
1663
|
+
*/
|
|
1664
|
+
const INTERRUPT_NOTICE_CAP = 3;
|
|
1665
|
+
export function announceSubtaskInterrupt(record, session, subtaskId, text) {
|
|
1666
|
+
if (!record || !session || typeof session.append !== 'function')
|
|
1667
|
+
return false;
|
|
1668
|
+
const row = Array.isArray(record.statuses)
|
|
1669
|
+
? record.statuses.find((item) => item?.subtaskId === subtaskId)
|
|
1670
|
+
: null;
|
|
1671
|
+
const sent = Number(row?.interruptNoticeCount ?? 0);
|
|
1672
|
+
if (sent >= INTERRUPT_NOTICE_CAP)
|
|
1673
|
+
return false;
|
|
1674
|
+
const notice = `【dsh-workplan·执行中断】${truncate(String(text ?? '').replace(/\s+/g, ' ').trim(), 400)}`;
|
|
1675
|
+
try {
|
|
1676
|
+
appendUserMessage(session, notice);
|
|
1677
|
+
}
|
|
1678
|
+
catch (error) {
|
|
1679
|
+
record.errors = [...(record.errors ?? []), `${subtaskId} 中断通知写入失败:${truncate(String(error?.message ?? error), 200)}`].slice(-20);
|
|
1680
|
+
return false;
|
|
1681
|
+
}
|
|
1682
|
+
if (row)
|
|
1683
|
+
row.interruptNoticeCount = sent + 1;
|
|
996
1684
|
return true;
|
|
997
1685
|
}
|
|
998
1686
|
async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
999
1687
|
const { parentSignal, deadline, modelSelection, conversationContext = '', child, guard } = options;
|
|
1688
|
+
/*
|
|
1689
|
+
* [2.2.7] 中断即报的目标会话:与 noticeChannel/finaliseNotice 同一取值链,
|
|
1690
|
+
* 拿不到就安静跳过(通知是观测设施,不是交付物)。
|
|
1691
|
+
*/
|
|
1692
|
+
const interruptSession = () => options.session ?? options.agent?.session
|
|
1693
|
+
?? findSession(ctx, String(record?.plan?.sessionId ?? ''));
|
|
1000
1694
|
let lastError = null;
|
|
1001
1695
|
/*
|
|
1002
1696
|
* [1.10.6] A retry that starts after a *ceiling* timeout is a second attempt
|
|
@@ -1009,6 +1703,97 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1009
1703
|
? options.attemptOffset
|
|
1010
1704
|
: 1;
|
|
1011
1705
|
let lastFailure = options.priorFailure ?? null;
|
|
1706
|
+
/*
|
|
1707
|
+
* [2.2.0][T3/O-2a] 子→主预告通道的两个动作,都在本函数内闭环:
|
|
1708
|
+
* recordNoticeChannel —— 派发瞬间写下「目标 / 调用方 / 时间戳」;
|
|
1709
|
+
* finaliseNotice —— 结算瞬间去父会话日志里核实预告到底有没有转达,
|
|
1710
|
+
* 没转达就写一条四项齐全的失败日志(不静默丢失)。
|
|
1711
|
+
*
|
|
1712
|
+
* 目标 id 只从注入值取;注入值缺失时才按 agent.id → session.id 再解析一次
|
|
1713
|
+
* (重启重建/续跑路径)。[2.2.1][T5][F4] 不再回落 plan.sessionId:计划正文
|
|
1714
|
+
* 可能属于另一个 root 会话,不能作为「发给谁」的依据;两级都没有就留空,
|
|
1715
|
+
* 让提示词走「禁止猜测」分支。
|
|
1716
|
+
*/
|
|
1717
|
+
const noticeLead = (() => {
|
|
1718
|
+
const injected = readLeadAgentId(options.leadAgentId);
|
|
1719
|
+
const liveAgentId = readLeadAgentId(options.agent?.id);
|
|
1720
|
+
/*
|
|
1721
|
+
* [2.2.0][T3/O-2a][F4] 目标完整性 fail-closed。
|
|
1722
|
+
*
|
|
1723
|
+
* 注入值来自 dispatchPlan 的 agent.id 优先解析;若未来某条重建/续跑路径
|
|
1724
|
+
* 只拿得到 plan.sessionId 兜底值,而执行侧又有活 Agent,则两者不一致
|
|
1725
|
+
* 时绝不能把兜底值写进子提示词(那等于把目标指向另一个 root 会话)。
|
|
1726
|
+
*/
|
|
1727
|
+
if (injected && liveAgentId && injected !== liveAgentId) {
|
|
1728
|
+
return { id: '', source: 'mismatch:agent.id' };
|
|
1729
|
+
}
|
|
1730
|
+
if (injected) {
|
|
1731
|
+
return {
|
|
1732
|
+
id: injected,
|
|
1733
|
+
source: typeof options.leadAgentIdSource === 'string' && options.leadAgentIdSource !== 'none'
|
|
1734
|
+
? options.leadAgentIdSource
|
|
1735
|
+
: 'options.leadAgentId',
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
return resolveLeadAgentId({ agent: options.agent, session: options.session });
|
|
1739
|
+
})();
|
|
1740
|
+
const recordNoticeChannel = (entry) => {
|
|
1741
|
+
try {
|
|
1742
|
+
writeSubtaskStatus(record, subtask.id, { noticeChannel: entry }, guard);
|
|
1743
|
+
}
|
|
1744
|
+
catch (error) {
|
|
1745
|
+
/*
|
|
1746
|
+
* 通道留痕失败不能影响子任务本身(它是观测设施,不是交付物),但也不能
|
|
1747
|
+
* 一点痕迹都不留——写进本轮错误列表,主 Agent 读记录时能看到。
|
|
1748
|
+
*/
|
|
1749
|
+
record.errors = [...(record.errors ?? []), `${subtask.id} noticeChannel 写入失败:${truncate(String(error?.message ?? error), 300)}`].slice(-20);
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
const finaliseNotice = () => {
|
|
1753
|
+
if (guard.timedOut) {
|
|
1754
|
+
/*
|
|
1755
|
+
* [2.2.0][T3/O-2a][F3] 超时路径 writeSubtaskStatus 会被 guard 静默拒绝,
|
|
1756
|
+
* 不能写状态行;但通道不能停在没有结论的 awaiting。至少把四项日志写进
|
|
1757
|
+
* record.errors,让主 Agent 知道「是超时导致没收到结论」,而不是猜测。
|
|
1758
|
+
*/
|
|
1759
|
+
const row = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
1760
|
+
const current = row?.noticeChannel;
|
|
1761
|
+
if (current) {
|
|
1762
|
+
record.errors = [...(record.errors ?? []), formatNoticeChannelLog({
|
|
1763
|
+
subtaskId: subtask.id,
|
|
1764
|
+
target: current.target,
|
|
1765
|
+
caller: current.caller,
|
|
1766
|
+
at: current.at,
|
|
1767
|
+
reason: 'TIMEOUT',
|
|
1768
|
+
})].slice(-20);
|
|
1769
|
+
}
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
const row = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
1773
|
+
const current = row?.noticeChannel;
|
|
1774
|
+
if (!current)
|
|
1775
|
+
return;
|
|
1776
|
+
const noticeSession = options.session && typeof options.session.eventAt === 'function'
|
|
1777
|
+
? options.session
|
|
1778
|
+
: findSession(ctx, current.target);
|
|
1779
|
+
const observed = observeRelayedNotice(noticeSession, { childId: current.caller, sinceMs: current.at });
|
|
1780
|
+
const entry = finaliseNoticeChannel(current, {
|
|
1781
|
+
observed: Boolean(observed),
|
|
1782
|
+
observedAt: observed?.at ?? null,
|
|
1783
|
+
sessionAvailable: Boolean(noticeSession),
|
|
1784
|
+
now: Date.now(),
|
|
1785
|
+
});
|
|
1786
|
+
recordNoticeChannel(entry);
|
|
1787
|
+
if (entry.state !== 'observed') {
|
|
1788
|
+
record.errors = [...(record.errors ?? []), formatNoticeChannelLog({
|
|
1789
|
+
subtaskId: subtask.id,
|
|
1790
|
+
target: entry.target,
|
|
1791
|
+
caller: entry.caller,
|
|
1792
|
+
at: entry.at,
|
|
1793
|
+
reason: entry.reason,
|
|
1794
|
+
})].slice(-20);
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1012
1797
|
/*
|
|
1013
1798
|
* [2.1.0] 格式退回通知必须在下一次激活送达部门人员(用户 2026-11-06 的
|
|
1014
1799
|
* 强制要求:不符合要求立刻退回,通知其重新检查格式后重交)。
|
|
@@ -1054,12 +1839,26 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1054
1839
|
let interruptedFlag = false;
|
|
1055
1840
|
let interruptedEvidence = null;
|
|
1056
1841
|
try {
|
|
1842
|
+
// [2.2.0][T4/O-3b] 尝试起点与协商截止同一时钟读数(C3 契约:deadlineAt −
|
|
1843
|
+
// startedAt 严格等于协商窗口)。deadlineAt 走 StatusEntry 未知字段保留通道
|
|
1844
|
+
// 直写:applyStatus(src/plan.ts,T3 领地)无路由分支,patch 会静默丢弃。
|
|
1845
|
+
const attemptStartMs = Date.now();
|
|
1846
|
+
const attemptWindowMs = Number(options.attemptTimeoutMs ?? 0);
|
|
1057
1847
|
if (!writeSubtaskStatus(record, subtask.id, {
|
|
1058
1848
|
status: 'in_progress',
|
|
1059
1849
|
progress: 5,
|
|
1060
|
-
startedAt:
|
|
1850
|
+
startedAt: attemptStartMs,
|
|
1061
1851
|
}, guard))
|
|
1062
1852
|
return;
|
|
1853
|
+
if (Number.isFinite(attemptWindowMs) && attemptWindowMs > 0) {
|
|
1854
|
+
const attemptRow = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
1855
|
+
if (attemptRow)
|
|
1856
|
+
attemptRow.deadlineAt = attemptStartMs + attemptWindowMs;
|
|
1857
|
+
if (options.attemptHandle) {
|
|
1858
|
+
options.attemptHandle.startedAt = attemptStartMs;
|
|
1859
|
+
options.attemptHandle.deadlineAt = attemptStartMs + attemptWindowMs;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1063
1862
|
for (let attempt = firstAttempt; attempt <= 2; attempt += 1) {
|
|
1064
1863
|
if (guard.timedOut)
|
|
1065
1864
|
return;
|
|
@@ -1094,6 +1893,32 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1094
1893
|
catch {
|
|
1095
1894
|
lessonsBrief = '';
|
|
1096
1895
|
}
|
|
1896
|
+
/*
|
|
1897
|
+
* [2.2.7] 子会话档位同样要过模型能力这道闸:计划里的 low / medium /
|
|
1898
|
+
* high / xhigh / max 五档值是规划器按通用五档规则写的([2.2.7][T4];旧
|
|
1899
|
+
* 三档计划中的 low/high/max 属五档子集,回放零迁移),可子会话用的就是
|
|
1900
|
+
* 主链路模型(modelSelection)。
|
|
1901
|
+
* 若该模型不声明这些档(qwen 只声明 low/medium/xhigh),照发必被宿主
|
|
1902
|
+
* 在请求前抛 UNSUPPORTED_REASONING_EFFORT——派发期即中断。查询不可用
|
|
1903
|
+
* 时保持旧行为;查询成功后钳制到等效档,空清单则不发送该字段。
|
|
1904
|
+
*/
|
|
1905
|
+
const requestedChildEffort = typeof subtask.reasoningEffort === 'string'
|
|
1906
|
+
&& REASONING_EFFORTS.includes(subtask.reasoningEffort)
|
|
1907
|
+
? subtask.reasoningEffort
|
|
1908
|
+
: DEFAULT_REASONING_EFFORT;
|
|
1909
|
+
/*
|
|
1910
|
+
* [2.2.7] 能力不可查询时保持同步路径:派发链上任何多余的 await 微任务都会
|
|
1911
|
+
* 把 awaiting 通道写入推晚一个 tick(notice-channel 运行时集成用例即因此
|
|
1912
|
+
* 断言失败)。只有真要向宿主查询时才引入这一次等待。
|
|
1913
|
+
*/
|
|
1914
|
+
const effortQueryable = Boolean(ctx.llm && typeof ctx.llm.resolveModelInfo === 'function'
|
|
1915
|
+
&& modelSelection?.provider && modelSelection?.model);
|
|
1916
|
+
const childEffortSupport = effortQueryable
|
|
1917
|
+
? await resolveSupportedEfforts(ctx.llm, modelSelection.provider, modelSelection.model, parentSignal)
|
|
1918
|
+
: null;
|
|
1919
|
+
const childEffort = childEffortSupport === null
|
|
1920
|
+
? requestedChildEffort
|
|
1921
|
+
: (clampEffortToSupported(requestedChildEffort, childEffortSupport) ?? '');
|
|
1097
1922
|
activation = await ctx.subagents.startActivation({
|
|
1098
1923
|
provider: 'spawn',
|
|
1099
1924
|
label: `${subtask.department}:${subtask.id} ${subtask.title}`.slice(0, 120),
|
|
@@ -1125,6 +1950,14 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1125
1950
|
cwd: options.cwd,
|
|
1126
1951
|
conversationContext,
|
|
1127
1952
|
statuses: record.statuses,
|
|
1953
|
+
/*
|
|
1954
|
+
* [2.2.0][T3/O-2a] 子→主预告通道的目标(真实父会话 id)。
|
|
1955
|
+
*
|
|
1956
|
+
* 宿主只在非 caller 投递时注入父会话 id,本插件用 caller 投递,
|
|
1957
|
+
* 所以这里必须自己给值;空值走「禁止猜测」分支,绝不编造 id。
|
|
1958
|
+
*/
|
|
1959
|
+
leadAgentId: noticeLead.id,
|
|
1960
|
+
leadAgentIdSource: noticeLead.source,
|
|
1128
1961
|
/*
|
|
1129
1962
|
* [2.1.0] 不再用 attempt>1 做门槛:被格式退回的行复位后第 1 次
|
|
1130
1963
|
* 激活也必须带上退回通知,否则「退回」只是写了一行状态。
|
|
@@ -1135,9 +1968,25 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1135
1968
|
}],
|
|
1136
1969
|
parent: options.agent,
|
|
1137
1970
|
cwd: typeof options.cwd === 'string' && options.cwd ? options.cwd : undefined,
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1971
|
+
/*
|
|
1972
|
+
* [2.2.0][T13/推理等级] 子 Agent 不得继承主 Agent 的推理等级。
|
|
1973
|
+
*
|
|
1974
|
+
* 用户规则原文:「禁止子agent继承主agent的推理等级,子agent必须根据
|
|
1975
|
+
* 自身任务的复杂度,自己使用推理等级为low、high或者是Max,其中,轻度
|
|
1976
|
+
* 复杂的任务使用low,中等复杂的任务使用high,非常复杂的任务使用Max。」
|
|
1977
|
+
* 宿主 resolveChildAgentOptions 在请求未点名 reasoningEffort 时会继承
|
|
1978
|
+
* 父 Agent 的等级(dsh-subagent child-agent.d.ts:40-50),旧实现在这里
|
|
1979
|
+
* 只传 provider/model,于是主 Agent 的等级被原样带进每个部门子会话。
|
|
1980
|
+
* 现在显式覆盖为子任务自己的档位;缺失(旧计划/回放)回落 high,绝不
|
|
1981
|
+
* 读取 modelSelection.reasoningEffort。
|
|
1982
|
+
*/
|
|
1983
|
+
agentOptions: {
|
|
1984
|
+
...(modelSelection?.provider && modelSelection?.model
|
|
1985
|
+
? { provider: modelSelection.provider, model: modelSelection.model }
|
|
1986
|
+
: {}),
|
|
1987
|
+
// [2.2.7] '' = 模型无 reasoning 元数据 ⇒ 不发送,避免派发期即中断。
|
|
1988
|
+
...(childEffort ? { reasoningEffort: childEffort } : {}),
|
|
1989
|
+
},
|
|
1141
1990
|
maxDepth: 1,
|
|
1142
1991
|
},
|
|
1143
1992
|
signal: child.controller.signal,
|
|
@@ -1177,6 +2026,19 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1177
2026
|
}, guard);
|
|
1178
2027
|
if (!assigned)
|
|
1179
2028
|
return;
|
|
2029
|
+
/*
|
|
2030
|
+
* [2.2.0][T3/O-2a] 通道条目:此刻写下目标、调用方与时间戳。
|
|
2031
|
+
*
|
|
2032
|
+
* 这一步只记事实,不猜结果——消息有没有真的到主会话,要等结算时去父
|
|
2033
|
+
* 会话日志里看(observeRelayedNotice)。旧实现里预告失败在计划记录上
|
|
2034
|
+
* 完全不可见,主 Agent 只能看到一句 `subagent "lead" is unavailable`。
|
|
2035
|
+
*/
|
|
2036
|
+
recordNoticeChannel(createNoticeChannel({
|
|
2037
|
+
target: noticeLead.id,
|
|
2038
|
+
targetSource: noticeLead.source,
|
|
2039
|
+
caller: activation.childId,
|
|
2040
|
+
at: assignedAt,
|
|
2041
|
+
}));
|
|
1180
2042
|
const ackTimers = [];
|
|
1181
2043
|
clearAckTimers = () => {
|
|
1182
2044
|
while (ackTimers.length > 0) {
|
|
@@ -1222,6 +2084,8 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1222
2084
|
summary: `未完成:${message}`,
|
|
1223
2085
|
}, guard);
|
|
1224
2086
|
recordSubtaskError(record, subtask.id, message, guard);
|
|
2087
|
+
// [2.2.7] 中断即报:no-ack 是「根本没启动」,不是「做失败了」。
|
|
2088
|
+
announceSubtaskInterrupt(record, interruptSession(), subtask.id, `子任务 ${subtask.id}(${subtask.title})${message};性质:子会话疑似根本没启动,不是执行失败;处理:已中止该子会话并把本行置为受阻(blockedKind=no-ack),主会话可决定重新下发指示或放弃该行,其余子任务不受影响。`);
|
|
1225
2089
|
if (!child.controller.signal.aborted) {
|
|
1226
2090
|
child.controller.abort(new PlanError(message, 'CHILD_NO_ACK', { subtaskId: subtask.id }));
|
|
1227
2091
|
}
|
|
@@ -1229,8 +2093,58 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1229
2093
|
deadlineTimer.unref?.();
|
|
1230
2094
|
ackTimers.push(deadlineTimer);
|
|
1231
2095
|
const idleTimeoutMs = normaliseIdleTimeout(options.idleTimeoutMs);
|
|
1232
|
-
|
|
2096
|
+
// [2.2.0][T4/O-3b][O-4d] 双计时同源(方案 §2.5):看门狗 hardMs 与本次尝试的
|
|
2097
|
+
// 协商执行时限同值(options.attemptTimeoutMs,缺省回落旧路径);两者必须同步
|
|
2098
|
+
// 推移——延期时 rearmApproachingDeadline 传「自尝试起点计的新完整窗口」。
|
|
2099
|
+
const hardTimeoutMs = Number.isFinite(Number(options.attemptTimeoutMs)) && Number(options.attemptTimeoutMs) > 0
|
|
2100
|
+
? Math.min(MAX_CHILD_TIMEOUT_MS, Math.max(MIN_CHILD_TIMEOUT_MS, Number(options.attemptTimeoutMs)))
|
|
2101
|
+
: normaliseChildTimeout(options.childTimeoutMs);
|
|
1233
2102
|
const watchdog = createProgressWatchdog({
|
|
2103
|
+
// [2.2.0][T4/O-3b][O-4b] 到点预警接线(T7 watchdog.ts 契约,原样消费):
|
|
2104
|
+
// 剩余 ≤ max(timeoutMs×0.2, 120000) 触发一次、同一武装周期幂等、extend 后
|
|
2105
|
+
// rearm 可再触发。最小处理器:时间链留档 timeWarning+本轮记录 notice+会话
|
|
2106
|
+
// 消息通知主 Agent(格式朴素,T6 波次统一润色)。
|
|
2107
|
+
subtaskId: String(subtask.id),
|
|
2108
|
+
onApproachingDeadline: (info) => {
|
|
2109
|
+
if (guard.timedOut)
|
|
2110
|
+
return;
|
|
2111
|
+
try {
|
|
2112
|
+
const warnRow = Array.isArray(record.statuses)
|
|
2113
|
+
? record.statuses.find((item) => item?.subtaskId === subtask.id)
|
|
2114
|
+
: null;
|
|
2115
|
+
if (warnRow) {
|
|
2116
|
+
// timeWarning 走未知字段通道直写(applyStatus 白名单属 T3 领地)。
|
|
2117
|
+
warnRow.timeWarning = {
|
|
2118
|
+
at: Date.now(),
|
|
2119
|
+
remainingMs: Math.max(0, Number(info?.remainingMs ?? 0)),
|
|
2120
|
+
newEstimateMinutes: null,
|
|
2121
|
+
channel: 'watchdog',
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
const text = `子任务 ${subtask.id} 即将到点:剩余 ${Math.max(0, Math.round(Number(info?.remainingMs ?? 0) / 1000))}s(协商上限 ${Number(info?.timeoutMs ?? 0)}ms);如需继续请尽快决定延期(extendMs),否则到点将按安全兜底结算(待裁决)`;
|
|
2125
|
+
record.notices = [...(record.notices ?? []), text].slice(-20);
|
|
2126
|
+
record.updatedAt = Date.now();
|
|
2127
|
+
/*
|
|
2128
|
+
* 会话消息只对「有决策余量」的窗口推送:窗口 < 120000ms(=触发规则
|
|
2129
|
+
* max(timeoutMs×0.2, 120000) 里的预警下限,生产最小派生窗口恰好
|
|
2130
|
+
* 120000ms)只出现在测试小窗场景,预警本身没有可执行的延期决策余量,
|
|
2131
|
+
* 此时只留档(record.notices+timeWarning),不推送会话消息——也不与
|
|
2132
|
+
* tests/workplan-stuck-recovery.test.ts「session.events 只计持久消息」
|
|
2133
|
+
* 的既有断言冲突。T6 波次统一润色通知渠道时再定稿推送策略。
|
|
2134
|
+
* [2.2.0][T6/O-1a] 渠道已定稿:与完成即时通知同走主会话
|
|
2135
|
+
* `user/message` 纯文本通道(方案 §2.3「即时通知消息」);决策余量
|
|
2136
|
+
* 门槛(timeoutMs ≥ 120000,取自触发规则预警下限)保持不变,故
|
|
2137
|
+
* 上述断言不受影响。
|
|
2138
|
+
*/
|
|
2139
|
+
if (Number(info?.timeoutMs ?? 0) >= 120000) {
|
|
2140
|
+
const warnSession = options.session ?? options.agent?.session;
|
|
2141
|
+
appendUserMessage(warnSession, text);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
catch {
|
|
2145
|
+
// 预警只做提示不得影响执行:写档失败静默忽略(T6 波次统一润色)。
|
|
2146
|
+
}
|
|
2147
|
+
},
|
|
1234
2148
|
getSeq: () => {
|
|
1235
2149
|
try {
|
|
1236
2150
|
const childSession = ctx.sessions?.get?.(activation.childId);
|
|
@@ -1277,6 +2191,9 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1277
2191
|
? `子任务 ${subtask.id} 无进展超时(${idleTimeoutMs}ms 内子 Agent 没有产生任何新事件)`
|
|
1278
2192
|
: `子任务 ${subtask.id} 超时(${hardTimeoutMs}ms)`, reason === 'stalled' ? 'CHILD_STALLED' : 'CHILD_TIMEOUT', { subtaskId: subtask.id }),
|
|
1279
2193
|
});
|
|
2194
|
+
// [2.2.0][T4/O-3b][O-4d] 看门狗挂到计时句柄:extendDeadline 延期成功后经
|
|
2195
|
+
// watchdog.rearmApproachingDeadline(传新完整窗口)同步推移两处计时。
|
|
2196
|
+
options.attemptHandle?.attachWatchdog?.(watchdog);
|
|
1280
2197
|
let result;
|
|
1281
2198
|
try {
|
|
1282
2199
|
const waiter = waitForActivation(activation, child.controller.signal);
|
|
@@ -1314,6 +2231,42 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1314
2231
|
}
|
|
1315
2232
|
if (!output)
|
|
1316
2233
|
throw new PlanError('子 Agent 没有返回文本结果', 'EMPTY_CHILD_OUTPUT');
|
|
2234
|
+
/*
|
|
2235
|
+
* [2.2.8][T7] 结果块解析失败 = 与 CHILD_NOT_COMPLETED 同路径的有界回喂重试。
|
|
2236
|
+
*
|
|
2237
|
+
* T4 事故(用户 2026-11-09 报告):子会话工作完成、交付物已在盘上,只是
|
|
2238
|
+
* 结果块 JSON 写坏;旧实现在这里一次即判 blocked,并级联阻断下游——
|
|
2239
|
+
* 侧栏(子会话实时活动态)与账本(结算态)出现十几分钟的可见错位。
|
|
2240
|
+
* 现在结算前先用纯函数裁决一次(不写状态、不留双源):
|
|
2241
|
+
* - unparsable 且还有回喂意义(`shouldRetryAttempt` 与 CHILD_NOT_COMPLETED
|
|
2242
|
+
* 同一道闸;最多两次由 attempt 上限统一把关,不会无限循环)→ 抛
|
|
2243
|
+
* EVIDENCE_UNPARSABLE,由下方 catch 把解析器具体错误回喂同一子会话,
|
|
2244
|
+
* 要求「修正结果块后重新回报,勿重做已完成工作」;
|
|
2245
|
+
* - 重试后仍 unparsable(或预算不再够一次回喂)→ 按实受阻,随行附上
|
|
2246
|
+
* attempt 摘要声明且确核在盘的产物清单,提示主 Agent 用
|
|
2247
|
+
* `dsh_workplan_update` 复核改判。
|
|
2248
|
+
* 结算严格性不变:非法 JSON 依旧绝不计 done——只修恢复路径。
|
|
2249
|
+
*/
|
|
2250
|
+
const settleRow = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
2251
|
+
const settleVerdict = settleRow?.closure === 'escalated'
|
|
2252
|
+
? null
|
|
2253
|
+
: adjudicateResult({
|
|
2254
|
+
output,
|
|
2255
|
+
strict: options.strictEvidence !== false,
|
|
2256
|
+
expectedAcceptance: Array.isArray(subtask?.acceptance) ? subtask.acceptance : [],
|
|
2257
|
+
});
|
|
2258
|
+
if (settleVerdict && settleVerdict.verification === 'unparsable') {
|
|
2259
|
+
const unparsableLanded = probeInterruptedArtifacts(output, subtask, options.cwd, options.artifactExists);
|
|
2260
|
+
const unparsableError = new PlanError(`结果块无法解析,本次回报不能结算(工作本身不计失败):${truncate(String(settleVerdict.error ?? ''), 600)}`
|
|
2261
|
+
+ (unparsableLanded.length > 0
|
|
2262
|
+
? `;上一次回报声明且已核到在盘的产物:${unparsableLanded.slice(0, 6).join('、')}——请勿重做已完成的工作,只修正结果块为合法 JSON 后重新完整回报`
|
|
2263
|
+
: ';请修正结果块为合法 JSON(引号、逗号、括号成对,标记成对出现)后重新回报'), 'EVIDENCE_UNPARSABLE', { subtaskId: subtask.id });
|
|
2264
|
+
if (shouldRetryAttempt(unparsableError, attempt, deadline - Date.now(), idleTimeoutMs)) {
|
|
2265
|
+
throw unparsableError;
|
|
2266
|
+
}
|
|
2267
|
+
settleFromOutput(record, subtask, output, guard, options, settleVerdict, probeInterruptedEvidence(output, subtask, options.cwd, options.artifactExists));
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
1317
2270
|
/*
|
|
1318
2271
|
* [1.7.0] Evidence decides the verdict.
|
|
1319
2272
|
*
|
|
@@ -1323,7 +2276,7 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1323
2276
|
* is the single deterministic table; `settleFromOutput` adds the
|
|
1324
2277
|
* environment-dependent artifact check.
|
|
1325
2278
|
*/
|
|
1326
|
-
settleFromOutput(record, subtask, output, guard, options);
|
|
2279
|
+
settleFromOutput(record, subtask, output, guard, options, settleVerdict ?? undefined);
|
|
1327
2280
|
return;
|
|
1328
2281
|
}
|
|
1329
2282
|
catch (error) {
|
|
@@ -1353,6 +2306,8 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1353
2306
|
`${subtask.id}: 第 ${attempt} 次执行失败(${lastFailure.code}),已带上失败原因重试`,
|
|
1354
2307
|
].slice(-20);
|
|
1355
2308
|
writeSubtaskStatus(record, subtask.id, { progress: 15 }, guard);
|
|
2309
|
+
// [2.2.7] 中断即报:用户当下就知道「谁被打断、为什么、系统正在怎么处理」。
|
|
2310
|
+
announceSubtaskInterrupt(record, interruptSession(), subtask.id, `子任务 ${subtask.id}(${subtask.title})第 ${attempt} 次执行被打断(${lastFailure.code}:${truncate(lastFailure.message, 140)});处理:插件已把失败原因回喂同一子会话并自动重试(第 ${attempt + 1} 次),任务整体仍在推进,这不是最终失败。`);
|
|
1356
2311
|
continue;
|
|
1357
2312
|
}
|
|
1358
2313
|
/* [1.10.3] CHILD_TIMEOUT 现在也会在预算充足时重试,所以「预算不足未重试」这条说明对它同样成立。 */
|
|
@@ -1383,7 +2338,7 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1383
2338
|
return interruptedFlag ? { interrupted: true } : undefined;
|
|
1384
2339
|
}
|
|
1385
2340
|
const message = describeError(lastError ?? new Error('未知失败'));
|
|
1386
|
-
writeSubtaskStatus(record, subtask.id, {
|
|
2341
|
+
const finalBlocked = writeSubtaskStatus(record, subtask.id, {
|
|
1387
2342
|
status: 'blocked',
|
|
1388
2343
|
closure: 'blocked',
|
|
1389
2344
|
blockedKind: 'failed',
|
|
@@ -1402,6 +2357,14 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1402
2357
|
: {}),
|
|
1403
2358
|
}, guard);
|
|
1404
2359
|
recordSubtaskError(record, subtask.id, message, guard);
|
|
2360
|
+
// [2.2.7] 中断即报:重试耗尽/不可重试走到终点时立即说清本质原因与后续处置,
|
|
2361
|
+
// 不等整轮结果消息。
|
|
2362
|
+
if (finalBlocked && !guard.timedOut && !parentSignal.aborted) {
|
|
2363
|
+
const landed = interruptedEvidence?.artifacts?.length
|
|
2364
|
+
? `已核到 ${interruptedEvidence.artifacts.length} 个产物在盘上:${interruptedEvidence.artifacts.slice(0, 3).join('、')}`
|
|
2365
|
+
: '子会话未留下已核实的在盘产物';
|
|
2366
|
+
announceSubtaskInterrupt(record, interruptSession(), subtask.id, `子任务 ${subtask.id}(${subtask.title})已受阻:${truncate(message, 160)};产物线索:${landed};处理:本行不再自动重试,整轮结果会如实列为未完成,由主会话据实决定续跑/改判/向你说明——期间其余子任务继续执行。`);
|
|
2367
|
+
}
|
|
1405
2368
|
return interruptedFlag ? { interrupted: true } : undefined;
|
|
1406
2369
|
}
|
|
1407
2370
|
catch (error) {
|
|
@@ -1426,8 +2389,130 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
1426
2389
|
// The status list itself is unusable; the outer dispatcher records the error.
|
|
1427
2390
|
}
|
|
1428
2391
|
recordSubtaskError(record, subtask.id, message, guard);
|
|
2392
|
+
// [2.2.7] 中断即报:执行链路自身出异常同样不能对用户沉默。
|
|
2393
|
+
announceSubtaskInterrupt(record, interruptSession(), subtask.id, `子任务 ${subtask.id}(${subtask.title})执行过程发生未预期异常:${truncate(message, 160)};处理:本行已置为受阻并如实留档,主会话将在结果消息后据实决定续跑/改判,不会伪造完成。`);
|
|
2394
|
+
}
|
|
2395
|
+
finally {
|
|
2396
|
+
/*
|
|
2397
|
+
* [2.2.0][T3/O-2a] 结算点唯一的通道收束入口(成功/受阻/待指示/中断都走这里)。
|
|
2398
|
+
*
|
|
2399
|
+
* 放在 finally 而不是各条 return 前面,是为了让「通道结论」与「子任务结论」
|
|
2400
|
+
* 一定是同一次执行的产物:任何一个出口漏写,都会让预告看起来像消失了。
|
|
2401
|
+
* [F3] 观测设施自身不得把已结算的子任务变成本轮异常:任何异常只进
|
|
2402
|
+
* record.errors,绝不从 finally 外抛。
|
|
2403
|
+
*/
|
|
2404
|
+
try {
|
|
2405
|
+
finaliseNotice();
|
|
2406
|
+
}
|
|
2407
|
+
catch (error) {
|
|
2408
|
+
record.errors = [...(record.errors ?? []), `${subtask.id} noticeChannel 收束失败:${truncate(String(error?.message ?? error), 300)}`].slice(-20);
|
|
2409
|
+
}
|
|
1429
2410
|
}
|
|
1430
2411
|
}
|
|
2412
|
+
/*
|
|
2413
|
+
* [2.2.0][T4/O-3b] 本次执行时限(柔性时长协商消费序;T3b 待决点③裁决:消费侧钳位)。
|
|
2414
|
+
*
|
|
2415
|
+
* 消费序:① subtask.timeoutMs 显式协商上限(O-3c 原样透传)→ ② 缺省
|
|
2416
|
+
* deriveSubtaskTimeoutMs(estimateMinutes)=clamp(预估分钟×2.0×60000, 1000,
|
|
2417
|
+
* 7200000) 派生(方案 §1③)→ ③ 两者皆无回落 normaliseChildTimeout(全局兜底
|
|
2418
|
+
* CHILD_TIMEOUT_MS,方案 ③C2 零回归)。结果统一钳 [MIN_CHILD_TIMEOUT_MS,
|
|
2419
|
+
* MAX_CHILD_TIMEOUT_MS](方案 ③C3)。
|
|
2420
|
+
*
|
|
2421
|
+
* 显式注入的 childTimeoutMs(测试小窗 / DSH_WORKPLAN_CHILD_TIMEOUT_MS 旋钮)
|
|
2422
|
+
* 语义是「兜底上限」而非「固定值」(方案 §5.2「协商的默认基准/兜底上限」):
|
|
2423
|
+
* 它对上面三步的结果取 min。必须区分「显式注入」与「缺省」——验收合同
|
|
2424
|
+
* tests/no-fixed-deadline-semantics.test.ts E4 注入 1000ms 小窗必须压过
|
|
2425
|
+
* estimateMinutes:10 派生的 1200000ms;而 tests/time-estimate-negotiation
|
|
2426
|
+
* .test.ts C3(无注入)派生值必须严格生效(deadlineAt − startedAt === 派生值)。
|
|
2427
|
+
* 因此 dispatchPlan 三处调用点改传 options.childTimeoutMs 原始值(未配置=
|
|
2428
|
+
* undefined),不再传 normalise 后的 limits.childTimeoutMs(后者恒为 900000,
|
|
2429
|
+
* 无法区分显式与缺省)。
|
|
2430
|
+
*/
|
|
2431
|
+
function resolveSubtaskTimeoutMs(subtask, configuredChildTimeoutMs) {
|
|
2432
|
+
const clampWindow = (value) => Math.min(MAX_CHILD_TIMEOUT_MS, Math.max(MIN_CHILD_TIMEOUT_MS, value));
|
|
2433
|
+
const explicit = Number(subtask?.timeoutMs);
|
|
2434
|
+
const derived = deriveSubtaskTimeoutMs(subtask?.estimateMinutes, MIN_CHILD_TIMEOUT_MS, MAX_CHILD_TIMEOUT_MS);
|
|
2435
|
+
let window;
|
|
2436
|
+
if (Number.isFinite(explicit) && explicit > 0)
|
|
2437
|
+
window = clampWindow(explicit);
|
|
2438
|
+
else if (derived !== undefined)
|
|
2439
|
+
window = clampWindow(derived);
|
|
2440
|
+
else
|
|
2441
|
+
window = normaliseChildTimeout(configuredChildTimeoutMs);
|
|
2442
|
+
// 显式注入=兜底上限(对协商结果取 min);未配置不封顶。
|
|
2443
|
+
const cap = Number(configuredChildTimeoutMs);
|
|
2444
|
+
if (Number.isFinite(cap) && cap > 0)
|
|
2445
|
+
window = Math.min(window, clampWindow(cap));
|
|
2446
|
+
return window;
|
|
2447
|
+
}
|
|
2448
|
+
/*
|
|
2449
|
+
* [2.2.0][T4/O-3b][O-4c/O-4d] 延期接口(D 项;T5 extendMs 事务的计时侧承接)。
|
|
2450
|
+
*
|
|
2451
|
+
* 调用契约(T5 按此接线):
|
|
2452
|
+
* extendDeadline(record, subtaskId, extendMs, { by?, reason? })
|
|
2453
|
+
* → 成功 { ok: true, deadlineAt, timerRearmed: true, watchdogRearmed }
|
|
2454
|
+
* → 拒绝 { ok: false, code: 'INVALID_EXTEND' | 'NO_ACTIVE_ATTEMPT', error, hint }
|
|
2455
|
+
*
|
|
2456
|
+
* 语义与边界:
|
|
2457
|
+
* - extendMs 须为正有限数(毫秒,向下取整),否则 INVALID_EXTEND。
|
|
2458
|
+
* - 只对「有活跃尝试」的子任务生效(runSubtaskAttempt 已注册计时句柄且未收束);
|
|
2459
|
+
* 已到点收束 / 已结束的尝试一律 NO_ACTIVE_ATTEMPT(不能复活已结算的行)。
|
|
2460
|
+
* - 累计放宽预算校验(≤初始协商上限×1,超限 EXTEND_BUDGET_EXHAUSTED→转新轮
|
|
2461
|
+
* 续跑或转 escalate)属 T5 事务层职责,本函数不重复校验:调用方先校验再调用。
|
|
2462
|
+
* - 线程/并发语义:Node 单线程;本函数「校验→改 deadlineAt→重置计时器→
|
|
2463
|
+
* watchdog.rearmApproachingDeadline→行内直写」在一个同步段完成,天然原子;
|
|
2464
|
+
* 并发调用按到达顺序串行,每次追加独立 timeJournal 条目(action:'extend')。
|
|
2465
|
+
* - 延期成功后 deadlineAt 同步更新(行上字段=句柄 deadlineAt),runSubtaskAttempt
|
|
2466
|
+
* 的一次性计时器重置为「新截止点 − now」,原截止点不再触发(O-4d:任务不被
|
|
2467
|
+
* 原截止点杀死)。
|
|
2468
|
+
* - 与 watchdog 的配合(F 项):watchdog.rearmApproachingDeadline(newTimeoutMs)
|
|
2469
|
+
* 传入「自尝试起点计的新完整窗口」=deadlineAt − 尝试起点(T7 watchdog.ts
|
|
2470
|
+
* 契约,不是剩余量);两处计时同步推移(方案 §2.5),先触发者仍会杀任务。
|
|
2471
|
+
* - 行字段直写原因:applyStatus(src/plan.ts,T3 领地)无 deadlineAt/timeJournal
|
|
2472
|
+
* 路由分支,patch 会静默丢弃;这里走 StatusEntry 未知字段保留通道直写,
|
|
2473
|
+
* 回放/重建白名单在 reconstructFromSession 同名直写(本文件 2931 一带)。
|
|
2474
|
+
*/
|
|
2475
|
+
export function extendDeadline(record, subtaskId, extendMs, meta = {}) {
|
|
2476
|
+
const id = String(subtaskId ?? '');
|
|
2477
|
+
const amount = Number(extendMs);
|
|
2478
|
+
if (!Number.isFinite(amount) || amount < 1) {
|
|
2479
|
+
return {
|
|
2480
|
+
ok: false,
|
|
2481
|
+
code: 'INVALID_EXTEND',
|
|
2482
|
+
error: `extendMs 必须是正有限数(毫秒):${String(extendMs)}`,
|
|
2483
|
+
hint: '请传入 1 以上的毫秒数;需要更长时限请转新轮续跑或转 escalate',
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
const delta = Math.floor(amount);
|
|
2487
|
+
const handle = record?.attemptHandles?.[id];
|
|
2488
|
+
if (!handle || handle.settled) {
|
|
2489
|
+
return {
|
|
2490
|
+
ok: false,
|
|
2491
|
+
code: 'NO_ACTIVE_ATTEMPT',
|
|
2492
|
+
error: `子任务 ${id} 当前没有可延期的执行中尝试`,
|
|
2493
|
+
hint: '已收束的尝试不能复活:请转新轮续跑或人工裁决(escalate)',
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
const deadlineAt = handle.extend(delta);
|
|
2497
|
+
const row = Array.isArray(record?.statuses)
|
|
2498
|
+
? record.statuses.find((item) => item?.subtaskId === id)
|
|
2499
|
+
: null;
|
|
2500
|
+
if (row) {
|
|
2501
|
+
// deadlineAt/timeJournal 走未知字段通道直写(applyStatus 白名单属 T3 领地)。
|
|
2502
|
+
row.deadlineAt = deadlineAt;
|
|
2503
|
+
const journal = Array.isArray(row.timeJournal) ? row.timeJournal : [];
|
|
2504
|
+
journal.push({
|
|
2505
|
+
at: Date.now(),
|
|
2506
|
+
action: 'extend',
|
|
2507
|
+
extendMs: delta,
|
|
2508
|
+
by: ['agent', 'child', 'system'].includes(meta?.by) ? meta.by : 'agent',
|
|
2509
|
+
reason: truncate(String(meta?.reason ?? ''), 300),
|
|
2510
|
+
});
|
|
2511
|
+
row.timeJournal = journal.slice(-20);
|
|
2512
|
+
}
|
|
2513
|
+
record.updatedAt = Date.now();
|
|
2514
|
+
return { ok: true, deadlineAt, timerRearmed: true, watchdogRearmed: Boolean(handle.watchdog) };
|
|
2515
|
+
}
|
|
1431
2516
|
/*
|
|
1432
2517
|
* One attempt under a deadline that belongs to that attempt alone.
|
|
1433
2518
|
*
|
|
@@ -1460,14 +2545,46 @@ async function runSubtaskAttempt(ctx, record, stage, subtask, options, timeoutMs
|
|
|
1460
2545
|
*/
|
|
1461
2546
|
let ceilingFingerprint = [];
|
|
1462
2547
|
const stat = typeof options.artifactStat === 'function' ? options.artifactStat : statSync;
|
|
2548
|
+
/*
|
|
2549
|
+
* [2.2.0][T4/O-3b][O-4d] 可延期计时句柄(D 项延期接口的运行时锚点,方案 §2.2/§2.5)。
|
|
2550
|
+
* 本次尝试的协商截止只属于这次尝试:extend() 重置一次性计时器并同步 watchdog
|
|
2551
|
+
* (rearmApproachingDeadline 传「自尝试起点计的新完整窗口」);settled 后不得
|
|
2552
|
+
* 复活(extendDeadline 一律 NO_ACTIVE_ATTEMPT)。行上 deadlineAt 由 executeSubtask
|
|
2553
|
+
* 以同一时钟读数写入(C3 契约),句柄权威值随写同步。
|
|
2554
|
+
*/
|
|
2555
|
+
const attemptStart = Date.now();
|
|
2556
|
+
const attemptHandle = {
|
|
2557
|
+
subtaskId: String(subtask.id),
|
|
2558
|
+
startedAt: attemptStart,
|
|
2559
|
+
deadlineAt: attemptStart + timeoutMs,
|
|
2560
|
+
settled: false,
|
|
2561
|
+
watchdog: null,
|
|
2562
|
+
arm: (_ms) => { },
|
|
2563
|
+
extend(ms) {
|
|
2564
|
+
if (this.settled)
|
|
2565
|
+
return this.deadlineAt;
|
|
2566
|
+
this.deadlineAt += ms;
|
|
2567
|
+
this.arm(this.deadlineAt - Date.now());
|
|
2568
|
+
this.watchdog?.rearmApproachingDeadline(this.deadlineAt - this.startedAt);
|
|
2569
|
+
return this.deadlineAt;
|
|
2570
|
+
},
|
|
2571
|
+
attachWatchdog(watchdog) {
|
|
2572
|
+
this.watchdog = watchdog;
|
|
2573
|
+
},
|
|
2574
|
+
};
|
|
2575
|
+
record.attemptHandles = { ...(record.attemptHandles ?? {}), [String(subtask.id)]: attemptHandle };
|
|
1463
2576
|
const deadlinePromise = new Promise((resolve) => {
|
|
1464
|
-
|
|
2577
|
+
const fire = () => {
|
|
1465
2578
|
ceilingFired = true;
|
|
1466
2579
|
guard.timedOut = true;
|
|
1467
|
-
|
|
1468
|
-
//
|
|
1469
|
-
//
|
|
1470
|
-
|
|
2580
|
+
attemptHandle.settled = true;
|
|
2581
|
+
// [2.2.0][T4/O-3b][O-4d] L4 安全兜底结算+「待裁决」标记(E4 契约):时间是
|
|
2582
|
+
// 协商出来的安全兜底,不是固定交付期限——到点不表述为「强制结束」式固定期限
|
|
2583
|
+
// 误杀,而是安全兜底结算落盘,供主 Agent 决定延期 / 重试 / 接受(或转新轮
|
|
2584
|
+
// 续跑、人工裁决)。Reached only when the child ignored both its idle window
|
|
2585
|
+
// and its abort signal; the message says so, otherwise the cause looks like
|
|
2586
|
+
// a plain "too slow" and the next investigation goes down the wrong path.
|
|
2587
|
+
const message = `子任务 ${subtask.id} 达到协商执行上限(${timeoutMs}ms),已按安全兜底结算(待裁决:请主 Agent 决定延期 / 重试 / 接受,或转新轮续跑、人工裁决)`;
|
|
1471
2588
|
try {
|
|
1472
2589
|
// [1.8.19] Keep the evidence of what already landed on disk.
|
|
1473
2590
|
const { patch, landed } = timeoutBlockedPatch(subtask, options.cwd, message, options.artifactExists);
|
|
@@ -1492,6 +2609,14 @@ async function runSubtaskAttempt(ctx, record, stage, subtask, options, timeoutMs
|
|
|
1492
2609
|
record.statuses = applyStatus(record.statuses, subtask.id, patch);
|
|
1493
2610
|
record.errors = [...(record.errors ?? []), `${subtask.id}: ${patch.error}`].slice(-20);
|
|
1494
2611
|
}
|
|
2612
|
+
/*
|
|
2613
|
+
* [2.2.0][T4/O-3b][C/E] 「待裁决」结构化标记(E4 契约):结算文案已含
|
|
2614
|
+
* 「待裁决」,这里再落机器可读标记供裁决/回放白名单透传(pendingAdjudication)。
|
|
2615
|
+
* 走 StatusEntry 未知字段通道直写(applyStatus 白名单属 T3 领地)。
|
|
2616
|
+
*/
|
|
2617
|
+
const settleRow = record.statuses.find((item) => item?.subtaskId === subtask.id);
|
|
2618
|
+
if (settleRow)
|
|
2619
|
+
settleRow.pendingAdjudication = true;
|
|
1495
2620
|
record.updatedAt = Date.now();
|
|
1496
2621
|
}
|
|
1497
2622
|
catch (error) {
|
|
@@ -1507,8 +2632,17 @@ async function runSubtaskAttempt(ctx, record, stage, subtask, options, timeoutMs
|
|
|
1507
2632
|
child.disposeListener();
|
|
1508
2633
|
resolve();
|
|
1509
2634
|
}
|
|
1510
|
-
}
|
|
1511
|
-
|
|
2635
|
+
};
|
|
2636
|
+
// [2.2.0][T4/O-3b][O-4d] 可延期计时(D 项):arm() 重置一次性计时器,extend()
|
|
2637
|
+
// 经 attemptHandle 调用它把截止点推移到新协商截止;原截止点不再触发。
|
|
2638
|
+
const arm = (ms) => {
|
|
2639
|
+
if (timer)
|
|
2640
|
+
clearTimeout(timer);
|
|
2641
|
+
timer = setTimeout(fire, Math.max(1, ms));
|
|
2642
|
+
timer.unref?.();
|
|
2643
|
+
};
|
|
2644
|
+
attemptHandle.arm = arm;
|
|
2645
|
+
arm(timeoutMs);
|
|
1512
2646
|
});
|
|
1513
2647
|
try {
|
|
1514
2648
|
// [1.8.6] The outcome (`{interrupted:true}`) has to reach the dispatcher;
|
|
@@ -1518,12 +2652,20 @@ async function runSubtaskAttempt(ctx, record, stage, subtask, options, timeoutMs
|
|
|
1518
2652
|
...options,
|
|
1519
2653
|
child,
|
|
1520
2654
|
guard,
|
|
2655
|
+
// [2.2.0][T4/O-3b] 本次尝试的协商执行时限与计时句柄(deadlineAt 写入同源、
|
|
2656
|
+
// 看门狗 hardMs 同值、延期接口锚点)。
|
|
2657
|
+
attemptTimeoutMs: timeoutMs,
|
|
2658
|
+
attemptHandle,
|
|
1521
2659
|
}),
|
|
1522
2660
|
deadlinePromise,
|
|
1523
2661
|
]);
|
|
1524
2662
|
return { outcome, ceilingFired, ceilingLanded, ceilingFingerprint };
|
|
1525
2663
|
}
|
|
1526
2664
|
finally {
|
|
2665
|
+
// [2.2.0][T4/O-3b] 收束即注销句柄:已收束的尝试不得再被 extendDeadline 复活。
|
|
2666
|
+
attemptHandle.settled = true;
|
|
2667
|
+
if (record.attemptHandles)
|
|
2668
|
+
delete record.attemptHandles[String(subtask.id)];
|
|
1527
2669
|
if (timer) {
|
|
1528
2670
|
clearTimeout(timer);
|
|
1529
2671
|
timer = null;
|
|
@@ -1548,7 +2690,10 @@ async function runSubtaskAttempt(ctx, record, stage, subtask, options, timeoutMs
|
|
|
1548
2690
|
* skipped and the row is marked `artifactConflict` instead of overwriting it.
|
|
1549
2691
|
*/
|
|
1550
2692
|
async function runSubtask(ctx, record, stage, subtask, options) {
|
|
1551
|
-
|
|
2693
|
+
// [2.2.0][T4/O-3b] 本次执行时限=柔性时长协商消费序(见 resolveSubtaskTimeoutMs):
|
|
2694
|
+
// ① subtask.timeoutMs 显式值 → ② deriveSubtaskTimeoutMs(estimateMinutes) 派生 →
|
|
2695
|
+
// ③ 缺省回落 CHILD_TIMEOUT_MS;显式注入的 childTimeoutMs 作兜底上限取 min。
|
|
2696
|
+
const childTimeoutMs = resolveSubtaskTimeoutMs(subtask, options.childTimeoutMs);
|
|
1552
2697
|
const first = await runSubtaskAttempt(ctx, record, stage, subtask, options, childTimeoutMs);
|
|
1553
2698
|
if (!first.ceilingFired)
|
|
1554
2699
|
return first.outcome;
|
|
@@ -1556,7 +2701,7 @@ async function runSubtask(ctx, record, stage, subtask, options) {
|
|
|
1556
2701
|
const now = Date.now();
|
|
1557
2702
|
const deadline = Number.isFinite(options.deadline) ? Number(options.deadline) : now + childTimeoutMs;
|
|
1558
2703
|
const remaining = deadline - now;
|
|
1559
|
-
const message = `子任务 ${subtask.id}
|
|
2704
|
+
const message = `子任务 ${subtask.id} 达到协商执行上限(${childTimeoutMs}ms)`;
|
|
1560
2705
|
/*
|
|
1561
2706
|
* [1.8.6] A parent abort outranks a retry: the round is being stopped on
|
|
1562
2707
|
* purpose, and a second child would only be aborted on arrival.
|
|
@@ -1610,7 +2755,7 @@ async function runSubtask(ctx, record, stage, subtask, options) {
|
|
|
1610
2755
|
const second = await runSubtaskAttempt(ctx, record, stage, subtask, {
|
|
1611
2756
|
...options,
|
|
1612
2757
|
attemptOffset: 2,
|
|
1613
|
-
priorFailure: { attempt: 1, code: 'CHILD_TIMEOUT', message: `${message}
|
|
2758
|
+
priorFailure: { attempt: 1, code: 'CHILD_TIMEOUT', message: `${message},已按安全兜底结算(待裁决)` },
|
|
1614
2759
|
}, retryTimeoutMs);
|
|
1615
2760
|
return second.outcome;
|
|
1616
2761
|
}
|
|
@@ -1694,6 +2839,29 @@ export function modelStatusLines(statuses) {
|
|
|
1694
2839
|
status: handoff.status,
|
|
1695
2840
|
})),
|
|
1696
2841
|
reportedAt: item.reportedAt ?? null,
|
|
2842
|
+
/*
|
|
2843
|
+
* [2.2.0][T4/O-3b][O-2.4] 柔性时长协商字段进入模型可读面(纯展示):
|
|
2844
|
+
* 协商截止 deadlineAt、尝试起点 startedAt、剩余协商时间、预警标记 timeWarning、
|
|
2845
|
+
* 待裁决标记 pendingAdjudication 与时间链审计 timeJournal。验收合同
|
|
2846
|
+
* tests/time-estimate-negotiation.test.ts C3 直接从 statusTool 输出读
|
|
2847
|
+
* deadlineAt/startedAt(字段名/单位照合同原文)。
|
|
2848
|
+
*/
|
|
2849
|
+
startedAt: item.startedAt ?? null,
|
|
2850
|
+
deadlineAt: item.deadlineAt ?? null,
|
|
2851
|
+
deadlineRemainingMs: Number.isFinite(Number(item.deadlineAt))
|
|
2852
|
+
? Math.max(0, Number(item.deadlineAt) - Date.now())
|
|
2853
|
+
: null,
|
|
2854
|
+
timeWarning: item.timeWarning ?? null,
|
|
2855
|
+
timeJournal: Array.isArray(item.timeJournal) ? item.timeJournal.slice(-10) : [],
|
|
2856
|
+
pendingAdjudication: item.pendingAdjudication === true,
|
|
2857
|
+
/*
|
|
2858
|
+
* [2.2.0][T3/O-2a] 子→主预告通道的结论必须进入模型可读面。
|
|
2859
|
+
*
|
|
2860
|
+
* 这条能力的目标就是「可观测」:主 Agent 要能一眼看出该子任务的开工预告
|
|
2861
|
+
* 有没有真的到达(observed/not-observed)、目标是谁、什么时候、失败原因。
|
|
2862
|
+
* 只写状态行不让读,等于又是一个「看不见的失败」。
|
|
2863
|
+
*/
|
|
2864
|
+
noticeChannel: item.noticeChannel ?? null,
|
|
1697
2865
|
}));
|
|
1698
2866
|
}
|
|
1699
2867
|
export function buildRoundResult(record, sessionId, limits) {
|
|
@@ -1717,7 +2885,15 @@ export function buildRoundResult(record, sessionId, limits) {
|
|
|
1717
2885
|
* `deliveryReady` 门禁读同一组输入(否则「结果说完成、present 被拒」)。
|
|
1718
2886
|
*/
|
|
1719
2887
|
changePending: record.changeRequest?.status === 'pending',
|
|
1720
|
-
|
|
2888
|
+
/*
|
|
2889
|
+
* [2.2.9][T3][M5] 冻结值与载荷同源:finishRound 已保证先 markReported
|
|
2890
|
+
* 再 build,这里若仍读 `record.reportPending` 可变标志,标志可能停在
|
|
2891
|
+
* 上一次失败的旧值,导致结果消息文本(plan.ts buildResultSummary 判
|
|
2892
|
+
* 「证据未通过(reportPending)」)与同一消息内 statuses 的门禁判定互相
|
|
2893
|
+
* 矛盾——正是震荡观感在消息侧的残留。改读派生函数后,冻结的 S3 恒等于
|
|
2894
|
+
* 载荷 statuses 的事实,摘要、指令与 present 门禁读到同一结论。
|
|
2895
|
+
*/
|
|
2896
|
+
reportPending: deriveReportPending(record),
|
|
1721
2897
|
});
|
|
1722
2898
|
}
|
|
1723
2899
|
/**
|
|
@@ -1765,7 +2941,18 @@ function describePendingCause(plan, statuses, id) {
|
|
|
1765
2941
|
}
|
|
1766
2942
|
export async function dispatchPlan(ctx, record, options) {
|
|
1767
2943
|
const { agent, signal, modelSelection, cwd, conversationContext = '' } = options;
|
|
1768
|
-
const
|
|
2944
|
+
const roundBudgetMs = Number(options.totalTimeoutMs ?? TOTAL_TIMEOUT_MS);
|
|
2945
|
+
const deadline = Date.now() + (roundBudgetMs > 0 ? roundBudgetMs : NO_ROUND_BUDGET_MS);
|
|
2946
|
+
/*
|
|
2947
|
+
* [2.2.0][T3/O-2a] 本轮子→主预告通道的目标会话 id,一轮只解析一次。
|
|
2948
|
+
*
|
|
2949
|
+
* 宿主只在**非 caller** 投递时把父会话 id 追加进子提示词
|
|
2950
|
+
* (dsh-subagent/lib/index.js:1466),本插件用 `delivery: 'caller'` 派发,
|
|
2951
|
+
* 所以必须自己注入。解析优先级见 notice-channel.ts(agent.id → session.id),
|
|
2952
|
+
* 两级都拿不到就留空,提示词改走「禁止猜测」分支([2.2.1][T5][F4] 不再用
|
|
2953
|
+
* plan.sessionId 兜底:计划正文可能属于另一个 root 会话)。
|
|
2954
|
+
*/
|
|
2955
|
+
const leadNotice = resolveLeadAgentId({ agent, session: options.session });
|
|
1769
2956
|
/*
|
|
1770
2957
|
* Resume, do not restart.
|
|
1771
2958
|
*
|
|
@@ -1844,7 +3031,9 @@ export async function dispatchPlan(ctx, record, options) {
|
|
|
1844
3031
|
parentSignal.addEventListener('abort', onAbort, { once: true });
|
|
1845
3032
|
const totalTimer = setTimeout(() => {
|
|
1846
3033
|
childController.abort(new PlanError('总执行超时', 'TOTAL_TIMEOUT'));
|
|
1847
|
-
|
|
3034
|
+
// [2.2.5][热修] 双重保险:即使哨兵值/配置未来被改成超限值,也把延时钳在
|
|
3035
|
+
// Node setTimeout 上限之内,杜绝“1ms 触发”的整轮秒杀。
|
|
3036
|
+
}, Math.min(Math.max(1000, deadline - Date.now()), ROUND_TIMER_MAX_MS));
|
|
1848
3037
|
totalTimer.unref?.();
|
|
1849
3038
|
record.dispatchedAt = Date.now();
|
|
1850
3039
|
record.phase = 'executing';
|
|
@@ -1933,6 +3122,15 @@ export async function dispatchPlan(ctx, record, options) {
|
|
|
1933
3122
|
// [1.10.6] Injectable stat for the pre-retry fingerprint check; tests
|
|
1934
3123
|
// use it so the conflict branch is provable without real files.
|
|
1935
3124
|
artifactStat: options.artifactStat,
|
|
3125
|
+
// [2.2.0][T6/O-1a] 即时通知接线:后台轮次标记、主会话与完成回调透传到结算点。
|
|
3126
|
+
notifyCompletion: options.notifyCompletion === true,
|
|
3127
|
+
session: options.session,
|
|
3128
|
+
// [2.2.0][T3/O-2a] 子→主预告通道:目标 id 与其来源随派发一起下传,
|
|
3129
|
+
// 提示词注入与结算观测必须用同一个值(否则「注入了什么」与
|
|
3130
|
+
// 「观测的是谁」会分叉,通道永远对不上)。
|
|
3131
|
+
leadAgentId: leadNotice.id,
|
|
3132
|
+
leadAgentIdSource: leadNotice.source,
|
|
3133
|
+
onSubtaskDone: options.onSubtaskDone,
|
|
1936
3134
|
});
|
|
1937
3135
|
// [1.8.6] Remember which failures were interrupts, so the cascade below
|
|
1938
3136
|
// can leave their dependents pending instead of blaming them.
|
|
@@ -2068,12 +3266,14 @@ export async function dispatchPlan(ctx, record, options) {
|
|
|
2068
3266
|
* 会让卡片显示「预算用完、可续跑」,而真正该做的是 instruct。
|
|
2069
3267
|
*/
|
|
2070
3268
|
record.phase = allDoneNow ? 'done' : (blockedNow > 0 ? 'blocked' : 'paused');
|
|
2071
|
-
const
|
|
3269
|
+
const roundBudgetMs = Number(options.totalTimeoutMs ?? TOTAL_TIMEOUT_MS);
|
|
3270
|
+
const minutes = roundBudgetMs > 0 ? Math.max(1, Math.round(roundBudgetMs / 60000)) : 0;
|
|
3271
|
+
const roundLabel = minutes > 0 ? `本轮执行预算(${minutes} 分钟)` : '本轮无固定总预算';
|
|
2072
3272
|
record.error = allDoneNow
|
|
2073
3273
|
? null
|
|
2074
3274
|
: blockedNow > 0
|
|
2075
|
-
?
|
|
2076
|
-
:
|
|
3275
|
+
? `${roundLabel}已到:已完成 ${done}/${total};${blockedNow} 项在等待指示或已受阻(续跑不会重派,请先 instruct 或改判),${pendingNow} 项保留为未完成,再次派发本计划即可继续`
|
|
3276
|
+
: `${roundLabel}已到:已完成 ${done}/${total},其余 ${total - done} 项保留为未完成,再次派发本计划即可续跑(已完成的不重跑)`;
|
|
2077
3277
|
/*
|
|
2078
3278
|
* Drop the failure lines the aborted children wrote on their way out.
|
|
2079
3279
|
* They used to survive into the result payload as
|
|
@@ -2335,7 +3535,8 @@ function serialisePlan(record, session) {
|
|
|
2335
3535
|
*/
|
|
2336
3536
|
planRevision: Number(record.planRevision ?? 0),
|
|
2337
3537
|
changeRequest: record.changeRequest ?? null,
|
|
2338
|
-
|
|
3538
|
+
// [2.2.9][T3][M4.1] 看板观测与门禁同源(纯派生),不再读可变标志。
|
|
3539
|
+
reportPending: deriveReportPending(record),
|
|
2339
3540
|
/*
|
|
2340
3541
|
* Liveness and resume bookkeeping. Without these the dashboard could not
|
|
2341
3542
|
* tell a slow-but-alive child from a wedged one, and the model could not
|
|
@@ -2574,6 +3775,38 @@ export function reconstructFromSession(session, targetPlanId) {
|
|
|
2574
3775
|
const snap = snapshots.get(result.planId);
|
|
2575
3776
|
if (snap) {
|
|
2576
3777
|
snap.statuses = applyResultStatuses(snap.statuses, result);
|
|
3778
|
+
/*
|
|
3779
|
+
* [2.2.0][T4/O-3b][E] 重建白名单(E 项,runtime 侧):applyResultStatuses
|
|
3780
|
+
* (src/plan.ts,T3 领地)逐字段重建不含柔性时长协商新字段,会把
|
|
3781
|
+
* deadlineAt/timeNotice/timeWarning/timeJournal/待裁决标记洗掉;结果消息
|
|
3782
|
+
* 整包透传行对象(字段在 entry 上),按 T3b plan.ts:2966-2971 同名修复
|
|
3783
|
+
* 口径补直写回放。
|
|
3784
|
+
*/
|
|
3785
|
+
for (const entry of (Array.isArray(result.statuses) ? result.statuses : [])) {
|
|
3786
|
+
const rebuiltRow = snap.statuses.find((item) => item?.subtaskId === entry?.subtaskId);
|
|
3787
|
+
if (!rebuiltRow || !isRecord(entry))
|
|
3788
|
+
continue;
|
|
3789
|
+
for (const field of ['deadlineAt', 'timeNotice', 'timeWarning', 'timeJournal', 'pendingAdjudication']) {
|
|
3790
|
+
if (entry[field] !== undefined)
|
|
3791
|
+
rebuiltRow[field] = entry[field];
|
|
3792
|
+
}
|
|
3793
|
+
/*
|
|
3794
|
+
* [2.2.0][T3/O-2a][F1] 通道结论也必须活过进程重启。
|
|
3795
|
+
* applyResultStatuses 已带该字段;这里再走一次校验,防止旧日志/
|
|
3796
|
+
* 未来字段来源把脏值直接拷进重建行(fail-closed)。
|
|
3797
|
+
*
|
|
3798
|
+
* [2.2.1][T5][F1] 非法值必须 `delete` 而不是写 `null`:写 null 会让
|
|
3799
|
+
* 脏字段跨每次重启自我延续(下一次回放又把整行丢掉,done 行永远显示
|
|
3800
|
+
* pending)。删除等价于「该结果消息没带这个字段」,合法值不受影响。
|
|
3801
|
+
*/
|
|
3802
|
+
if (entry.noticeChannel !== undefined) {
|
|
3803
|
+
const checked = validateNoticeChannel(entry.noticeChannel);
|
|
3804
|
+
if (checked.ok)
|
|
3805
|
+
rebuiltRow.noticeChannel = checked.value;
|
|
3806
|
+
else
|
|
3807
|
+
delete rebuiltRow.noticeChannel;
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
2577
3810
|
// Resume bookkeeping must survive a page refresh, otherwise the budget
|
|
2578
3811
|
// silently resets and a never-succeeding subtask can loop forever.
|
|
2579
3812
|
snap.resumeCount = Number(result.resumeCount ?? snap.resumeCount) || 0;
|
|
@@ -2601,14 +3834,59 @@ export function reconstructFromSession(session, targetPlanId) {
|
|
|
2601
3834
|
* `dsh_workplan_update` used to live only in the live cache, so a refresh
|
|
2602
3835
|
* reverted the dashboard to the child's original verdict. The durable
|
|
2603
3836
|
* `workplan-update` message is small and append-only, so replay is just
|
|
2604
|
-
* "apply it when its turn comes"
|
|
2605
|
-
*
|
|
3837
|
+
* "apply it when its turn comes". [2.2.9][T2][mono-gate] used to claim a
|
|
3838
|
+
* protection that only existed on the result-message path
|
|
3839
|
+
* (`applyResultStatuses`): a durable update with a lower revision could
|
|
3840
|
+
* still overwrite a newer settled row. The gate below now enforces it —
|
|
3841
|
+
* a strictly-lower revision never overwrites; equal revision passes
|
|
3842
|
+
* (dedup for the same write lives in `appliedUpdates`).
|
|
2606
3843
|
*/
|
|
2607
3844
|
const update = parseUpdateMessage(event.data);
|
|
2608
3845
|
if (update && typeof update.planId === 'string' && typeof update.subtaskId === 'string') {
|
|
2609
3846
|
const snap = snapshots.get(update.planId);
|
|
2610
3847
|
if (snap) {
|
|
2611
3848
|
try {
|
|
3849
|
+
/*
|
|
3850
|
+
* [2.2.9][T2][mono-gate] 结算事件写入单调性闸(M1,症状①主闸)。
|
|
3851
|
+
*
|
|
3852
|
+
* 事故形状(wp-215ed52f T5 实证):结算 rev16 已落 durable 结果消息,
|
|
3853
|
+
* 主 Agent 基于落后的 live 快照做 handoff 答复,追加了 rev9/10 的
|
|
3854
|
+
* workplan-update(seq 更晚)。回放按 seq 升序,后到的旧事件无条件
|
|
3855
|
+
* 覆盖先落盘的新结算——「后到即覆盖」与「revision 单调、已结算内容
|
|
3856
|
+
* 不可回退」的业务不变量正面冲突。
|
|
3857
|
+
*
|
|
3858
|
+
* 闸语义(与 plan.ts applyResultStatuses 的 result 族闸对齐):
|
|
3859
|
+
* - evRev < rowRev → 回退事件:拒绝整事件语义(含 3936 一带的直写
|
|
3860
|
+
* 白名单与 extendMs 合成,防止旧事件的状态性字段漏进新行),只有
|
|
3861
|
+
* handoffs 走逐项单调合并(M2:答复是字段级增量,新登记永远合法、
|
|
3862
|
+
* answered/closed 终态永不回退);
|
|
3863
|
+
* - 仍必须 appliedUpdates.set:否则同一次改判的 tool/result 配对
|
|
3864
|
+
* 记录(patch 不带 rev,applyStatus 强算 current+1)会绕过本闸从
|
|
3865
|
+
* 第二通道把旧内容灌回;
|
|
3866
|
+
* - evRev === rowRev → 前向通过(等 rev 补写是合法场景;同一条写入
|
|
3867
|
+
* 的重复应用由既有 appliedUpdates/1.8.11 去重通道拦截);
|
|
3868
|
+
* - evRev 为 null(旧格式无 revision 字段 / 非整数)→ 不猜、放行,
|
|
3869
|
+
* 向后兼容(applyStatus 尾部按 current+1 单调抬号)。
|
|
3870
|
+
*/
|
|
3871
|
+
const gateRow = snap.statuses.find((item) => item?.subtaskId === update.subtaskId);
|
|
3872
|
+
const rowRev = Number(gateRow?.revision ?? 0);
|
|
3873
|
+
const evRev = Number.isInteger(update.revision) ? Number(update.revision) : null;
|
|
3874
|
+
if (gateRow && evRev !== null && evRev < rowRev) {
|
|
3875
|
+
if (Array.isArray(update.handoffs)) {
|
|
3876
|
+
const merged = mergeHandoffEntriesByUpdatedAt(gateRow.handoffs, update.handoffs);
|
|
3877
|
+
if (merged.changed)
|
|
3878
|
+
gateRow.handoffs = merged.value;
|
|
3879
|
+
}
|
|
3880
|
+
console.warn('[dsh-workplan] monotonicity gate skipped a stale replayed update: '
|
|
3881
|
+
+ `${String(update.planId)}/${String(update.subtaskId)} `
|
|
3882
|
+
+ `(event rev ${evRev} < row rev ${rowRev}); row content kept, `
|
|
3883
|
+
+ 'handoff entries merged monotonically');
|
|
3884
|
+
appliedUpdates.set(updateKey(update.planId, update.subtaskId), {
|
|
3885
|
+
seq: Number(event.seq ?? 0),
|
|
3886
|
+
status: String(update.status ?? ''),
|
|
3887
|
+
});
|
|
3888
|
+
continue;
|
|
3889
|
+
}
|
|
2612
3890
|
snap.statuses = applyStatus(snap.statuses, update.subtaskId, {
|
|
2613
3891
|
/*
|
|
2614
3892
|
* handoff 的 durable 记录携带的是状态快照,不是一次状态迁移。
|
|
@@ -2616,6 +3894,18 @@ export function reconstructFromSession(session, targetPlanId) {
|
|
|
2616
3894
|
* INVALID_TRANSITION(wp-79c31abf 的 H1 就是这样被丢掉的)。
|
|
2617
3895
|
*/
|
|
2618
3896
|
status: update.handoffs === undefined ? update.status : undefined,
|
|
3897
|
+
/*
|
|
3898
|
+
* [2.2.6][D-1] 人工改判的 closure 必须随 patch 回放。
|
|
3899
|
+
*
|
|
3900
|
+
* durable 的 workplan-update 自 1.11.0 起携带 closure
|
|
3901
|
+
* (buildUpdateMessage),但这里的 patch 一直没把它传给
|
|
3902
|
+
* applyStatus:行停在 escalated 时,status=done 的改判会因
|
|
3903
|
+
* 「非法闭环迁移 escalated→done / closure=escalated 必须同时
|
|
3904
|
+
* status=blocked」被拒,整条 update 被下面的裸 catch 吞掉,
|
|
3905
|
+
* 重启后「待指示」行永久卡死(2026-11-08 wp-3c8c84b2 T2 实证,
|
|
3906
|
+
* 见 artifacts/2.2.5-post-restart-regression.md §4 D-1)。
|
|
3907
|
+
*/
|
|
3908
|
+
closure: typeof update.closure === 'string' ? update.closure : undefined,
|
|
2619
3909
|
progress: typeof update.progress === 'number' ? update.progress : undefined,
|
|
2620
3910
|
summary: typeof update.note === 'string' ? update.note : undefined,
|
|
2621
3911
|
// [1.8.13] Evidence written through the update tool must survive replay.
|
|
@@ -2625,15 +3915,87 @@ export function reconstructFromSession(session, targetPlanId) {
|
|
|
2625
3915
|
missingArtifacts: update.missingArtifacts,
|
|
2626
3916
|
handoffs: update.handoffs,
|
|
2627
3917
|
revision: Number.isInteger(update.revision) ? update.revision : undefined,
|
|
3918
|
+
// [2.2.0][T4/O-3b][E] 回放白名单(T3b TODO#2):O-3b/O-2c 留档字段随
|
|
3919
|
+
// update 记录回放;timeoutMs 有 applyStatus 分支,走 patch 即可。
|
|
3920
|
+
timeoutMs: update.timeoutMs,
|
|
2628
3921
|
updatedBy: 'agent',
|
|
2629
3922
|
});
|
|
3923
|
+
/*
|
|
3924
|
+
* [2.2.9][T3][M4] 回放侧人工改判的回报闭环——与 live 路径(改判
|
|
3925
|
+
* 工具在 durable 落盘成功后 markReported)配成同一条不变量:
|
|
3926
|
+
* durable 的 workplan-update 携带显式 status:'done' 时,这条消息
|
|
3927
|
+
* 本身就是主 Agent 亲笔写进会话日志的「完成已回报」证据。旧日志
|
|
3928
|
+
* 嵌的是 closure:'done'(2.2.9 之前的口径),回放在此一并升级为
|
|
3929
|
+
* reported;report.ref 指向这条 durable 消息的 seq——引用真实存在、
|
|
3930
|
+
* 可复核。不升 handoffs 快照消息(它们的 status 未被应用,handoff
|
|
3931
|
+
* 记录不是一次回报),子结算行的回报仍须来自结果消息或 pre-step
|
|
3932
|
+
* 自愈(M4.2)。live 与重建由此在同一份日志上逐行同判,
|
|
3933
|
+
* 「可交付↔门禁未放行」的震荡失去立足点。
|
|
3934
|
+
*/
|
|
3935
|
+
if (update.status === 'done' && update.handoffs === undefined) {
|
|
3936
|
+
const healedRow = snap.statuses.find((item) => item?.subtaskId === update.subtaskId);
|
|
3937
|
+
if (healedRow?.status === 'done' && healedRow?.closure === 'done') {
|
|
3938
|
+
healedRow.closure = 'reported';
|
|
3939
|
+
healedRow.reportedAt = Number(update.at) || Date.now();
|
|
3940
|
+
healedRow.report = {
|
|
3941
|
+
state: 'sent',
|
|
3942
|
+
at: Number(update.at) || Date.now(),
|
|
3943
|
+
ref: `${String(update.planId)}:replay:${String(Number(event.seq ?? 0))}`,
|
|
3944
|
+
turn: null,
|
|
3945
|
+
};
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
/*
|
|
3949
|
+
* [2.2.0][T4/O-3b][E] 柔性时长协商新字段回放(E 项,runtime.ts 2931 一带)。
|
|
3950
|
+
*
|
|
3951
|
+
* deadlineAt/timeNotice/timeWarning/timeJournal/待裁决标记在 applyStatus
|
|
3952
|
+
* (src/plan.ts,T3 领地)无路由分支,走 patch 会被静默丢弃;按 T3b
|
|
3953
|
+
* plan.ts:2966-2971 同名修复口径在此直写重建行。extendMs 走累加语义
|
|
3954
|
+
* (与线上 extendDeadline 一致:deadlineAt += extendMs 并追加 timeJournal),
|
|
3955
|
+
* 仅当记录未自带 timeJournal 时合成,避免同一条 journal 被回放两次。
|
|
3956
|
+
*/
|
|
3957
|
+
const replayRow = snap.statuses.find((item) => item?.subtaskId === update.subtaskId);
|
|
3958
|
+
if (replayRow) {
|
|
3959
|
+
for (const field of ['deadlineAt', 'timeNotice', 'timeWarning', 'timeJournal', 'pendingAdjudication']) {
|
|
3960
|
+
if (update[field] !== undefined)
|
|
3961
|
+
replayRow[field] = update[field];
|
|
3962
|
+
}
|
|
3963
|
+
const replayExtend = Number(update.extendMs);
|
|
3964
|
+
if (update.timeJournal === undefined && Number.isFinite(replayExtend) && replayExtend > 0
|
|
3965
|
+
&& Number.isFinite(Number(replayRow.deadlineAt))) {
|
|
3966
|
+
replayRow.deadlineAt = Number(replayRow.deadlineAt) + Math.floor(replayExtend);
|
|
3967
|
+
replayRow.timeJournal = [
|
|
3968
|
+
...(Array.isArray(replayRow.timeJournal) ? replayRow.timeJournal : []),
|
|
3969
|
+
{
|
|
3970
|
+
at: Date.now(),
|
|
3971
|
+
action: 'extend',
|
|
3972
|
+
extendMs: Math.floor(replayExtend),
|
|
3973
|
+
by: 'agent',
|
|
3974
|
+
reason: truncate(String(update.reason ?? ''), 300),
|
|
3975
|
+
},
|
|
3976
|
+
].slice(-20);
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
2630
3979
|
appliedUpdates.set(updateKey(update.planId, update.subtaskId), {
|
|
2631
3980
|
seq: Number(event.seq ?? 0),
|
|
2632
3981
|
status: String(update.status ?? ''),
|
|
2633
3982
|
});
|
|
2634
3983
|
}
|
|
2635
|
-
catch {
|
|
2636
|
-
|
|
3984
|
+
catch (error) {
|
|
3985
|
+
/*
|
|
3986
|
+
* [2.2.6][D-1] fail-closed 而非 fail-silent:历史 update 不合法时
|
|
3987
|
+
* 至少留一条日志,否则「改判丢失」永远无从发现(本缺陷因此潜伏
|
|
3988
|
+
* 自 1.7.0)。回放继续,不让单条坏记录拖垮整个重建。
|
|
3989
|
+
*/
|
|
3990
|
+
console.warn('[dsh-workplan] 回放忽略一条不合法的历史改判:'
|
|
3991
|
+
+ `${String(update?.planId ?? '')}/${String(update?.subtaskId ?? '')}:`
|
|
3992
|
+
+ /*
|
|
3993
|
+
* [2.2.9][T3][M4.3] 可诊断化:旧快照携带的 closure/revision 与被保留
|
|
3994
|
+
* 的行现状一并带出,「改判丢失」不再只有一句 error.message。
|
|
3995
|
+
*/
|
|
3996
|
+
`event rev=${String(update?.revision ?? 'none')} closure=${String(update?.closure ?? 'none')} `
|
|
3997
|
+
+ `vs row rev=${String(snap.statuses.find((item) => item?.subtaskId === update?.subtaskId)?.revision ?? 'none')}:`
|
|
3998
|
+
+ `${error instanceof Error ? error.message : String(error)}`);
|
|
2637
3999
|
}
|
|
2638
4000
|
}
|
|
2639
4001
|
}
|
|
@@ -2833,12 +4195,19 @@ export function reconstructFromSession(session, targetPlanId) {
|
|
|
2833
4195
|
planRevision: chosen.planRevision,
|
|
2834
4196
|
changeRequest: chosen.changeRequest,
|
|
2835
4197
|
/*
|
|
2836
|
-
* [
|
|
2837
|
-
*
|
|
2838
|
-
*
|
|
2839
|
-
*
|
|
4198
|
+
* [2.2.9][T3][M4.2] 重建记录必须带 `resultWritten`。
|
|
4199
|
+
*
|
|
4200
|
+
* 事故实证(wp-215ed52f 症状②第三拍):pre-step 回报自愈的条件是
|
|
4201
|
+
* `reportPending && resultWritten`,而重建对象从不携带该字段(恒
|
|
4202
|
+
* undefined)→ 条件永不成立 → 重启后派生出的「未回报」态永远无法
|
|
4203
|
+
* 自愈,只能靠幂等复核+人工改判收敛——这正是「震荡三次」的机制解释。
|
|
4204
|
+
* durable 会话里存在本轮结果消息(resultSeen)就是「已写入」的事实,
|
|
4205
|
+
* 用它补齐后自愈在重建态可达:重启 → reportPending 派生 true →
|
|
4206
|
+
* pre-step 幂等 markReported → 门禁一次收敛。
|
|
2840
4207
|
*/
|
|
2841
|
-
|
|
4208
|
+
resultWritten: resultSeen,
|
|
4209
|
+
// [2.2.9][T3][M4.1] 派生口径与门禁/看板/冻结单源(deriveReportPending)。
|
|
4210
|
+
reportPending: deriveReportPending({ statuses }),
|
|
2842
4211
|
};
|
|
2843
4212
|
}
|
|
2844
4213
|
function liveSessions(ctx) {
|
|
@@ -2969,10 +4338,20 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
2969
4338
|
};
|
|
2970
4339
|
}
|
|
2971
4340
|
const limits = {
|
|
4341
|
+
/*
|
|
4342
|
+
* [2.1.6] 规划器的两扇窗此前不在 limits 里:`options.limits.plannerTimeoutMs`
|
|
4343
|
+
* 永远是 undefined,调用处只能靠兜底常量,状态/诊断也因此读不到「当前生效
|
|
4344
|
+
* 的规划器时限」。补齐后配置 → limits → 单次调用是同一条链路。
|
|
4345
|
+
*/
|
|
4346
|
+
plannerTimeoutMs: normalisePlannerWindow(options.plannerTimeoutMs, PLANNER_TIMEOUT_MS),
|
|
4347
|
+
plannerIdleTimeoutMs: normalisePlannerWindow(options.plannerIdleTimeoutMs, PLANNER_IDLE_TIMEOUT_MS),
|
|
2972
4348
|
childTimeoutMs: normaliseChildTimeout(options.childTimeoutMs),
|
|
2973
4349
|
idleTimeoutMs: normaliseIdleTimeout(options.idleTimeoutMs),
|
|
2974
|
-
|
|
2975
|
-
|
|
4350
|
+
// [2.2.5] 0 = 不设整轮硬预算;正数才启用(最小 60s)。未配置按 0。
|
|
4351
|
+
totalTimeoutMs: Number.isFinite(Number(options.totalTimeoutMs)) && Number(options.totalTimeoutMs) >= 0
|
|
4352
|
+
? (Number(options.totalTimeoutMs) === 0
|
|
4353
|
+
? 0
|
|
4354
|
+
: Math.max(60000, Math.floor(Number(options.totalTimeoutMs))))
|
|
2976
4355
|
: TOTAL_TIMEOUT_MS,
|
|
2977
4356
|
maxResumes: Number.isFinite(Number(options.maxResumes)) && Number(options.maxResumes) >= 0
|
|
2978
4357
|
? Math.min(5, Math.floor(Number(options.maxResumes)))
|
|
@@ -3003,12 +4382,16 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3003
4382
|
modelSelection: record.modelSelection,
|
|
3004
4383
|
cwd: session.header?.cwd ?? options.cwd,
|
|
3005
4384
|
conversationContext: record.conversationContext ?? '',
|
|
4385
|
+
// [2.2.0][T6/O-1a] 自动派发是后台轮次:结算成功即推送完成即时通知。
|
|
4386
|
+
notifyCompletion: true,
|
|
4387
|
+
onSubtaskDone: (recordArg, subtask, verdict) => emitSubtaskDoneNotice(recordArg, session, subtask, verdict),
|
|
3006
4388
|
};
|
|
3007
4389
|
record.dispatchStartedAt = Date.now();
|
|
3008
4390
|
record.dispatchPromise = dispatchPlan(ctx, record, {
|
|
3009
4391
|
...roundOptions,
|
|
3010
4392
|
signal: controller.signal,
|
|
3011
|
-
|
|
4393
|
+
// [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
|
|
4394
|
+
childTimeoutMs: options.childTimeoutMs,
|
|
3012
4395
|
idleTimeoutMs: limits.idleTimeoutMs,
|
|
3013
4396
|
totalTimeoutMs: limits.totalTimeoutMs,
|
|
3014
4397
|
maxResumes: limits.maxResumes,
|
|
@@ -3046,13 +4429,20 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3046
4429
|
/*
|
|
3047
4430
|
* [1.11.0] 回报自愈(契约 §7.3 B4):上一轮结果消息已写入,但回报标记
|
|
3048
4431
|
* 写失败/进程中断时,下一步 pre-step 幂等补齐,不重复追加上下文。
|
|
4432
|
+
*
|
|
4433
|
+
* [2.2.9][T3][M4.1/M4.2] 判定改读派生谓词 `deriveReportPending`:live
|
|
4434
|
+
* 记录的标志只是审计镜像,自愈若读镜像,镜像过期时该自愈的不自愈、
|
|
4435
|
+
* 不该自愈的白跑一遍。配合重建对象补上的 `resultWritten`(M4.2,
|
|
4436
|
+
* 此前该字段在重建态恒 undefined、条件永不成立,自愈对重启后的会话
|
|
4437
|
+
* 形同虚设——「震荡三次靠人工收敛」的第三拍),重启 → 派生 true →
|
|
4438
|
+
* 首个 pre-step 幂等 markReported → 门禁一次收敛,无需人工改判。
|
|
3049
4439
|
*/
|
|
3050
4440
|
const session = payload.agent?.session;
|
|
3051
4441
|
const known = session ? state.records.get(session.id) : null;
|
|
3052
|
-
if (known?.plan && known
|
|
4442
|
+
if (known?.plan && deriveReportPending(known) && known.resultWritten === true) {
|
|
3053
4443
|
const changed = markReported(known, session, `${known.plan.planId}:${known.dispatchedAt ?? 0}`);
|
|
3054
4444
|
if (changed > 0) {
|
|
3055
|
-
known.reportPending = (known
|
|
4445
|
+
known.reportPending = deriveReportPending(known);
|
|
3056
4446
|
}
|
|
3057
4447
|
}
|
|
3058
4448
|
return await maybePlan(ctx, state, payload, downstream, { ...options, limits });
|
|
@@ -3117,6 +4507,84 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3117
4507
|
state.records.set(session.id, rebuilt);
|
|
3118
4508
|
return rebuilt;
|
|
3119
4509
|
}
|
|
4510
|
+
/*
|
|
4511
|
+
* [2.2.0][T5/O-4c/O-4d] 延期预算(防滥用,方案 §5.4 #1/#2;数值只引方案原文)。
|
|
4512
|
+
*
|
|
4513
|
+
* 初始协商上限的解析完全复用 T4 的 resolveSubtaskTimeoutMs(显式
|
|
4514
|
+
* subtask.timeoutMs → deriveSubtaskTimeoutMs(estimateMinutes) → 回落
|
|
4515
|
+
* CHILD_TIMEOUT_MS)。方案没有给出 MAX_EXTEND_MS 的具体数值,因此**不自拟
|
|
4516
|
+
* 常量**:单次延期上限派生为「剩余延期预算」=初始协商上限 × 1 − 已累计延期
|
|
4517
|
+
* (timeJournal 中 action:'extend' 之和)。累计超限即拒绝并转「请主 Agent
|
|
4518
|
+
* 裁决」(EXTEND_BUDGET_EXHAUSTED),放宽永远有界。
|
|
4519
|
+
*
|
|
4520
|
+
* 为什么初始上限不传 options.childTimeoutMs:显式注入的 childTimeoutMs 是
|
|
4521
|
+
* 运维兜底上限(见 resolveSubtaskTimeoutMs 注释),不是本子任务的协商上限;
|
|
4522
|
+
* 延期预算按方案 §2.2 的口径取计划层解析值。验收合同也用同一口径(D4 用
|
|
4523
|
+
* 显式 timeoutMs 定 2000ms;D2 用例在 1200ms 小窗上放宽 1500ms 是合法的)。
|
|
4524
|
+
*/
|
|
4525
|
+
function extendBudgetOf(record, subtaskId) {
|
|
4526
|
+
const entry = flattenSubtasks(record?.plan ?? { stages: [] })
|
|
4527
|
+
.find((candidate) => candidate?.subtask?.id === subtaskId);
|
|
4528
|
+
const initialMs = resolveSubtaskTimeoutMs(entry?.subtask, undefined);
|
|
4529
|
+
const row = Array.isArray(record?.statuses)
|
|
4530
|
+
? record.statuses.find((item) => item?.subtaskId === subtaskId)
|
|
4531
|
+
: null;
|
|
4532
|
+
const usedMs = (Array.isArray(row?.timeJournal) ? row.timeJournal : [])
|
|
4533
|
+
.filter((item) => item?.action === 'extend')
|
|
4534
|
+
.reduce((sum, item) => {
|
|
4535
|
+
const value = Number(item?.extendMs);
|
|
4536
|
+
return Number.isFinite(value) && value > 0 ? sum + Math.floor(value) : sum;
|
|
4537
|
+
}, 0);
|
|
4538
|
+
// 方案 §5.4 #2:累计 extendMs ≤ 初始协商上限 × 1(最多再给一倍)。
|
|
4539
|
+
const capMs = initialMs;
|
|
4540
|
+
return { initialMs, capMs, usedMs, remainingMs: Math.max(0, capMs - usedMs) };
|
|
4541
|
+
}
|
|
4542
|
+
/*
|
|
4543
|
+
* [2.2.0][T5/O-4c] timeNotice 的形状校验(方案 §2.4:{declaredMinutes, reason})。
|
|
4544
|
+
* 只记录、不改判定;非法值返回可读错误而不是抛裸错(与 STALE_WRITE 同风格)。
|
|
4545
|
+
*/
|
|
4546
|
+
function validateTimeNotice(notice) {
|
|
4547
|
+
const declared = Number(notice?.declaredMinutes);
|
|
4548
|
+
if (!Number.isFinite(declared) || declared <= 0) {
|
|
4549
|
+
return {
|
|
4550
|
+
code: 'INVALID_TIME_NOTICE',
|
|
4551
|
+
error: `timeNotice.declaredMinutes 必须是正数分钟:${String(notice?.declaredMinutes)}`,
|
|
4552
|
+
hint: '预告只做记录(仅供参考、非承诺):请传正数分钟与可选 reason。',
|
|
4553
|
+
};
|
|
4554
|
+
}
|
|
4555
|
+
return null;
|
|
4556
|
+
}
|
|
4557
|
+
/*
|
|
4558
|
+
* [2.2.0][T5/O-4c] 写入专家开工预告(O-2a):状态行 timeNotice + timeJournal
|
|
4559
|
+
* 的 action:'estimate' 条目。applyStatus(plan.ts,T3 领地)还没有该字段的
|
|
4560
|
+
* 路由分支,按 T4 直写通道写行(StatusEntry 保留未知字段;回放白名单已透传
|
|
4561
|
+
* timeNotice,刷新后不丢)。
|
|
4562
|
+
*/
|
|
4563
|
+
function recordTimeNotice(record, subtaskId, notice) {
|
|
4564
|
+
const row = Array.isArray(record?.statuses)
|
|
4565
|
+
? record.statuses.find((item) => item?.subtaskId === subtaskId)
|
|
4566
|
+
: null;
|
|
4567
|
+
if (!row)
|
|
4568
|
+
return;
|
|
4569
|
+
const at = Date.now();
|
|
4570
|
+
const reason = truncate(String(notice?.reason ?? ''), 300);
|
|
4571
|
+
row.timeNotice = {
|
|
4572
|
+
declaredMinutes: Number(notice?.declaredMinutes),
|
|
4573
|
+
at,
|
|
4574
|
+
channel: 'agent',
|
|
4575
|
+
reason,
|
|
4576
|
+
};
|
|
4577
|
+
const journal = Array.isArray(row.timeJournal) ? row.timeJournal : [];
|
|
4578
|
+
journal.push({
|
|
4579
|
+
at,
|
|
4580
|
+
action: 'estimate',
|
|
4581
|
+
declaredMinutes: Number(notice?.declaredMinutes),
|
|
4582
|
+
by: 'agent',
|
|
4583
|
+
reason,
|
|
4584
|
+
});
|
|
4585
|
+
row.timeJournal = journal.slice(-20);
|
|
4586
|
+
record.updatedAt = at;
|
|
4587
|
+
}
|
|
3120
4588
|
async function updateStatus(agent, args) {
|
|
3121
4589
|
const session = agent?.session;
|
|
3122
4590
|
if (!session)
|
|
@@ -3129,21 +4597,87 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3129
4597
|
record = adoptRequestedPlan(session, record, args?.planId);
|
|
3130
4598
|
if (!record?.plan)
|
|
3131
4599
|
throw new PlanError('当前会话还没有已生成的计划', 'NO_PLAN');
|
|
3132
|
-
// [1.10.4] 人工改判优先于任何已排期的自动续跑:先撤销定时器,再写状态。
|
|
3133
|
-
clearAutoResumeTimer(record, 'manual-update');
|
|
3134
4600
|
const subtaskId = typeof args?.subtaskId === 'string' ? args.subtaskId : '';
|
|
3135
4601
|
if (!subtaskId)
|
|
3136
4602
|
throw new PlanError('缺少 subtaskId', 'MISSING_SUBTASK');
|
|
3137
4603
|
const status = typeof args?.status === 'string' ? args.status : '';
|
|
3138
|
-
|
|
3139
|
-
|
|
4604
|
+
/*
|
|
4605
|
+
* [2.2.0][T5/O-4c] 延期事务的入口判定(D2/D3/D4,方案 §2.2):
|
|
4606
|
+
* extendMs / timeNotice 属于「只改时限、只做记录」的字段,不改状态判定,
|
|
4607
|
+
* 因此允许不带 status 单独提交;运行中也不需要 force——TASK_RUNNING 的
|
|
4608
|
+
* 唯一豁免来自「不改判定」这一事实,而不是特权。
|
|
4609
|
+
*/
|
|
4610
|
+
const extendMsArg = args?.extendMs;
|
|
4611
|
+
const hasExtend = extendMsArg !== undefined && extendMsArg !== null;
|
|
4612
|
+
const timeNoticeArg = args?.timeNotice;
|
|
4613
|
+
const hasTimeNotice = timeNoticeArg !== undefined && timeNoticeArg !== null;
|
|
4614
|
+
const statusRequested = ['pending', 'in_progress', 'done', 'blocked'].includes(status);
|
|
4615
|
+
if (!statusRequested && !hasExtend && !hasTimeNotice) {
|
|
4616
|
+
throw new PlanError('status 必须是 pending / in_progress / done / blocked(仅协商时限时可省略 status,改传 extendMs / timeNotice)', 'INVALID_STATUS');
|
|
4617
|
+
}
|
|
4618
|
+
if (hasExtend && !(typeof extendMsArg === 'number' && Number.isInteger(extendMsArg) && extendMsArg > 0)) {
|
|
4619
|
+
return {
|
|
4620
|
+
ok: false,
|
|
4621
|
+
code: 'INVALID_EXTEND',
|
|
4622
|
+
planId: record.plan.planId,
|
|
4623
|
+
subtaskId,
|
|
4624
|
+
error: `extendMs 必须是正整数毫秒:${String(extendMsArg)}`,
|
|
4625
|
+
hint: '请传入 1 以上的整数毫秒;放宽永远有界(累计 ≤ 初始协商上限 × 1),超出请转新轮续跑或转 escalate 请主 Agent 裁决。',
|
|
4626
|
+
};
|
|
4627
|
+
}
|
|
4628
|
+
/*
|
|
4629
|
+
* [2.2.0][T5/O-4c] timeNotice 的校验放在入口统一做(所有路径共享):
|
|
4630
|
+
* 非法预告不该因为调用同时带了 status/instruction 就被静默接受。
|
|
4631
|
+
*/
|
|
4632
|
+
if (hasTimeNotice) {
|
|
4633
|
+
const problem = validateTimeNotice(timeNoticeArg);
|
|
4634
|
+
if (problem) {
|
|
4635
|
+
return {
|
|
4636
|
+
ok: false,
|
|
4637
|
+
code: problem.code,
|
|
4638
|
+
planId: record.plan.planId,
|
|
4639
|
+
subtaskId,
|
|
4640
|
+
error: problem.error,
|
|
4641
|
+
hint: problem.hint,
|
|
4642
|
+
};
|
|
4643
|
+
}
|
|
3140
4644
|
}
|
|
4645
|
+
/*
|
|
4646
|
+
* [2.2.0][T5/O-4c] 延期事务与状态改判分开提交:方案 §2.2 把 extendMs 定为
|
|
4647
|
+
* 「放宽时间的唯一写路径」,要求原子与可审计;一次调用既改判定又改时限会让
|
|
4648
|
+
* 失败路径出现半写(判定已落、时限未落,或相反)。组合调用显式拒绝,模型分
|
|
4649
|
+
* 两次提交即可(两者都不需要 force)。
|
|
4650
|
+
*/
|
|
4651
|
+
if (hasExtend && statusRequested) {
|
|
4652
|
+
return {
|
|
4653
|
+
ok: false,
|
|
4654
|
+
code: 'EXTEND_REQUIRES_DEDICATED_CALL',
|
|
4655
|
+
planId: record.plan.planId,
|
|
4656
|
+
subtaskId,
|
|
4657
|
+
error: '延期事务必须单独提交:同一次调用不要同时传 status 与 extendMs(放宽是原子、可审计的唯一写路径)',
|
|
4658
|
+
hint: '先单独调用 extendMs 放宽时限,再用另一次调用改判状态。',
|
|
4659
|
+
};
|
|
4660
|
+
}
|
|
4661
|
+
/*
|
|
4662
|
+
* [1.10.4] 人工改判优先于任何已排期的自动续跑:先撤销定时器,再写状态。
|
|
4663
|
+
* [2.2.0][T5/O-4c] 纯延期/纯预告不改判定,不撤销自动续跑(否则一次失败的
|
|
4664
|
+
* 延期尝试会把已排期的续跑静默取消,计划停在 paused 无人推进)。
|
|
4665
|
+
*/
|
|
4666
|
+
if (statusRequested)
|
|
4667
|
+
clearAutoResumeTimer(record, 'manual-update');
|
|
3141
4668
|
const note = typeof args?.note === 'string' ? args.note : '';
|
|
3142
4669
|
const evidence = Array.isArray(args?.evidence)
|
|
3143
4670
|
? args.evidence.filter((item) => typeof item === 'string').join(';')
|
|
3144
4671
|
: '';
|
|
3145
4672
|
const summary = [note, evidence].filter(Boolean).join('|');
|
|
3146
4673
|
const current = record.statuses.find((item) => item.subtaskId === subtaskId);
|
|
4674
|
+
/*
|
|
4675
|
+
* [2.2.0][T5/O-4c] 纯时限事务(不带 status)不经过 applyStatus,必须自己
|
|
4676
|
+
* 拒绝未知子任务——否则一次对不存在行的 timeNotice 会得到「成功」。
|
|
4677
|
+
*/
|
|
4678
|
+
if (!statusRequested && !current) {
|
|
4679
|
+
throw new PlanError(`未知子任务:${subtaskId}`, 'UNKNOWN_SUBTASK');
|
|
4680
|
+
}
|
|
3147
4681
|
/*
|
|
3148
4682
|
* [1.7.0] Two write guards, both non-throwing.
|
|
3149
4683
|
*
|
|
@@ -3169,7 +4703,13 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3169
4703
|
};
|
|
3170
4704
|
}
|
|
3171
4705
|
const running = Boolean(record.dispatchPromise);
|
|
3172
|
-
|
|
4706
|
+
/*
|
|
4707
|
+
* [2.2.0][T5/O-4c] TASK_RUNNING 的唯一豁免:只给「不改状态判定」的时限事务。
|
|
4708
|
+
* 纯 extendMs / timeNotice 更新(statusRequested=false)照常放行;只要同一次
|
|
4709
|
+
* 调用还带 status,仍走原守卫——其余状态字段不得被顺手改掉(行为不变)。
|
|
4710
|
+
*/
|
|
4711
|
+
const writeWhileRunning = running && !args?.force && statusRequested
|
|
4712
|
+
&& (current?.status === 'pending' || current?.status === 'in_progress');
|
|
3173
4713
|
if (writeWhileRunning) {
|
|
3174
4714
|
return {
|
|
3175
4715
|
ok: false,
|
|
@@ -3211,11 +4751,18 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3211
4751
|
error: '下发 instruction 时 status 必须是 in_progress(或改用 dsh_workplan_instruct)。',
|
|
3212
4752
|
};
|
|
3213
4753
|
}
|
|
3214
|
-
|
|
4754
|
+
const instructed = await instructSubtask(agent, {
|
|
3215
4755
|
planId: args?.planId,
|
|
3216
4756
|
subtaskId,
|
|
3217
4757
|
instruction,
|
|
3218
4758
|
}, undefined, record);
|
|
4759
|
+
/*
|
|
4760
|
+
* [2.2.0][T5/O-4c] 预告与指示同一次到达时,指示成功落行后再记预告:
|
|
4761
|
+
* 指示失败不该留下一笔「专家已预告」的记录。
|
|
4762
|
+
*/
|
|
4763
|
+
if (hasTimeNotice && instructed?.ok !== false)
|
|
4764
|
+
recordTimeNotice(record, subtaskId, timeNoticeArg);
|
|
4765
|
+
return instructed;
|
|
3219
4766
|
}
|
|
3220
4767
|
if (current?.closure === 'escalated') {
|
|
3221
4768
|
if (status === 'done') {
|
|
@@ -3237,6 +4784,90 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3237
4784
|
};
|
|
3238
4785
|
}
|
|
3239
4786
|
}
|
|
4787
|
+
/*
|
|
4788
|
+
* [2.2.0][T5/O-4c] 延期事务(放宽时间的唯一写路径,方案 §2.2;D2/D3 效果 +
|
|
4789
|
+
* §5.4 防滥用):
|
|
4790
|
+
* 1. 预算:初始协商上限取 T4 resolveSubtaskTimeoutMs 的计划层解析值;累计
|
|
4791
|
+
* 放宽(timeJournal 中 action:'extend' 之和)≤ 初始上限 × 1。方案没有给
|
|
4792
|
+
* MAX_EXTEND_MS 数值,单次上限派生为「剩余延期预算」,不自拟常量。
|
|
4793
|
+
* 2. 执行:校验通过才调用 T4 extendDeadline——它负责 deadlineAt += extendMs、
|
|
4794
|
+
* 重置一次性计时器、同步 watchdog,并追加 timeJournal(action:'extend')。
|
|
4795
|
+
* 回放侧(本文件 replay 白名单)的累加语义与此一致:deadlineAt 累加 +
|
|
4796
|
+
* 同形 journal 条目,所以回放代码不需要改。
|
|
4797
|
+
* 3. 纯时限事务不改状态判定:回执只带时限结果与审计字段。
|
|
4798
|
+
*/
|
|
4799
|
+
let extension = null;
|
|
4800
|
+
if (hasExtend) {
|
|
4801
|
+
const budget = extendBudgetOf(record, subtaskId);
|
|
4802
|
+
if (extendMsArg > budget.remainingMs) {
|
|
4803
|
+
return {
|
|
4804
|
+
ok: false,
|
|
4805
|
+
code: 'EXTEND_BUDGET_EXHAUSTED',
|
|
4806
|
+
planId: record.plan.planId,
|
|
4807
|
+
subtaskId,
|
|
4808
|
+
budget,
|
|
4809
|
+
error: `extendMs ${extendMsArg}ms 超出剩余延期预算 ${budget.remainingMs}ms:`
|
|
4810
|
+
+ `累计延期 ${budget.usedMs}ms,初始协商上限 ${budget.initialMs}ms(上限 × 1 = ${budget.capMs}ms)`,
|
|
4811
|
+
hint: '放宽永远有界:该任务应转入新轮续跑(auto-resume)或转 escalate 请主 Agent/用户裁决。',
|
|
4812
|
+
};
|
|
4813
|
+
}
|
|
4814
|
+
const extended = extendDeadline(record, subtaskId, extendMsArg, {
|
|
4815
|
+
by: 'agent',
|
|
4816
|
+
reason: typeof args?.reason === 'string'
|
|
4817
|
+
? args.reason
|
|
4818
|
+
: (typeof args?.note === 'string' ? args.note : ''),
|
|
4819
|
+
});
|
|
4820
|
+
if (!extended.ok) {
|
|
4821
|
+
return {
|
|
4822
|
+
ok: false,
|
|
4823
|
+
code: extended.code,
|
|
4824
|
+
planId: record.plan.planId,
|
|
4825
|
+
subtaskId,
|
|
4826
|
+
error: extended.error,
|
|
4827
|
+
hint: extended.hint,
|
|
4828
|
+
};
|
|
4829
|
+
}
|
|
4830
|
+
extension = extended;
|
|
4831
|
+
}
|
|
4832
|
+
if (!statusRequested) {
|
|
4833
|
+
if (hasTimeNotice)
|
|
4834
|
+
recordTimeNotice(record, subtaskId, timeNoticeArg);
|
|
4835
|
+
/*
|
|
4836
|
+
* 纯时限事务到此结束。方案 §2.2 效果 3:状态行 revision +1(延期/预告也是
|
|
4837
|
+
* 行变更,同样受 STALE_WRITE 乐观锁保护);状态与判定一个字段都不改。
|
|
4838
|
+
*/
|
|
4839
|
+
const row = record.statuses.find((item) => item?.subtaskId === subtaskId);
|
|
4840
|
+
if (row) {
|
|
4841
|
+
row.revision = Number(current?.revision ?? 0) + 1;
|
|
4842
|
+
row.updatedBy = 'agent';
|
|
4843
|
+
}
|
|
4844
|
+
record.updatedAt = Date.now();
|
|
4845
|
+
const snapshot = derivePlanSnapshot(record.statuses);
|
|
4846
|
+
const written = snapshot.statuses.find((item) => item.subtaskId === subtaskId);
|
|
4847
|
+
const readiness = readinessOf(record, snapshot);
|
|
4848
|
+
return {
|
|
4849
|
+
ok: true,
|
|
4850
|
+
planId: record.plan.planId,
|
|
4851
|
+
subtaskId,
|
|
4852
|
+
status: written?.status ?? current?.status ?? null,
|
|
4853
|
+
revision: written?.revision ?? Number(current?.revision ?? 0),
|
|
4854
|
+
updatedBy: written?.updatedBy ?? 'agent',
|
|
4855
|
+
...(extension
|
|
4856
|
+
? {
|
|
4857
|
+
deadlineAt: extension.deadlineAt,
|
|
4858
|
+
timerRearmed: extension.timerRearmed,
|
|
4859
|
+
watchdogRearmed: extension.watchdogRearmed,
|
|
4860
|
+
}
|
|
4861
|
+
: {}),
|
|
4862
|
+
...(hasTimeNotice ? { timeNotice: written?.timeNotice ?? null } : {}),
|
|
4863
|
+
timeJournal: Array.isArray(written?.timeJournal) ? written.timeJournal.slice(-10) : [],
|
|
4864
|
+
stats: snapshot.stats,
|
|
4865
|
+
deliveryReady: readiness.ready,
|
|
4866
|
+
deliveryBlockers: readiness.blockers.slice(0, 12),
|
|
4867
|
+
deliveryRemaining: readiness.remaining.slice(0, 20),
|
|
4868
|
+
hint: '时限协商已记录:状态与判定未改,不需要 force;放宽永远有界,超出累计上限请转新轮续跑或转 escalate 请主 Agent 裁决。',
|
|
4869
|
+
};
|
|
4870
|
+
}
|
|
3240
4871
|
const revision = Number(current?.revision ?? 0) + 1;
|
|
3241
4872
|
/*
|
|
3242
4873
|
* [1.8.13] A manual verdict can carry structured evidence.
|
|
@@ -3273,6 +4904,12 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3273
4904
|
revision,
|
|
3274
4905
|
updatedBy: 'agent',
|
|
3275
4906
|
});
|
|
4907
|
+
/*
|
|
4908
|
+
* [2.2.0][T5/O-4c] 带 status 的调用同时带 timeNotice 时,预告记录在改判落行
|
|
4909
|
+
* 之后写入:applyStatus 抛错(如非法 verification)时不会留下半写的预告。
|
|
4910
|
+
*/
|
|
4911
|
+
if (hasTimeNotice)
|
|
4912
|
+
recordTimeNotice(record, subtaskId, timeNoticeArg);
|
|
3276
4913
|
if (status === 'blocked') {
|
|
3277
4914
|
record.statuses = markDependentsBlocked(record.plan, record.statuses, subtaskId, { reason: summary || '主 Agent 标记受阻' });
|
|
3278
4915
|
}
|
|
@@ -3285,7 +4922,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3285
4922
|
*/
|
|
3286
4923
|
try {
|
|
3287
4924
|
const writtenRow = record.statuses.find((item) => item.subtaskId === subtaskId);
|
|
3288
|
-
session
|
|
4925
|
+
appendUserMessage(session, buildUpdateMessage({
|
|
3289
4926
|
planId: record.plan.planId,
|
|
3290
4927
|
subtaskId,
|
|
3291
4928
|
status,
|
|
@@ -3302,7 +4939,20 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3302
4939
|
options: writtenRow?.options,
|
|
3303
4940
|
instruction: writtenRow?.instruction,
|
|
3304
4941
|
instructionSeq: writtenRow?.instructionSeq,
|
|
3305
|
-
})
|
|
4942
|
+
}));
|
|
4943
|
+
/*
|
|
4944
|
+
* [2.2.9][T3][M4] 人工改判的这条 durable update 消息本身就是「完成已
|
|
4945
|
+
* 回报」的会话证据(主 Agent 亲笔写进会话日志),落盘成功后立即闭环
|
|
4946
|
+
* closure done→reported,否则派生闸会把改判行当成未回报而永久拦死
|
|
4947
|
+
* ——改判→present 是主 Agent 的正常工作流(wp-215ed52f T5/R1-1 实证)。
|
|
4948
|
+
* append 失败时不进此支:行留在 closure:'done',门禁 fail-closed,
|
|
4949
|
+
* 绝不留下无证据的已回报(与 finishRound 同一铁律)。回放侧对
|
|
4950
|
+
* status:'done' 的改判消息做同样的升级(见 reconstructFromSession),
|
|
4951
|
+
* live 与重建在同一份日志上逐行同判——W2 分叉就此封死。
|
|
4952
|
+
*/
|
|
4953
|
+
if (status === 'done') {
|
|
4954
|
+
markReported(record, session, `${record.plan.planId}:${record.dispatchedAt ?? 0}`, subtaskId);
|
|
4955
|
+
}
|
|
3306
4956
|
}
|
|
3307
4957
|
catch (error) {
|
|
3308
4958
|
pushRecordError(record, error);
|
|
@@ -3422,7 +5072,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3422
5072
|
* 「内存里已经改了、刷新后又退回去」的分叉。
|
|
3423
5073
|
*/
|
|
3424
5074
|
try {
|
|
3425
|
-
session
|
|
5075
|
+
appendUserMessage(session, buildReplanMessage(result.payload));
|
|
3426
5076
|
}
|
|
3427
5077
|
catch (error) {
|
|
3428
5078
|
return {
|
|
@@ -3577,7 +5227,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3577
5227
|
*/
|
|
3578
5228
|
const appendCancelRecord = () => {
|
|
3579
5229
|
try {
|
|
3580
|
-
session
|
|
5230
|
+
appendUserMessage(session, cancelMessage);
|
|
3581
5231
|
record.cancelRecorded = true;
|
|
3582
5232
|
record.cancelReason = reason;
|
|
3583
5233
|
return true;
|
|
@@ -3843,8 +5493,11 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3843
5493
|
book.doneBefore = Number(live.stats?.done ?? 0);
|
|
3844
5494
|
record.dispatchPromise = dispatchPlan(ctx, record, {
|
|
3845
5495
|
...base,
|
|
5496
|
+
// [2.2.0][T6/O-1a] 自动续跑同样在后台执行:保持完成即时通知。
|
|
5497
|
+
notifyCompletion: true,
|
|
3846
5498
|
signal: controller.signal,
|
|
3847
|
-
|
|
5499
|
+
// [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
|
|
5500
|
+
childTimeoutMs: options.childTimeoutMs,
|
|
3848
5501
|
idleTimeoutMs: limits.idleTimeoutMs,
|
|
3849
5502
|
totalTimeoutMs: limits.totalTimeoutMs,
|
|
3850
5503
|
maxResumes: limits.maxResumes,
|
|
@@ -3888,12 +5541,18 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3888
5541
|
* `closure:'reported'` + `report{state,at,ref,turn}`,与左侧栏 chip 同源。
|
|
3889
5542
|
* 返回本次新标记的条数;已是 reported 的行不重复写,避免每轮刷新 revision。
|
|
3890
5543
|
*/
|
|
3891
|
-
function markReported(record, session, ref) {
|
|
5544
|
+
function markReported(record, session, ref, onlySubtaskId) {
|
|
3892
5545
|
const at = Date.now();
|
|
3893
5546
|
const rawTurn = Number(state.activeTurns?.get?.(session?.id) ?? NaN);
|
|
3894
5547
|
const turn = Number.isFinite(rawTurn) ? rawTurn : null;
|
|
3895
5548
|
let changed = 0;
|
|
3896
5549
|
for (const item of Array.isArray(record?.statuses) ? record.statuses : []) {
|
|
5550
|
+
/*
|
|
5551
|
+
* [2.2.0][T6/O-1a] 即时通知只标记「刚结算的这一条」;finishRound 批量
|
|
5552
|
+
* 补齐不传 onlySubtaskId,保持原有「所有 done 未回报行」语义。
|
|
5553
|
+
*/
|
|
5554
|
+
if (onlySubtaskId !== undefined && String(item?.subtaskId) !== String(onlySubtaskId))
|
|
5555
|
+
continue;
|
|
3897
5556
|
if (item?.status !== 'done')
|
|
3898
5557
|
continue;
|
|
3899
5558
|
if (item?.closure === 'reported' && item?.report?.state === 'sent')
|
|
@@ -3915,6 +5574,49 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3915
5574
|
}
|
|
3916
5575
|
return changed;
|
|
3917
5576
|
}
|
|
5577
|
+
/**
|
|
5578
|
+
* [2.2.0][T6/O-1a] 完成即时通知的插件兜底投递器(后台轮次专用)。
|
|
5579
|
+
*
|
|
5580
|
+
* 方案 §2.3 双通道:①协议通道由子 Agent 完成即 `send_message`;②兜底通道
|
|
5581
|
+
* 由这里在 `settleFromOutput` 结算成功后立刻写一条纯文本 `user/message`
|
|
5582
|
+
* (含子任务 ID、摘要、验收计数、用时),不等待整轮结束。消息不带任何
|
|
5583
|
+
* workplan 标记,回放解析器按未知消息跳过(A2:回放是纯读)。
|
|
5584
|
+
*
|
|
5585
|
+
* 幂等:同一子任务已有 `closure:'reported'` + `report.state:'sent'` 时直接
|
|
5586
|
+
* 跳过——重复结算、finishRound 轮级批量补齐都不得重报。先写通知、后记
|
|
5587
|
+
* 回报:写失败只置 reportPending,交结果消息补齐(绝不留无证据已回报)。
|
|
5588
|
+
*/
|
|
5589
|
+
function emitSubtaskDoneNotice(record, session, subtask, verdict) {
|
|
5590
|
+
if (!record || !session || typeof session.append !== 'function')
|
|
5591
|
+
return;
|
|
5592
|
+
const row = Array.isArray(record.statuses)
|
|
5593
|
+
? record.statuses.find((item) => item?.subtaskId === subtask?.id)
|
|
5594
|
+
: null;
|
|
5595
|
+
if (row?.closure === 'reported' && row?.report?.state === 'sent')
|
|
5596
|
+
return;
|
|
5597
|
+
const acceptance = Array.isArray(verdict?.acceptance) ? verdict.acceptance : [];
|
|
5598
|
+
const passed = acceptance.filter((item) => item?.result === 'pass').length;
|
|
5599
|
+
const acceptanceCount = acceptance.length > 0
|
|
5600
|
+
? `验收 ${passed}/${acceptance.length} 通过`
|
|
5601
|
+
: '验收记录 0 条(legacy 未提供结构化验收)';
|
|
5602
|
+
const elapsedMs = Number.isFinite(Number(row?.startedAt))
|
|
5603
|
+
? Math.max(0, Date.now() - Number(row.startedAt))
|
|
5604
|
+
: 0;
|
|
5605
|
+
const elapsed = elapsedMs < 1000 ? `${elapsedMs}ms` : `${(elapsedMs / 1000).toFixed(1)}s`;
|
|
5606
|
+
const summary = truncate(String(row?.summary ?? '').replace(/\s+/g, ' ').trim(), 160) || '(无摘要)';
|
|
5607
|
+
const text = `[dsh-workplan] 子任务 ${String(subtask?.id ?? '')} 已完成并结算:${summary};${acceptanceCount};用时 ${elapsed}`;
|
|
5608
|
+
try {
|
|
5609
|
+
appendUserMessage(session, text);
|
|
5610
|
+
}
|
|
5611
|
+
catch (error) {
|
|
5612
|
+
ctx.logger?.warn?.(`dsh-workplan: 完成即时通知写入失败 ${String(subtask?.id ?? '')}:`
|
|
5613
|
+
+ `${error instanceof Error ? error.message : String(error)}`);
|
|
5614
|
+
record.reportPending = true;
|
|
5615
|
+
return;
|
|
5616
|
+
}
|
|
5617
|
+
const ref = `${record?.plan?.planId ?? 'plan'}:${record?.dispatchedAt ?? 0}`;
|
|
5618
|
+
markReported(record, session, ref, subtask?.id);
|
|
5619
|
+
}
|
|
3918
5620
|
function finishRound(record, session) {
|
|
3919
5621
|
const ref = `${record.plan?.planId ?? 'plan'}:${record.dispatchedAt ?? 0}`;
|
|
3920
5622
|
if (!record.resultWritten) {
|
|
@@ -3926,14 +5628,19 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3926
5628
|
* 绝不留下没有证据的 reported。
|
|
3927
5629
|
*/
|
|
3928
5630
|
const before = (record.statuses ?? []).map((item) => ({ ...item }));
|
|
3929
|
-
|
|
3930
|
-
// ^ 本轮结算:done 且未到 reported 的行(含旧日志的 null)都算待回报。
|
|
3931
|
-
const reported = markReported(record, session, ref);
|
|
5631
|
+
markReported(record, session, ref);
|
|
3932
5632
|
const resultMessage = buildRoundResult(record, session.id, limits);
|
|
3933
5633
|
try {
|
|
3934
|
-
session
|
|
5634
|
+
appendUserMessage(session, resultMessage);
|
|
3935
5635
|
record.resultWritten = true;
|
|
3936
|
-
|
|
5636
|
+
/*
|
|
5637
|
+
* [2.2.9][T3][M4] 标志自此只是审计镜像,一律按派生函数回填。
|
|
5638
|
+
* 旧公式 `needReport > 0 && reported < needReport` 自带第三套口径
|
|
5639
|
+
* (把旧日志 closure=null 的行也算待回报),与门禁/重建/自愈使用的
|
|
5640
|
+
* 严格 `closure==='done'` 判据并存——多套判据互不一致正是震荡的
|
|
5641
|
+
* 温床。收敛后镜像与 statuses 事实恒等,任何读取方都对得上。
|
|
5642
|
+
*/
|
|
5643
|
+
record.reportPending = deriveReportPending(record);
|
|
3937
5644
|
}
|
|
3938
5645
|
catch (error) {
|
|
3939
5646
|
// 消息没写成功 ⇒ 回报没有证据:把状态回滚成写之前的快照。
|
|
@@ -3946,10 +5653,11 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3946
5653
|
*/
|
|
3947
5654
|
pushRecordError(record, `写入结果消息失败:${error instanceof Error ? error.message : String(error)}`);
|
|
3948
5655
|
/*
|
|
3949
|
-
* [1.11.0]
|
|
3950
|
-
*
|
|
5656
|
+
* [1.11.0] 写失败时不能假装回报过。回滚后镜像同步为回滚事实
|
|
5657
|
+
* (done 行回到 closure:'done' ⇒ 派生 true),交下一次 pre-step
|
|
5658
|
+
* 自愈或下一轮 finishRound 幂等补齐(契约 §7.3 B4)。
|
|
3951
5659
|
*/
|
|
3952
|
-
record.reportPending =
|
|
5660
|
+
record.reportPending = deriveReportPending(record);
|
|
3953
5661
|
}
|
|
3954
5662
|
}
|
|
3955
5663
|
else {
|
|
@@ -3959,9 +5667,9 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3959
5667
|
*/
|
|
3960
5668
|
const pending = (record.statuses ?? []).some((item) => item?.status === 'done' && item?.closure !== 'reported');
|
|
3961
5669
|
if (pending) {
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
5670
|
+
markReported(record, session, ref);
|
|
5671
|
+
// [2.2.9][T3][M4] 镜像按派生回填:部分标记失败时不谎报「已回报」。
|
|
5672
|
+
record.reportPending = deriveReportPending(record);
|
|
3965
5673
|
}
|
|
3966
5674
|
}
|
|
3967
5675
|
/*
|
|
@@ -4066,6 +5774,15 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4066
5774
|
version: pluginVersion,
|
|
4067
5775
|
runtime: runtimeIdentity(),
|
|
4068
5776
|
planId: record.plan.planId,
|
|
5777
|
+
/*
|
|
5778
|
+
* [2.2.2][D5] 规划器档位遥测进入模型可读面。
|
|
5779
|
+
*
|
|
5780
|
+
* 之前只写进内存 record / 失败降级消息;成功计划没有可复核的
|
|
5781
|
+
* planner reasoningEffort 证据,D5 只能 CONDITIONAL。现在 status
|
|
5782
|
+
* 返回 provider/model/reasoningEffort/source/outcome/at,便于在
|
|
5783
|
+
* 真实运行态核对“规划器未继承主 Agent”。
|
|
5784
|
+
*/
|
|
5785
|
+
planner: record.planner ?? null,
|
|
4069
5786
|
running,
|
|
4070
5787
|
phase: record.phase,
|
|
4071
5788
|
elapsedMs: record.dispatchStartedAt ? Date.now() - record.dispatchStartedAt : null,
|
|
@@ -4297,13 +6014,14 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4297
6014
|
message: '这条请示已经在上报队列里,不要重复提交;停止推进,等待主 Agent 指示。',
|
|
4298
6015
|
};
|
|
4299
6016
|
}
|
|
6017
|
+
// [2.2.6][T4] 同模式共犯(T1 W4):对象感知读取,消灭 String(对象) 分支。
|
|
4300
6018
|
const options = (Array.isArray(args?.options) ? args.options : [])
|
|
4301
6019
|
.slice(0, MAX_ESCALATION_OPTIONS)
|
|
4302
|
-
.map((item) => truncate(
|
|
6020
|
+
.map((item) => truncate(needEntryText(item), 300))
|
|
4303
6021
|
.filter(Boolean);
|
|
4304
6022
|
const needs = (Array.isArray(args?.needs) ? args.needs : [])
|
|
4305
6023
|
.slice(0, 10)
|
|
4306
|
-
.map((item) => truncate(
|
|
6024
|
+
.map((item) => truncate(needEntryText(item), 300))
|
|
4307
6025
|
.filter(Boolean);
|
|
4308
6026
|
const now = Date.now();
|
|
4309
6027
|
const revision = Number(row.revision ?? 0) + 1;
|
|
@@ -4327,7 +6045,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4327
6045
|
try {
|
|
4328
6046
|
const parent = ctx.sessions?.get?.(parentId);
|
|
4329
6047
|
const written = record.statuses.find((item) => item?.subtaskId === row.subtaskId);
|
|
4330
|
-
parent
|
|
6048
|
+
appendUserMessage(parent, buildUpdateMessage({
|
|
4331
6049
|
planId: record.plan.planId,
|
|
4332
6050
|
subtaskId: row.subtaskId,
|
|
4333
6051
|
status: 'blocked',
|
|
@@ -4339,7 +6057,10 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4339
6057
|
escalatedAt: now,
|
|
4340
6058
|
escalationSeq: revision,
|
|
4341
6059
|
revision,
|
|
4342
|
-
})
|
|
6060
|
+
}));
|
|
6061
|
+
// [2.2.7] 中断即报:请示同样要让用户当下看到「有人卡在哪、等什么决定」,
|
|
6062
|
+
// 结构化 update 消息是给回放/主 Agent 的,这条纯文本是给用户的。
|
|
6063
|
+
announceSubtaskInterrupt(record, parent, row.subtaskId, `子任务 ${row.subtaskId} 执行中请求指示:${truncate(question, 160)};性质:等待主会话拍板,不是执行失败;处理:主会话答复后用 dsh_workplan_instruct 下发决定,该行将恢复执行。`);
|
|
4343
6064
|
}
|
|
4344
6065
|
catch (error) {
|
|
4345
6066
|
pushRecordError(record, error);
|
|
@@ -4571,7 +6292,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4571
6292
|
record.updatedAt = now;
|
|
4572
6293
|
try {
|
|
4573
6294
|
const written = record.statuses.find((item) => item?.subtaskId === subtaskId);
|
|
4574
|
-
session
|
|
6295
|
+
appendUserMessage(session, buildUpdateMessage({
|
|
4575
6296
|
planId: record.plan.planId,
|
|
4576
6297
|
subtaskId,
|
|
4577
6298
|
status: 'in_progress',
|
|
@@ -4579,7 +6300,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4579
6300
|
instruction: written?.instruction,
|
|
4580
6301
|
instructionSeq: revision,
|
|
4581
6302
|
revision,
|
|
4582
|
-
})
|
|
6303
|
+
}));
|
|
4583
6304
|
}
|
|
4584
6305
|
catch (error) {
|
|
4585
6306
|
pushRecordError(record, error);
|
|
@@ -4697,13 +6418,13 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4697
6418
|
});
|
|
4698
6419
|
record.updatedAt = Date.now();
|
|
4699
6420
|
try {
|
|
4700
|
-
session
|
|
6421
|
+
appendUserMessage(session, buildUpdateMessage({
|
|
4701
6422
|
planId: record.plan.planId,
|
|
4702
6423
|
subtaskId,
|
|
4703
6424
|
status: row.status,
|
|
4704
6425
|
handoffs,
|
|
4705
6426
|
revision,
|
|
4706
|
-
})
|
|
6427
|
+
}));
|
|
4707
6428
|
}
|
|
4708
6429
|
catch (error) {
|
|
4709
6430
|
pushRecordError(record, error);
|
|
@@ -4850,7 +6571,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4850
6571
|
* A wedged promise keeps the old stale escape hatch (see below).
|
|
4851
6572
|
*/
|
|
4852
6573
|
const startedAt = Number(record.dispatchStartedAt ?? 0);
|
|
4853
|
-
const staleAfter = limits.totalTimeoutMs + 120000;
|
|
6574
|
+
const staleAfter = limits.totalTimeoutMs > 0 ? limits.totalTimeoutMs + 120000 : NO_ROUND_BUDGET_MS + 120000;
|
|
4854
6575
|
if (!(startedAt > 0 && Date.now() - startedAt > staleAfter)) {
|
|
4855
6576
|
try {
|
|
4856
6577
|
await record.dispatchPromise;
|
|
@@ -4874,7 +6595,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4874
6595
|
* stops claiming the plan is running and hands the work back instead.
|
|
4875
6596
|
*/
|
|
4876
6597
|
const startedAt = Number(record.dispatchStartedAt ?? 0);
|
|
4877
|
-
const staleAfter = limits.totalTimeoutMs + 120000;
|
|
6598
|
+
const staleAfter = limits.totalTimeoutMs > 0 ? limits.totalTimeoutMs + 120000 : NO_ROUND_BUDGET_MS + 120000;
|
|
4878
6599
|
if (startedAt > 0 && Date.now() - startedAt > staleAfter) {
|
|
4879
6600
|
return {
|
|
4880
6601
|
ok: false,
|
|
@@ -4957,11 +6678,19 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
4957
6678
|
modelSelection: selection.provider && selection.model ? selection : record.modelSelection,
|
|
4958
6679
|
cwd: session.header?.cwd ?? options.cwd,
|
|
4959
6680
|
conversationContext: record.conversationContext ?? '',
|
|
6681
|
+
/*
|
|
6682
|
+
* [2.2.0][T6/O-1a] 只有后台(async)轮次推即时通知:wait 模式主 Agent
|
|
6683
|
+
* 在调用栈内等待,轮级结果消息就是该模式的完成通道,避免同一轮重复
|
|
6684
|
+
* 两条消息;既有的「每轮恰 1 条持久结果消息」断言因此保持不变。
|
|
6685
|
+
*/
|
|
6686
|
+
notifyCompletion: mode === 'async',
|
|
6687
|
+
onSubtaskDone: (recordArg, subtask, verdict) => emitSubtaskDoneNotice(recordArg, session, subtask, verdict),
|
|
4960
6688
|
};
|
|
4961
6689
|
record.dispatchPromise = dispatchPlan(ctx, record, {
|
|
4962
6690
|
...roundOptions,
|
|
4963
6691
|
signal: dispatchController.signal,
|
|
4964
|
-
|
|
6692
|
+
// [2.2.0][T4/O-3b] 传原始配置值:未配置=undefined 时协商派生生效,显式配置=兜底上限(resolveSubtaskTimeoutMs)。
|
|
6693
|
+
childTimeoutMs: options.childTimeoutMs,
|
|
4965
6694
|
idleTimeoutMs: limits.idleTimeoutMs,
|
|
4966
6695
|
totalTimeoutMs: limits.totalTimeoutMs,
|
|
4967
6696
|
maxResumes: limits.maxResumes,
|
|
@@ -5353,7 +7082,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5353
7082
|
ctx.logger?.warn?.(`dsh-workplan: 回合 ${turn} 连续 ${book.count} 次未通过交付就绪,按 B 方案放行但留痕:`
|
|
5354
7083
|
+ `${stuck.stats.done}/${stuck.stats.total},未完成 ${released.join(', ') || '无'}`);
|
|
5355
7084
|
try {
|
|
5356
|
-
session
|
|
7085
|
+
appendUserMessage(session, makeUserMessage([
|
|
5357
7086
|
`⚠️ 本轮未通过交付就绪检查,已按「放行但留痕」结束(计划 ${record.plan.planId})`,
|
|
5358
7087
|
`进度 ${stuck.stats.done}/${stuck.stats.total};未完成:${released.join(', ') || '无'}`,
|
|
5359
7088
|
'本回合的内容不是最终交付;产物若已在盘上,下一回合核验后仍可交付。',
|
|
@@ -5361,7 +7090,7 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5361
7090
|
kind: 'workplan-release',
|
|
5362
7091
|
form: 'notice',
|
|
5363
7092
|
summary: `未就绪放行 ${stuck.stats.done}/${stuck.stats.total}`,
|
|
5364
|
-
})
|
|
7093
|
+
}));
|
|
5365
7094
|
}
|
|
5366
7095
|
catch (error) {
|
|
5367
7096
|
ctx.logger?.warn?.(`dsh-workplan: 放行留痕写入失败:${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -5389,7 +7118,8 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5389
7118
|
statuses: snapshot.statuses,
|
|
5390
7119
|
attempt: book.count,
|
|
5391
7120
|
changePending: record.changeRequest?.status === 'pending',
|
|
5392
|
-
|
|
7121
|
+
// [2.2.9][T3][M4.1] 强制收尾提示与门禁同源(纯派生)。
|
|
7122
|
+
reportPending: deriveReportPending(record),
|
|
5393
7123
|
}), {
|
|
5394
7124
|
kind: 'workplan-continue',
|
|
5395
7125
|
form: 'notice',
|
|
@@ -6280,6 +8010,51 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6280
8010
|
return enterDecision(downstream, [message]);
|
|
6281
8011
|
}
|
|
6282
8012
|
let plan;
|
|
8013
|
+
/*
|
|
8014
|
+
* [2.1.6] 规划器遥测的落点:成功写进记录、失败写进降级消息,让「为什么没
|
|
8015
|
+
* 分解成功」不再是一句没有现场的「超时」。
|
|
8016
|
+
*/
|
|
8017
|
+
const plannerTelemetry = {};
|
|
8018
|
+
/*
|
|
8019
|
+
* [2.2.5][T5] 分解期间可见性——占位卡片(T1 P-5 / T3 §2 S1、§3 C1)。
|
|
8020
|
+
*
|
|
8021
|
+
* 缺陷:runPlanner 全程(最长 3 次尝试 × 300s 窗口 + 退避)此前零写入,
|
|
8022
|
+
* 用户看到的是「发出去一句话后界面没有任何反应」,无法区分「正在重试」
|
|
8023
|
+
* 与「卡死」(T1 断点层判定=未发出,插件层)。现在进入规划前先放一张
|
|
8024
|
+
* phase:'planning' 的占位记录:侧栏 4 秒轮询只要记录存在就下发(serialisePlan
|
|
8025
|
+
* 对 plan:null 已兜底),卡片徽标走既有词汇「正在安排」(client.ts LOCALE)。
|
|
8026
|
+
* 后续出口不新增路径:成功/降级由下方既有 records.set 整体覆盖;用户中止
|
|
8027
|
+
* 路径由 serialisePlan 的终态收敛(turnEnded → phase:'ended')兜住,不会
|
|
8028
|
+
* 残留假「进行中」。
|
|
8029
|
+
*/
|
|
8030
|
+
const planningStartedAt = Date.now();
|
|
8031
|
+
const planningRecord = {
|
|
8032
|
+
planId: null,
|
|
8033
|
+
plan: null,
|
|
8034
|
+
title: '正在生成任务分解…',
|
|
8035
|
+
degraded: false,
|
|
8036
|
+
statuses: [],
|
|
8037
|
+
phase: 'planning',
|
|
8038
|
+
errors: [],
|
|
8039
|
+
createdAt: planningStartedAt,
|
|
8040
|
+
updatedAt: planningStartedAt,
|
|
8041
|
+
createdTurn: payload.turn,
|
|
8042
|
+
};
|
|
8043
|
+
state.records.set(session.id, planningRecord);
|
|
8044
|
+
/*
|
|
8045
|
+
* [2.2.5][T5] 进度回调落点(T1 P-6 / T3 §3 C2/C3、§4 频率规则):
|
|
8046
|
+
* 通道 A = 占位卡片 errors 区追加重试摘要(≤2 行,保底通道);通道 B =
|
|
8047
|
+
* appendUserMessage 通知(仅「会退避重试」的失败发,≤2 条,aborted 静默)。
|
|
8048
|
+
* 文案组装与频率硬规则全部在 createPlannerProgressReporter / plannerProgressLines
|
|
8049
|
+
* (plan.ts,可独立回归);这里只注入宿主交互面。
|
|
8050
|
+
*/
|
|
8051
|
+
const onPlannerProgress = createPlannerProgressReporter({
|
|
8052
|
+
signal: payload.signal,
|
|
8053
|
+
record: planningRecord,
|
|
8054
|
+
setRecord: (record) => state.records.set(session.id, record),
|
|
8055
|
+
appendNotice: (text) => appendUserMessage(session, text),
|
|
8056
|
+
maxAttempts: PLANNER_MAX_ATTEMPTS,
|
|
8057
|
+
});
|
|
6283
8058
|
try {
|
|
6284
8059
|
plan = await runPlanner(ctx, {
|
|
6285
8060
|
taskText,
|
|
@@ -6287,7 +8062,11 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6287
8062
|
sessionId: session.id,
|
|
6288
8063
|
modelSelection,
|
|
6289
8064
|
signal: payload.signal,
|
|
6290
|
-
plannerTimeoutMs:
|
|
8065
|
+
plannerTimeoutMs: normalisePlannerWindow(options?.limits?.plannerTimeoutMs ?? options?.plannerTimeoutMs, PLANNER_TIMEOUT_MS),
|
|
8066
|
+
plannerIdleTimeoutMs: normalisePlannerWindow(options?.limits?.plannerIdleTimeoutMs ?? options?.plannerIdleTimeoutMs, PLANNER_IDLE_TIMEOUT_MS),
|
|
8067
|
+
telemetry: plannerTelemetry,
|
|
8068
|
+
// [2.2.5][T5] 分解期间进度事件(T1 P-6):只追加观察回调,不改重试语义。
|
|
8069
|
+
onProgress: onPlannerProgress,
|
|
6291
8070
|
conversationContext,
|
|
6292
8071
|
sourceMessageIds: human.map((message) => message.id).filter((id) => typeof id === 'string'),
|
|
6293
8072
|
/*
|
|
@@ -6297,7 +8076,9 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6297
8076
|
* and asks for `estimateMinutes` on every subtask.
|
|
6298
8077
|
*/
|
|
6299
8078
|
budget: {
|
|
6300
|
-
totalMinutes:
|
|
8079
|
+
totalMinutes: Number(options?.limits?.totalTimeoutMs ?? TOTAL_TIMEOUT_MS) > 0
|
|
8080
|
+
? Math.max(1, Math.round(Number(options.limits.totalTimeoutMs) / 60000))
|
|
8081
|
+
: 0,
|
|
6301
8082
|
childMinutes: Math.max(1, Math.round(Number(options?.limits?.childTimeoutMs ?? CHILD_TIMEOUT_MS) / 60000)),
|
|
6302
8083
|
concurrency: MAX_CONCURRENT,
|
|
6303
8084
|
maxResumes: Number(options?.limits?.maxResumes ?? MAX_PLAN_RESUMES),
|
|
@@ -6305,8 +8086,17 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6305
8086
|
});
|
|
6306
8087
|
}
|
|
6307
8088
|
catch (error) {
|
|
6308
|
-
if (payload.signal.aborted)
|
|
8089
|
+
if (payload.signal.aborted) {
|
|
8090
|
+
/*
|
|
8091
|
+
* [2.2.5][T5] 用户中止:静默退出(T3 §2 中止分支,不发通知)。占位卡片
|
|
8092
|
+
* 若本轮前无旧记录,交给 serialisePlan 终态收敛转 'ended',不留假
|
|
8093
|
+
* 「进行中」;若本轮前已有旧计划记录,恢复它——中止不该把用户上一份
|
|
8094
|
+
* 终态进度从内存里挤掉(旧实现中止路径不写记录,此行为保持不变)。
|
|
8095
|
+
*/
|
|
8096
|
+
if (existing?.plan)
|
|
8097
|
+
state.records.set(session.id, existing);
|
|
6309
8098
|
return downstream;
|
|
8099
|
+
}
|
|
6310
8100
|
const planId = `wp-${randomUUID()}`;
|
|
6311
8101
|
const createdAt = Date.now();
|
|
6312
8102
|
const message = buildDegradedMessage({
|
|
@@ -6315,6 +8105,7 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6315
8105
|
createdTurn: payload.turn,
|
|
6316
8106
|
createdAt,
|
|
6317
8107
|
error: error instanceof Error ? error.message : String(error),
|
|
8108
|
+
detail: plannerTelemetryLine(plannerTelemetry),
|
|
6318
8109
|
taskText,
|
|
6319
8110
|
});
|
|
6320
8111
|
state.records.set(session.id, {
|
|
@@ -6323,6 +8114,7 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6323
8114
|
title: '自动分解降级',
|
|
6324
8115
|
degraded: true,
|
|
6325
8116
|
error: error instanceof Error ? error.message : String(error),
|
|
8117
|
+
planner: { ...plannerTelemetry, at: createdAt },
|
|
6326
8118
|
statuses: [],
|
|
6327
8119
|
phase: 'degraded',
|
|
6328
8120
|
errors: [truncate(error instanceof Error ? error.message : String(error), 1000)],
|
|
@@ -6332,8 +8124,12 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6332
8124
|
});
|
|
6333
8125
|
return enterDecision(downstream, [message]);
|
|
6334
8126
|
}
|
|
6335
|
-
if (payload.signal.aborted)
|
|
8127
|
+
if (payload.signal.aborted) {
|
|
8128
|
+
// [2.2.5][T5] 计划已生成但回合被中止:同中止分支,恢复旧记录再静默退出。
|
|
8129
|
+
if (existing?.plan)
|
|
8130
|
+
state.records.set(session.id, existing);
|
|
6336
8131
|
return downstream;
|
|
8132
|
+
}
|
|
6337
8133
|
const planId = `wp-${randomUUID()}`;
|
|
6338
8134
|
const createdAt = Date.now();
|
|
6339
8135
|
const fullPlan = attachPlanMeta(plan, {
|
|
@@ -6348,6 +8144,9 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6348
8144
|
statuses: createStatuses(fullPlan),
|
|
6349
8145
|
phase: 'pending',
|
|
6350
8146
|
errors: [],
|
|
8147
|
+
// [2.1.6] 规划这一步花了多久、用的哪个模型:成功也留痕,失败才好对比。
|
|
8148
|
+
// [2.1.7] 抢救成功的计划保留 SALVAGED 判定,别被 'ok' 覆盖——它是复盘的关键证据。
|
|
8149
|
+
planner: { ...plannerTelemetry, outcome: plannerTelemetry.outcome === 'SALVAGED' ? 'SALVAGED' : 'ok', at: createdAt },
|
|
6351
8150
|
createdAt,
|
|
6352
8151
|
updatedAt: createdAt,
|
|
6353
8152
|
dispatchedAt: null,
|
|
@@ -6380,7 +8179,9 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
6380
8179
|
* cancels the stale plan ("计划已取消:上一轮未派发") and plans again.
|
|
6381
8180
|
*/
|
|
6382
8181
|
const planMessage = buildPlanMessage(fullPlan, {
|
|
6383
|
-
totalBudgetMinutes:
|
|
8182
|
+
totalBudgetMinutes: Number(options?.limits?.totalTimeoutMs ?? TOTAL_TIMEOUT_MS) > 0
|
|
8183
|
+
? Math.max(1, Math.round(Number(options.limits.totalTimeoutMs) / 60000))
|
|
8184
|
+
: 0,
|
|
6384
8185
|
maxResumes: Number(options?.limits?.maxResumes ?? MAX_PLAN_RESUMES),
|
|
6385
8186
|
planMode,
|
|
6386
8187
|
autoDispatched,
|
|
@@ -6506,6 +8307,7 @@ export function statusToolOutputSchema() {
|
|
|
6506
8307
|
// [1.8.14] Loaded-build identity: version alone cannot prove which bytes
|
|
6507
8308
|
// the process is running after a rebuild or a profile recomposition.
|
|
6508
8309
|
runtime: { type: 'object' },
|
|
8310
|
+
planner: { oneOf: [{ type: 'object' }, { type: 'null' }] },
|
|
6509
8311
|
deliveryReady: { type: 'boolean' },
|
|
6510
8312
|
deliveryBlockers: { type: 'array' },
|
|
6511
8313
|
deliveryRemaining: { type: 'array' },
|