Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
45 changes: 45 additions & 0 deletions docs/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,51 @@ the tab degrades to a restart notice plus an open-Web-UI button instead of
guessing. Plain React from dsh's own runtime — no iframe, no added
dependencies.

**Long-running sessions can hit a wall that no automatic recovery reaches
(#5058).** In plugin mode dsh keeps its own full local session log, and dsh's
pre-send overflow guard measures THAT local log — not what bili renders onto
the wire. While bili owns the lane, dsh's native compaction is stood down by
design (above), so in a long-lived session (hundreds of turns, days — e.g. a
QQ-bridge companion) the local log grows until it exceeds the model window;
from then on dsh refuses every request BEFORE sending it. No provider error
ever happens, so dsh's overflow recovery (which waits for the provider's
`CONTEXT_WINDOW_EXCEEDED`) never fires, and — because nothing is sent — no
traffic reaches bili either: nudge-driven compression, manual `/compact`, and
any host-side fallback keyed on provider errors are all unreachable. The
session is permanently unusable; the only exit is deleting it and starting a
fresh one (in companion scenarios that means losing the conversation memory —
keep durable memory OUTSIDE the context: character card, journal, memory
files). In the reported case the local log reached 30 MB / 24,051 events and
dsh's native compaction had never run once in that session's life. One
clarification: the compress action cost on the MODEL-facing side is bounded —
re-sent compress calls ride the wire stubbed to ~200 chars per range entry —
what grows unboundedly is the host's local store.

Known refusal wording (for host-side detection regexes, as of the #5058
report):

> payload core text alone is ~… bytes … that is >= ~… tokens vs the model
> window …; no upstream can accept it, so it was NOT forwarded even for
> evidence.

Mitigations for companion / always-on sessions:

- **Rotate the session periodically** (e.g. daily) and keep persistent memory
in files, not in context length.
- **Raise `compress.nudgeGrowthTokens`** (e.g. `500000`) or turn nudging off
for such sessions, so the compression cadence does not chase the session's
own growth.
- **Watch the session file size** (`~/.dsh/sessions/…/session.v4.jsonl.zstd`)
— several MB of compressed events is a warning long before the window
fills.
- Since this build, bili's **net-progress guard** stops sending compression
nudges once consecutive folds stop shrinking the session (Web UI badge
"swelling", `[net-progress]` lines in the proxy log, 10-minute wall cap).
It breaks the compress-action feedback loop that accelerates the approach to
the wall; it cannot trim dsh's local store itself.
- A per-session "transport only, no compression" setting is tracked in
[#5052](https://github.com/ranxianglei/billion-context/issues/5052).

**DSH Go host (third-party Android app):** the app
(`ccch1mneyyy/dsh-Go`) ships its own dsh runtime — dsh `0.2.2-rc.1` on node
24.22.1 / Ubuntu 24.04.5 inside a proot rootfs, ~135 patched dsh files per app
Expand Down
16 changes: 16 additions & 0 deletions docs/clients.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@

**宿主侧上下文计量与模型实际视图按设计不一致(#2837):**plugin 模式下宿主本地持久会话日志有意保持无损 —— 完整未折叠历史会因前缀缓存与严格回显而重发(见 technical-notes.md「两种压缩模式」)。因此宿主或其插件从该本地日志算出的任何计量,量的都是**未折叠的本地表面**,而不是下一次请求实际携带的量;压缩生效期间本地数字远高于真实输入属预期,不是压缩卡死。有效尺寸以代理为准:读 `/acp`(或 `GET /__bili/plugin/status` 的 `contextTokens`,来源见 `contextTokensSource`),不要本地重新推算。

**长会话会撞上一堵没有任何自动恢复能触及的墙(#5058)。** plugin 模式下 dsh 自己保留一份完整的本地会话日志,dsh 发送前的超窗守卫量的是**这份本地日志** —— 不是 bili 渲染上线的内容。bili 持有泳道期间 dsh 原生压缩按设计撤下(见上),于是长寿命会话(几百轮、跨天,例如 QQ 桥接陪伴)的本地日志一路涨到超过模型窗口;此后 dsh 在**发送前**拒绝每一条请求。没有 provider 报错,dsh 自己的 overflow 恢复(等 provider 回 `CONTEXT_WINDOW_EXCEEDED`)永远等不到信号;又因为什么都没发出去,bili 也收不到任何流量:nudge 驱动的压缩、手动 `/compact`、以及一切以 provider 错误为触发条件的宿主侧兜底全部够不着。会话从此永久不可用,唯一出路是删掉重建 —— 对陪伴类场景这意味着对话记忆清零,所以**持久记忆要放在上下文之外**(角色卡、日记、记忆文件)。报告案例里本地日志涨到 30 MB / 24,051 条事件,而整条生命周期内 dsh 原生压缩一次都没跑过。一点澄清:压缩动作在**模型侧**的开销是有界的 —— 重发的 compress 调用在线上被截成每段约 200 字符 —— 无界增长的是宿主的本地存储。

已知拒发文案(供宿主侧检测正则使用,#5058 报告时的版本):

> payload core text alone is ~… bytes … that is >= ~… tokens vs the model
> window …; no upstream can accept it, so it was NOT forwarded even for
> evidence.

陪伴类 / 常驻会话的缓解手段:

- **定期换会话**(例如每天一次),持久记忆放文件里,不押在上下文长度上。
- **调大 `compress.nudgeGrowthTokens`**(如 `500000`)或对这类会话直接关掉 nudge,别让压缩节奏追着会话自身的增长跑。
- **盯会话文件大小**(`~/.dsh/sessions/…/session.v4.jsonl.zstd`)—— 压缩后几个 MB 就是预警,远早于窗口撑满。
- 本构建起 bili 的**净进展守卫**会在连续折叠不再缩小会话时停发压缩 nudge(Web UI 徽标 "swelling"、代理日志 `[net-progress]` 行、10 分钟墙钟上限)。它打断的是压缩动作自我放大的正反馈,不能替 dsh 裁剪本地存储。
- 逐会话「仅传输不压缩」设置见 [#5052](https://github.com/ranxianglei/billion-context/issues/5052)。

**dsh-go 宿主(第三方安卓 App):** 该 App(`ccch1mneyyy/dsh-Go`)自带一套 dsh 运行时 —— proot rootfs 里的 dsh `0.2.2-rc.1` / node 24.22.1 / Ubuntu 24.04.5,每次 App 更新替换约 135 个 dsh 文件。上面的 profile 泳道在这里原样可用:在它的 Linux 环境里执行 `dsh plugin --profile <name> add billion-context`,引擎即挂载该 bundle 并把代理拉成自己的子进程。已在 Redmi K80 / Android 16 / arm64-v8a 上验证:首次对话经代理转发(`[window] source=plugin`、`effective window 1048576 -> 792576 (reserved 256000)`、`forward POST → api.deepseek.com/anthropic/v1/messages`),`GET /__bili/plugin/status` 的 `contextTokens` 取自 usage。该宿主的客户端是原生实现,因此只带 `dsh.client.platform: web` 的 bundle(本插件的 Context 标签页与设置页)在那里没有落点 —— 宿主面、工具与 HTTP 面板不受影响,原生界面经 `dshGo` 槽另行接入(dsh-Go 的 `docs/plugins/native-for-free.md`)。它还定义了 `preset-dsh-go-companion` 与 `preset-dsh-go-companion-full`,其内嵌的 `compaction-basic` 行应由 #4147 的结构化遍历覆盖。

## Kimi Code(Moonshot)
Expand Down
62 changes: 62 additions & 0 deletions docs/technical-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,68 @@ remove <client>` best-effort queries the live proxy (instance file →
`GET /__bili/sessions`, 2.5 s timeout, silent on failure) and prints a note
when sessions of that client were active within the last **10 minutes**.

## Net-progress guard — stop compressing when folding stops shrinking (#5058)

D1 above only arms when reductions STOP landing — it is blind to the opposite
failure: folds keep committing while the session keeps GROWING. That is the
companion-session spiral (#5058): every nudge round ends in a successful
compress whose own action cost (tool-call args, receipts, reasoning — all
re-sent next round) outweighs what the fold removed, so the flat-50K growth
gate re-arms forever and the session walks past its window with no guard
firing. The net-benefit gate (#2748/#3322) checks each commit in isolation;
it cannot see the cross-round trajectory.

`src/net-progress-guard.ts` adds the trajectory view:

- **Lane scope** — plugin lanes only (`session.metadata.pluginAgent` bound).
Only a plugin host persists and re-sends the compression action itself, so
only there does the resent payload shrink when a fold works. Proxy-mode
clients keep their full local history and re-send it verbatim every turn —
once folded coverage exceeds the margin the raw resend structurally never
drops below pre-fold-minus-margin, so an unscoped latch would arm on every
mature proxy session and silence the flat-50K cadence without defending
anything.
- **Baseline** — recorded at every successful fold commit in `src/stream.ts`:
`recordNetProgressBaseline(session, rawViewTokens, postCtx)`. The baseline
is the INBOUND RESEND total (same array class as the round check's
observation, #1911 same-space discipline); postCtx stays the rendered
post-fold estimate (diagnostic only). The rendered live view must not feed
this pair — mixing spaces would distort the bar by the reasoning-drop delta
on heavy-reasoning hosts. Each new fold opens a fresh evidence window;
strikes reset.
- **Round check** — once per request on nudge-carrying lanes (inside the same
`!selfHealRoundDone && prepared.nudge !== undefined` block as D1/D2),
`evaluateNetProgressRound(session, observedTokens, log)` compares the
inbound resend size (`countMessageTokens` over `prepared.originalMessages`)
against the baseline: `observed < baseline − NET_PROGRESS_MARGIN_TOKENS`
(25_000 — half the flat step; large enough to absorb estimator noise and
the one-round materialization lag where the post-compress re-request still
carries the unfolded history, #252) counts as progress and resets;
otherwise it is a strike. `NET_PROGRESS_STRIKE_LIMIT` (2) consecutive
non-progress rounds arm the latch.
- **Remedy** — suppress the nudge at all four `willInjectNudge` gates via
`nudgeInjectionBlocked(session)` (the D1 predicate OR'd with this one); the
decide ladder's fallback escape still punches through ONE legacy advisory
while suppressed (same #3004 deadlock guard as D1). Latch state
`{ baseline, expectedFloor, strikes, armedAt }` lives PROCESS-LOCAL in a
WeakMap keyed by the session object — persist serializes session.metadata
into the state file, and this guard fires on every successful fold commit,
so a persisted latch would drift the byte-for-byte storage goldens on every
long session (#4790 precedent); an evicted-and-reloaded session re-seeds
silently, which is harmless because wall expiry reuses
`SELF_HEAL_SUPPRESS_CAP_MS` (10 min) so a latched session is never silent
past that without fresh evidence; any real reduction lifts it early; and a
fresh arm needs one more successful fold commit followed by at most
`NET_PROGRESS_STRIKE_LIMIT` non-progress rounds. Evaluate MUST run while
suppressed or recovery could never be observed (the #3004 circular-wait trap).

Observability: armed state is exposed in `/__bili/sessions` (`netProgress`,
live sessions only) and badged in the web UI ("swelling"); arm/recovery/
expiry each log one `[net-progress]` line with the observed vs baseline
numbers and the rotate-to-fresh-session advice. No config surface — constants
by design (same precedent as #2155); operators who want a lazier cadence set
`compress.nudgeGrowthTokens`.

## Degraded direct fallback — refuse, self-heal, announce (#4516, #3304, #2924, #4079)

When a native lane's proxy is unavailable, model traffic falls back to direct
Expand Down
1 change: 1 addition & 0 deletions reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ billion-context/
│ ├── fake-completion.ts # Opt-in fake-completion retry hint (#371)
│ ├── reasoning-drop.ts # Drops oversized reasoning from closed-round compress calls (#651)
│ ├── reasoning-guard.ts # Live-fold guard for signed reasoning payloads
│ ├── net-progress-guard.ts # Net-progress guard: per-session nudge quiet-down when folds stop shrinking the resent context (#5058)
│ ├── output-steering.ts # Output-side compression: verbosity steering / effort routing (#1093)
│ ├── image-tokens.ts # Image token cost estimation (pixels/bytes modes, #767)
│ ├── image-note.ts # Image-block placeholder → rich note rendering
Expand Down
Loading
Loading