Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8982a2f
feat: expose isolated plugin forks and attributed context observations
yingzhongshuoqi Oct 3, 2026
f44dd24
test: keep fork and provenance fixtures type safe
yingzhongshuoqi Oct 3, 2026
18c58a5
fix(plugin): preserve attributable outbound context and retained orig…
yingzhongshuoqi Oct 3, 2026
63cd3ec
test(plugin): cover manual compression after idle context expiry
yingzhongshuoqi Oct 3, 2026
85ec9c1
test(plugin): harden fork process test
yingzhongshuoqi Oct 3, 2026
22f464c
Merge origin/master into PR #2017 fork-context-provenance
yingzhongshuoqi Oct 4, 2026
aa7b0ef
fix: honor explicit plugin main request intent before side demotion
yingzhongshuoqi Oct 4, 2026
ac8d88e
fix: merge latest master with fork-safe native tool routing
yingzhongshuoqi Oct 4, 2026
af4ada3
fix(plugin): publish Responses usage before terminal frame
yingzhongshuoqi Oct 4, 2026
9609bb7
Merge remote-tracking branch 'origin/master' into 2026-10-04_plugin-f…
yingzhongshuoqi Oct 4, 2026
29e2be9
fix(#2016): cap public raw-snapshot retention, fail closed (BILI_PUBL…
ranxianglei Oct 4, 2026
d9b44fc
fix(#2017): cache the fork revision behind a mutation epoch; document…
ranxianglei Oct 4, 2026
f0bfa26
Merge branch 'master' into 2026-10-04_plugin-fork-context-provenance
ranxianglei Oct 4, 2026
0915335
Merge branch 'master' into 2026-10-04_plugin-fork-context-provenance
ranxianglei Oct 4, 2026
090c7cf
Merge branch 'master' into 2026-10-04_plugin-fork-context-provenance
ranxianglei Oct 4, 2026
e425226
Merge branch 'master' into 2026-10-04_plugin-fork-context-provenance
ranxianglei Oct 4, 2026
830da41
fix(#2017): register BILI_PUBLIC_SNAPSHOT_CAP_BYTES through knobs.ts …
ranxianglei Oct 4, 2026
300fd03
Merge remote-tracking branch 'fork/master-sync' into 2026-10-04_plugi…
ranxianglei Oct 4, 2026
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
9 changes: 9 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ Since #2030 every pure-behavior knob has a config-file key alongside its env var
- **Status:** ACTIVE
- **Description:** `max` caps in-memory sessions with LRU eviction (twin `BILI_MAX_SESSIONS`; disk remains the source of truth). `gc` controls stale-session-file cleanup (twins `BILI_SESSION_GC*`) — **opt-in**, because session files are user data: compressed sessions are never deleted, deletions are audit-logged, and the age + lossless-size gates apply. Details in the [env table](#config-file-keys-for-environment-knobs-2030).

### `plugin`

- **Type:** `{ snapshotCapBytes?: number }`
- **Default:** `{ snapshotCapBytes: 16777216 }`
- **Status:** ACTIVE
- **Description:** Plugin-surface knobs (#2017). `snapshotCapBytes` caps the raw wire-history snapshot retained per plugin session for the public fork API (`GET /__bili/plugin/snapshot`, `POST /__bili/plugin/fork`): when the serialized snapshot exceeds the cap, bili refuses to retain it — the session stops being forkable (snapshot/fork answer `409` with the capped reason) instead of retaining an unbounded raw copy on disk. Default `16 MiB`; `0` disables retention entirely (no session is forkable); twins `BILI_PUBLIC_SNAPSHOT_CAP_BYTES`. Details in the [env table](#config-file-keys-for-environment-knobs-2030).

### `update`

- **Type:** `{ registry?: string; checkIntervalMs?: number }`
Expand Down Expand Up @@ -956,6 +963,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_SESSION_GC_MAX_AGE_DAYS` | `sessions.gc.maxAgeDays` | `7` |
| `BILI_SESSION_GC_MAX_TOKENS` | `sessions.gc.maxTokens` | `1000000` |
| `BILI_SESSION_GC_INTERVAL_MS` | `sessions.gc.intervalMs` | `3600000` |
| `BILI_PUBLIC_SNAPSHOT_CAP_BYTES` | `plugin.snapshotCapBytes` | `16777216` |
| `BILI_UPDATE_REGISTRY` | `update.registry` | npm public registry |
| `BILI_UPDATE_CHECK_INTERVAL_MS` | `update.checkIntervalMs` | `180000` |
| `BILI_CCR_RETRIEVAL_TTL_MS` | `ccrRetrievalTtlMs` | `600000` |
Expand Down Expand Up @@ -1045,6 +1053,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_PERSIST_EPERM_ALERT_REPEAT_MS` | Re-alert window for the persist EPERM alert, in ms. `0` (default) = alert once then stay silent; `>0` = re-alert at most every that many ms while the failures continue. |
| `BILI_TUNNEL_ALLOWED_HOSTS` | `/bili/<absolute-url>` tunnel admission for **remote clients** (#409): comma-separated `host` or `host:port` entries that unlock loopback/private destinations (e.g. a LAN relay or the machine's own sglang) for non-loopback clients. The proxy itself and link-local/metadata addresses are always denied; local (loopback) clients always pass. |
| `BILI_MAX_SESSIONS` | Max sessions held in memory (default `256`; LRU eviction — disk is the source of truth). |
| `BILI_PUBLIC_SNAPSHOT_CAP_BYTES` | Retention cap (bytes) for the raw wire-history snapshot kept per plugin session to serve the public fork API (#2017). A plugin session whose serialized snapshot exceeds the cap stops being forkable — `GET /__bili/plugin/snapshot` and `POST /__bili/plugin/fork` fail closed with `409` and the capped reason — instead of retaining an unbounded raw copy of the history forever. The cap is re-evaluated on every plugin model request: a session that shrinks back under the cap (after a fork trimmed it, or the host shrank the history) resumes being forkable. Default `16777216` (16 MiB); `0` disables retention entirely (no session is forkable; existing snapshots are dropped on the next request). File twin: `plugin.snapshotCapBytes`. |
| `BILI_SESSIONS_DIR` | Directory for persisted session state (default XDG data dir). |
| `BILI_SESSION_GC` | Cleanup of stale session files (#1082) is **opt-in**: set to `1`/`true`/`on` to enable — off by default, because session files are user data (exportable, resumable) and there is no silent deletion policy. When enabled, the sweep (boot + hourly) deletes a file only when BOTH conditions hold: older than `BILI_SESSION_GC_MAX_AGE_DAYS`, AND small in the lossless sense — the session was **never compressed** (zero folded blocks) and its newest request body ≤ the token ceiling below, so resuming it costs one cold rebuild from the client's own history and nothing else. Safety rails: compressed sessions are NEVER deleted (their summaries cannot be rebuilt losslessly); a session still held in memory is skipped unless idle since its last disk write; unreadable/corrupt files are left in place; every deletion is audit-logged individually (path, size, age) plus one summary line per non-empty sweep; only the sessions dir is ever touched; emptied protocol subdirectories are removed. Note the resident guard is per-process: another proxy instance sharing `BILI_SESSIONS_DIR` that does not persist (e.g. `BILI_PERSIST=0`) never refreshes file mtimes, so its still-live session files can age out and be swept — the cost is the same bounded cold rebuild, backstopped by the age gate. CCR content stores (#1097) share the session's lifecycle (#1180): a `<hash>.content-store.json` companion is deleted together with its session file, an orphaned companion (session file already gone) is swept once past the age gate, and an unreadable companion keeps its session file too (never guessed at). |
| `BILI_SESSION_GC_MAX_AGE_DAYS` | Minimum age (days) before a session file becomes a GC candidate (default `7`). Keep it far beyond any plausible resume window: after deletion a resumed session restarts message numbering from m00001 while a resuming agent's transcript may still cite old numbers (kernel contract: ids are never reused). |
Expand Down
9 changes: 9 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@
- **状态:** ACTIVE
- **说明:** `max` 以 LRU 淘汰约束内存会话数(对应 `BILI_MAX_SESSIONS`;磁盘仍是事实来源)。`gc` 控制陈旧会话文件清理(对应 `BILI_SESSION_GC*`)—— **显式开启**,因为会话文件是用户数据:压缩过的会话永不删除、每次删除都审计记录、年龄 + 无损尺寸双闸门同时满足才删。详见[环境变量表](#环境变量的配置键对照-2030)。

### `plugin`

- **类型:** `{ snapshotCapBytes?: number }`
- **默认:** `{ snapshotCapBytes: 16777216 }`
- **状态:** ACTIVE
- **说明:** 插件面开关(#2017)。`snapshotCapBytes` 限制为公开 fork API(`GET /__bili/plugin/snapshot`、`POST /__bili/plugin/fork`)按插件会话保留的原始 wire 历史快照大小:序列化快照超限时 bili 拒绝留存 —— 该会话不再可 fork(snapshot/fork 返回 `409` 并注明原因),而不是在磁盘上无限保留全量原始副本。默认 `16 MiB`;`0` 完全停用留存;对应环境变量 `BILI_PUBLIC_SNAPSHOT_CAP_BYTES`。详见[环境变量表](#环境变量的配置键对照-2030)。

### `update`

- **类型:** `{ registry?: string; checkIntervalMs?: number }`
Expand Down Expand Up @@ -961,6 +968,7 @@
| `BILI_SESSION_GC_MAX_AGE_DAYS` | `sessions.gc.maxAgeDays` | `7` |
| `BILI_SESSION_GC_MAX_TOKENS` | `sessions.gc.maxTokens` | `1000000` |
| `BILI_SESSION_GC_INTERVAL_MS` | `sessions.gc.intervalMs` | `3600000` |
| `BILI_PUBLIC_SNAPSHOT_CAP_BYTES` | `plugin.snapshotCapBytes` | `16777216` |
| `BILI_UPDATE_REGISTRY` | `update.registry` | npm 公共 registry |
| `BILI_UPDATE_CHECK_INTERVAL_MS` | `update.checkIntervalMs` | `180000` |
| `BILI_CCR_RETRIEVAL_TTL_MS` | `ccrRetrievalTtlMs` | `600000` |
Expand Down Expand Up @@ -1047,6 +1055,7 @@
| `BILI_PERSIST_EPERM_ALERT_THRESHOLD` | 同一会话连续 N 次持久化写失败(`EPERM`/`EBUSY`/`EACCES`)后触发一次性「把该目录加入杀软排除项」告警的阈值(默认 `5`)。仅 Windows。见下文「Windows:把会话目录加入杀软排除项」章节。 |
| `BILI_PERSIST_EPERM_ALERT_REPEAT_MS` | persist EPERM 告警的重复窗口(毫秒)。`0`(默认)= 只告警一次后静默;`>0` = 失败持续期间最多每这么久重复告警一次。 |
| `BILI_MAX_SESSIONS` | 内存中最多保留的会话数(默认 `256`;LRU 淘汰 —— 磁盘是事实源)。 |
| `BILI_PUBLIC_SNAPSHOT_CAP_BYTES` | 为公开 fork API 按插件会话保留的原始 wire 历史快照的大小上限(字节,#2017)。序列化快照超限的插件会话不再可 fork —— `GET /__bili/plugin/snapshot` 与 `POST /__bili/plugin/fork` 以 `409` fail-closed 并注明原因 —— 而不是永久保留无上限的原始历史副本。上限在每次插件模型请求时重新评估:会话缩回上限内(fork 裁剪后或宿主缩短历史)即恢复可 fork。默认 `16777216`(16 MiB);`0` 完全停用留存(所有会话不可 fork,已有快照在下一次请求时丢弃)。文件孪生键:`plugin.snapshotCapBytes`。 |
| `BILI_SESSIONS_DIR` | 会话持久化目录(默认 XDG data 目录)。 |
| `BILI_SESSION_GC` | 过期会话文件清理(#1082)为**可选开启**:设 `1`/`true`/`on` 启用 —— 默认关闭,因为会话文件是用户数据(可导出、可续聊),不应有静默删除策略。启用后,扫描(启动 + 每小时)只在**两个条件同时满足**时删除一个文件:年龄超过 `BILI_SESSION_GC_MAX_AGE_DAYS`,并且"小"到无损 —— 该会话**从未被压缩过**(零折叠块)且最近一次请求体 ≤ 下述 token 上限,这样继续对话只损失一次冷重建(用客户端自己的历史重建),别无其他。安全边界:被压缩过的会话永不删除(其摘要无法无损重建);内存中仍持有的会话会被跳过,除非该会话自上次落盘后一直空闲;不可读/损坏的文件原地保留;每次删除逐条写审计日志(路径、大小、年龄),另有一次非空扫描的汇总日志;只触碰会话目录;清空后的协议子目录一并删除。注意 resident 守卫是进程内的:共享 `BILI_SESSIONS_DIR` 但不落盘的另一实例(如 `BILI_PERSIST=0`)不会刷新文件 mtime,其仍活跃的会话文件可能老化被扫 —— 代价同样是有限的一次冷重建,且有年龄门兜底。CCR 内容存储(#1097)与会话共享生命周期(#1180):`<hash>.content-store.json` 伴随文件随其会话文件一起删除;孤儿伴随文件(会话文件已不存在)超过年龄门后被清扫;不可读的伴随文件会连同其会话文件一起保留(绝不猜测)。 |
| `BILI_SESSION_GC_MAX_AGE_DAYS` | 会话文件成为清理候选的最小年龄(天,默认 `7`)。必须远超任何合理续聊窗口:文件删除后同会话再续聊,消息编号会从 m00001 重新分配,而续聊 agent 的转录里可能还引用着旧编号(内核契约:编号永不复用)。 |
Expand Down
Loading
Loading