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
4 changes: 2 additions & 2 deletions .github/workflows/ci-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jobs:
run: echo "BILI_E2E_REAL_BASELINE=$(npm view billion-context version)" >> "$GITHUB_ENV"

- name: Run hermetic registry E2E
run: ACP_TEST_REGISTRY=1 node --import tsx --test tests/e2e/e2e-registry.test.ts tests/e2e/e2e-advisory-rollback.test.ts
run: ACP_TEST_REGISTRY=1 node --import tsx --test tests/e2e/e2e-registry.test.ts tests/e2e/e2e-advisory-rollback.test.ts tests/e2e/e2e-lane-autorestart.test.ts

- name: Collect E2E artifacts
if: failure()
run: |
mkdir -p tmp/e2e-artifacts
for d in tmp/e2e-registry-* tmp/e2e-advisory-* tmp/e2e-npm-global-*; do [ -d "$d" ] && cp -r "$d" tmp/e2e-artifacts/ || true; done
for d in tmp/e2e-registry-* tmp/e2e-advisory-* tmp/e2e-lane-autorestart-* tmp/e2e-npm-global-*; do [ -d "$d" ] && cp -r "$d" tmp/e2e-artifacts/ || true; done

- uses: actions/upload-artifact@v4
if: failure()
Expand Down
10 changes: 5 additions & 5 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| Key | Type | Default | Env | Description |
|-----|------|---------|-----|-------------|
| `autoUpdate` | boolean | true | ACP_AUTO_UPDATE | Automatic npm version checks (every ~3 min); disable via ACP_AUTO_UPDATE=0 or --no-auto-update. |
| `autoRestartOnUpdate` | boolean | false | ACP_AUTO_RESTART_ON_UPDATE | Restart the daemon automatically once a newer version has been installed. |
| `autoRestartOnUpdate` | boolean | false (manual start) / true (host-spawned lane proxy, #2507) | ACP_AUTO_RESTART_ON_UPDATE | Restart the daemon automatically once a newer version has been installed. Default ON for host-spawned resident proxies (their host never restarts); OFF for a manual bili start. |
| `updateTag` | string | latest | ACP_UPDATE_TAG | npm dist-tag channel for self-updates: latest (default), dev, or pr. |
| `update` | object | {} (all defaults) | — | Self-update channel settings. |
| `update.registry` | string | "npmjs" (registry.npmjs.org) | BILI_UPDATE_REGISTRY | Custom npm registry base URL for self-updates (private mirrors). |
Expand Down Expand Up @@ -582,9 +582,9 @@ Top-level keys that control how the proxy listens and behaves globally.
### `autoRestartOnUpdate`

- **Type:** `boolean`
- **Default:** `false`
- **Default:** lane-aware (#2507): `true` for host-spawned resident proxies (every dsh/opencode/pi/... native or launcher lane stamps `BILI_LAUNCHER_LANE` on its proxy child), `false` for manual `bili start` (#811)
- **Status:** ACTIVE
- **Description:** Opt-in self-restart after an auto-update install (#811): requires zero in-flight requests, passes an install sanity check, and honors a 10-minute cooldown marker; on failure the original listener resumes. Enabled by `ACP_AUTO_RESTART_ON_UPDATE=1` (any non-`0` value).
- **Description:** Self-restart after an auto-update install (#811): requires zero in-flight requests, passes an install sanity check, and honors a 10-minute cooldown marker; on failure the original listener resumes. The lane-aware default exists because a resident host never restarts on its own — without self-activation an auto-update installs files that never take effect (#2507). Explicit values always win: `"autoRestartOnUpdate": false` / `ACP_AUTO_RESTART_ON_UPDATE=0` disable it anywhere; `true` / any non-`0` env value enable it anywhere.

### `updateTag`

Expand Down Expand Up @@ -1569,7 +1569,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
<!-- bili:gen env-map -->
| Env var | Config key | Default |
|---------|------------|--------|
| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false |
| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false (manual start) / true (host-spawned lane proxy, #2507) |
| `ACP_AUTO_UPDATE` | `autoUpdate` | true |
| `ACP_COMPRESS_NUDGE` | `compress.injectNudge` | true |
| `ACP_COMPRESS_PROTOCOL` | `diagnostics.compressProtocol` | "tools" |
Expand Down Expand Up @@ -1689,7 +1689,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `ACP_UPSTREAM` | Override the default upstream base URL. |
| `ACP_LOG` | Set to `0` to disable request logging. |
| `ACP_AUTO_UPDATE` | Set to `0` to disable auto-update checks. File-config key: `autoUpdate`. |
| `ACP_AUTO_RESTART_ON_UPDATE` | Set to `1` (any non-`0` value) to enable self-restart after an auto-update install (#811): the restart requires zero in-flight requests, passes an install sanity check, honors a 10-minute cooldown marker, and resumes the original listener on failure. File-config key: `autoRestartOnUpdate`. |
| `ACP_AUTO_RESTART_ON_UPDATE` | Set to `1` (any non-`0` value) to enable self-restart after an auto-update install (#811): the restart requires zero in-flight requests, passes an install sanity check, honors a 10-minute cooldown marker, and resumes the original listener on failure. File-config key: `autoRestartOnUpdate`. Default when unset: OFF for manual `bili start`, ON for host-spawned resident proxies (`BILI_LAUNCHER_LANE`) since their host never restarts (#2507). |
| `ACP_UPDATE_TAG` | Dist-tag channel the auto-updater follows (default `latest`, e.g. `dev`). File-config key: `updateTag`. The rolling `pr` tag tracks the newest PR test build across all PRs; legacy per-PR `pr-N` tags are frozen at that PR's last build and are only followed when explicitly configured. The rolling `master` tag tracks the newest build merged to master — every non-release merge publishes one (#2049); set it to follow merged-but-unreleased state. |
| `BILI_UPDATE_REGISTRY` | Base URL override for the npm registry used by the auto-updater and `bili update` (default `https://registry.npmjs.org`). Intended for hermetic testing against a loopback registry (the verdaccio instance in the `ACP_TEST_REGISTRY` e2e suite); leave unset in production (#1153). |
| `BILI_UPDATE_CHECK_INTERVAL_MS` | Auto-update check period in milliseconds (default `180000`, i.e. 3 minutes; values ≤ 0 are ignored and the default applies). Shortened by the hermetic e2e suite so it never waits a full cycle (#1153). |
Expand Down
10 changes: 5 additions & 5 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
| Key | Type | Default | Env | Description |
|-----|------|---------|-----|-------------|
| `autoUpdate` | boolean | true | ACP_AUTO_UPDATE | 自动 npm 版本检查(约每 3 分钟);ACP_AUTO_UPDATE=0 或 --no-auto-update 关闭。 |
| `autoRestartOnUpdate` | boolean | false | ACP_AUTO_RESTART_ON_UPDATE | 新版本装好后自动重启守护进程。 |
| `autoRestartOnUpdate` | boolean | false (manual start) / true (host-spawned lane proxy, #2507) | ACP_AUTO_RESTART_ON_UPDATE | 新版本装好后自动重启守护进程。宿主拉起的常驻代理默认开启(宿主自身永不重启);手动 bili start 默认关闭。 |
| `updateTag` | string | latest | ACP_UPDATE_TAG | 自更新的 npm dist-tag 通道:latest(默认)、dev 或 pr。 |
| `update` | object | {} (all defaults) | — | 自更新通道设置。 |
| `update.registry` | string | "npmjs" (registry.npmjs.org) | BILI_UPDATE_REGISTRY | 自更新用的自定义 npm registry 基础地址(私有镜像)。 |
Expand Down Expand Up @@ -582,9 +582,9 @@
### `autoRestartOnUpdate`

- **类型:** `boolean`
- **默认值:** `false`
- **默认值:** lane 感知(#2507):宿主拉起的常驻代理为 `true`(所有 dsh/opencode/pi/... 原生或 launcher lane 都会给代理子进程打上 `BILI_LAUNCHER_LANE`),手动 `bili start` 为 `false`(#811)
- **状态:** ACTIVE
- **说明:** 自动更新安装后的 opt-in 自我重启(#811):要求零在途请求、通过安装自检、遵守 10 分钟冷却标记;失败时恢复原监听器。`ACP_AUTO_RESTART_ON_UPDATE=1`(任意非 `0` 值)开启。
- **说明:** 自动更新安装后的自我重启(#811):要求零在途请求、通过安装自检、遵守 10 分钟冷却标记;失败时恢复原监听器。lane 感知默认值的存在是因为常驻宿主自身永不重启——没有自我激活,自动更新装下的文件永远不生效(#2507)。显式取值始终优先:`"autoRestartOnUpdate": false` / `ACP_AUTO_RESTART_ON_UPDATE=0` 在任何场景下关闭;`true` / 任意非 `0` 环境变量值在任何场景下开启。

### `updateTag`

Expand Down Expand Up @@ -1568,7 +1568,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报
<!-- bili:gen env-map -->
| 环境变量 | 配置文件键 | 默认值 |
|---------|------------|--------|
| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false |
| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false (manual start) / true (host-spawned lane proxy, #2507) |
| `ACP_AUTO_UPDATE` | `autoUpdate` | true |
| `ACP_COMPRESS_NUDGE` | `compress.injectNudge` | true |
| `ACP_COMPRESS_PROTOCOL` | `diagnostics.compressProtocol` | "tools" |
Expand Down Expand Up @@ -1687,7 +1687,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报
| `ACP_UPSTREAM` | 覆盖默认上游 base URL。 |
| `ACP_LOG` | 设为 `0` 关闭请求日志。 |
| `ACP_AUTO_UPDATE` | 设为 `0` 禁用自动更新检查。文件配置键:`autoUpdate`。 |
| `ACP_AUTO_RESTART_ON_UPDATE` | 设为 `1`(任意非 `0` 值)启用自动更新安装后的自我重启(#811):重启要求零在途请求、通过安装自检、遵守 10 分钟冷却标记,失败时恢复原监听器。文件配置键:`autoRestartOnUpdate`。 |
| `ACP_AUTO_RESTART_ON_UPDATE` | 设为 `1`(任意非 `0` 值)启用自动更新安装后的自我重启(#811):重启要求零在途请求、通过安装自检、遵守 10 分钟冷却标记,失败时恢复原监听器。文件配置键:`autoRestartOnUpdate`。未设置时的默认值:手动 `bili start` 为 OFF,宿主拉起的常驻代理(`BILI_LAUNCHER_LANE`)为 ON——因为其宿主自身永不重启(#2507)。 |
| `ACP_UPDATE_TAG` | 自动更新跟随的 dist-tag 通道(默认 `latest`,如 `dev`)。文件配置键:`updateTag`。滚动 `pr` tag 指向所有 PR 中最新的测试构建;旧版按 PR 划分的 `pr-N` tag 已冻结在该 PR 的最后一个构建,仅在显式配置时才会被跟随。滚动 `master` tag 指向最新合入 master 的构建——每次非 release 合并都会发布一个(#2049);设置它即可跟随已合并但未正式发布的状态。 |
| `BILI_UPDATE_REGISTRY` | 自动更新与 `bili update` 使用的 npm registry base URL 覆盖(默认 `https://registry.npmjs.org`)。仅供 hermetic 测试指向回环 registry(`ACP_TEST_REGISTRY` e2e 套件自带的 verdaccio 实例);生产环境请勿设置(#1153)。 |
| `BILI_UPDATE_CHECK_INTERVAL_MS` | 自动更新检查周期(毫秒,默认 `180000` 即 3 分钟;≤ 0 的值被忽略,回退默认)。hermetic e2e 套件用它缩短周期,避免等待完整间隔(#1153)。 |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bili --passthrough # forward without compression (smoke-test mode)
bili --config ~/my-bili.json # use a different config file
bili update # check & install a newer version now (bypasses throttle)
bili --no-auto-update # disable self-update for this run
bili --auto-restart-on-update # self-restart when a new version is installed (default off)
bili --auto-restart-on-update # self-restart when a new version is installed (default: off for manual start, on for host-spawned lanes)
```

Flags override env vars and the config file. `bili --help` lists them all.
Expand All @@ -424,7 +424,7 @@ Client-facing connections close gracefully after the final response: when the pr

### Self-update

The proxy checks npm on startup and every 3 minutes; a newer version is installed in place and a notice is logged — **restart `bili` to pick it up**, unless you enable opt-in self-restart (`--auto-restart-on-update` flag, env `ACP_AUTO_RESTART_ON_UPDATE=1`, or `"autoRestartOnUpdate": true` in config — default OFF): with zero in-flight requests it verifies the new install, stops accepting connections, drains, spawns a replacement on the same port, and exits once it accepts connections (clients reconnect automatically; session state survives on disk). Safety gates: zero in-flight through the drain window, an install sanity check before re-exec, and a 10-minute cooldown marker so a flapping version can never loop-restart; any failure resumes the original listener and falls back to the plain reminder.
The proxy checks npm on startup and every 3 minutes; a newer version is installed in place and a notice is logged. **Host-spawned resident proxies self-activate by default (#2507)**: every dsh/opencode/pi/... plugin or `bili <client>` launcher lane stamps its proxy child with `BILI_LAUNCHER_LANE`, and those processes self-restart after an install — their host never restarts on its own, so without this the update would sit on disk forever. Manual `bili start` keeps opt-in self-restart (`--auto-restart-on-update` flag, env `ACP_AUTO_RESTART_ON_UPDATE=1`, or `"autoRestartOnUpdate": true` in config — default OFF there; disable anywhere via `"autoRestartOnUpdate": false` / `ACP_AUTO_RESTART_ON_UPDATE=0`). The restart requires zero in-flight requests, verifies the new install, stops accepting connections, drains, spawns a replacement on the same port, and exits once it accepts connections (clients reconnect automatically; session state survives on disk). Safety gates: zero in-flight through the drain window, an install sanity check before re-exec, and a 10-minute cooldown marker so a flapping version can never loop-restart; any failure resumes the original listener and falls back to the plain reminder.

While the running process is behind the on-disk install ("stale"), the web UI shows a banner (running vs installed version, auto-restart state) and `GET /__bili/status` returns `{version, diskVersion, stale, autoRestartOnUpdate, advisory, inFlight}` for scripting (`advisory` is the active critical-defect entry or `null`, see below). Disable permanently via `"autoUpdate": false` in config or `ACP_AUTO_UPDATE=0`.

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ bili --no-auto-update # 本次启动禁用自动更新

### 自动更新

代理启动时和每 3 分钟检查 npm 是否有新版本。发现新版本就原位安装并打印通知 —— **重启 `bili` 才能生效**,除非启用可选自重启(`--auto-restart-on-update` 参数 / `ACP_AUTO_RESTART_ON_UPDATE=1` 环境变量 / 配置 `"autoRestartOnUpdate": true`,默认关闭):零在途请求时校验新安装、停止接收连接、排空、在同一端口拉起替代进程并在其开始接受连接后退出(客户端自动重连;会话状态在磁盘上保留)。安全门:排空窗口全程零在途、re-exec 前安装完整性检查、10 分钟冷却标记防止版本抖动循环重启;任何失败恢复原监听器并回落到普通提醒。运行进程落后于磁盘安装("stale")时,Web UI 显示横幅,`GET /__bili/status` 返回 `{version, diskVersion, stale, autoRestartOnUpdate, advisory, inFlight}` 供脚本使用(`advisory` 为生效中的严重缺陷公告或 `null`,见下节)。永久禁用:配置(`"autoUpdate": false`)或环境变量(`ACP_AUTO_UPDATE=0`)。
代理启动时和每 3 分钟检查 npm 是否有新版本。发现新版本就原位安装并打印通知。**宿主拉起的常驻代理默认自我激活(#2507)**:所有 dsh/opencode/pi/... 插件或 `bili <client>` launcher lane 都会给代理子进程打上 `BILI_LAUNCHER_LANE`,这些进程在安装后自动自我重启——宿主自身永不重启,没有这一步更新会永远躺在磁盘上。手动 `bili start` 保持 opt-in 自重启(`--auto-restart-on-update` 参数 / `ACP_AUTO_RESTART_ON_UPDATE=1` 环境变量 / 配置 `"autoRestartOnUpdate": true`,该场景默认关闭;任何场景可用 `"autoRestartOnUpdate": false` / `ACP_AUTO_RESTART_ON_UPDATE=0` 禁用)。自重启要求零在途请求,校验新安装、停止接收连接、排空、在同一端口拉起替代进程并在其开始接受连接后退出(客户端自动重连;会话状态在磁盘上保留)。安全门:排空窗口全程零在途、re-exec 前安装完整性检查、10 分钟冷却标记防止版本抖动循环重启;任何失败恢复原监听器并回落到普通提醒。运行进程落后于磁盘安装("stale")时,Web UI 显示横幅,`GET /__bili/status` 返回 `{version, diskVersion, stale, autoRestartOnUpdate, advisory, inFlight}` 供脚本使用(`advisory` 为生效中的严重缺陷公告或 `null`,见下节)。永久禁用:配置(`"autoUpdate": false`)或环境变量(`ACP_AUTO_UPDATE=0`)。

**插件模式**(`bili opencode` / `bili pi` / `bili dsh` —— 代理内嵌在长驻宿主里运行时),"重启 bili"指的是重启**宿主**:内嵌进程无法自行退出,所以一直开着的宿主会持续运行它启动时的那份代码,默默地错过自动更新报告为"已安装"的每一处修复(#1603)。启用 `--auto-restart-on-update` 可让它在安全点自重启;或运行 `/acp`(当前仅 OpenCode 宿主,pi/dsh 覆盖见 #2084)—— 当磁盘安装领先于运行进程时,状态面板会追加一行过期警告(运行版本 vs 已安装版本)。

Expand Down
2 changes: 1 addition & 1 deletion src/agent/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export async function fetchStaleNotice(proxyBase: string): Promise<string | unde
const runningCommit = typeof s.commit === "string" && s.commit.length > 0 ? s.commit : undefined;
const tail = s.autoRestartOnUpdate === true
? " — auto-restart is enabled but did not fire this cycle; check the bili log"
: " — restart the host to activate (or enable --auto-restart-on-update)";
: " — restart the host to activate (or enable autoRestartOnUpdate)";
return `⚠️ billion-context is stale: running v${running}${runningCommit ? ` (${runningCommit})` : ""} but v${installed} is installed${tail}.`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Options (override config file / env):
--passthrough forward without compression
--no-passthrough force compression on (overrides config)
--no-auto-update disable background self-update this run
--auto-restart-on-update self-restart when a newer version is already installed on disk (default off)
--auto-restart-on-update self-restart when a newer version is already installed on disk (default: off for manual start, on for host-spawned lanes)

Config: ${defaultConfigFile()}
Set port/host/debug/providers/compress/autoUpdate there. See README §Configuration.
Expand Down
Loading
Loading