Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The full file-by-file map lives in [reference/architecture.md](reference/archite
- **pluginMode** (the `x-bili-plugin` header / registered agent, e.g. `bili pi`): the ACP-native agent OWNS compression — it executes `compress` locally, the call+result live in its own re-sent history, and the wire summary carrier is the **tool call** (the proxy suppresses tool + nudge injection; the agent's view never renders the kernel's `acp_summary`).
- **proxy mode** (plain client, no header): the proxy executes `compress` server-side; the tool call is ephemeral (never enters the client's history) and preflight blocks have none, so the carrier is the **`acp_summary` message** — the kernel renders it role `system`, but `systemToUser` (`src/util.ts`) re-voices it as a **`user` message** (leaving it at its anchor) so strict backends (SGLang: exactly one system at index 0, #377) accept it and the head system message stays byte-stable for the prefix cache.
- The mode is decided per request and bound per session (`session.metadata.pluginAgent`, sticky, upgrade-only). See TECHNICAL-NOTES.md "Two compression modes".
8. **Nudge cadence is flat 50K by design (kernel contract)** — acp-kernel pins the growth interval at 50000 for every window size (`nudge.growthFloor == nudge.growthCap == 50000`; window-percentage scaling was deliberately removed — #379/#380 settled "growth-driven, no usage/count proxy gates"). Do NOT re-scale the interval with the context window or reintroduce percentage gates; a 1M-window session folding every 50K of growth is intended lean-context behavior. User escape hatch: `compress.nudgeGrowthTokens` (flattens `growthFloor`+`growthCap` to a fixed step) — big-window users who want a lazier cadence set it explicitly. Prompt wording is kernel-owned (`src/nudge-text.ts`).
8. **Nudge cadence is growth-driven, window-scaled within [20k, 50k] (kernel contract)** — acp-kernel resolves the growth step as `clamp(growthRatio × modelContextLimit, growthFloor, growthCap)` with defaults `growthFloor: 20000`, `growthCap: 50000`, `growthRatio: 0.05` — i.e. `clamp(5% × window, 20k, 50k)`: ≥1M windows keep the legacy flat 50k step byte-identical, sub-400k windows floor at 20k (#2110 RC2 / #2278 — the #379/#380 flat-50k-at-every-window calibration made a 50k gate ~24% of a 204k budget line and starved small-window cadence, so it was explicitly reversed for sub-1M windows). What survives from #379/#380: cadence is GROWTH-driven — no usage-percentage or message-count proxy gates on the day-to-day path (the pressure layer's maxContextLimit/emergency thresholds remain the percentage backstop), and a 1M-window session folding every 50K of growth stays intended lean-context behavior. Do NOT add usage/count proxy gates or widen the [20k, 50k] band without a dedicated decision issue. User escape hatch: `compress.nudgeGrowthTokens` (flattens `growthFloor`+`growthCap` to a fixed step) — set it explicitly to pin a flat step at any window. Prompt wording is kernel-owned (`src/nudge-text.ts`).
9. **Hosts that reuse ONE session id across personas get id + system-hash session keys ("hash 不一样自动分裂")** — when a plugin host stamps the SAME conversation id on every model request of a session INCLUDING auxiliary personas (dsh auto-review `classifyRisk()`: fixed REVIEW_POLICY system + a fresh flattened blob before every tool call — #1916/#1307/#1314), those auxiliary requests must be keyed by `subagentNamespace(id, systemText)` so the persona forks onto its own `<id>|sub:<fp>` session instead of overwriting the main session's baseline/snapshots. The FIRST system seen under the id keeps the raw key (kernel anchor), so main turns never fork; an empty system is non-anchoring (verbatim); SIDE REQUESTS never claim the anchor either — dsh's title-gen sidecar fires at session start before/concurrent with the first main turn, and claiming it would fork the whole main conversation onto `|sub:<fp>` while every host-stamped ACP management call (compress/decompress/acp_status) routes into the ghost's empty session and fails forever (#2156/#2160; the `sideRequestLike` gate in `src/server.ts` mirrors the #388 passthrough predicate). This is an EVIDENCE-PERMITLIST (`dshPersonaFingerprintApplies` in `src/session-id.ts`), the same discipline as the instructions fingerprint (#1104/#1107): do NOT enable it wholesale — for everyone else system drift mid-id means "same conversation, evolved", and forking resets compression for no defending bug (#1106). A future host found reusing session ids across personas gets added to that predicate WITH traffic evidence (shape + stability proof: the host's main system must be session-stable, e.g. dsh composes it once per session and puts volatile time-context in a USER message). The fork must record itself under its suffixed id (`personaForked` → `recordPluginSession`) so the single-valued conversations map keeps the raw key owned by the main session (#970 discipline). Tests: `tests/dsh-persona-fingerprint.test.ts`.

10. **Thinking-family blocks are signature-verified — NEVER rewrite them (#1960)** — Anthropic `thinking`/`redacted_thinking` blocks and Gemini `thoughtSignature` parts are verified byte-for-byte when the latest assistant message is replayed ("thinking blocks ... cannot be modified"). The bytes the proxy forwards become the client's persisted history, and the bytes the loop accumulates become the re-request rebuild — BOTH must stay verbatim. Any transformation (tag/marker stripping, dedup, trimming, re-laying-out block order, dropping empty segments) desynchronizes text from signature and bricks the session: first on the in-turn re-request, then on every subsequent request via the client's echo. #1882 put a prose filter on the thinking channel and it was exactly this bug. Treat ANY future change touching thinking-family payloads as high-risk: it needs loop-level byte-equality tests (re-request body AND client-visible stream) on both signed wires, not just adapter-level ones. The prose filters (#206/#1881) are for the TEXT channel only.
Expand Down
34 changes: 18 additions & 16 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `compress.maxContextLimit` | number \| "N%" | "75%" | — | Forced-compression nudge threshold: once history passes this share of the window the nudge fires immediately, bypassing growth gates. Not a hard cap. |
| `compress.emergencyThresholdPercent` | number \| % | "95%" | — | Emergency truncation of oversized tool outputs when history passes this share of the window (must be >= maxContextLimit). |
| `compress.outputHeadroomMaxPct` | number \| % | 0.25 | — | Cap on the share of the window reserved for output via max_tokens. |
| `compress.nudgeGrowthTokens` | number | 50000 (kernel flat cadence) | — | Growth gate: nudges fire only when a foldable range exceeds baseline growth by this many tokens (flat by design, independent of window size). |
| `compress.nudgeGrowthTokens` | number | unset — window-scaled: clamp(5% × window, 20k, 50k) | — | Growth gate: nudges fire only when a foldable range exceeds baseline growth by this many tokens. Default scales with the window (50k at ≥1M, 20k below 400k — #2110); set a number to pin a flat window-independent step. |
| `compress.streamSummary` | boolean | false (unset) | — | Force preflight summarization to run as a streaming (SSE) call from the first attempt. Needed when the upstream sits behind a gateway that times out long non-streaming completions (e.g. Cloudflare HTTP 524): the error-driven self-learn only sees 400 "stream required" rejections and never arms on gateway timeouts. |
| `compress.preserveRecentMessages` | number | kernel ≈5 | — | The most recent messages stay soft-protected from folds. |
| `compress.preserveRecentTokens` | number | kernel ≈5000 | — | The most recent tokens stay soft-protected from folds. |
Expand Down Expand Up @@ -1094,9 +1094,9 @@ For each request, the proxy resolves the settings by longest-URL-prefix match (t
#### `nudgeGrowthTokens`

- **Type:** `number`
- **Default:** `50000`
- **Default:** *(unset — window-scaled step `clamp(5% × window, 20000, 50000)`: 50k at ≥1M windows, 20k below 400k; #2110)*
- **Status:** ACTIVE
- **Description:** Token-growth step for soft compression nudges. A nudge fires roughly every time this many tokens become compressible. Lower values produce more frequent nudges. Maps to the kernel fields `nudge.growthFloor` and `nudge.growthCap` (it flattens the engine's adaptive band to this fixed step).
- **Description:** Token-growth step for soft compression nudges. A nudge fires roughly every time this many tokens become compressible. Lower values produce more frequent nudges. Maps to the kernel fields `nudge.growthFloor` and `nudge.growthCap` (it flattens the engine's adaptive band to this fixed step; when unset the band defaults to [20k, 50k] and the step scales with the window).

#### `preserveRecentMessages`

Expand Down Expand Up @@ -1356,14 +1356,16 @@ These two toggles are honoured only at the **global** level. Setting them inside

Compaction does **not** trigger on absolute window position — it triggers on
**growth intervals**: by default the first soft compaction fires after the
session grows **50k tokens past its boot content**
([`nudgeGrowthTokens`](#nudgegrowthtokens), a flat step independent of window
size). The absolute position of the first compaction is therefore ≈ **boot +
50k**:
session grows **one growth step past its boot content**
([`nudgeGrowthTokens`](#nudgegrowthtokens), default window-scaled
`clamp(5% × window, 20k, 50k)` — 50k at ≥1M windows, 20k below 400k, #2110).
The absolute position of the first compaction is therefore ≈ **boot + step**
(boot + 50k on a ≥1M window, boot + 20k on a ≤400k window):

- boot 30k–50k (the dsh default) → first compaction at ~80k–100k;
- a boot around 100k, or a growth step set to ~100k → the first compaction may
wait until **~200k**.
- boot 30k–50k (the dsh default) on a ≥1M window → first compaction at
~80k–100k;
- a boot around 100k on a ≥1M window, or a growth step set to ~100k → the
first compaction may wait until **~200k**.

The forced threshold ([`maxContextLimit`](#maxcontextlimit), default 75%) is
only a backstop, and it applies to the *effective* window — the output reserve
Expand All @@ -1374,16 +1376,16 @@ carries a very large `max_tokens`: a 262,144-token window with
`max_tokens = 131072` → effective window 196,608 → forced line ≈147k; the same
window with an 8k reserve → forced line ≈190k.

After that the cadence stays growth-based: one incremental compaction per +50k
of compressible growth. On local models each compaction is a full re-prefill —
a heavy boot plus a large window puts several of them into one long task, which
is how wall-clock ends up 2–3× longer.
After that the cadence stays growth-based: one incremental compaction per
growth step of compressible growth. On local models each compaction is a full
re-prefill — a heavy boot plus a large window puts several of them into one
long task, which is how wall-clock ends up 2–3× longer.

To make the first compaction fire earlier (and save tokens), in this order:

1. **trim the system prompt, disable unneeded tools, prune skills** — boot
size directly determines the absolute position of the first compaction;
2. **lower `nudgeGrowthTokens` to ~50k** (especially if it was raised to 100k);
2. **lower `nudgeGrowthTokens`** (especially if it was raised to 100k);
3. **enable lean mode** (`promptPack: "lean"`).

Measure actual boot/context usage with `/acp` or the web UI before tuning.
Expand All @@ -1406,7 +1408,7 @@ Express it with the existing soft bands instead: keep the limit at the native wi

How compression actually decides (acp-kernel, verified):

1. **Growth layer (day-to-day driver, absolute tokens):** a proactive nudge fires once cumulative growth since the last anchor (session start / last nudge / post-compression reset) reaches the growth gate **and** enough compressible mass has accumulated. Both numbers are absolute and window-independent by design: the growth step is flat 50k at every window size (kernel `nudge.growthFloor == nudge.growthCap == 50000`, golden-pinned; window-percentage scaling was deliberately removed — #379/#380; override with `nudgeGrowthTokens`); the growth gate is `max(20k, 0.45 × step)` ≈ 22.5k, and the T1 path additionally needs ≥ one step (50k) of compressible mass. This layer keeps compressing long sessions even far below any percentage band.
1. **Growth layer (day-to-day driver):** a proactive nudge fires once cumulative growth since the last anchor (session start / last nudge / post-compression reset) reaches the growth gate **and** enough compressible mass has accumulated. The growth step scales with the window by default — `clamp(5% × window, 20k, 50k)`: flat 50k at every window ≥1M (byte-identical to the old #379/#380 calibration), 20k below 400k; the flat-at-every-window behavior of #379/#380 was reverted for sub-1M windows because a 50k step on a 204k budget line (~24% of the window) starved the nudge cadence — #2110 (override with a flat step via `nudgeGrowthTokens`). The growth gate is `max(20k, 0.45 × step)` — 22.5k at the 50k step, exactly 20k at smaller steps — and the T1 path additionally needs ≥ one step of compressible mass. This layer keeps compressing long sessions even far below any percentage band.
2. **Pressure layer (percent of the window):** `usage ≥ maxContextLimit` (default 75%) → a nudge is injected every turn until context drops back under; `usage ≥ emergencyThresholdPercent` (default 95%) → forced nudge + emergency truncation.
3. **Qualification layer (kernel default 45%, not exposed):** gates only the turn-1 cold-start ticket and the block-count floor for T2/T3 tier escalation — not part of the day-to-day path.

Expand Down
Loading
Loading