@magic6/dsh-compaction-policy-engine 0.5.9 → 0.5.11
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 +67 -0
- package/README.md +36 -17
- package/cordis.patch.yml +47 -33
- package/docs/DESIGN.md +13 -3
- package/docs/PLAN-oversize.md +70 -0
- package/lib/index.js +10 -55
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,73 @@ All notable changes to this project are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.5.10] - 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Fixed — installing the plugin now actually takes over compaction
|
|
10
|
+
|
|
11
|
+
The bundle shipped its engine row `disabled: true`, on the theory that "superseding the
|
|
12
|
+
stock engine is a deployment decision". That reasoning silently assumed the stock engine
|
|
13
|
+
was *running*. On a preset-based host it is not: `dsh-web-app` — which backs both the
|
|
14
|
+
`web` and `desktop` profiles — disables the host-plane `compaction-basic` itself. So with
|
|
15
|
+
this plugin installed there were **two disabled engines and no owner of `ctx.compaction`**:
|
|
16
|
+
|
|
17
|
+
- the settings card rendered and returned the configured threshold;
|
|
18
|
+
- `engine up` printed nothing, because the engine never mounted;
|
|
19
|
+
- nothing compacted, ever.
|
|
20
|
+
|
|
21
|
+
Observed on a Win11 `desktop` profile: a session grew to 158,118 tokens and then could
|
|
22
|
+
not compact at all. Four forced compactions ran (two in turn 27, one in turn 28, one
|
|
23
|
+
manual `/compact`) and every one came back `context_length_exceeded` from the gateway,
|
|
24
|
+
because the summary request has to carry the same oversized history that triggered it.
|
|
25
|
+
The session was unrecoverable — retrying sent the same request, and compaction could not
|
|
26
|
+
shrink it.
|
|
27
|
+
|
|
28
|
+
The fix is for the bundle to do both halves of the swap in one place:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
- id: compaction-basic
|
|
32
|
+
disabled: true
|
|
33
|
+
|
|
34
|
+
- insert:
|
|
35
|
+
- id: compaction-control
|
|
36
|
+
name: '@magic6/dsh-compaction-policy-engine/engine'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Uninstalling removes both, so the stock engine comes back automatically. The plugin can no
|
|
40
|
+
longer leave a profile with no compaction at all.
|
|
41
|
+
|
|
42
|
+
`ctx.compaction` is a **single-slot service**, not an agreement between engines: a second
|
|
43
|
+
engine in the same context throws `service "compaction" has been registered at
|
|
44
|
+
<BasicCompactionEngine>` during construction and never mounts (the host only prints
|
|
45
|
+
`dsh: warning: 1 entry did not activate`). That is why "leave the stock engine enabled as
|
|
46
|
+
a late backstop" is not an option — verified by hand on the same Win11 host.
|
|
47
|
+
|
|
48
|
+
### Fixed — a test fixture that hid the bug
|
|
49
|
+
|
|
50
|
+
`e2e/run.sh` wrote `- id: compaction-control / disabled: false` into the fixture profile.
|
|
51
|
+
That was intended to mean "the engine has to be on for the test to run", but it also meant
|
|
52
|
+
the suite could never observe the bundle's own default. Every scenario stayed green while
|
|
53
|
+
the shipped bundle was unusable.
|
|
54
|
+
|
|
55
|
+
The fixture now overrides only `config:`, leaving `disabled` at whatever the bundle ships.
|
|
56
|
+
`fired` additionally asserts that the engine printed its own `[compaction] engine up:` line
|
|
57
|
+
before it judges anything about thresholds — the precondition that the old suite silently
|
|
58
|
+
assumed.
|
|
59
|
+
|
|
60
|
+
Regression check with the corrected fixture (same suite, same fake provider):
|
|
61
|
+
|
|
62
|
+
| version | result |
|
|
63
|
+
|:--|:--|
|
|
64
|
+
| `0.5.9` (buggy) | **0 passed, 1 failed** — "our engine never started", plus "no compaction fired" |
|
|
65
|
+
| this release | 2 passed, 0 failed |
|
|
66
|
+
|
|
67
|
+
### Changed — README
|
|
68
|
+
|
|
69
|
+
The mounting section now states that installing the plugin *is* the takeover, that the
|
|
70
|
+
stock row must be disabled because the seam is single-slot, and that uninstalling restores
|
|
71
|
+
it. The two silent-bad-combination warnings keep their original text but now name which
|
|
72
|
+
one this release fixed.
|
|
73
|
+
|
|
7
74
|
## [0.5.9] - 2026-11-25
|
|
8
75
|
|
|
9
76
|
### Fixed — three bugs that only a real host could expose
|
package/README.md
CHANGED
|
@@ -86,38 +86,55 @@ cd dsh-compaction-policy-engine
|
|
|
86
86
|
dsh plugin --profile web add "$PWD"
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
包本身是 bundle
|
|
89
|
+
包本身是 bundle,**装上即接管压缩**:
|
|
90
90
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
91
|
+
- 把官方 `compaction-basic` 行设为 `disabled: true`;
|
|
92
|
+
- **启用**引擎行(`compaction-control`);
|
|
93
|
+
- companion 行(`compaction-control-settings`)始终启用,负责设置卡片与上下文提示词;
|
|
93
94
|
它**不**认领 `ctx.compaction`。
|
|
94
95
|
|
|
96
|
+
卸载插件时这三件事一起消失:`compaction-basic` 的覆盖随 bundle 走,官方引擎自动恢复。
|
|
97
|
+
**不会出现「卸掉插件后什么都不压缩」的状态**,这一点有 e2e 守着(见 `e2e/` 的 `fired` 场景)。
|
|
98
|
+
|
|
99
|
+
### 为什么必须自己关官方引擎
|
|
100
|
+
|
|
101
|
+
`ctx.compaction` 是**单槽服务**,不是两个引擎之间的约定:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
super(ctx, "compaction") // 第二个 -> 'service "compaction" has been registered at …'
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
同一 context 里放第二个引擎**不会**退化成「低阈值赢」,而是在构造时抛错、那一行根本不挂载。
|
|
108
|
+
所以「留着官方引擎当兜底」不成立——要么关掉它,要么本插件无法启动。
|
|
109
|
+
|
|
110
|
+
> **上一版(≤0.5.9)出厂把引擎设成 `disabled: true`**,理由是「替换官方引擎属于部署决策」。
|
|
111
|
+
> 那条推理默认官方引擎**正在运行**;而 `dsh-web-app`(`web` / `desktop` profile)本来就把宿主
|
|
112
|
+
> 平面的 `compaction-basic` 停了。两边都没开 → 设置卡片正常渲染、阈值读得回来、压缩一次都不触发。
|
|
113
|
+
> Win11 上一个会话就是这样涨到 158k token,随后四次压缩全被上游拒绝。见 CHANGELOG 0.5.10。
|
|
114
|
+
|
|
95
115
|
### 先确定挂载平面
|
|
96
116
|
|
|
97
|
-
`ctx.compaction` 是**按 realm
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
`ctx.compaction` 是**按 realm 解析的单槽服务**。`isolate: compaction: true` 让每个 preset realm
|
|
118
|
+
各有一份,所以 preset 宿主里会同时存在「宿主平面一个 + preset 内一个」——两个 context,不冲突。
|
|
119
|
+
宿主平面的引擎服务 `headless` 与解析到宿主平面的 agent;想让策略进到某个 preset 内部,
|
|
120
|
+
替换它自己的 `compaction` 组(见下)。
|
|
100
121
|
|
|
101
|
-
| profile | agent 的压缩引擎属于谁 |
|
|
122
|
+
| profile | agent 的压缩引擎属于谁 | 需要做什么 |
|
|
102
123
|
|:--|:--|:--|
|
|
103
|
-
| `headless` | 宿主平面(没有 preset) |
|
|
104
|
-
| `web` | **agent preset
|
|
124
|
+
| `headless` | 宿主平面(没有 preset) | 无。bundle 已接管 |
|
|
125
|
+
| `web` / `desktop` | **agent preset**(宿主平面的 `compaction-basic` 由 `dsh-web-app` 停用) | 宿主平面已接管;要让 preset 内部也用策略,需覆盖 preset 声明 |
|
|
105
126
|
|
|
106
127
|
#### headless(宿主平面)
|
|
107
128
|
|
|
108
|
-
bundle
|
|
129
|
+
无。装上就生效,bundle 已经写好了那两行。要改门槛就改 `config:`:
|
|
109
130
|
|
|
110
131
|
```yaml
|
|
111
132
|
# $DSH_HOME/profiles/<profile>/cordis.patch.yml
|
|
112
|
-
- id: compaction-basic
|
|
113
|
-
disabled: true
|
|
114
|
-
|
|
115
133
|
- id: compaction-control
|
|
116
|
-
disabled: false
|
|
117
134
|
config:
|
|
118
135
|
default:
|
|
119
|
-
threshold: 0.
|
|
120
|
-
retain: 0.
|
|
136
|
+
threshold: 0.42
|
|
137
|
+
retain: 0.08
|
|
121
138
|
```
|
|
122
139
|
|
|
123
140
|
loader 认的键是 **`disabled`**,不是 `disable`;写错不会报错,会被静态配置静默丢掉
|
|
@@ -145,8 +162,10 @@ dsh plugin --profile web add "$PWD/examples/standard-with-policy"
|
|
|
145
162
|
|
|
146
163
|
两种静默坏组合:
|
|
147
164
|
|
|
148
|
-
-
|
|
165
|
+
- 宿主平面挂了引擎,同一 realm 里原版 `compaction-basic` 还在 → 第二个引擎注册失败,
|
|
166
|
+
只有一行 warning(`dsh: warning: 1 entry did not activate`),策略静默失效;
|
|
149
167
|
- 原版停用了却没有挂任何替代引擎 → 接缝无人认领,会话静默停止压缩,一路涨到被上游拒绝。
|
|
168
|
+
**这正是 0.5.9 及更早版本在 `web` / `desktop` 上的默认行为**,已由 bundle 自身修掉。
|
|
150
169
|
|
|
151
170
|
「停用旧的」和「启用新的」必须写在同一个组合里,一起 review。
|
|
152
171
|
|
package/cordis.patch.yml
CHANGED
|
@@ -1,45 +1,56 @@
|
|
|
1
|
-
# Plugin bundle for dsh-compaction-policy-engine: mounts the policy engine
|
|
2
|
-
#
|
|
1
|
+
# Plugin bundle for dsh-compaction-policy-engine: mounts the policy engine and the
|
|
2
|
+
# host-plane companion.
|
|
3
3
|
#
|
|
4
4
|
# The engine subclasses `BasicCompactionEngine`, so region selection, tool-pairing
|
|
5
5
|
# balance, summary framing, and the durable compaction transaction stay the
|
|
6
6
|
# official implementation — only the policy (three-layer threshold + summarization
|
|
7
7
|
# model) becomes configurable here.
|
|
8
8
|
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
9
|
+
# ── Mounting this plugin swaps the engine (2026-11-26) ────────────────────────
|
|
10
|
+
#
|
|
11
|
+
# `ctx.compaction` is a SINGLE-SLOT service, not an agreement between engines:
|
|
12
|
+
#
|
|
13
|
+
# super(ctx, "compaction") // -> 'service "compaction" has been registered
|
|
14
|
+
# // at <BasicCompactionEngine>'
|
|
15
|
+
#
|
|
16
|
+
# A second engine in the same context does not lose a threshold race — it throws
|
|
17
|
+
# during construction and never mounts at all. So "leave the stock engine on as a
|
|
18
|
+
# late backstop" is not available: the bundle must disable it, or the policy engine
|
|
19
|
+
# cannot start. This file therefore does both halves in one place:
|
|
20
|
+
#
|
|
21
|
+
# - disables the stock `compaction-basic` row, and
|
|
22
|
+
# - enables the policy engine.
|
|
23
|
+
#
|
|
24
|
+
# Doing only one half is the failure this file used to ship. It shipped the engine
|
|
25
|
+
# `disabled` on the theory that "superseding the stock engine is a deployment
|
|
26
|
+
# decision" — but that theory silently assumed the stock engine was *running*.
|
|
27
|
+
# On a preset-based host (`dsh-web-app`: `web` and `desktop` profiles) the host
|
|
28
|
+
# plane's `compaction-basic` is disabled by the app itself, so a bundle that also
|
|
29
|
+
# left its own engine disabled yielded **no compaction at all**: the settings card
|
|
30
|
+
# rendered, the threshold read back, and nothing ever fired. That is how a Win11
|
|
31
|
+
# session grew past 158k tokens and then could not compact — four forced
|
|
32
|
+
# compactions in a row, every one rejected upstream, and every local test green.
|
|
33
|
+
#
|
|
34
|
+
# Unmounting the plugin reverses both halves automatically: these rows and the
|
|
35
|
+
# `compaction-basic` override disappear together, restoring the stock engine.
|
|
36
|
+
#
|
|
37
|
+
# ── Which realm the engine lands in ──────────────────────────────────────────
|
|
38
|
+
#
|
|
39
|
+
# `isolate: compaction: true` in the agent presets gives each preset realm its own
|
|
40
|
+
# `compaction` slot, so a preset host keeps a stock `compaction-basic` inside the
|
|
41
|
+
# realm alongside this host-plane engine — two engines, two contexts, no conflict.
|
|
42
|
+
# The host-plane one (this row) serves `headless` and any agent that resolves the
|
|
43
|
+
# host plane; a preset that wants the policy inside its realm replaces its own
|
|
44
|
+
# `compaction` group, see `examples/standard-with-policy/`.
|
|
32
45
|
#
|
|
33
46
|
# Thresholds are ratios, never absolute token counts: a model's advertised window
|
|
34
47
|
# is not stable, and a model that declares no window cannot honor a token budget.
|
|
35
48
|
#
|
|
36
|
-
# The companion row
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
# seam resolves per realm, so a host-plane engine would run *beside* the preset
|
|
42
|
-
# one on the same bubbling `agent/pre-step` and the lower threshold would win.
|
|
49
|
+
# The companion row is a **separate, enabled, host-plane** row because the browser
|
|
50
|
+
# bundle is discovered from enabled loader entries (`dsh-client-modules` walks
|
|
51
|
+
# `ctx.loader.entries()` and skips disabled or fiberless ones) — the engine can
|
|
52
|
+
# live inside an agent preset, where that scan cannot see it. It deliberately does
|
|
53
|
+
# NOT claim `ctx.compaction`.
|
|
43
54
|
#
|
|
44
55
|
# `name` is the **bare package name**, which resolves to `lib/companion.js`. That
|
|
45
56
|
# split is load-bearing: the loader mounts a row's `exports.default` and reads no
|
|
@@ -47,10 +58,13 @@
|
|
|
47
58
|
# `export:` key, which was silently dropped — putting a second engine on the host
|
|
48
59
|
# plane at the shipped default and capping every raised threshold. Two
|
|
49
60
|
# `[compact-debug]` lines per step with the same `measured` were the signature.)
|
|
61
|
+
|
|
62
|
+
- id: compaction-basic
|
|
63
|
+
disabled: true
|
|
64
|
+
|
|
50
65
|
- insert:
|
|
51
66
|
- id: compaction-control
|
|
52
67
|
name: '@magic6/dsh-compaction-policy-engine/engine'
|
|
53
|
-
disabled: true
|
|
54
68
|
|
|
55
69
|
- insert:
|
|
56
70
|
- id: compaction-control-settings
|
package/docs/DESIGN.md
CHANGED
|
@@ -85,9 +85,19 @@ the disable and the mount together.
|
|
|
85
85
|
The loader key is `disabled`, not `disable`. The typo is dropped by the schema and the row
|
|
86
86
|
stays enabled.
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
**`ctx.compaction` is a single-slot service, not an agreement between engines.** A second
|
|
89
|
+
engine in the same context does not lose a threshold race — it throws
|
|
90
|
+
`service "compaction" has been registered at <BasicCompactionEngine>` while constructing and
|
|
91
|
+
never mounts (the host prints only `dsh: warning: 1 entry did not activate`). "Keep the stock
|
|
92
|
+
engine as a late backstop" is therefore not available.
|
|
93
|
+
|
|
94
|
+
Because of that, the bundle does both halves of the swap in one place: it sets
|
|
95
|
+
`compaction-basic` to `disabled: true` and enables the engine row. Uninstalling removes both,
|
|
96
|
+
so the stock engine comes back — a profile can never end up with no compaction at all.
|
|
97
|
+
|
|
98
|
+
≤0.5.9 shipped the engine row `disabled`, on the theory that superseding the stock engine was
|
|
99
|
+
a deployment decision. That assumed the stock engine was running; on `dsh-web-app` presets it
|
|
100
|
+
is not, so both engines were off and the seam was unclaimed. See `exp.md` (2026-11-26).
|
|
91
101
|
|
|
92
102
|
The companion row is host-plane and always enabled because the browser bundle is discovered
|
|
93
103
|
from enabled loader entries; the engine row lives in a preset and is invisible to that scan.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 压缩高可用方案
|
|
2
|
+
|
|
3
|
+
> 目标:**压缩永远不因"发不出去"而失败**。
|
|
4
|
+
|
|
5
|
+
## 0. 已解决:全量重放(2026-11-26)
|
|
6
|
+
|
|
7
|
+
`summarize()` 曾把整段对话重放,让摘要请求成为 live state 的精确 token-前缀延伸
|
|
8
|
+
(为了本地引擎的 `--prompt-cache` 命中)。**该机制已删除**,用官方的 region-only。
|
|
9
|
+
|
|
10
|
+
它不是"偶发过大",而是**结构上必然失败**。Win11 会话实测(`session-91ac1b04`,
|
|
11
|
+
从未成功压缩过):
|
|
12
|
+
|
|
13
|
+
| 请求体 | tokens |
|
|
14
|
+
|:--|--:|
|
|
15
|
+
| 全量重放(带 reasoning) | 2,182,311 |
|
|
16
|
+
| 全量重放(剥掉 reasoning) | 1,247,719 |
|
|
17
|
+
| 网关实际请求峰值 | **217,373** |
|
|
18
|
+
| 声明窗口 | 1,000,000 |
|
|
19
|
+
|
|
20
|
+
区别在于**正常请求只发当前窗口内的内容**,而全量重放试图把**累计历史**(1.25M)
|
|
21
|
+
全部塞进一次请求。剥掉 reasoning 只能从 2.2M 降到 1.25M —— 仍然超窗。
|
|
22
|
+
|
|
23
|
+
**结论:需要压缩的会话,恰好就是全量重放装不下的会话。** 用来救它的请求,正是
|
|
24
|
+
发不出去的那个。四次压缩全部 `context_length_exceeded`,会话永久不可恢复。
|
|
25
|
+
|
|
26
|
+
region-only 的区域由触发压缩的 gate 限定,**因此天然有界**。这是唯一正确的做法。
|
|
27
|
+
|
|
28
|
+
## 1. 剩余风险
|
|
29
|
+
|
|
30
|
+
回到 region-only 后,摘要请求体积 = 被压区间。该区间由 gate 选中,正常情况有界。
|
|
31
|
+
但仍有一种情况会超:
|
|
32
|
+
|
|
33
|
+
**1M 会话切到 256K 模型。** gate 按 256K 计算,选中区间相当大,摘要请求可能装不进
|
|
34
|
+
256K 窗口。
|
|
35
|
+
|
|
36
|
+
## 2. 保底方案(`lib/summarize-budget.js`,已写好 19 个测试)
|
|
37
|
+
|
|
38
|
+
显式给摘要请求设上限,超了就分级降级:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
① region-only 父类 input 装得下 → 直接用 (默认路径)
|
|
42
|
+
② 分批压缩 装不下 → 切成 N 批,每批带前批摘要
|
|
43
|
+
③ 离线裁剪 分批仍不行 → 砍 tool 输出,不调模型
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**分批的接续方式**:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
batch 1: [最早的节点…塞满 80%] → S1
|
|
50
|
+
batch 2: [S1] + [后续节点…塞满 80%] → S2
|
|
51
|
+
batch 3: [S2] + [后续…] → S3
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
每批带上前一批摘要,信息不丢。批次数上限 12,超了就明说"开新会话"而不是无限烧钱。
|
|
55
|
+
|
|
56
|
+
**离线裁剪只动 tool 输出** —— 那是长会话的体积主体,也是唯一可重建的部分;
|
|
57
|
+
user/assistant 消息是语义主干,永不删除。
|
|
58
|
+
|
|
59
|
+
## 3. 状态
|
|
60
|
+
|
|
61
|
+
- [x] 移除全量重放,回到 region-only(`780e74c`)
|
|
62
|
+
- [x] `lib/summarize-budget.js`:预算/切分/裁剪,19 测试
|
|
63
|
+
- [ ] 接线到 `summarize()`:按预算选择 ①②③
|
|
64
|
+
- [ ] e2e 场景 `shrink`:1M 会话 → 256K 模型
|
|
65
|
+
|
|
66
|
+
## 4. 不做的事
|
|
67
|
+
|
|
68
|
+
- 不改父类 `BasicCompactionEngine` 的事务语义
|
|
69
|
+
- 不动 `compactRegion` 的持久化逻辑
|
|
70
|
+
- 不再为缓存命中牺牲可用性 —— 压不动比压得慢严重得多
|
package/lib/index.js
CHANGED
|
@@ -246,55 +246,6 @@ function conversationTarget(agent) {
|
|
|
246
246
|
return undefined;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
/**
|
|
250
|
-
* The message list the last routed request actually sent: the system head plus
|
|
251
|
-
* every surface node's projected message, in surface order.
|
|
252
|
-
*
|
|
253
|
-
* Why the summary call must replay all of it rather than only the shadowed
|
|
254
|
-
* region (measured against a local inference engine): that engine
|
|
255
|
-
* resumes only from a stored state that is an exact token-prefix of the new
|
|
256
|
-
* prompt, and it keeps at most `--prompt-cache` (6) checkpoints, taken at
|
|
257
|
-
* assistant-turn boundaries and every `--prompt-cache-every` (16384) fresh
|
|
258
|
-
* tokens. Those six slots hold the *recent* turn boundaries, so the shadowed
|
|
259
|
-
* region's own checkpoints are long evicted: a region-only replay matches
|
|
260
|
-
* nothing but the pinned system-prompt root and re-reads the whole region.
|
|
261
|
-
* Measured: a 403,413-token prompt read over 311 s, then killed by provider-d's
|
|
262
|
-
* 300 s idle watchdog, because a prefill emits no tokens and a slow engine
|
|
263
|
-
* therefore looks idle. Appending the instruction after the FULL conversation
|
|
264
|
-
* instead makes the call an exact extension of the live state, so the engine
|
|
265
|
-
* resumes at the live end and prefills only the instruction.
|
|
266
|
-
*
|
|
267
|
-
* The trade-off is deliberate: the summary now condenses the whole
|
|
268
|
-
* conversation, so the checkpoint and the verbatim-retained tail overlap. That
|
|
269
|
-
* costs the tail's tokens once per compaction, against re-reading the entire
|
|
270
|
-
* context on every one.
|
|
271
|
-
*
|
|
272
|
-
* @param session - the session whose surface to project.
|
|
273
|
-
* @returns the projected messages, or `undefined` when the surface is unreadable.
|
|
274
|
-
*/
|
|
275
|
-
function fullConversationMessages(session) {
|
|
276
|
-
const nodes = session?.surface?.nodes;
|
|
277
|
-
if (!Array.isArray(nodes) || nodes.length === 0) return undefined;
|
|
278
|
-
const messages = [];
|
|
279
|
-
for (const seq of nodes) {
|
|
280
|
-
const event = session.eventAt?.(seq);
|
|
281
|
-
if (event === undefined || event === null) continue;
|
|
282
|
-
const message = session.deriveEventMessage?.(event);
|
|
283
|
-
if (message === null || message === undefined) continue;
|
|
284
|
-
messages.push(message);
|
|
285
|
-
}
|
|
286
|
-
return messages.length === 0 ? undefined : messages;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* The summary request's message list: the full conversation when the session
|
|
291
|
-
* can project it, otherwise the caller's own region-only input unchanged.
|
|
292
|
-
*/
|
|
293
|
-
function summarizationInput(input, agent) {
|
|
294
|
-
const messages = fullConversationMessages(agent?.session);
|
|
295
|
-
return messages === undefined ? input : { ...input, messages };
|
|
296
|
-
}
|
|
297
|
-
|
|
298
249
|
/**
|
|
299
250
|
* Say once when the pressure gate falls back to the engine's constructor baseline
|
|
300
251
|
* because no layer states a threshold for this target.
|
|
@@ -1052,14 +1003,18 @@ export class CompactionControlEngine extends BasicCompactionEngine {
|
|
|
1052
1003
|
* fall back to the latest routed request, which preserves the provider's warm
|
|
1053
1004
|
* prefix cache.
|
|
1054
1005
|
*
|
|
1055
|
-
* The message list is
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
* that by re-reading all of it. On `auto` the target is therefore the very
|
|
1059
|
-
* route whose live state this request now extends.
|
|
1006
|
+
* The message list is the caller's own: upstream replays only the shadowed
|
|
1007
|
+
* region, and that region is bounded by the gate that selected it, so the
|
|
1008
|
+
* request is bounded too.
|
|
1060
1009
|
*/
|
|
1061
1010
|
async summarize(input, agent, signal) {
|
|
1062
|
-
|
|
1011
|
+
// The parent's own region-only input is used verbatim. A full-conversation
|
|
1012
|
+
// replay was tried to reuse a local engine's prefix cache and removed on
|
|
1013
|
+
// 2026-11-26: it made the summary request carry the whole session, which is
|
|
1014
|
+
// the one payload that must stay bounded — a conversation large enough to
|
|
1015
|
+
// need compaction is one whose replay no longer fits, so the request that
|
|
1016
|
+
// was supposed to rescue the session could not be sent at all.
|
|
1017
|
+
const effective = input;
|
|
1063
1018
|
const target = conversationTarget(agent);
|
|
1064
1019
|
// The window goes with the policy for the same reason it does in the gate:
|
|
1065
1020
|
// an absolute retention has to be converted before the parent can compare
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic6/dsh-compaction-policy-engine",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "Layered, live-reloading context compaction policy for DeepSeek Harness: provider-level rules, field-by-field inheritance, ratio/token units and a settings panel on top of the official engine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/companion.js",
|