dsh-workplan 1.8.18 → 1.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +354 -0
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/client.js +55 -4
- package/docs/postmortem-1.8.7-20261031.md +113 -0
- package/docs/release-notes-1.9.1.md +67 -0
- package/lib/auto-resume.js +175 -0
- package/lib/client.js +2605 -0
- package/lib/host.js +134 -5
- package/lib/plan.js +295 -12
- package/lib/runtime.js +892 -63
- package/lib/supersede-digest.js +115 -0
- package/lib/supersede.js +378 -0
- package/package.json +2 -2
- package/src/auto-resume.ts +246 -0
- package/src/client.ts +59 -3
- package/src/host.ts +152 -4
- package/src/plan.ts +308 -12
- package/src/runtime.ts +925 -61
- package/src/supersede-digest.ts +116 -0
- package/src/supersede.ts +429 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# v1.9.1 — 圈注三行能自己变绿,1.9.0 的四项遗留全修完
|
|
2
|
+
|
|
3
|
+
## 一句话
|
|
4
|
+
|
|
5
|
+
`dsh_workplan_followup` 让被中止的子会话在**用户授权后自己再跑完一个正常回合**,
|
|
6
|
+
界面据此变绿;同时把 1.9.0 明确留到「下一批」的四项(superseded 写侧、P1 拒绝码、
|
|
7
|
+
W1 digest、W5 真实取消联测)全部落地。npm 上此前最新是 **1.8.18**,`1.9.0` 与
|
|
8
|
+
`1.9.1` 都从未发布,所以升到 1.9.1 会一次性拿到 1.9.0 与 1.9.1 的全部修复。
|
|
9
|
+
|
|
10
|
+
## 你会看到什么变化
|
|
11
|
+
|
|
12
|
+
| 之前 | 现在 |
|
|
13
|
+
|---|---|
|
|
14
|
+
| 被整轮预算 / 900s 上限中止的子会话永远是灰点(`lastTurnCompleted=false`),改台账也不会变绿 | `dsh_workplan_followup` 把说明投递给父会话登记过的**直接**子会话;子会话自己跑完一轮后 `turn/end` 正常,界面自然变绿 |
|
|
15
|
+
| 想把一个已取消计划的交付责任转给另一个计划,只能手改记录 → 重启后 live 与 replay 分叉 | `dsh_workplan_cancel` 支持 `disposition:'superseded'` + `supersededBy`,V1–V8 核验全过才写、`coverage`/`digest` 由运行时复算,append 成功才翻内存状态 |
|
|
16
|
+
| 全部子任务 done 但证据有缺口时,`present` 的拒绝码是 `ACTIVE_NOT_READY`,用户分不清「没做完」和「证据不齐」 | 统一走 `activeDenyCode()`:`remaining` 空 + `blockers` 非空 ⇒ `EVIDENCE_GAP`,其余 ⇒ `ACTIVE_NOT_READY`;拒绝文案不变 |
|
|
17
|
+
| 覆盖映射存进日志后无法复核是否被改动 | `sha256(canonical(mapping))` 规范化摘要(sort_keys + 紧凑分隔符 + 非 ASCII 不转义),读侧只重算、不信任缓存值,重算不一致即 stale |
|
|
18
|
+
| 取消 / 取代的信封只在单测里用桩件验证 | W5 联测直接走真实 `buildCancelMessage` 信封 → durable 记录 → replay 读回,覆盖两种处置与终态互斥 |
|
|
19
|
+
|
|
20
|
+
## 修复内容
|
|
21
|
+
|
|
22
|
+
### 1. `dsh_workplan_followup`(1.9.1 主体)
|
|
23
|
+
|
|
24
|
+
- 只允许根会话调用;目标必须是父会话 `subagent/catalog` 里登记的**直接**子会话。
|
|
25
|
+
- 只投递、不改状态:不写台账、不触发 `present`、不改 `lastTurnCompleted`;
|
|
26
|
+
是否变绿由子会话自己的下一轮 `turn/end` 决定。
|
|
27
|
+
- 拒绝码:`NOT_ROOT` / `NOT_DIRECT_CHILD` / `NO_SUBAGENT_SERVICE` / `DELIVERY_FAILED`;
|
|
28
|
+
空 message 或超 4000 字符直接拒绝。
|
|
29
|
+
|
|
30
|
+
### 2. superseded 写侧(唯一入口)
|
|
31
|
+
|
|
32
|
+
- `src/supersede.ts`:`supersedePlanRecord()` 是 `superseded` 的唯一写路径;
|
|
33
|
+
V1–V8 任一失败返回 `ok:false` + `SUPERSEDE_*` 码,**不改内存、不写日志**。
|
|
34
|
+
- `src/plan.ts`:`buildCancelMessage(..., { disposition:'superseded' })` 是全仓库唯一
|
|
35
|
+
拼装 `workplan-cancel` 信封的出口;自动覆盖路径只允许写 `cancelled`。
|
|
36
|
+
- 用户确认(V8)必须是真实用户消息:同时包含两个 planId 且含
|
|
37
|
+
「确认/同意/可以/按此执行」之一;模型自述不算确认。
|
|
38
|
+
|
|
39
|
+
### 3. P1 拒绝码统一
|
|
40
|
+
|
|
41
|
+
- `PRESENT_DENY_CODES` + `activeDenyCode()` 收敛 `present` 的两个未完成分支;
|
|
42
|
+
码值对外可断言,文案逐字保留;`EVIDENCE_GAP` 散落字符串 0 处。
|
|
43
|
+
|
|
44
|
+
### 4. W1 digest
|
|
45
|
+
|
|
46
|
+
- `src/supersede-digest.ts`:`canonicalMappingJson()` / `computeMappingDigest()` /
|
|
47
|
+
`verifyMappingDigest()` / `withMappingDigest()`;摘要只证明「存下来的 mapping
|
|
48
|
+
没被改动」,不证明两项工作在语义上等价。
|
|
49
|
+
|
|
50
|
+
### 5. W5 真实取消信封联测
|
|
51
|
+
|
|
52
|
+
- `tests/workplan-w5-cancel-e2e.test.ts` 5 例:1.8.19 真实信封字段契约不变、
|
|
53
|
+
事故同构场景、生产写路径 schema 一致、D2 未放宽、superseded 增量字段降级可读。
|
|
54
|
+
|
|
55
|
+
## 升级与兼容
|
|
56
|
+
|
|
57
|
+
- 旧调用不受影响:`dsh_workplan_cancel` 的 `disposition` 缺省仍是 `cancelled`。
|
|
58
|
+
- 旧会话可回放:`superseded` 是增量字段,旧读侧按 `cancelled` 降级可读。
|
|
59
|
+
- 需要 Node ≥ 22(`engines.node` 未变)。
|
|
60
|
+
|
|
61
|
+
## 证据(发布时复核)
|
|
62
|
+
|
|
63
|
+
- `npm run check` EXIT 0(无诊断)。
|
|
64
|
+
- `npm test` EXIT 0:**306 / 306**(1.9.0 基线 277,净增 29)。
|
|
65
|
+
- 两次构建 7 个产物(`lib/*.js` + `client.js`)sha256 完全一致。
|
|
66
|
+
- `npm pack`:产物清单、体积与 `shasum` 在发布记录 `docs/release-record-1.9.1-20261101.md` 中逐项登记
|
|
67
|
+
(本文件自身也在包内,因此不在此处写会随本文件变化的体积数字)。
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [1.10.4][auto-resume] Automatic continuation of a plan whose round budget ran out.
|
|
3
|
+
*
|
|
4
|
+
* Why this module exists
|
|
5
|
+
* ----------------------
|
|
6
|
+
* The 2026-11-01 incident: subtask T12 was killed by the whole-round budget
|
|
7
|
+
* (`TOTAL_TIMEOUT`, 20 min) at 15:31:26, reset to `pending`, and then **never
|
|
8
|
+
* ran again** — the plan stayed `paused` until a human dispatched it 24 minutes
|
|
9
|
+
* later. `shouldRetryAttempt()` is right to refuse `ABORTED`/`TOTAL_TIMEOUT`
|
|
10
|
+
* *inside* a round: that round has no budget left, so a retry would be cut by
|
|
11
|
+
* the same blade. The missing layer is not "retry the child"; it is
|
|
12
|
+
* "start the next round" — a new deadline, the same plan, and `done` work
|
|
13
|
+
* never re-run.
|
|
14
|
+
*
|
|
15
|
+
* This module owns only the decision table (`should we continue?`). It is a
|
|
16
|
+
* pure function with no timer, no I/O and no record mutation, so every branch
|
|
17
|
+
* can be pinned by a unit test without mounting the host. The runtime supplies
|
|
18
|
+
* the bookkeeping; `src/runtime.ts` owns the timer.
|
|
19
|
+
*
|
|
20
|
+
* Safety stance (the reason it is more than a loop)
|
|
21
|
+
* -------------------------------------------------
|
|
22
|
+
* Automatic recovery must never manufacture a green result. Therefore:
|
|
23
|
+
* - it only ever continues a `paused` plan; `blocked` means a real failure and
|
|
24
|
+
* is repaired by a human adjudication or the resume budget, never silently;
|
|
25
|
+
* - `done` rows are never re-run (the resumer calls `resetBlockedStatuses`,
|
|
26
|
+
* which only clears blocked/in_progress, and a paused round leaves them
|
|
27
|
+
* `pending`);
|
|
28
|
+
* - it never adjudicates evidence: every continuation goes through the normal
|
|
29
|
+
* child path (`settleFromOutput` → `deliveryReadiness`), so "all done" is
|
|
30
|
+
* still decided by structured evidence;
|
|
31
|
+
* - "all done but evidence gaps" stops here on purpose (`NOTHING_PENDING`):
|
|
32
|
+
* re-running a done subtask cannot fix a missing acceptance item, it only
|
|
33
|
+
* produces duplicate work and a chance to overwrite the evidence.
|
|
34
|
+
*
|
|
35
|
+
* Default: **off**. See `AUTO_RESUME_DEFAULTS.enabled`.
|
|
36
|
+
*/
|
|
37
|
+
/** Tunables that are policy, not deployment config. */
|
|
38
|
+
export const AUTO_RESUME_DEFAULTS = Object.freeze({
|
|
39
|
+
/**
|
|
40
|
+
* [1.10.6] On by default.
|
|
41
|
+
*
|
|
42
|
+
* The 2026-11-01 user verdict on the previous "off by default" stance was
|
|
43
|
+
* unambiguous: a subtask killed by the round budget sat untouched for 1h57m
|
|
44
|
+
* and the only reason was a flag nobody had been told to flip. A recovery
|
|
45
|
+
* feature that ships silent is indistinguishable from a missing one.
|
|
46
|
+
*
|
|
47
|
+
* Every safety branch below still applies when this is on (cancel, plan mode,
|
|
48
|
+
* blocked rows, no-progress, attempt cap), and `autoResume: false` in the
|
|
49
|
+
* profile or `DSH_WORKPLAN_AUTO_RESUME=0` turns it off for one deployment.
|
|
50
|
+
*/
|
|
51
|
+
enabled: true,
|
|
52
|
+
/** How many continuation rounds one plan may start without a human. */
|
|
53
|
+
maxAttempts: 2,
|
|
54
|
+
/** Delay before the first continuation round. */
|
|
55
|
+
baseDelayMs: 30_000,
|
|
56
|
+
/** Upper bound of the exponential backoff. */
|
|
57
|
+
maxDelayMs: 300_000,
|
|
58
|
+
/** Consecutive continuation rounds that completed no new subtask before stopping. */
|
|
59
|
+
stallLimit: 1,
|
|
60
|
+
});
|
|
61
|
+
/** Hard cap for a configured attempt budget (0 disables the chain). */
|
|
62
|
+
export const AUTO_RESUME_MAX_ATTEMPTS_CAP = 4;
|
|
63
|
+
/**
|
|
64
|
+
* Clamp a configured attempt budget.
|
|
65
|
+
*
|
|
66
|
+
* Non-numeric input falls back to the default instead of disabling the feature
|
|
67
|
+
* silently; only an explicit in-range number is honoured.
|
|
68
|
+
*
|
|
69
|
+
* @param value - configured value, if any.
|
|
70
|
+
* @returns an integer within `[0, AUTO_RESUME_MAX_ATTEMPTS_CAP]`.
|
|
71
|
+
*/
|
|
72
|
+
export function autoResumeAttemptCap(value) {
|
|
73
|
+
const numeric = Number(value);
|
|
74
|
+
if (!Number.isFinite(numeric))
|
|
75
|
+
return AUTO_RESUME_DEFAULTS.maxAttempts;
|
|
76
|
+
return Math.min(AUTO_RESUME_MAX_ATTEMPTS_CAP, Math.max(0, Math.floor(numeric)));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* [1.10.6] Resolve the feature flag from profile config + environment.
|
|
80
|
+
*
|
|
81
|
+
* Explicit config wins; an explicit environment value wins over the default;
|
|
82
|
+
* anything unset falls back to `AUTO_RESUME_DEFAULTS.enabled` (now true).
|
|
83
|
+
* Values are read the same way for both sources so `0/false/no/off` turn it off
|
|
84
|
+
* instead of being treated as "present, therefore on".
|
|
85
|
+
*
|
|
86
|
+
* @param configValue - `autoResume` from the profile config, if any.
|
|
87
|
+
* @param envValue - `DSH_WORKPLAN_AUTO_RESUME`, if set.
|
|
88
|
+
* @returns whether automatic continuation rounds are allowed.
|
|
89
|
+
*/
|
|
90
|
+
export function autoResumeEnabledFrom(configValue, envValue) {
|
|
91
|
+
if (typeof configValue === 'boolean')
|
|
92
|
+
return configValue;
|
|
93
|
+
const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim();
|
|
94
|
+
if (raw !== '') {
|
|
95
|
+
if (/^(1|true|yes|on)$/i.test(raw))
|
|
96
|
+
return true;
|
|
97
|
+
if (/^(0|false|no|off)$/i.test(raw))
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return AUTO_RESUME_DEFAULTS.enabled === true;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Decide whether one more round may start, and when.
|
|
104
|
+
*
|
|
105
|
+
* Branch order is the contract (first match wins):
|
|
106
|
+
* 1. feature flag / no plan
|
|
107
|
+
* 2. user stop (`cancelled`, `superseded`) — never resurrect a decision
|
|
108
|
+
* 3. already running / plan mode
|
|
109
|
+
* 4. only a `paused` phase is auto-continuable
|
|
110
|
+
* 5. nothing pending (includes "all done, evidence gap" — human work)
|
|
111
|
+
* 6. any `blocked` row — a real failure, not a budget artifact
|
|
112
|
+
* 7. attempt / progress budgets
|
|
113
|
+
*
|
|
114
|
+
* @param input - the frozen facts of the round that just ended.
|
|
115
|
+
* @returns the decision plus a model-readable reason.
|
|
116
|
+
*/
|
|
117
|
+
export function decideAutoResume(input) {
|
|
118
|
+
const attempt = Math.max(0, Math.floor(Number(input.attempt) || 0));
|
|
119
|
+
const maxAttempts = Math.max(0, Math.floor(Number(input.maxAttempts) || 0));
|
|
120
|
+
const stop = (code, reason) => ({
|
|
121
|
+
action: 'stop',
|
|
122
|
+
code,
|
|
123
|
+
reason,
|
|
124
|
+
attempt,
|
|
125
|
+
delayMs: 0,
|
|
126
|
+
});
|
|
127
|
+
if (input.enabled !== true) {
|
|
128
|
+
return stop('AUTO_RESUME_DISABLED', '自动续跑开关未开启(默认关闭)');
|
|
129
|
+
}
|
|
130
|
+
if (input.degraded === true || Number(input.total) <= 0) {
|
|
131
|
+
return stop('NO_PLAN', '没有可续跑的计划(自动分解降级或子任务数为 0)');
|
|
132
|
+
}
|
|
133
|
+
if (input.cancelled === true || input.phase === 'cancelled') {
|
|
134
|
+
return stop('CANCELLED', '用户已取消:自动重来等于违背停下的决定');
|
|
135
|
+
}
|
|
136
|
+
if (input.phase === 'superseded') {
|
|
137
|
+
return stop('SUPERSEDED', '责任已转移到承接计划,本计划不得自动续跑');
|
|
138
|
+
}
|
|
139
|
+
if (input.running === true) {
|
|
140
|
+
return stop('ALREADY_RUNNING', '已有一轮在跑,不能并发再开一轮');
|
|
141
|
+
}
|
|
142
|
+
if (input.planMode === true) {
|
|
143
|
+
return stop('PLAN_MODE', 'plan 模式下计划只供审阅,不自动执行');
|
|
144
|
+
}
|
|
145
|
+
if (input.phase !== 'paused') {
|
|
146
|
+
return stop('PHASE_NOT_PAUSED', `计划阶段是 ${String(input.phase ?? 'unknown')},只有 paused(预算到点)才自动续跑`);
|
|
147
|
+
}
|
|
148
|
+
if (Number(input.pending) <= 0) {
|
|
149
|
+
/*
|
|
150
|
+
* Also the evidence-gap case: all rows done but deliveryReady=false.
|
|
151
|
+
* Re-running done work is forbidden by the delivery contract; the gap can
|
|
152
|
+
* only be closed by a human re-adjudication, so stop and say so.
|
|
153
|
+
*/
|
|
154
|
+
return stop('NOTHING_PENDING', '没有 pending 项:若仍未就绪,那是证据缺口,需主 Agent 复核,不能靠重跑 done 项解决');
|
|
155
|
+
}
|
|
156
|
+
if (Number(input.blocked) > 0) {
|
|
157
|
+
return stop('HAS_BLOCKED', `存在 ${input.blocked} 个 blocked 子任务:那是真实失败,需人工改判或显式续跑,不自动修复`);
|
|
158
|
+
}
|
|
159
|
+
if (attempt >= maxAttempts) {
|
|
160
|
+
return stop('BUDGET_EXHAUSTED', `自动续跑已用满 ${maxAttempts} 轮,交给主 Agent 决定`);
|
|
161
|
+
}
|
|
162
|
+
if (Number(input.noProgressRounds) >= Math.max(1, Number(input.stallLimit) || 1)) {
|
|
163
|
+
return stop('NO_PROGRESS', `连续 ${input.noProgressRounds} 轮没有新增完成项,停止空转`);
|
|
164
|
+
}
|
|
165
|
+
const base = Math.max(0, Number(input.baseDelayMs) || 0);
|
|
166
|
+
const cap = Math.max(base, Number(input.maxDelayMs) || base);
|
|
167
|
+
const delayMs = Math.min(cap, base * Math.pow(2, attempt));
|
|
168
|
+
return {
|
|
169
|
+
action: 'schedule',
|
|
170
|
+
code: 'SCHEDULED',
|
|
171
|
+
reason: `第 ${attempt + 1}/${maxAttempts} 轮自动续跑将在 ${Math.round(delayMs / 1000)}s 后开始`,
|
|
172
|
+
attempt: attempt + 1,
|
|
173
|
+
delayMs,
|
|
174
|
+
};
|
|
175
|
+
}
|