From d10fe595d57db2a93e6e1a53970014582db9b2f7 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 12:36:27 +0800 Subject: [PATCH 1/6] feat: default autoRestartOnUpdate on for host-spawned lane proxies (#2507) --- CONFIGURATION.md | 10 ++-- CONFIGURATION.zh-CN.md | 10 ++-- README.md | 2 +- README.zh-CN.md | 2 +- src/config.ts | 22 +++++++- src/restart.ts | 6 +- ...issue2507-lane-autorestart-default.test.ts | 56 +++++++++++++++++++ 7 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 tests/issue2507-lane-autorestart-default.test.ts diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 711d80cd7b..c315ff5f21 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -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 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). | @@ -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` @@ -1569,7 +1569,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | Env var | Config key | Default | |---------|------------|--------| -| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false | +| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false (true on host-spawned lane proxies, #2507) | | `ACP_AUTO_UPDATE` | `autoUpdate` | true | | `ACP_COMPRESS_NUDGE` | `compress.injectNudge` | true | | `ACP_COMPRESS_PROTOCOL` | `diagnostics.compressProtocol` | "tools" | @@ -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). | diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index addb74bc3c..40fe794f7a 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -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(手动启动)/ true(宿主拉起的 lane 代理,#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 基础地址(私有镜像)。 | @@ -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` @@ -1568,7 +1568,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | 环境变量 | 配置文件键 | 默认值 | |---------|------------|--------| -| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false | +| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false(宿主拉起的 lane 代理为 true,#2507) | | `ACP_AUTO_UPDATE` | `autoUpdate` | true | | `ACP_COMPRESS_NUDGE` | `compress.injectNudge` | true | | `ACP_COMPRESS_PROTOCOL` | `diagnostics.compressProtocol` | "tools" | @@ -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)。 | diff --git a/README.md b/README.md index 5aa99fec3d..91f0749d1d 100644 --- a/README.md +++ b/README.md @@ -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 ` 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`. diff --git a/README.zh-CN.md b/README.zh-CN.md index ac69547b62..fb64ec55e5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -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 ` 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 已安装版本)。 diff --git a/src/config.ts b/src/config.ts index 204afb14ba..f591563391 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1274,6 +1274,22 @@ function warnCcrPluginDivergences(routes: ProviderRoutes, globalCompress?: Compr } +/** #2507: resolution for autoRestartOnUpdate — explicit env > explicit file + * value > lane-aware default. Host-spawned resident proxies (every native / + * lane bootstrap stamps BILI_LAUNCHER_LANE on the child) default ON: their + * host never restarts on its own, so without self-activation an auto-update + * installs files that never take effect (#2507; the #811 opt-in was designed + * back when the typical deployment was a user-managed `bili start`). Manual + * `bili start` keeps the conservative OFF default. Explicit off stays + * available via `"autoRestartOnUpdate": false` or ACP_AUTO_RESTART_ON_UPDATE=0. */ +export function resolveAutoRestartOnUpdate(env: NodeJS.ProcessEnv, fileValue: boolean | undefined): boolean { + const e = env.ACP_AUTO_RESTART_ON_UPDATE; + if (e !== undefined) return e !== "0"; + if (fileValue === true) return true; + if (fileValue === false) return false; + return nonEmpty(env.BILI_LAUNCHER_LANE) !== undefined; +} + export function loadOptions(env: NodeJS.ProcessEnv = process.env): ProxyOptions { // --- Source 1: JSON config file (~/.config/billion-context/billion-context.json) --- // The canonical, user-editable config. Loaded first so env vars below can @@ -1394,9 +1410,9 @@ export function loadOptions(env: NodeJS.ProcessEnv = process.env): ProxyOptions passthrough: passthrough.enabled, passthroughSource: passthrough.source, autoUpdate: (env.ACP_AUTO_UPDATE ?? (fileConfig.autoUpdate === false ? "0" : "1")) !== "0", - // Default OFF: unlike autoUpdate, self-restart touches process - // liveness, so it requires an explicit opt-in (#811). - autoRestartOnUpdate: (env.ACP_AUTO_RESTART_ON_UPDATE ?? (fileConfig.autoRestartOnUpdate === true ? "1" : "0")) !== "0", + // Lane-aware default (#2507): ON for host-spawned resident proxies, + // OFF for manual `bili start` (#811) — see resolveAutoRestartOnUpdate. + autoRestartOnUpdate: resolveAutoRestartOnUpdate(env, fileConfig.autoRestartOnUpdate), updateTag: (env.ACP_UPDATE_TAG ?? fileConfig.updateTag ?? "latest").trim() || "latest", // Default ON: unlike autoRestartOnUpdate, this never touches process // liveness — it only installs files and warns (#1481). diff --git a/src/restart.ts b/src/restart.ts index a60d651b62..51188ea78b 100644 --- a/src/restart.ts +++ b/src/restart.ts @@ -5,8 +5,10 @@ * process so the new version actually takes over. * * Gated by --auto-restart-on-update / ACP_AUTO_RESTART_ON_UPDATE / - * "autoRestartOnUpdate" in the config file — default OFF, where behavior stays - * exactly the #808 warn-once reminder. + * "autoRestartOnUpdate" in the config file. Default is lane-aware (#2507): ON + * for host-spawned resident proxies (BILI_LAUNCHER_LANE set), OFF for manual + * `bili start` (#811) — where behavior stays exactly the #808 warn-once + * reminder. Resolution: src/config.ts resolveAutoRestartOnUpdate. * * Safety gates, all applied before the listener is touched: * - zero in-flight requests (session inFlight counters) at decision time AND diff --git a/tests/issue2507-lane-autorestart-default.test.ts b/tests/issue2507-lane-autorestart-default.test.ts new file mode 100644 index 0000000000..8289d7c532 --- /dev/null +++ b/tests/issue2507-lane-autorestart-default.test.ts @@ -0,0 +1,56 @@ +import { test, after } from "node:test"; +import assert from "node:assert/strict"; +import path from "node:path"; +import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { rmrf } from "./tmp-rm.ts"; + +// #2507: autoRestartOnUpdate defaults ON for host-spawned resident proxies +// (BILI_LAUNCHER_LANE stamped by every native/lane bootstrap) and OFF for +// manual `bili start` (#811) — without self-activation an auto-update on a +// resident lane installs files that never take effect. +const root = mkdtempSync(path.join(tmpdir(), "bc-issue2507-")); +process.env.XDG_CONFIG_HOME = path.join(root, "config"); + +const { resolveAutoRestartOnUpdate, loadOptions } = await import("../src/config.ts"); + +after(() => { + delete process.env.XDG_CONFIG_HOME; + rmrf(root); +}); + +test("resolveAutoRestartOnUpdate: lane-aware default matrix (#2507)", () => { + // lane-aware default + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "dsh" }, undefined), true); + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "opencode" }, undefined), true); + assert.equal(resolveAutoRestartOnUpdate({}, undefined), false); + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "" }, undefined), false); + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: " " }, undefined), false); + // explicit env wins in both directions (any non-"0" value enables — #811 parity) + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "dsh", ACP_AUTO_RESTART_ON_UPDATE: "0" }, undefined), false); + assert.equal(resolveAutoRestartOnUpdate({ ACP_AUTO_RESTART_ON_UPDATE: "1" }, undefined), true); + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "dsh", ACP_AUTO_RESTART_ON_UPDATE: "yes" }, undefined), true); + // explicit file values beat the lane default + assert.equal(resolveAutoRestartOnUpdate({ BILI_LAUNCHER_LANE: "dsh" }, false), false); + assert.equal(resolveAutoRestartOnUpdate({}, true), true); +}); + +test("loadOptions: lane env flips the default end-to-end (#2507)", () => { + assert.equal(loadOptions({ BILI_LAUNCHER_LANE: "pi" }).autoRestartOnUpdate, true); + assert.equal(loadOptions({}).autoRestartOnUpdate, false); + assert.equal(loadOptions({ BILI_LAUNCHER_LANE: "pi", ACP_AUTO_RESTART_ON_UPDATE: "0" }).autoRestartOnUpdate, false); +}); + +test("loadOptions: explicit config-file values stay authoritative on a lane (#2507)", () => { + const cfgDir = path.join(process.env.XDG_CONFIG_HOME!, "billion-context"); + mkdirSync(cfgDir, { recursive: true }); + const cfgFile = path.join(cfgDir, "billion-context.json"); + writeFileSync(cfgFile, JSON.stringify({ autoRestartOnUpdate: false })); + assert.equal(loadOptions({ BILI_LAUNCHER_LANE: "pi" }).autoRestartOnUpdate, false); + writeFileSync(cfgFile, JSON.stringify({ autoRestartOnUpdate: true })); + assert.equal(loadOptions({}).autoRestartOnUpdate, true); + // non-boolean garbage in the file falls through to the lane-aware default + writeFileSync(cfgFile, JSON.stringify({ autoRestartOnUpdate: "yes" })); + assert.equal(loadOptions({ BILI_LAUNCHER_LANE: "pi" }).autoRestartOnUpdate, true); + assert.equal(loadOptions({}).autoRestartOnUpdate, false); +}); From f869791ecdceff32192957f7a763f92f2285c6e5 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 12:36:27 +0800 Subject: [PATCH 2/6] fix: align stale-restart user-facing strings with lane-aware default (#2507) --- src/agent/shared.ts | 2 +- src/cli.ts | 2 +- src/web/i18n.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/agent/shared.ts b/src/agent/shared.ts index 31991163d8..063a915646 100644 --- a/src/agent/shared.ts +++ b/src/agent/shared.ts @@ -339,7 +339,7 @@ export async function fetchStaleNotice(proxyBase: string): Promise 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}.`; } diff --git a/src/cli.ts b/src/cli.ts index dfb8bb458d..e7357b9855 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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. diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 3ee1e071f2..f4efdb2dd7 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -101,7 +101,7 @@ export const MESSAGES: Record> = { "sys.blind_tunnels": "MITM 盲隧道(CONNECT 后无 TLS)", "sys.stale": "磁盘已有新版本 v{disk} —— 重启 bili 生效(当前运行 v{running})", "sys.stale_auto": "自动重启已启用,空闲时自动切换", - "sys.stale_manual": "自动重启未启用(需要 --auto-restart-on-update)", + "sys.stale_manual": "自动重启未启用(可开启 autoRestartOnUpdate)", "sys.pt_on": "Passthrough 已开启:所有请求原样转发,压缩关闭。来源:", "sys.pt_env": "ACP_PASSTHROUGH 环境变量(或 --passthrough 参数)", "sys.pt_file": "配置文件 passthrough: true", @@ -526,7 +526,7 @@ export const MESSAGES: Record> = { "sys.blind_tunnels": "MITM blind tunnels (CONNECT without TLS)", "sys.stale": "Newer version v{disk} on disk — restart bili to apply (running v{running})", "sys.stale_auto": "Auto-restart enabled — switches automatically when idle", - "sys.stale_manual": "Auto-restart not enabled (needs --auto-restart-on-update)", + "sys.stale_manual": "Auto-restart not enabled (enable autoRestartOnUpdate to switch automatically)", "sys.pt_on": "Passthrough ON: all requests forwarded as-is, compression disabled. Source:", "sys.pt_env": "ACP_PASSTHROUGH env var (or --passthrough flag)", "sys.pt_file": "config file passthrough: true", From cbc8630c6a9cb5288f50613b65f6ab899158e1b5 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 13:00:06 +0800 Subject: [PATCH 3/6] fix: source lane-aware autoRestartOnUpdate docs from config-reference seed (#2597) --- CONFIGURATION.md | 4 ++-- CONFIGURATION.zh-CN.md | 4 ++-- website/config-reference/updates.yaml | 10 +++++----- website/docs/index.html | 2 +- website/main.js | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index c315ff5f21..168e256d63 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -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 (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 manual `bili start`. | +| `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). | @@ -1569,7 +1569,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | Env var | Config key | Default | |---------|------------|--------| -| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false (true on host-spawned lane proxies, #2507) | +| `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" | diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 40fe794f7a..8a536cd730 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -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(手动启动)/ true(宿主拉起的 lane 代理,#2507) | ACP_AUTO_RESTART_ON_UPDATE | 新版本装好后自动重启守护进程。宿主拉起的常驻代理默认开启(宿主自身永不重启);手动 `bili start` 默认关闭。 | +| `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 基础地址(私有镜像)。 | @@ -1568,7 +1568,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | 环境变量 | 配置文件键 | 默认值 | |---------|------------|--------| -| `ACP_AUTO_RESTART_ON_UPDATE` | `autoRestartOnUpdate` | false(宿主拉起的 lane 代理为 true,#2507) | +| `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" | diff --git a/website/config-reference/updates.yaml b/website/config-reference/updates.yaml index a0b02744b3..c39c78d884 100644 --- a/website/config-reference/updates.yaml +++ b/website/config-reference/updates.yaml @@ -15,15 +15,15 @@ entries: site_zh: "autoUpdate —— 自动版本检查(默认开;ACP_AUTO_UPDATE=0 或 --no-auto-update 关闭)。" - key: autoRestartOnUpdate type: boolean - default: "false" + default: "false (manual start) / true (host-spawned lane proxy, #2507)" env: ACP_AUTO_RESTART_ON_UPDATE group: updates id: tt.arst site_group: diag - desc_en: "Restart the daemon automatically once a newer version has been installed." - desc_zh: "新版本装好后自动重启守护进程。" - site_en: "autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (opt-in)." - site_zh: "autoRestartOnUpdate —— 新版本装好后自动重启守护进程(可选开启)。" + desc_en: "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." + desc_zh: "新版本装好后自动重启守护进程。宿主拉起的常驻代理默认开启(宿主自身永不重启);手动 bili start 默认关闭。" + site_en: "autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (on by default for host-spawned lane proxies; off for manual start)." + site_zh: "autoRestartOnUpdate —— 新版本装好后自动重启守护进程(宿主拉起的 lane 代理默认开;手动启动默认关)。" - key: updateTag type: string default: "latest" diff --git a/website/docs/index.html b/website/docs/index.html index c3f1408631..42abfc52bd 100644 --- a/website/docs/index.html +++ b/website/docs/index.html @@ -286,7 +286,7 @@

Other top-level fields

  • diagnostics — local troubleshooting knobs: dumpBody false · dumpReq true · rawDumpDir · dump4xx false (+MaxBytes 2 MiB) · renderNone/noInjectTool/noCompressPrompt false · countTokensPassthrough false · compressProtocol "tools".
  • fakeCompletion — retry loop for truncated final chunks: retries 0 (opt-in) · bufCapBytes 16 MiB.
  • autoUpdate — automatic version checks (on by default; disable via ACP_AUTO_UPDATE=0 or --no-auto-update).
  • -
  • autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (opt-in).
  • +
  • autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (on by default for host-spawned lane proxies; off for manual start).
  • updateTag — npm dist-tag channel: latest (default), dev, or pr.
  • advisoryCheck / advisoryUrl — critical-defect advisory watcher (on by default; force-installs the recommended fix when your version is affected).
  • releaseNotesCheck / releaseNotesUrl — release-notes feed for the panel (on by default; fetch + cache only, never installs).
  • diff --git a/website/main.js b/website/main.js index 1b1d77ed13..46dc67e8a5 100644 --- a/website/main.js +++ b/website/main.js @@ -154,7 +154,7 @@ "tt.mitm": "mitm.enabled / mitm.domains — HTTPS interception switch and whitelist domains for login clients.", "tt.mitm2": "mitm.handshakeTimeoutMs — TLS handshake timeout (default 10000).", "tt.aupd": "autoUpdate — automatic version checks (on by default; disable via ACP_AUTO_UPDATE=0 or --no-auto-update).", - "tt.arst": "autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (opt-in).", + "tt.arst": "autoRestartOnUpdate — restart the daemon automatically once a newer version is installed (on by default for host-spawned lane proxies; off for manual start).", "tt.utag": "updateTag — npm dist-tag channel: latest (default), dev, or pr.", "tt.update": "update — self-update channel: registry \"npmjs\" · checkIntervalMs 180000.", "tt.advisory": "advisoryCheck / advisoryUrl — critical-defect advisory watcher (on by default; force-installs the recommended fix when your version is affected).", @@ -390,7 +390,7 @@ "tt.mitm": "mitm.enabled / mitm.domains —— 登录客户端 HTTPS 拦截开关与白名单域名。", "tt.mitm2": "mitm.handshakeTimeoutMs —— TLS 握手超时(默认 10000)。", "tt.aupd": "autoUpdate —— 自动版本检查(默认开;ACP_AUTO_UPDATE=0 或 --no-auto-update 关闭)。", - "tt.arst": "autoRestartOnUpdate —— 新版本装好后自动重启守护进程(可选开启)。", + "tt.arst": "autoRestartOnUpdate —— 新版本装好后自动重启守护进程(宿主拉起的 lane 代理默认开;手动启动默认关)。", "tt.utag": "updateTag —— npm dist-tag 通道:latest(默认)、dev 或 pr。", "tt.update": "update —— 自更新通道:registry \"npmjs\" · checkIntervalMs 180000。", "tt.advisory": "advisoryCheck / advisoryUrl —— 关键缺陷公告监视器(默认开;本机版本命中受影响范围时装填推荐修复版本)。", From 1d108bd4015ef3af4280f5883d57c3b93d1e97f6 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 13:00:07 +0800 Subject: [PATCH 4/6] docs: align README flag default note with lane-aware default (#2597) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91f0749d1d..e0461b3aed 100644 --- a/README.md +++ b/README.md @@ -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. From a4dd4b37fd898f6ee438023fc9f86d059a2dc394 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 13:01:04 +0800 Subject: [PATCH 5/6] test: hermetic lane-aware auto-restart e2e over the real update chain (#2507) --- tests/e2e/e2e-lane-autorestart.test.ts | 241 +++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 tests/e2e/e2e-lane-autorestart.test.ts diff --git a/tests/e2e/e2e-lane-autorestart.test.ts b/tests/e2e/e2e-lane-autorestart.test.ts new file mode 100644 index 0000000000..bdb3f01042 --- /dev/null +++ b/tests/e2e/e2e-lane-autorestart.test.ts @@ -0,0 +1,241 @@ +// #2507 hermetic e2e: the lane-aware autoRestartOnUpdate default against the +// REAL self-update chain (local verdaccio + real dist build + real spawn/re-exec): +// lane proxy (BILI_LAUNCHER_LANE set) -> default ON -> the update lands on +// disk and the proxy self-restarts, serving the new version with no host +// action (the resident-mode gap the issue reports); +// manual start (no lane marker) -> default OFF -> the update lands but +// the process keeps serving the old code (stale=true, opt-in preserved). +// Shares the ACP_TEST_REGISTRY gate and fixture infra with e2e-registry (#1153); +// loopback only, zero secrets, zero external network. +import { spawn, type ChildProcess, execFileSync } from "node:child_process"; +import fs from "node:fs"; +import net from "node:net"; +import path from "node:path"; +import { strict as assert } from "node:assert"; +import { test } from "node:test"; +import * as tar from "tar"; +import { startRegistry } from "./registry-fixture.js"; +import { biliSpawnEnv, IS_WIN, isolatedEnv, npmHomeEnv, npmRunSync } from "./crossplat.ts"; +import { rmrf } from "../tmp-rm.ts"; + +const run = process.env.ACP_TEST_REGISTRY === "1"; +const skipReason = !run ? "set ACP_TEST_REGISTRY=1 (hermetic local-registry e2e; loopback only)" : undefined; + +const REPO_ROOT = path.resolve(import.meta.dirname, "..", ".."); +const DIST_ENTRY = path.join(REPO_ROOT, "dist", "index.js"); +const PKG = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, "package.json"), "utf8")) as { name: string; version: string; files: string[]; scripts?: Record }; +const OLD_VERSION = PKG.version; + +function bumpPatch(v: string): string { + const m = v.match(/^(\d+)\.(\d+)\.(\d+)/); + if (!m) throw new Error(`unexpected version format: ${v}`); + return `${m[1]}.${m[2]}.${Number(m[3]) + 1}`; +} +const NEW_VERSION = bumpPatch(OLD_VERSION); + +// Stage a publishable tarball of THIS package at a synthetic version: same +// files field, same dist build, rewritten package.json version (mirrors +// makeFixtureTarball in e2e-registry.test.ts). +async function makeFixtureTarball(work: string, version: string): Promise { + const packs = path.join(work, "packs"); + fs.mkdirSync(packs, { recursive: true }); + const stage = path.join(work, "fixtures", version); + fs.mkdirSync(stage, { recursive: true }); + const stagedBase = { ...PKG, version }; + // The staged copy models a PUBLISHED artifact: registry installs never run + // prepare, and scripts/ is outside `files`, so drop the hook referencing + // the non-shipped guard script (#2471). + const stagedPkg = { + ...stagedBase, + scripts: Object.fromEntries(Object.entries(stagedBase.scripts ?? {}).filter(([name]) => name !== "prepare")), + }; + fs.writeFileSync(path.join(stage, "package.json"), `${JSON.stringify(stagedPkg, null, 2)}\n`); + for (const entry of PKG.files) { + const src = path.join(REPO_ROOT, entry); + if (fs.existsSync(src)) await fs.promises.cp(src, path.join(stage, entry), { recursive: true }); + } + const home = path.join(work, "home-pkg"); + fs.mkdirSync(home, { recursive: true }); + const listing = npmRunSync(["pack", "--silent", "--pack-destination", packs], { cwd: stage, env: { PATH: process.env.PATH ?? "", ...npmHomeEnv(home) } }) + .trim() + .split("\n") + .pop() + ?.trim(); + assert.ok(listing?.endsWith(".tgz"), `npm pack produced no tarball for ${version}: ${listing}`); + return path.join(packs, listing!); +} + +// The fake install MUST sit under a node_modules directory: isNpmInstallForm +// keys off that path shape (same layout requirement as e2e-registry). +async function extractInstall(work: string, tgz: string, sub: string): Promise { + const installDir = path.join(work, "global", sub, "node_modules", PKG.name); + fs.mkdirSync(installDir, { recursive: true }); + await tar.x({ file: tgz, cwd: installDir, strip: 1 }); + return installDir; +} + +async function readPkgVersion(dir: string): Promise { + return (JSON.parse(await fs.promises.readFile(path.join(dir, "package.json"), "utf8")) as { version: string }).version; +} + +function freePort(): Promise { + return new Promise((resolve, reject) => { + const s = net.createServer(); + s.listen(0, "127.0.0.1", () => { + const p = (s.address() as net.AddressInfo).port; + s.close(() => resolve(p)); + }); + s.on("error", reject); + }); +} + +type BiliProc = { child: ChildProcess; port: number }; + +function spawnBiliStart(installDir: string, port: number, env: Record): BiliProc { + const child = spawn(process.execPath, [path.join(installDir, "dist", "index.js"), "start", "--port", String(port)], { + env: biliSpawnEnv(env), + }); + const proc: BiliProc = { child, port }; + child.stderr?.on("data", () => {}); + child.stdout?.on("data", () => {}); + return proc; +} + +function killPid(pid: number): void { + try { + if (IS_WIN) execFileSync("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore" }); + else process.kill(pid, "SIGTERM"); + } catch { + // already gone + } +} + +async function stopBili(proc: BiliProc | undefined): Promise { + if (!proc || proc.child.exitCode !== null || proc.child.signalCode !== null) return; + proc.child.kill("SIGTERM"); + await new Promise((resolve) => { + const t = setTimeout(() => { + proc.child.kill("SIGKILL"); + resolve(); + }, 5_000); + t.unref?.(); + proc.child.once("exit", () => { + clearTimeout(t); + resolve(); + }); + }); +} + +function sleep(ms: number): Promise { + return new Promise((r) => setTimeout(r, ms)); +} + +async function waitFor(what: string, deadlineMs: number, fn: () => Promise): Promise { + const deadline = Date.now() + deadlineMs; + while (Date.now() < deadline) { + if (await fn()) return; + await sleep(500); + } + assert.fail(`timed out waiting for ${what}`); +} + +interface StatusDoc { + version?: string; + diskVersion?: string; + stale?: boolean; + autoRestartOnUpdate?: boolean; +} + +async function fetchStatus(port: number): Promise { + try { + const res = await fetch(`http://127.0.0.1:${port}/__bili/status`); + if (!res.ok) return undefined; + return (await res.json()) as StatusDoc; + } catch { + return undefined; + } +} + +test("e2e: lane-aware auto-restart default (#2507)", { skip: skipReason }, async (t) => { + assert.ok(fs.existsSync(DIST_ENTRY), "dist/index.js missing — run `npm run build` first"); + const workRoot = path.join(process.cwd(), "tmp"); + fs.mkdirSync(workRoot, { recursive: true }); + const work = fs.mkdtempSync(path.join(workRoot, "e2e-lane-autorestart-")); + const procs: BiliProc[] = []; + const extraPids: number[] = []; + let reg: Awaited> | undefined; + t.after(async () => { + for (const p of procs) await stopBili(p); + for (const pid of extraPids) killPid(pid); + await reg?.stop(); + await rmrf(work); + }); + + reg = await startRegistry(path.join(work, "registry")); + const envBase = isolatedEnv(work); + const biliEnv = { ...envBase, BILI_UPDATE_REGISTRY: reg.url, BILI_UPDATE_CHECK_INTERVAL_MS: "1500" }; + + const oldTgz = await makeFixtureTarball(work, OLD_VERSION); + const newTgz = await makeFixtureTarball(work, NEW_VERSION); + await reg.publish(oldTgz); + await reg.publish(newTgz); + + const logFile = path.join(work, "state", "billion-context", "bili.log"); + const readLog = (): string => { + try { + return fs.readFileSync(logFile, "utf8"); + } catch { + return ""; + } + }; + + await t.test("lane proxy (BILI_LAUNCHER_LANE set): default ON, self-activates after update", async () => { + const installDir = await extractInstall(work, oldTgz, "lane"); + const port = await freePort(); + const proc = spawnBiliStart(installDir, port, { ...biliEnv, BILI_LAUNCHER_LANE: "dsh" }); + procs.push(proc); + await waitFor("lane proxy ready", 60_000, async () => (await fetchStatus(port)) !== undefined); + const before = (await fetchStatus(port))!; + assert.equal(before.autoRestartOnUpdate, true, "lane-spawned proxy must default autoRestartOnUpdate ON (#2507)"); + assert.equal(before.version, OLD_VERSION); + assert.equal(before.stale, false); + + // The whole point of the issue: no host action — the update lands AND + // activates. Original child exits via the handover; the replacement + // (spawned re-exec) takes over the same port with the new version. + await waitFor("self-restart handover", 120_000, async () => { + if (proc.child.exitCode === null && proc.child.signalCode === null) return false; + const s = await fetchStatus(port); + return s?.version === NEW_VERSION; + }); + const m = readLog().match(/\[restart\] replacement is up \(pid (\d+)\)/); + assert.ok(m, `expected the handover log line in ${logFile}:\n${readLog()}`); + extraPids.push(Number(m[1])); + const after = (await fetchStatus(port))!; + assert.equal(after.version, NEW_VERSION, "replacement serves the updated code"); + assert.equal(after.autoRestartOnUpdate, true); + assert.equal(after.stale, false, "handover leaves no stale state behind"); + assert.equal(await readPkgVersion(installDir), NEW_VERSION); + }); + + await t.test("manual start (no lane marker): default OFF, update lands but no restart", async () => { + const installDir = await extractInstall(work, oldTgz, "manual"); + const port = await freePort(); + const proc = spawnBiliStart(installDir, port, biliEnv); + procs.push(proc); + await waitFor("manual proxy ready", 60_000, async () => (await fetchStatus(port)) !== undefined); + const before = (await fetchStatus(port))!; + assert.equal(before.autoRestartOnUpdate, false, "manual start must keep the opt-in default OFF (#811)"); + assert.equal(before.version, OLD_VERSION); + + await waitFor("on-disk flip", 120_000, async () => (await readPkgVersion(installDir)) === NEW_VERSION); + // Give a (wrongly armed) restart handler a beat to misfire, then prove quiescence. + await sleep(3_000); + assert.equal(proc.child.exitCode, null, "manual-start process must NOT self-exit"); + const after = (await fetchStatus(port))!; + assert.equal(after.version, OLD_VERSION, "still serving the pre-update code"); + assert.equal(after.diskVersion, NEW_VERSION); + assert.equal(after.stale, true, "staleness stays visible for the host-restart nudge"); + assert.equal(after.autoRestartOnUpdate, false); + }); +}); From 34d1ac901b922aff2690c7dc33cfc71797f46299 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 10 Oct 2026 13:12:15 +0800 Subject: [PATCH 6/6] test: wire lane-aware auto-restart e2e into registry CI job (#2597) --- .github/workflows/ci-registry.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-registry.yml b/.github/workflows/ci-registry.yml index 82e14038f4..b419a06715 100644 --- a/.github/workflows/ci-registry.yml +++ b/.github/workflows/ci-registry.yml @@ -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()