dsh-fast-mode 1.5.29 → 1.5.31
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 +17 -0
- package/bench/README.md +14 -0
- package/bench/replay.mjs +154 -0
- package/bench/turns.py +22 -3
- package/index.js +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.31(`turns.py` 顺手审另一条提醒:压缩后重述规则的那条,会不会无理由地多出来)
|
|
4
|
+
|
|
5
|
+
- 插件只主动发两条提醒:入场步的「少写散文」(每轮恰好一次)和压缩后的「规则重申」(每次压缩后一次,因为规则可能被裁掉)。`bench/turns.py` 原来只审第一条,第二条只当噪音忽略——如果它的标志位泄漏,就会在每个合格轮里白送一段规则文本。
|
|
6
|
+
- 新增读数:有多少轮带过重述、其中有多少轮的重述条数**超过**该轮的压缩次数 + 1(+1 是允许的:压缩发生在上一轮末尾时,重申落在下一轮第一步)。近 72 小时真实会话:**624 轮**带重述,**0 轮**没有压缩可指。
|
|
7
|
+
- 同时把「首次提醒落在第几步」的直方图、`--explain-doubles`(列出每个重复提醒的轮、步号、seq 与压缩点)固化进脚本,方便下次换版本时重跑对照。
|
|
8
|
+
- 只动 `bench/turns.py` 与文档,`src/` 无改动。
|
|
9
|
+
|
|
10
|
+
## 1.5.30(把 1.5.28 的修复拿真实流量做 A/B:同一份会话,同一串事件,两个版本)
|
|
11
|
+
|
|
12
|
+
- **新增 `bench/replay.mjs`**:把一份留存会话的事件流原样喂给插件自己的钩子(`session/event` + `agent/pre-step`),数出「这一版会发几条提醒、落在第几步」。会话 id 是合成的,`metrics`/`benchmarkFile` 关掉,不碰 `~/.dsh` 状态。
|
|
13
|
+
- **量化修复效果**:轮内压缩时宿主用**同一个 turn 号**重入该轮,而这次重入不落盘——所以真实会话记录里看不到它,只看得到「同一轮两条提醒」。`--simulate-reentry` 在每次 `compaction/start` 后按当前 turn 号补发一条 `turn/start`,把这个假设显式化:
|
|
14
|
+
- 1.5.27 的接线(`noteTurn` 不知道 turn 号):1529 个合格轮里 **940 轮**会被发两次以上;
|
|
15
|
+
- 1.5.28 的接线:同样 1529 轮 **0 轮**;
|
|
16
|
+
- 单会话对照更直观:`session-1ee3a310` 111 个合格轮,旧版 82 轮重复(最长的 121 号轮在第 4/13/38/65/102 步各发一次),新版 0 轮。
|
|
17
|
+
- **真实流量侧读数不变**:`bench/turns.py` 近 72 小时 651 个合格轮里 120 轮真收到两条、其中 110 轮两次之间夹着压缩,与重入假设一致。
|
|
18
|
+
- **没有行为变更**:只加脚本、改文档与版本号;`src/` 与 1.5.29 逐字相同。
|
|
19
|
+
|
|
3
20
|
## 1.5.29(1.5.28 的补丁:把 `bench/turns.py` 真的放进包里)
|
|
4
21
|
|
|
5
22
|
- `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 逐字相同**。
|
package/bench/README.md
CHANGED
|
@@ -136,6 +136,20 @@ 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/replay.mjs` 把留存会话的事件流喂回插件自己的钩子(`session/event` + `agent/pre-step`),输出每一轮的步数、压缩次数、提醒条数与落点。会话 id 是合成的,`metrics`/`benchmarkFile` 关掉,不写任何 `~/.dsh` 状态。
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
node bench/replay.mjs ~/.dsh/sessions/<slug>/session-<uuid>/session.v4.jsonl.zstd
|
|
145
|
+
node bench/replay.mjs <transcript> --json
|
|
146
|
+
node bench/replay.mjs <transcript> --simulate-reentry # 每次压缩后按当前 turn 号重入
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`turns.py` 同时审两条提醒:入场步的「少写散文」(每轮恰好一次)与压缩后的「规则重申」(每次压缩后一次)。后者允许比该轮压缩次数多一条(压缩发生在上一轮末尾时重申落在下一轮第一步),超过就是标志位泄漏;近 72 小时真实会话是 624 轮带重申、0 轮无压缩可指。`--explain-doubles` 会逐条列出重复提醒所在的轮、步号、seq 与压缩点。
|
|
150
|
+
|
|
151
|
+
`--simulate-reentry` 补的是会话记录里**不存在**的那条事件:宿主压缩后重入同一轮时用同一个 turn 号再发一次 `turn/start`,而这次重入不落盘。加上它以后,1.5.27 与 1.5.28 的差别就能在同一份数据上量出来(1529 个合格轮:940 → 0)。
|
|
152
|
+
|
|
139
153
|
### 提醒是否每轮重新上膛、且每轮只发一次
|
|
140
154
|
|
|
141
155
|
`bench/turns.py` 读留存会话,按 `turn/start` 切轮,输出:轮数/会话、合格轮(默认 ≥ 4 步)、**没收到提醒**的合格轮、**收到两次以上**的轮、多轮会话里后续轮的重新上膛率。只有 `user/message` / `agent/inbox/spliced` / `system/message` 里的文案算投递,模型在自己正文里复述的不算。
|
package/bench/replay.mjs
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Replay one retained transcript through the plugin's own hooks.
|
|
4
|
+
*
|
|
5
|
+
* The reminder is delivered at a step boundary, so a transcript could only ever
|
|
6
|
+
* count *delivered* reminders, never the ones the plugin would have sent under a
|
|
7
|
+
* different version. This replays the recorded event stream into `apply()` with a
|
|
8
|
+
* stand-in context, counts what the scheduler decides to emit, and prints one
|
|
9
|
+
* line per turn: steps, reminders, and the step each reminder landed on.
|
|
10
|
+
*
|
|
11
|
+
* That is how the 1.5.28 latch fix is checked against real traffic instead of
|
|
12
|
+
* synthetic test events: same transcript, same hook order, two versions of
|
|
13
|
+
* `noteTurn`, two counts.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* node bench/replay.mjs ~/.dsh/sessions/<slug>/session-<uuid>/session.v4.jsonl.zstd
|
|
17
|
+
* node bench/replay.mjs <transcript> --min-steps 4 --json
|
|
18
|
+
* node bench/replay.mjs <transcript> --simulate-reentry
|
|
19
|
+
*
|
|
20
|
+
* `--simulate-reentry` adds the event the transcript cannot show: after each
|
|
21
|
+
* `compaction/start` it re-fires `turn/start` with the same turn number, which is
|
|
22
|
+
* the hypothesis for the doubled reminders (the harness re-enters a turn it
|
|
23
|
+
* compacted mid-flight, and that re-entry is not persisted). With the event
|
|
24
|
+
* added, the pre-1.5.28 latch resets and the same turn is reminded twice; with
|
|
25
|
+
* the turn guard it is not.
|
|
26
|
+
*
|
|
27
|
+
* The session id is synthetic, so the run never touches `~/.dsh` state; metrics
|
|
28
|
+
* and benchmark output are switched off in the config passed to `apply()`.
|
|
29
|
+
*/
|
|
30
|
+
import { execFileSync } from 'node:child_process'
|
|
31
|
+
import { readFileSync } from 'node:fs'
|
|
32
|
+
|
|
33
|
+
import { apply } from '../index.js'
|
|
34
|
+
|
|
35
|
+
const NEEDLE = 'prose is now the cost'
|
|
36
|
+
const CONFIG = { enabled: true, gear: 'auto', outputDiscipline: 'late', metrics: false, benchmarkFile: '' }
|
|
37
|
+
|
|
38
|
+
/** Minimal stand-in for the Cordis context: handlers plus a silent logger. */
|
|
39
|
+
function fakeContext() {
|
|
40
|
+
const handlers = new Map()
|
|
41
|
+
return {
|
|
42
|
+
handlers,
|
|
43
|
+
on(event, handler) {
|
|
44
|
+
handlers.set(event, handler)
|
|
45
|
+
return () => handlers.delete(event)
|
|
46
|
+
},
|
|
47
|
+
inject: () => undefined,
|
|
48
|
+
get: () => undefined,
|
|
49
|
+
logger: { info: () => {} },
|
|
50
|
+
fire(event, ...args) {
|
|
51
|
+
const handler = handlers.get(event)
|
|
52
|
+
if (!handler) return undefined
|
|
53
|
+
return handler(...args)
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Decide the way the harness does: enter, and keep whatever the plugin added. */
|
|
59
|
+
const preStep = (ctx, agentId, step) => {
|
|
60
|
+
const decision = {
|
|
61
|
+
kind: 'enter',
|
|
62
|
+
messages: [{ id: 'sys', role: 'system', content: [] }, { id: `last-${step}`, role: 'assistant', content: [] }],
|
|
63
|
+
}
|
|
64
|
+
return ctx.fire('agent/pre-step', { agent: { id: agentId }, messages: [] }, async () => decision)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const events = path => {
|
|
68
|
+
const raw = path.endsWith('.zstd')
|
|
69
|
+
? execFileSync('zstd', ['-dc', path], { maxBuffer: 1 << 30 })
|
|
70
|
+
: readFileSync(path)
|
|
71
|
+
const out = []
|
|
72
|
+
for (const line of raw.toString('utf8').split('\n')) {
|
|
73
|
+
if (!line.trim()) continue
|
|
74
|
+
try {
|
|
75
|
+
out.push(JSON.parse(line))
|
|
76
|
+
} catch {
|
|
77
|
+
// a torn tail line is not fatal: the replay is a census, not a forensic read
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const reminderText = notice => {
|
|
84
|
+
const text = notice?.content?.[0]?.text ?? ''
|
|
85
|
+
return text.includes(NEEDLE)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function main() {
|
|
89
|
+
const argv = process.argv.slice(2)
|
|
90
|
+
const path = argv.find(arg => !arg.startsWith('--'))
|
|
91
|
+
if (!path) throw new Error('usage: node bench/replay.mjs <transcript.jsonl.zstd> [--min-steps N] [--json]')
|
|
92
|
+
const minSteps = Number(argv[argv.indexOf('--min-steps') + 1]) || 4
|
|
93
|
+
const asJson = argv.includes('--json')
|
|
94
|
+
const reentry = argv.includes('--simulate-reentry')
|
|
95
|
+
|
|
96
|
+
const ctx = fakeContext()
|
|
97
|
+
apply(ctx, CONFIG)
|
|
98
|
+
const session = { id: 'replay' }
|
|
99
|
+
const turns = []
|
|
100
|
+
let cur = { steps: 0, reminders: [], compactions: 0, turnNo: 0 }
|
|
101
|
+
for (const event of events(path)) {
|
|
102
|
+
const type = event.type
|
|
103
|
+
const data = event.data ?? {}
|
|
104
|
+
if (type === 'turn/start') {
|
|
105
|
+
if (cur.steps || cur.reminders.length) turns.push(cur)
|
|
106
|
+
cur = { steps: 0, reminders: [], compactions: 0, turnNo: data.turn ?? turns.length + 1 }
|
|
107
|
+
await ctx.fire('session/event', session, event)
|
|
108
|
+
} else if (type === 'step/start') {
|
|
109
|
+
cur.steps += 1
|
|
110
|
+
await ctx.fire('session/event', session, event)
|
|
111
|
+
const decision = await preStep(ctx, session.id, cur.steps)
|
|
112
|
+
const added = (decision?.messages ?? []).filter(message => message?.source?.form === 'notice' && reminderText(message))
|
|
113
|
+
if (added.length) cur.reminders.push(cur.steps)
|
|
114
|
+
} else if (type === 'compaction/start') {
|
|
115
|
+
cur.compactions += 1
|
|
116
|
+
await ctx.fire('session/event', session, event)
|
|
117
|
+
if (reentry) {
|
|
118
|
+
// Same turn number, delivered the way the harness delivers it: the event
|
|
119
|
+
// exists in the hook stream but never reaches the transcript.
|
|
120
|
+
await ctx.fire('session/event', session, { type: 'turn/start', turn: cur.turnNo, time: event.time })
|
|
121
|
+
}
|
|
122
|
+
} else if (type === 'compaction/end') {
|
|
123
|
+
await ctx.fire('session/event', session, event)
|
|
124
|
+
} else if (type === 'assistant/message' || type === 'tool/call' || type === 'tool/result') {
|
|
125
|
+
await ctx.fire('session/event', session, event)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (cur.steps || cur.reminders.length) turns.push(cur)
|
|
129
|
+
|
|
130
|
+
const rows = turns.map((turn, index) => ({
|
|
131
|
+
turn: index + 1,
|
|
132
|
+
steps: turn.steps,
|
|
133
|
+
compactions: turn.compactions,
|
|
134
|
+
reminders: turn.reminders.length,
|
|
135
|
+
at: turn.reminders,
|
|
136
|
+
}))
|
|
137
|
+
if (asJson) {
|
|
138
|
+
console.log(JSON.stringify({ path, minSteps, simulateReentry: reentry, turns: rows }, null, 2))
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
const qualifying = rows.filter(row => row.steps >= minSteps)
|
|
142
|
+
const doubled = qualifying.filter(row => row.reminders > 1)
|
|
143
|
+
console.log(`${path}`)
|
|
144
|
+
for (const row of qualifying) {
|
|
145
|
+
console.log(` turn ${row.turn}: steps ${row.steps} compactions ${row.compactions} `
|
|
146
|
+
+ `reminders ${row.reminders}${row.at.length ? ` at ${row.at.join(',')}` : ''}`)
|
|
147
|
+
}
|
|
148
|
+
console.log(`qualifying turns (>= ${minSteps} steps) ${qualifying.length} doubled ${doubled.length}`)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
main().catch(error => {
|
|
152
|
+
console.error(error.message)
|
|
153
|
+
process.exit(1)
|
|
154
|
+
})
|
package/bench/turns.py
CHANGED
|
@@ -33,6 +33,11 @@ import time
|
|
|
33
33
|
|
|
34
34
|
SESS = os.path.expanduser('~/.dsh/sessions')
|
|
35
35
|
NEEDLE = 'this turn is long enough that prose'
|
|
36
|
+
# The other notice the plugin can deliver, the one that restates the rules after a
|
|
37
|
+
# compaction. It is *supposed* to repeat, once per compaction whose rules were
|
|
38
|
+
# evicted; the audit question is only whether it ever fires with no compaction to
|
|
39
|
+
# point at, which would mean a stale flag.
|
|
40
|
+
REASSERT = 'the context was just compacted'
|
|
36
41
|
# A delivered directive is a message part; the model quoting it back inside its
|
|
37
42
|
# own prose is an echo, so assistant-authored text never counts as delivery.
|
|
38
43
|
PLUGIN_ROLES = {'user/message', 'agent/inbox/spliced', 'system/message'}
|
|
@@ -70,10 +75,11 @@ def scan(path):
|
|
|
70
75
|
started = 0
|
|
71
76
|
turns = []
|
|
72
77
|
cur = {'steps': 0, 'reminders': 0, 'reminderSeqs': [], 'compactions': [],
|
|
73
|
-
'reminderSteps': []}
|
|
78
|
+
'reminderSteps': [], 'reasserts': 0}
|
|
74
79
|
for line in p.stdout.decode('utf-8', 'replace').splitlines():
|
|
75
80
|
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
|
|
81
|
+
and 'Auto schedule' not in line and 'compaction/start' not in line
|
|
82
|
+
and 'context was just compacted' not in line):
|
|
77
83
|
continue
|
|
78
84
|
try:
|
|
79
85
|
o = json.loads(line)
|
|
@@ -87,11 +93,13 @@ def scan(path):
|
|
|
87
93
|
if cur['steps'] or cur['reminders']:
|
|
88
94
|
turns.append(cur)
|
|
89
95
|
cur = {'steps': 0, 'reminders': 0, 'reminderSeqs': [], 'compactions': [],
|
|
90
|
-
|
|
96
|
+
'reminderSteps': [], 'reasserts': 0}
|
|
91
97
|
elif kind == 'step/start':
|
|
92
98
|
cur['steps'] += 1
|
|
93
99
|
elif kind == 'compaction/start':
|
|
94
100
|
cur['compactions'].append(o.get('seq'))
|
|
101
|
+
elif kind in PLUGIN_ROLES and REASSERT in text_of(data):
|
|
102
|
+
cur['reasserts'] += 1
|
|
95
103
|
elif kind in PLUGIN_ROLES and NEEDLE in text_of(data):
|
|
96
104
|
cur['reminders'] += 1
|
|
97
105
|
cur['reminderSeqs'].append(o.get('seq'))
|
|
@@ -121,6 +129,7 @@ def main():
|
|
|
121
129
|
later_qualifying = later_reminded = 0
|
|
122
130
|
per_session_turns = collections.Counter()
|
|
123
131
|
entry_steps = collections.Counter()
|
|
132
|
+
reasserted = reassert_orphan = 0
|
|
124
133
|
offenders = []
|
|
125
134
|
cutoff = (time.time() - a.since_hours * 3600) * 1000 if a.since_hours else 0
|
|
126
135
|
skipped_old = 0
|
|
@@ -151,6 +160,12 @@ def main():
|
|
|
151
160
|
later_reminded += 1 if t['reminders'] else 0
|
|
152
161
|
if t['reminders']:
|
|
153
162
|
entry_steps[t['reminderSteps'][0]] += 1
|
|
163
|
+
if t['reasserts']:
|
|
164
|
+
reasserted += 1
|
|
165
|
+
# One reassert belongs to a compaction from the previous turn: the
|
|
166
|
+
# flag is set, the turn ends, the next step of the next turn speaks.
|
|
167
|
+
if t['reasserts'] > len(t['compactions']) + 1:
|
|
168
|
+
reassert_orphan += 1
|
|
154
169
|
if t['reminders'] > 1:
|
|
155
170
|
doubled += 1
|
|
156
171
|
seqs = t['reminderSeqs']
|
|
@@ -178,6 +193,8 @@ def main():
|
|
|
178
193
|
'doubled': doubled,
|
|
179
194
|
'doubled_with_compaction_between': doubled_compacted,
|
|
180
195
|
'entry_steps': dict(sorted(entry_steps.items())),
|
|
196
|
+
'turns_with_compaction_reassert': reasserted,
|
|
197
|
+
'reasserts_without_compaction': reassert_orphan,
|
|
181
198
|
'later_qualifying_turns': later_qualifying,
|
|
182
199
|
'later_reminded': later_reminded,
|
|
183
200
|
'skipped_old': skipped_old,
|
|
@@ -195,6 +212,8 @@ def main():
|
|
|
195
212
|
f"(with a compaction between: {doubled_compacted})")
|
|
196
213
|
if entry_steps:
|
|
197
214
|
print(f"first reminder landed at step: {dict(sorted(entry_steps.items()))}")
|
|
215
|
+
print(f"compaction re-assert: {reasserted} turns carried one, "
|
|
216
|
+
f"{reassert_orphan} had more of them than compactions to point at")
|
|
198
217
|
if a.explain_doubles and offenders:
|
|
199
218
|
print('doubled turns:')
|
|
200
219
|
for o in offenders[:20]:
|
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.
|
|
100
|
+
export const VERSION = '1.5.31'
|
|
101
101
|
const GLOBAL_AGENT = '__global__'
|
|
102
102
|
|
|
103
103
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-fast-mode",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.31",
|
|
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",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"bench/patchshare.py",
|
|
46
46
|
"bench/ablate.py",
|
|
47
47
|
"bench/turns.py",
|
|
48
|
+
"bench/replay.mjs",
|
|
48
49
|
"docs/",
|
|
49
50
|
"LICENSE"
|
|
50
51
|
],
|