Skip to content

fix: advisory rollback form — block affected candidates in the normal loop, persist restart prompt (#1588) - #1596

Merged
ranxianglei merged 4 commits into
masterfrom
2026-09-28_advisory-rollback-fix
Oct 1, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-09-28_advisory-rollback-fix

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1588

Rollback-form advisories (target OLDER than latest, with latest inside affected) had two defects. Both are fixed at their decision points:

A — target↔latest ping-pong (autoUpdate=ON)

The normal self-update loop only deferred while the current version matched an active advisory. After a rollback install, runAdvisoryCheck re-evaluated against the freshly installed disk version (clean by construction) and cleared state.active — so the next cycle's follow-latest pulled the machine back into the defect, and the watcher rolled it back again. Every ~2 cycles: two tarball downloads + in-place installs + log spam, for the whole advisory lifetime.

Fix: checkForUpdate now consults a new advisoryBlocksVersion(candidate) predicate before installing any candidate (src/update.ts). A candidate inside any freshly parsed advisory's affected range is skipped with an info log and retried next cycle. The predicate:

  • fails open when the feed is unreachable/malformed (a down feed never blocks normal updates);
  • releases together with the deferral when the target cannot be resolved (F2 composition — no new wedge class; the escape hatch stays one mechanism);
  • does not apply to forced manual checks.

B — no persistent restart prompt after a successful rollback install

After a rollback install, disk < running, so staleInstallStatus() stayed silent — and the same re-evaluation that cleared state.active killed the web banner too. The only signal was one log line. (Upgrade form worked because disk > running.)

Fix: the post-install re-evaluation is re-keyed from the freshly installed disk version to the running version. The banner/status persists with pendingRestart: true + installedVersion until a restart completes and the running version leaves the affected range — in BOTH upgrade and rollback forms. The web banner renders a dedicated "safe version installed, restart to activate" line (zh/en); /__bili/status.advisory carries the two fields automatically.

Behavior changes (old → new)

  1. Banner/status lifecycle: old = cleared immediately after a successful advisory install; new = persists until the running version leaves the affected range (i.e. after the restart completes), in both forms. Web banner wording switches to the restart prompt while pending.
  2. Normal self-update loop: old = deferred only while the current version matched an active advisory; new = additionally skips any candidate covered by a freshly parsed advisory's affected range (logged [update] skipping X: covered by a critical-bug advisory's affected range (#1588), retried next cycle). Fails open on unhealthy feed / unresolvable target.
  3. /__bili/status.advisory + web banner: gain pendingRestart / installedVersion.
  4. Test-only seam _resetUpdateThrottleForTest() (src/update.ts): the THROTTLE_FILE path resolves once at module load, so all in-process tests share one throttle state; non-forced checkForUpdate tests need an explicit reset. Zero production impact.

Deliberately UNCHANGED: staleInstallStatus() and decideAutoRestart() still treat only disk > running as stale — whether a rollback should also trigger auto-restart is a separate product decision (flagged in #1588, not bundled here).

config surface

Unchanged — no new config fields, env vars, or CLI flags. All changes are internal decision logic in src/update.ts / src/advisory.ts plus the two additive status/banner fields above.

Tests

tests/advisory.test.ts: 16 → 19 tests.

  • Two existing tests that pinned the buggy clear-on-install behavior updated: the banner now persists with pendingRestart/installedVersion and clears only after a simulated restart (re-run with currentVersion = installed target).
  • New regression for the ping-pong window: clean machine + a freshly published advisory whose range covers versions ABOVE current → watcher no-ops, then checkForUpdate must not pull the latest candidate into the defect (zero tarball fetches, disk untouched, skip logged).
  • New: main variant — after a rollback install, the normal loop keeps deferring (zero registry calls).
  • New: fail-open when the feed goes unhealthy; F2 composition — an unresolvable target releases the blocklist together with the deferral.

Gate on rebased head 07624b3e (on 25edbbc1): typecheck clean · 3109/3125 pass, 0 fail · build OK.

Release note (§5)

This touches load-bearing src/update.ts. Recommended sequence: ship a no-op v0.1.168 first, observe a real upgrade succeed, then release this change. Note v0.1.167 already ships the pre-fix lifecycle (the #1582 reland landed in it), so this fix matters for every future rollback-form advisory — the defect itself stays dormant until such an advisory is actually published (advisories/package.json currently carries zero entries).

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-28_advisory-rollback-fix (8ca6808)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1860-pr.1596.144c52c

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1596.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Received — reviewing PR #1596 (branch 2026-09-28_advisory-rollback-fix, head 07624b3). Plan: pull the branch, audit the diff against current master (focus: src/update.ts / src/advisory.ts decision points, both advisory forms, wire/status surface), check CI status, run local gate (typecheck + tests + build) on the rebased head, then report verdict. Will update here with findings.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — verdict: mergeable (pending CI on the new head + human approval; per §7.4 this stays human-merged anyway since it touches load-bearing src/update.ts).

What I did: pulled 2026-09-28_advisory-rollback-fix, audited the full diff against current master (head was exactly master+1, no stale base), traced every affected code path in both advisory forms, checked CI, and ran the local gate on the tree. One nit fixed directly on the branch (below).

① Direction (original issue #1588): correct root-cause framing, not symptom-masking. Both defects were defects at decision points — the normal loop's install decision (only deferred while THIS machine matched) and the post-install re-evaluation key (disk instead of running version). The fix lands exactly there: advisoryBlocksVersion() consulted at the install decision in checkForUpdate, and re-evaluation re-keyed to the running version in runAdvisoryCheck. Fail-open discipline is consistent with the rest of the module (unhealthy feed → entries cleared → block released; F2 unresolvable target → block released together with the deferral). I verified the placement of the skip in src/update.ts: it sits after the reportNotNewer up-to-date check and before the tarball download, so it only fires when an install would actually happen, and the throttle timestamp write ordering matches every other early return.

② Regression audit — existing behaviors on touched paths:

  • Normal loop early returns (registry error, source-checkout guard, native模式下自动更新问题需要解决 #991 host-managed guard, dsh owner-channel refresh): semantically untouched — the only additions are the new covered-candidate skip and the opts.installDir ?? test seam (absent in production, no-op). Forced manual checks bypass both new gates. ✔
  • Advisory deferral block: same semantics, comment rewritten, #1196 refresh path intact. ✔
  • state.active lifecycle: the one real behavior change (disclosed fix: keep system prompt byte-stable for prefix cache #1). Traced all branches: clears after restart completes (running leaves range); self-heals if the advisory is removed from the feed mid-window; unhealthy feed leaves active untouched (same as pre-existing behavior). Side effect: advisoryDeferring() stays true during the pending-restart window, so the normal loop fully defers then — complementary to the blocklist, intentional, prevents the very ping-pong being fixed. ✔
  • /__bili/status.advisory: spreads adv.active, so pendingRestart/installedVersion flow through automatically (verified in src/server.ts); internal entries is not exposed. Additive wire surface only. ✔
  • Web banner/i18n: old wording retained whenever pendingRestart is absent (shape-safe); new zh/en strings added symmetrically in both locales. ✔
  • Deliberately unchanged: staleInstallStatus()/decideAutoRestart() still treat only disk>running as stale — rollback does NOT trigger auto-restart (correctly flagged as a separate product decision). ✔
  • Wire/compression modes: no message-shape or stream changes at all — §6 N/A. Config surface: unchanged, matching the claim. ✔

③ Code: clean. Module-level facts verified (rm import, THROTTLE_FILE/firstCheckDone module scope for the new test seam, startAutoUpdate passes opts straight through so the cli.ts wiring is live in production). One cosmetic note (non-blocking): during the upgrade-form pending-restart window the process-level stale indicator (disk>running, independent endpoint machinery) can coexist with the new restart banner — duplicate-but-harmless signals; the advisory banner remains the canonical prompt.

④ Tests: real teeth, not ceremony. The two updated tests pin the new lifecycle with exact field assertions (id/pendingRestart/installedVersion) plus a simulated-restart second pass; the new ping-pong test reproduces the exact residual window (clean machine + range covering latest → packument fetched once, zero tarballs, disk byte-identical, skip logged); fail-open and F2-composition tests assert the release semantics precisely. All five would catch a regression of the original bug.

⑤ Diff cleanliness: found one defect — the restructured parse/catch section in src/advisory.ts and the deferral block in src/update.ts were left at inconsistent indent levels relative to their enclosing blocks (syntactically valid, zero semantic impact, but against the repo's clean-diff standard). Fixed directly on the branch: commit 83904816 ("style: normalize indentation…"), whitespace-only, 2 files ±21 lines. Re-ran the full gate on the resulting tree: typecheck clean · 3109/3125 pass, 0 fail, 16 skipped (exactly matching the PR's claimed numbers) · build OK.

CI: prior head 07624b3e was fully green — 12/12 jobs (test ubuntu 22/24 + windows 22/24, hermetic registry e2e, real-client codex/pi/dsh/opencode lanes, version-guard, build-artifact). mergeable_state: blocked is the required-review gate, not failing checks. My nit commit re-triggers CI on 83904816; the local gate on that exact tree is already green.

Release sequencing (§5): agreed with the PR's own recommendation — ship a no-op v0.1.168 first, observe a real auto-updated hop, then ship this. The defect stays dormant until a rollback-form advisory is ever published, so there's no urgency pressure.

中文摘要:审核了回滚型公告的两个缺陷(正常更新回路把机器拉回缺陷版本的乒乓、回滚安装后无持久重启提示)——修复打在决策点根因上(安装前候选黑名单 + 按运行版本而非磁盘版本重评估),失败路径全部 fail-open,5 个测试断言有牙且复现原始缺陷,CI 全绿;我在 PR 分支直接补了一个纯空白缩进修正(已重新验证全绿),可以合并(按 §7.4 由人合并,发布建议先走 no-op v0.1.168)。

@ranxianglei
ranxianglei force-pushed the 2026-09-28_advisory-rollback-fix branch from 8390481 to c1d9e1b Compare October 1, 2026 13:48
@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebased onto current master (was 3 days behind, mergeable=unknown) and completed the #1588 verification the issue asked for.

Rebase resolution notes (the old CI green was misleading — it ran against the stale base):

  1. src/update.ts:747 — both sides made the same opts.installDir ?? findInstallDir edit; kept master's formatting, dropped the now-duplicate UpdateOptions.installDir declaration.
  2. src/web/i18n.ts zh/en — adjacent insertions (master's alert.* keys vs this PR's advisory.restart*); took the union.
  3. tests/advisory.test.ts — auto-merge dropped the rmSync import (ReferenceError at :540, whole suite crash); restored.

New in this push (c1d9e1b):

  • tests/e2e/e2e-advisory-rollback.test.ts — a resident-bili start e2e on the e2e-registry verdaccio infra, publishing START (affected) / LATEST (latest, affected) / TARGET (older, clean) + a billion-context-advisories packument, asserting the full advisory 回滚形态公告:target↔latest 振荡(autoUpdate=ON)与回滚成功后无持久重启提示 #1588 contract: ① control self-update works, ② forced rollback to TARGET + persistent restart banner (pendingRestart on /__bili/status), ③ no ping-pong across ≥3 cycles (pre-restart), ④ post-restart candidate gate refuses the affected latest (skipping … covered by a critical-bug advisory's affected range (#1588)) and the advisory state clears. Wired into ci-registry.yml + documented in tests/e2e/README.md.
  • src/advisory.ts — the post-install restart hint now warns under ${adv.id}:restart instead of adv.id: the forced-install line already consumed the adv.id warnOnce key in the same process, so the restart hint was deduped away (dead log line; the status/banner surfaces were unaffected).

Gates on the rebased head: typecheck ✓ · full unit suite 3582 tests / 0 fail ✓ · both registry e2e suites 9/9 ✓ (incl. the new 4-phase drill) · build ✓.

§5 note: src/update.ts is touched, but the no-op-first requirement is already satisfied in practice — v0.1.177 was the no-op validation release and the 0.1.177→0.1.178→0.1.179 upgrade chain has run clean since.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Re-reviewing the rebased head c1d9e1b7 now. Plan: verify the branch sits on current master (fe92be6d) and audit the three rebase resolutions against master's own state (especially the dropped duplicate UpdateOptions.installDir), read the new e2e drill end-to-end (hermeticity + teeth + CI wiring), check the warnOnce key change, then run targeted local gates (typecheck · build · tests/advisory.test.ts · both registry e2e suites) and check CI on the head. Verdict to follow.

ework-agent and others added 4 commits October 1, 2026 21:59
… loop, persist restart prompt (#1588)

Rollback-form advisories (target older than latest, latest inside affected) had two defects: (A) the normal self-update loop only deferred while the CURRENT version matched an active advisory — after a rollback install cleared state.active, follow-latest pulled the machine back into the defect every cycle; (B) after a successful rollback install disk < running, so staleInstallStatus and the banner went silent with no persistent restart signal.

Fix A: checkForUpdate now consults advisoryBlocksVersion(candidate) before installing — a candidate inside any freshly parsed advisory's affected range is skipped (logged, retried next cycle). Fails open on unhealthy feeds and releases together with the deferral when the target cannot be resolved (F2 composition).

Fix B: runAdvisoryCheck re-evaluates against the RUNNING version instead of the freshly installed disk version; the banner/status persists (pendingRestart + installedVersion) until a restart completes and the running version leaves the range, in both upgrade and rollback forms.
Whitespace-only: the restructured runAdvisoryCheck parse/catch section
(src/advisory.ts) and the advisory deferral block (src/update.ts) were
left at inconsistent indent levels relative to their enclosing try/if.
No semantic change.
…ct restart-hint warnOnce key

- tests/e2e/e2e-advisory-rollback.test.ts: same verdaccio fixture infra as
  e2e-registry.test.ts; publishes START(affected)/LATEST(latest, affected)/
  TARGET(older, clean) + a billion-context-advisories packument, drives a
  resident 'bili start' through the full #1588 contract: control self-update,
  forced rollback to TARGET, no ping-pong across cycles (pre-restart), and
  the candidate gate refusing affected latest after restart.
- src/advisory.ts: the post-install restart hint now warns under
  '${adv.id}:restart' instead of adv.id — the forced-install line already
  consumed the adv.id key in the same process, deduping the restart hint
  away (dead log line; the banner/status surfaces still worked).
- ci-registry.yml + tests/e2e/README.md: wire the new suite + docs.
…hardened rmrf helper

The tmp-rm.ts sweep (#1646) standardized recursive teardowns on rmrf (maxRetries/retryDelay against ENOTEMPTY on loaded CI runners); the three teardowns added for #1588 still used bare rmSync without retry options. Aligns them with the file's existing convention.
@ranxianglei
ranxianglei force-pushed the 2026-09-28_advisory-rollback-fix branch from c1d9e1b to 8ca6808 Compare October 1, 2026 14:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Round-2 review of rebased head c1d9e1b7 — verdict: mergeable (human merge per §7.4; CI 13/13 green on this head).

What I did: pulled the rebased branch, verified all three rebase resolutions against master, audited the new e2e drill line-by-line, traced the warnOnce key change, and ran the local gate: typecheck ✓ · build ✓ · tests/advisory.test.ts 19/19 ✓ · both hermetic registry e2e suites 9/9 ✓ · plus two extra runs of the new advisory-rollback suite (3/3 consistent, ~60s each) to probe a startup-timing question I found (below).

① Rebase resolutions — all three verified correct:

② New additions audited:

  • warnOnce key fix (adv.id → ${adv.id}:restart): correct, and it fixes a real defect I missed in round 1 — the forced-install line consumes the bare adv.id key earlier in the same process, so the old restart hint was deduped into a dead log line. New behavior: the hint logs once per process per advisory id. Log-surface only; status/banner were never affected, as stated.
  • New e2e (tests/e2e/e2e-advisory-rollback.test.ts): meets every AGENTS.md E2E rule — own verdaccio instance (never external), random loopback ports via listen(0), fully isolated HOME/XDG_* env, zero secrets/tokens/external network, crash-safe teardown, gated behind ACP_TEST_REGISTRY=1. The four phases have teeth: control (normal loop alive pre-advisory), forced rollback with exact /__bili/status field asserts (pendingRestart/installedVersion/targetFailed) and an assertion on the exact restart-banner log line (which pins the new warnOnce key end-to-end — if the dedup regressed, that line never appears and the test fails), pre-restart no-ping-pong across ≥3 cycles, and the post-restart candidate gate asserting the exact skipping … (#1588) skip line plus banner clearing. Publish choreography (ascending TARGET→START→LATEST so the implicit latest tag lands right) is sound; decPatch fails loudly instead of misbehaving at patch 0. ci-registry.yml wiring and README docs are minimal and accurate (2500ms cadence via the documented test: 自带本地 npm registry 的 hermetic 测试基建——解锁自更新/钉版本/解析全链路 e2e #1153 seam, default unchanged).

③ Structured seven questions:

  1. 是什么问题: 回滚型公告的两个缺陷(advisory 回滚形态公告:target↔latest 振荡(autoUpdate=ON)与回滚成功后无持久重启提示 #1588:正常回路乒乓、回滚后无持久重启提示)+ 本轮暴露的第三个:重启提示日志行与强制安装日志行共用 warnOnce 键,同进程内被去重成死行。
  2. 什么原因导致的: 安装决策点不查询新鲜解析的 affected 范围;安装后重评估以磁盘版本而非运行版本为键;两条日志行键冲突。
  3. 怎么修复的: 决策点加候选黑名单谓词(fail-open);重评估改按运行版本;独立 ${id}:restart 键;新增 hermetic e2e 把四段行为契约端到端钉死。
  4. 是否有回归问题: 无。三处 rebase 决议逐一核对无误;与 master 的最终 diff 干净;分支落后当前 master 的 3 个提交(aedd29ce/41958d52/fe92be6d,compat.dropFields 域)与本 PR 文件集完全不相交,无语义冲突;warnOnce 变更仅日志面。行为变更维持第 1 轮已披露的两项(横幅生命周期、候选跳过),另新增一项小变更:重启提示行现在会真正出现在日志里(旧值:同进程内从不出现=死行 → 新值:每进程每公告 id 出现一次)。
  5. 是否破坏缓存: 不涉及。节流文件语义未动(测试 seam 仅测试用),无任何 wire 变化。
  6. 是否改了设计方向: 不涉及——沿用既有 advisory 模块模式(fail-open、warnOnce、state.active 生命周期),e2e 复用 test: 自带本地 npm registry 的 hermetic 测试基建——解锁自更新/钉版本/解析全链路 e2e #1153 hermetic registry 基建。
  7. 是否引入了新的配置: 无新配置。BILI_UPDATE_CHECK_INTERVAL_MS 是既有文档化 seam,仅套件内加速到 2500ms,默认 180000 不变。

⚠ 一个非阻塞观察(启动时序): cli.ts 中 startAutoUpdate(:583)先于 startAdvisoryWatcher(:613)注册,两者首次触发都是 +10s——意味着进程冷启动后 updater 的首次检查会先于 advisory 首次解析到达候选门。若某次调度下 updater 抢在 state.entries 装填前完成决策,门 fail-open 放行一次(一次有界的乒乓:装上 LATEST、watcher 再滚回 TARGET,下一周期即恢复门禁)。分析表明 advisory 路径结构性更短(首个 await 到 fetch 之间的 fs 工作更少,parse→entries 早于 updater 的 json→semver→readDiskVersion→gate),且本地 3/3 + CI 全绿均按此顺序通过;该模式对既有的 deferral 检查同样存在(非本 PR 新引入)。记录在案,不构成拦阻;若想彻底消除可考虑启动时立即跑一次强制 advisory check——属后续优化,不在本 PR 范围。

§5 release sequencing: 接受 no-op-first 已满足的论断(v0.1.177 即验证性 no-op 发布,0.1.177→0.1.178→0.1.179 升级链已干净跑过)。

CI: c1d9e1b7 上 13/13 check runs 全绿(含扩展后的 hermetic registry e2e job——现在同时跑两个套件;跨平台 test 矩阵、real-client lanes、version-guard 全过)。

分支新鲜度: 落后当前 master 3 个提交(compat-drop 域,不相交),mergeable=true, state=behind——按仓库惯例 BEHIND 不是阻塞项,合并按钮会自动带上那 3 个提交,无需额外动作。

中文摘要:第二轮审核了 rebase 后的 head(c1d9e1b7)——三处 rebase 决议全部核对正确(installDir 去重、i18n 并集、rmSync 恢复),warnOnce 键修复了我第一轮漏掉的真缺陷(重启提示被去重成死日志行),新增 hermetic e2e 完全符合规范且四段断言有牙;本地 typecheck/build/单测 19/19/两 e2e 套件 9/9 + 新套件追加 2 次共 3/3 稳定,CI 13/13 全绿;发现一个非阻塞的启动时序观察(首查竞争,有界自愈,既有模式),可以合并(按 §7.4 由人合并)。

@ranxianglei
ranxianglei merged commit 16fcd94 into master Oct 1, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-28_advisory-rollback-fix branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

advisory 回滚形态公告:target↔latest 振荡(autoUpdate=ON)与回滚成功后无持久重启提示

1 participant