Skip to content

feat: loud provenance detection for wedged dsh profile copies (#3160) - #3169

Closed
YunzhouLi-hub wants to merge 1 commit into
ranxianglei:masterfrom
YunzhouLi-hub:2026-10-14_dsh-profile-copy-provenance
Closed

YunzhouLi-hub wants to merge 1 commit into
ranxianglei:masterfrom
YunzhouLi-hub:2026-10-14_dsh-profile-copy-provenance

Conversation

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor

Refs #3160 (partial — stage 2 of the maintainer's staged plan; the equality gate is deliberately NOT in this PR, see "Deferred" below).

What

The dsh-lane self-heal paths all compare the on-disk copy's version against the target with ONE-WAY semver:

  • refreshDshProfileCopy (src/update.ts:1127) — if (!isVersionNewer(latest, currentVersion)) return
  • refreshDshDesktopCopy (src/update.ts:1172) — if (!isVersionNewer(targetVersion, diskVersion ?? "0.0.0")) return
  • staleDshProfileCopies (src/update.ts:1289) — only collects copies older than global

A copy dropped out-of-band at a fabricated higher version (the #3160 incident: a hand-made 1.2.9 beside a lockfile that still resolves 0.1.196) reads as "already newest" on every path, so the inner === targetVersion skip in refreshDshProfileBundles (src/dsh-channel.ts:490) is never reached and the profile wedges forever — silently, because readDiskVersion (src/update.ts:778) has no provenance.

This PR adds DETECTION ONLY — it never installs, writes, or spawns:

  • src/provenance.ts — per-profile findings across four rungs: copy-vs-lock, manifest-vs-lock, copy-vs-manifest (no lockfile), spec-above-registry (a spec whose base version is newer than the registry's latest cannot be a real resolution), plus build-divergence (same version from different build commits across profiles). Local pins (link:/file:) and declared-but-missing copies stay silent — both are legitimate states under the dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196 install-lane contract.
  • src/cli.ts — one detached, fail-open audit at startup (after the auto-update block); a wedged copy can never delay or break startup, and the registry lookup happens only when at least one profile carries a registry-pinned copy.
  • src/doctor.ts — the same findings ride the dsh lane's existing warnings channel (alongside dshBundleShadowWarning); the freshness verdict is untouched, because a wedged copy keeps a legitimately "ok" verdict while the one-way gate skips it.

Why detection and not the gate

src/update.ts is load-bearing and human-gated: any change to the updater itself requires a no-op validation release first (AGENTS.md §5) — a broken updater bricks every future upgrade. This PR touches src/update.ts only through a read-only import (isVersionNewer), so it carries none of that risk and can land immediately. The equality gate — local != target and not a local pin -> converge with a loud warning — lands as the follow-up once the no-op release proves the existing upgrade path healthy.

Deferred (stage 1 of the plan)

  • The equality gate in src/update.ts (needs the no-op release first).
  • Web-UI banner surface: findings currently reach the log, bili doctor, and (via doctor) the advisory-style status paths; the dedicated banner rides the follow-up with the gate.

Pre-flight

  • npm run typecheck — clean.
  • Targeted suites green: tests/issue3160-dsh-profile-copy-provenance.test.ts (12/12 — includes the exact Profile 副本自愈可被本地高版本号永久卡死,且 out-of-band 副本无来源校验(#1196 变体) #3160 incident shape: 1.2.9 copy vs 0.1.196 lockfile, ^1.2.9 manifest, registry 0.1.197), tests/update-dsh-self-refresh.test.ts, tests/dsh-refresh.test.ts. (tests/doctor.test.ts cannot complete its teardown on this Windows host — a pre-existing esbuild temp-dir Access is denied that reproduces with the change stashed; all its assertions pass.)
  • npm run build — success; node dist/index.js --version = 0.1.197.
  • Rebased onto current master (4db1536) before push; full-suite verdict belongs to the CI test lanes on this head.

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor Author

CI 复查结论:当前 5 个红灯全部是 master 既有失败/flake,与本 PR 的 diff 无关。证据逐条列在下面,并已按仓库规范另立 issue。

红灯清单(run 38555448599,head 3b6e7f5)

失败项 性质 证据
test (ubuntu-latest, 24, 3) master 既有失败 #2185: factory wiring 必失败
test (ubuntu-latest, 22, 3) master 既有失败 同上
test (windows-latest, 24, 3) master 既有失败 同上 + resolveLockPath(Windows 限定)
test (windows-latest, 22, 3) master 既有失败 同上
static-gates (windows-latest, 22) flake pi-subagents/tests/delegate-widget-refresh.test.ts:198(#2737,600ms 计时敏感断言)

证据 1:#2185: factory wiring 在干净 master 上同样失败

本地把工作区切到干净 master 7f96abe0(无任何本 PR 改动)后复现:

$ git checkout 7f96abe0 && node --import tsx --test tests/pi-subagent-registry.test.ts
ℹ tests 10
ℹ pass 9
ℹ fail 1   ← #2185: factory wiring — session_start self-registers, session_shutdown disposes
TypeError: Cannot read properties of undefined (reading 'sessionManager')
    at <anonymous> (src/agent/tool-guardrails.ts:292:29)

交叉确认:PR #3072(无关 PR)的 CI 也报同一个失败。已立 issue:#3174(含根因与建议修复:rawCtx?.sessionManager?.getSessionId?.() 两处 handler + 测试侧补真实 ctx)。

证据 2:resolveLockPath 在干净 master 的 Windows 上同样失败

$ node --import tsx --test tests/test-suite-lock.test.ts
ℹ tests 16
ℹ pass 15
ℹ fail 1   ← resolveLockPath mirrors paths.ts cacheDir() under XDG_CACHE_HOME
+ actual:   'D:\tmp\x\cache-home\billion-context\test-suite.lock'
- expected: '\tmp\x\cache-home\billion-context\test-suite.lock'

被测实现(scripts/test-suite-lock.mjs:48 的 path.resolve)与 src/paths.ts:22 语义一致,是对的;是 tests/test-suite-lock.test.ts:65-70 的期望值用了 join 而实现用 resolve,Windows 上对 POSIX 路径两者不等。该测试今天 10:44 随 #3112/#3103 合入 master,push 时 test lanes 被 guards skip,所以合并时没暴露。已立 issue:#3175(含一行修复)。

证据 3:static-gates 的 flake

static-gates (windows, 22) 挂在 npm --prefix pi-subagents test 的 queued run renders once it enters running under maxConcurrent=1 (#2737)(delegate-widget-refresh.test.ts:198,duration 600ms 的时序断言)。同一个 pi-subagents 套件本地全绿(237/237),且另外 3 个 static-gates leg 通过——典型的 loaded-runner 时序 flake。同 run 里 hook e2e: an occupied stable port never crashes the host 也是已知端口争用 flake。

本 PR 自身的验证

  • npm run typecheck 干净。
  • 定向 38 个测试全绿(本 PR 的 12 个新用例 + update-dsh-self-refresh + dsh-refresh 相关)。
  • node dist/index.js --version = 0.1.197 (9db9cb1c-dirty),构建通过。

即:本 PR 引入的代码在本地与 CI 的非既有失败项上全绿;红灯修复后(#3174 / #3175)test lanes 应可转绿,无需改动本 PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants