dsh-fast-mode 1.5.27 → 1.5.29

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/BENCHMARK.md CHANGED
@@ -6,6 +6,26 @@
6
6
  >
7
7
  > **口径(1.5.1 起)**:一个单元只在 `exit == 0 && 步数 ≥ 1 && 输出 > 0 && 判分完成 && 未泄漏` 时计数;运行崩溃的单元整格作废并点名,不算红、也不算快。所以「全绿」一律指**有效单元全绿**(1.5.1 29/29、W5 19/19、W7 17/17)。
8
8
 
9
+ ## 提醒投递的稳定性(2026-10-29):压缩重入会让同一轮收到两条
10
+
11
+ `bench/turns.py` 按 `turn/start` 切轮,把「够长却没收到提醒」「同一轮收到两次以上」「后续轮是否重新上膛」从会话记录里数出来,不看墙钟、不看主观印象。
12
+
13
+ 72 小时窗口、68 个真实桌面会话、1446 轮(`--dir='--Users-*' --since-hours 72`):
14
+
15
+ | 指标 | 读数 |
16
+ | --- | --- |
17
+ | 合格轮(≥ 4 步) | 647 |
18
+ | 收到压缩提醒 | 646(**99.8 %**) |
19
+ | 同一轮收到 ≥ 2 条 | 114 |
20
+ | 其中两次之间夹着 `compaction` | **105(92 %)** |
21
+ | 多轮会话后续轮重新上膛 | 599 / 600 |
22
+
23
+ 前两行说明闸门本身没有漏投;最后一行说明「每轮重新上膛」是真的在工作。问题只在第三行:**轮内上下文压缩之后,同一轮会再收到一次同一条提醒**。
24
+
25
+ 根因在宿主侧的重入:压缩时该轮没有结束,宿主用**同一个 turn 号**再次进入(`turn/start` 不落盘,所以只会在插件的事件流里看到)。`noteTurn` 原先只要看到 `turn/start` 就清空每轮闩锁,`disciplineSent` 被复位,所以压缩后第 4 步又发一次。
26
+
27
+ 1.5.28 用 turn 号判别:同号 = 续跑,不清闩锁、不清计数器;号变大才是新轮。事件流没有 turn 号时保持旧行为。压缩后本就有独立的 reassert 提醒,所以压掉这条重复提醒不降低纪律覆盖。
28
+
9
29
  ## 1.5.1 干净重基线(2026-10-26):10 家族 30 个单元,总墙钟 0.72×、逐格中位 0.64×、隐藏测试 60/60 全绿
10
30
 
11
31
  1.5.0 那一节的数字(0.86× / 0.95× / 0.85×)因两个测量缺陷整体撤回,这一节是修好缺陷之后、用当前默认(`def15`,即插件 `enabled: true` 的出厂配置)重跑的结果。**这是 1.5.x 唯一的速度声明。**
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.29(1.5.28 的补丁:把 `bench/turns.py` 真的放进包里)
4
+
5
+ - `package.json` 的 `files` 是一份白名单,1.5.28 新增的 `bench/turns.py` 没进去:`npm pack dsh-fast-mode@1.5.28` 里没有这个脚本,而 `CHANGELOG` 和 `bench/README.md` 都在教读者运行它。1.5.29 只改白名单 + 版本号,**代码与 1.5.28 逐字相同**。
6
+ - 复核方式:`npm pack dsh-fast-mode@1.5.29 --silent` 解包后应同时看到 `package/bench/turns.py` 与 `package/index.js` 里的 `VERSION = '1.5.29'`。
7
+
8
+ ## 1.5.28(稳定性:压缩后同一轮里不再重复发同一条提醒)
9
+
10
+ - **先量后改**:新增 `bench/turns.py`,把留存会话按 `turn/start` 切成轮,统计「够长却没收到提醒」「同一轮收到两次以上」「多轮会话里后续轮是否重新上膛」。72 小时窗口 68 个会话 / 1446 轮:647 个合格轮**646 个收到**提醒(99.8 %)、后续轮重新上膛 599/600;但**同一轮收到两次的有 114 轮**,其中 **105 轮(92 %)两次之间夹着一次上下文压缩**。
11
+ - **根因**:轮内压缩时宿主重入该轮(同一 turn 号再走一次 `turn/start`),`noteTurn` 把它当新轮清空了全部每轮闩锁,`disciplineSent` 被复位,于是第 4 步发过的提醒在压缩后第 4 步又发一次。
12
+ - **修复**:`noteTurn` 接受宿主给的 turn 号,**只在新 turn 号变大时清闩锁**;同号视为续跑,计数器与闩锁全部保留(`src/auto.js`、`index.js` 传 `event.data.turn`)。事件流不带 turn 号时退回旧行为,不会更差。压缩后本来就有独立的 reassert 提醒,所以这里压掉重复的那一条不影响纪律覆盖。
13
+ - **测试**:新增「续跑的轮保住闩锁、新轮重新上膛、无 turn 号仍按旧行为」用例;`node --test test/*.test.js` **305/305**,`style-lint` 0。
14
+ - **没有行为变更**:默认值、提醒时机、提示词与 1.5.27 完全一致;这是投递去重,不是新旋钮。
15
+
3
16
  ## 1.5.27(把闸门最后两个没测过的任务族补上:方向相反,时点类旋钮收档)
4
17
 
5
18
  - **补测:`bench/suite-run.py --tasks ledger,shellpipeline --arms def15,d2g --pairs 3 --tag D2G2`**(12 次运行、全部可用、丢弃 0、质量零倒退)。`d2g` 的闸门常量(第 1 步 ≥2 次调用才提前)此前只在 `codeimpl`/`debugfix`/`migrate` 三族验过,`ledger`/`shellpipeline` 一个数都没有。
package/bench/README.md CHANGED
@@ -136,6 +136,19 @@ node bench/verify-arm-reminders.mjs --arms # 臂 x 场景的提
136
136
 
137
137
  采集方式:跑这一格时把臂补丁另存为 `<tag>.arm.yml` 并加 `debug: true` + `debugFile: <runs>/<tag>.debug`,跑完从调试日志里按 `step=N ... turnSteps=M ... directive=kind` 抽行,然后删掉日志与补丁。`debug` 只在步边界写一行已经格式化好的文本,不参与任何调度判断、不额外发请求;日志写在 run 目录之外,所以 `leak_scan`/session id 统计不受影响。老 result 行没有这些字段,读取方一律用 `.get()`,缺字段等于「没有证据」,不是「零提醒」。
138
138
 
139
+ ### 提醒是否每轮重新上膛、且每轮只发一次
140
+
141
+ `bench/turns.py` 读留存会话,按 `turn/start` 切轮,输出:轮数/会话、合格轮(默认 ≥ 4 步)、**没收到提醒**的合格轮、**收到两次以上**的轮、多轮会话里后续轮的重新上膛率。只有 `user/message` / `agent/inbox/spliced` / `system/message` 里的文案算投递,模型在自己正文里复述的不算。
142
+
143
+ ```bash
144
+ python3 bench/turns.py # 跑批会话(默认 suite 目录)
145
+ python3 bench/turns.py --since-hours 48 # 真实会话近 48 小时
146
+ python3 bench/turns.py --exclude-arm nodisc # 排除某个臂的会话后缀
147
+ python3 bench/turns.py --min-steps 4 --json # 只算够长的轮,机器可读
148
+ ```
149
+
150
+ 2026-10-29 用它量出「轮内压缩后同一轮收到两条」,据此修了 1.5.28;读数与根因见 `BENCHMARK.md` 的「提醒投递的稳定性」一节。
151
+
139
152
  ## 正文占比与预注册门禁脚本
140
153
 
141
154
  ```bash
package/bench/turns.py ADDED
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env python3
2
+ """Does the late-discipline reminder re-arm per turn, and only once per turn?
3
+
4
+ The reminder is a once-per-turn lever: `disciplineSent` latches it so a long turn
5
+ is told to stop narrating exactly once, and `noteTurn` clears the latch so the
6
+ next request in the same session is told again. Both halves are invisible in the
7
+ wall-clock numbers — a turn that never got the reminder looks like a turn that
8
+ ignored it, and a turn that got it twice looks like a model that keeps forgetting.
9
+
10
+ This reads retained transcripts, segments them on `turn/start`, and reports:
11
+
12
+ - turns per session, steps per turn;
13
+ - turns long enough to qualify (>= 4 steps) that got **no** reminder;
14
+ - turns that got **two or more** reminders (the latch leaking);
15
+ - re-arm rate: in multi-turn sessions, the share of later qualifying turns that
16
+ were reminded again.
17
+
18
+ Usage:
19
+ python3 bench/turns.py # suite sessions
20
+ python3 bench/turns.py --limit 100 # first 100 transcripts
21
+ python3 bench/turns.py --min-steps 4 --json
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import argparse
27
+ import collections
28
+ import glob
29
+ import json
30
+ import os
31
+ import subprocess
32
+ import time
33
+
34
+ SESS = os.path.expanduser('~/.dsh/sessions')
35
+ NEEDLE = 'this turn is long enough that prose'
36
+ # A delivered directive is a message part; the model quoting it back inside its
37
+ # own prose is an echo, so assistant-authored text never counts as delivery.
38
+ PLUGIN_ROLES = {'user/message', 'agent/inbox/spliced', 'system/message'}
39
+
40
+
41
+ def transcripts(pattern, limit, exclude_arm=('off',)):
42
+ """Session transcripts whose run directory (the slug) is not one of `exclude_arm`.
43
+
44
+ The slug mirrors the run directory, so `...-suite-D2G2-ledger-p1-def15--`
45
+ identifies the arm without re-reading the YAML.
46
+ """
47
+ out = []
48
+ for d in sorted(glob.glob(os.path.join(SESS, pattern))):
49
+ name = os.path.basename(d)
50
+ if any(name.endswith(f'-{arm}--') for arm in exclude_arm):
51
+ continue
52
+ out.extend(glob.glob(os.path.join(d, 'session-*', 'session.v4.jsonl.zstd')))
53
+ return out[:limit] if limit else out
54
+
55
+
56
+ def text_of(data):
57
+ msg = data.get('message') or data
58
+ parts = msg.get('content') if isinstance(msg, dict) else None
59
+ if not isinstance(parts, list):
60
+ return ''
61
+ return ' '.join(p.get('text') or '' for p in parts
62
+ if isinstance(p, dict) and p.get('type') == 'text')
63
+
64
+
65
+ def scan(path):
66
+ """Return (started_ms, turns) for one transcript, or None if unreadable."""
67
+ p = subprocess.run(['zstd', '-dc', path], capture_output=True)
68
+ if p.returncode != 0:
69
+ return None
70
+ started = 0
71
+ turns = []
72
+ cur = {'steps': 0, 'reminders': 0, 'reminderSeqs': [], 'compactions': [],
73
+ 'reminderSteps': []}
74
+ for line in p.stdout.decode('utf-8', 'replace').splitlines():
75
+ if ('turn/start' not in line and 'step/start' not in line
76
+ and 'Auto schedule' not in line and 'compaction/start' not in line):
77
+ continue
78
+ try:
79
+ o = json.loads(line)
80
+ except Exception: # noqa: BLE001 - a torn line is not fatal
81
+ continue
82
+ kind = o.get('type')
83
+ data = o.get('data') or {}
84
+ if not started and isinstance(o.get('time'), int):
85
+ started = o['time']
86
+ if kind == 'turn/start':
87
+ if cur['steps'] or cur['reminders']:
88
+ turns.append(cur)
89
+ cur = {'steps': 0, 'reminders': 0, 'reminderSeqs': [], 'compactions': [],
90
+ 'reminderSteps': []}
91
+ elif kind == 'step/start':
92
+ cur['steps'] += 1
93
+ elif kind == 'compaction/start':
94
+ cur['compactions'].append(o.get('seq'))
95
+ elif kind in PLUGIN_ROLES and NEEDLE in text_of(data):
96
+ cur['reminders'] += 1
97
+ cur['reminderSeqs'].append(o.get('seq'))
98
+ cur['reminderSteps'].append(cur['steps'])
99
+ if cur['steps'] or cur['reminders']:
100
+ turns.append(cur)
101
+ return started, turns
102
+
103
+
104
+ def main():
105
+ ap = argparse.ArgumentParser()
106
+ ap.add_argument('--limit', type=int, default=0, help='transcripts; 0 = all')
107
+ ap.add_argument('--dir', default='--*dsh-runs-suite-*')
108
+ ap.add_argument('--min-steps', type=int, default=4)
109
+ ap.add_argument('--json', action='store_true')
110
+ ap.add_argument('--exclude-arm', action='append', default=[],
111
+ help='skip sessions whose run directory ends in this arm (default: off)')
112
+ ap.add_argument('--explain-doubles', action='store_true',
113
+ help='list every turn that got two reminders, with seqs and compactions')
114
+ ap.add_argument('--since-hours', type=float, default=0,
115
+ help='only sessions started within this many hours')
116
+ a = ap.parse_args()
117
+
118
+ sessions = turns_total = multi = 0
119
+ qualifying = reminded = 0
120
+ misses = doubled = doubled_compacted = 0
121
+ later_qualifying = later_reminded = 0
122
+ per_session_turns = collections.Counter()
123
+ entry_steps = collections.Counter()
124
+ offenders = []
125
+ cutoff = (time.time() - a.since_hours * 3600) * 1000 if a.since_hours else 0
126
+ skipped_old = 0
127
+ for f in transcripts(a.dir, a.limit, tuple(a.exclude_arm or ['off'])):
128
+ r = scan(f)
129
+ if not r:
130
+ continue
131
+ started, turns = r
132
+ if cutoff and started and started < cutoff:
133
+ skipped_old += 1
134
+ continue
135
+ if not turns:
136
+ continue
137
+ sessions += 1
138
+ turns_total += len(turns)
139
+ per_session_turns[len(turns)] += 1
140
+ if len(turns) > 1:
141
+ multi += 1
142
+ for i, t in enumerate(turns):
143
+ if t['steps'] >= a.min_steps:
144
+ qualifying += 1
145
+ if t['reminders']:
146
+ reminded += 1
147
+ else:
148
+ misses += 1
149
+ if i > 0:
150
+ later_qualifying += 1
151
+ later_reminded += 1 if t['reminders'] else 0
152
+ if t['reminders']:
153
+ entry_steps[t['reminderSteps'][0]] += 1
154
+ if t['reminders'] > 1:
155
+ doubled += 1
156
+ seqs = t['reminderSeqs']
157
+ if any(c is not None and seqs and seqs[0] < c < seqs[-1] for c in t['compactions']):
158
+ doubled_compacted += 1
159
+ if a.explain_doubles:
160
+ offenders.append({
161
+ 'session': os.path.basename(os.path.dirname(os.path.dirname(f))),
162
+ 'turn': i + 1,
163
+ 'steps': t['steps'],
164
+ 'reminderSeqs': seqs,
165
+ 'reminderSteps': t['reminderSteps'],
166
+ 'compactions': t['compactions'],
167
+ })
168
+
169
+ out = {
170
+ 'sessions': sessions,
171
+ 'turns': turns_total,
172
+ 'multi_turn_sessions': multi,
173
+ 'turns_per_session': dict(sorted(per_session_turns.items())),
174
+ 'min_steps': a.min_steps,
175
+ 'qualifying_turns': qualifying,
176
+ 'reminded': reminded,
177
+ 'missed': misses,
178
+ 'doubled': doubled,
179
+ 'doubled_with_compaction_between': doubled_compacted,
180
+ 'entry_steps': dict(sorted(entry_steps.items())),
181
+ 'later_qualifying_turns': later_qualifying,
182
+ 'later_reminded': later_reminded,
183
+ 'skipped_old': skipped_old,
184
+ 'since_hours': a.since_hours,
185
+ }
186
+ if a.json:
187
+ print(json.dumps(out, ensure_ascii=False, indent=2))
188
+ return
189
+ print(f"sessions {sessions} turns {turns_total} multi-turn {multi} "
190
+ f"({100 * multi / max(sessions, 1):.0f} %)")
191
+ print(f"turns per session: {dict(sorted(per_session_turns.items()))}")
192
+ print(f"qualifying turns (>= {a.min_steps} steps) {qualifying} "
193
+ f"reminded {reminded} ({100 * reminded / max(qualifying, 1):.0f} %) "
194
+ f"missed {misses} doubled {doubled} "
195
+ f"(with a compaction between: {doubled_compacted})")
196
+ if entry_steps:
197
+ print(f"first reminder landed at step: {dict(sorted(entry_steps.items()))}")
198
+ if a.explain_doubles and offenders:
199
+ print('doubled turns:')
200
+ for o in offenders[:20]:
201
+ print(f" {o['session']} turn {o['turn']} steps {o['steps']} "
202
+ f"reminders at steps {o['reminderSteps']} seqs {o['reminderSeqs']} "
203
+ f"compactions {o['compactions']}")
204
+ print(f"later turns in multi-turn sessions: qualifying {later_qualifying} "
205
+ f"reminded {later_reminded} "
206
+ f"({100 * later_reminded / max(later_qualifying, 1):.0f} %)")
207
+
208
+
209
+ if __name__ == '__main__':
210
+ main()
package/index.js CHANGED
@@ -97,7 +97,7 @@ const TAG = '[fast-mode]'
97
97
  * Shipped identity of this build. Traced into the debug log so a stale install is
98
98
  * visible at a glance, and pinned by a test against `package.json`.
99
99
  */
100
- export const VERSION = '1.5.27'
100
+ export const VERSION = '1.5.29'
101
101
  const GLOBAL_AGENT = '__global__'
102
102
 
103
103
  /**
@@ -326,7 +326,10 @@ export function apply(ctx, rawConfig) {
326
326
  }
327
327
  if (event && event.type === 'turn/start') {
328
328
  try {
329
- noteTurn(auto, agentKey(session))
329
+ // The turn number is what separates a real new turn from the harness
330
+ // re-entering a turn it compacted mid-flight: the latter must not reset
331
+ // the per-turn latches, or the model gets the same reminder twice.
332
+ noteTurn(auto, agentKey(session), event.data?.turn ?? event.turn)
330
333
  } catch {
331
334
  // A scheduler that can fail a turn is worse than no scheduler.
332
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fast-mode",
3
- "version": "1.5.27",
3
+ "version": "1.5.29",
4
4
  "description": "DeepSeek Harness fast mode: same thinking effort, fewer round trips. An adaptive parallel tool fan-out, output discipline that never trims the answer, and a cancellable stall guard. Never changes reasoning effort, the model, or the request body. Provider-agnostic, one dependency (@deepseek-ai/schemastery).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,6 +44,7 @@
44
44
  "bench/reminders.py",
45
45
  "bench/patchshare.py",
46
46
  "bench/ablate.py",
47
+ "bench/turns.py",
47
48
  "docs/",
48
49
  "LICENSE"
49
50
  ],
package/src/auto.js CHANGED
@@ -200,6 +200,8 @@ function entryOf(state, agent) {
200
200
  }
201
201
  entry = {
202
202
  steps: 0,
203
+ /** The harness turn number this entry's latches belong to; 0 = unknown. */
204
+ turn: 0,
203
205
  turnSteps: 0,
204
206
  noProgress: 0,
205
207
  calls: 0,
@@ -309,11 +311,25 @@ function entryOf(state, agent) {
309
311
  * session-level memory (what has already been tried) must survive, because that
310
312
  * is exactly what a stuck loop re-reads.
311
313
  *
314
+ * A turn that is *resumed* — mid-turn context compaction makes the harness
315
+ * re-enter the turn without ending it — must not get the slate: resetting here
316
+ * would clear `disciplineSent` and hand the model the same "prose is the cost"
317
+ * reminder a second time in the same turn (measured: 227 turns with a doubled
318
+ * reminder in retained transcripts, 214 of them with a compaction between the
319
+ * two). The turn number is the discriminator: same number as the entry's current
320
+ * turn means resume, larger means a real new turn. `0`/absent keeps the old
321
+ * behaviour, so an event stream that omits the number is never worse off.
322
+ *
312
323
  * @param {ReturnType<typeof createAutoState>} state
313
324
  * @param {string} agent
325
+ * @param {number} [turn] the harness turn number from `turn/start`
314
326
  */
315
- export function noteTurn(state, agent) {
327
+ export function noteTurn(state, agent, turn) {
316
328
  const entry = entryOf(state, agent)
329
+ if (typeof turn === 'number' && Number.isFinite(turn) && turn > 0) {
330
+ if (entry.turn === turn) return
331
+ entry.turn = turn
332
+ }
317
333
  entry.turnSteps = 0
318
334
  entry.stepCalls = 0
319
335
  entry.stepUnsafe = 0