Skip to content

ci: 每个发布渠道都必须在发布 sha 上完整跑完全套 CI 才能发布 - #2693

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-10_release-full-ci-gate
Oct 11, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-10_release-full-ci-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

问题

v0.1.192(bugfix 通道,#2664)暴露的流程漏洞:该渠道只跑了内嵌 pre-flight(npm ci && typecheck && test && build),没有任何 e2e lane 在发布 sha 上跑过 —— 因为该渠道没有 PR,而所有 e2e workflow 都不触发 bugfix-release/** push。当时是靠人工核对回归证据放行的,不能作为常态机制。

方案(所有发布渠道统一补全)

新增 scripts/release-ci-gate.mjs,四个发布 workflow 全部接入:

渠道 接入点 说明
release.yml(master PR 合并) dispatch 早启 + Create tag 前硬门 EXTRA_MATCH_SHAS=HEAD^2 复用 PR head 的绿 run → 常规 PR 发布零额外 CI 成本(与分支保护 required checks 语义一致)
release-bugfix.yml(切香肠渠道) pre-flight 前 dispatch(lanes 与 pre-flight 并行)+ pre-flight 后硬门 补上 v0.1.192 的洞;+actions:write
release-kernel.yml 同 release.yml 同样复用 PR-head run
release-manual.yml(一键直推 master) push 后 dispatch+硬门 GITHUB_TOKEN push 不触发任何事件,发布 commit 上什么 CI 都不会跑 → 必须显式 dispatch;fallback 路径走 release.yml 已覆盖

门语义(fail-safe)

  • --dispatch:对发布 sha 上没有 run 的 lane 逐个 workflow_dispatch(幂等,已有 run 的绝不重跑);无法 dispatch(无 trigger/文件不在默认分支)→ 硬失败,拒绝发布。
  • --wait:轮询直到每个 lane 在发布 sha 上的最新 run = success;任何 red(failure/cancelled/timed_out/startup_failure/action_required/非 success)→ exit 1;超时(默认 60min)→ exit 1。任何失败形态都阻塞 publish。
  • 复用规则严格单向:发布 sha 上有 red run 时,PR-head 的绿 run 永远不能覆盖它(只在没有发布 sha run 时才允许复用)。

必跑 lane 集(REQUIRED_CI_WORKFLOWS 可覆盖)

ci.yml(含 windows×node22/24 矩阵)+ 全部 6 条 every-PR e2e lane + 2 条 path-filtered 但安全相关的 e2e lane(ci-e2e.yml / ci-e2e-dsh.yml,src/server/**)。排除:ci-zcode-real(需真实 AppImage+版本输入)、ci-windows-codex(无 dispatch trigger,ci.yml 矩阵已覆盖 windows)、theorem/image/registry(path-gated 辅助 lane)。

成本

  • 常规 PR 发布:0 额外 CI(复用 PR-head 绿 run)。
  • 切香肠/一键渠道:每次发布多一轮全 lane CI(e2e 每条约 1 分钟,总增量 ~10 分钟,与 pre-flight 并行起跑)。

测试

  • 新增 tests/release-ci-gate.test.ts:8 条回归测试,内联 mock GitHub Actions API(runs 列表 + dispatch 端点),无网络无 token,覆盖:dry-run/幂等 dispatch、不可 dispatch 硬失败、wait 转绿通过、red 快速失败、发布 sha red 不被 PR-head green 覆盖、extra sha 绿 run 复用、超时阻塞。本地 node --import tsx --test 8/8 通过,npm run typecheck 通过。
  • 4 个 workflow 全部 YAML 解析验证,步骤插入位置逐个核对(publish 步骤之前)。

风险与边界

  • dispatch 落在 ref 当前 head;若 dispatch 后 ref 又被推进,run 的 head_sha 不再匹配发布 sha → gate 超时 → 不发布(失败方向安全,重试即可)。
  • 依赖各 lane 均带 workflow_dispatch trigger(已逐一核实,除被排除的 ci-windows-codex)。
  • release.yml 的 *_release-v* 触发分支由 PR 合并产生(真实账号 push),事件正常;GITHUB_TOKEN push 无事件的问题只影响 release-manual.yml 直推路径,已显式处理。

人类合并,机器人不合并。

Follow-up to the v0.1.192 carve-out (#2664): the bugfix channel shipped
with only its embedded pre-flight (typecheck+test+build) — no e2e lane
ever ran on the publish sha, because no PR existed and no e2e workflow
triggers on bugfix-release/** pushes.

Policy (2026-10-10): no matter the release channel, the COMPLETE CI lane
set must be green at the exact publish sha before npm publish.

- new scripts/release-ci-gate.mjs:
  --dispatch: idempotently workflow_dispatch every required lane that has
    no run at the publish sha (or a green run at an EXTRA_MATCH_SHAS,
    e.g. the PR head — same semantics as branch-protection required
    checks, so routine PR-based releases pay zero extra CI);
  --wait: block until every lane's latest run at the publish sha is
    success; any red lane / timeout / un-dispatchable lane ⇒ exit 1,
    publish step never runs (fail-safe).
- release.yml / release-kernel.yml: dispatch early + gate before Create
  tag, gated on is_release; EXTRA_MATCH_SHAS=HEAD^2 reuses PR-head runs.
- release-bugfix.yml: dispatch before the pre-flight (lanes run in
  parallel with it) + gate after it; +actions:write.
- release-manual.yml: direct path (GITHUB_TOKEN push fires no events,
  nothing runs CI on the release commit) gets dispatch+gate before
  Create tag; fallback path is already gated via release.yml after merge.
- required set (override with REQUIRED_CI_WORKFLOWS): ci.yml, ci-e2e.yml,
  ci-e2e-fake.yml, ci-e2e-dsh.yml, ci-e2e-dsh-native.yml,
  ci-e2e-codex-persona.yml, ci-e2e-native.yml, ci-e2e-native-opencode.yml,
  ci-e2e-pi-ws.yml
- tests/release-ci-gate.test.ts: 8 regression tests against an inline
  mock of the GitHub Actions API (no network, no token).
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_release-full-ci-gate (341c0e8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2924-pr.2693.0d0c4e9

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-pr2693.tgz
npm install -g package

Install instructions are refreshed on each push.

… polling

Review fix for #2693: a single transient GitHub Actions API error (network blip, 5xx, secondary rate limit) during --wait polling threw immediately and killed an otherwise-green release. Read-only (GET) calls now retry up to 3 times with backoff; POST dispatches are never retried (a double dispatch would burn CI on duplicate runs). Exhausted retries still exit 1 — the fail-safe direction is unchanged.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成。结论先行:PR 代码本身可合(你的原始 commit CI 全绿,审查通过);当前 CI 红不是本 PR 造成的——master 自身在干净 checkout 上 typecheck 已红(详见第 5 问),已单独立项 #2697。

我做的工作

  1. 完整审查(①issue 方向 → ②既有行为回归清单 → ③代码主关 → ④测试有效性 → ⑤diff 整洁度),逐项结论见下方八问。
  2. 审中发现一个小的健壮性缺口,按「小问题直接修」在 PR 分支上补了 additive commit(不动你的原 commit):2d7f80976 fix(release-ci-gate): tolerate transient API errors on read-only gate polling。门在 60min 轮询窗口内,任何一次 GitHub API 瞬时抖动(5xx / 429 / 网络异常)都会立即 throw → exit 1 → 整次发布被杀,需人工重跑整个 release workflow。修法:仅只读 GET 有界重试(≤3 次、递增退避;429/5xx/403+ratelimit 头可重试),POST dispatch 绝不重试(避免重复触发 lane),重试耗尽仍 exit 1——fail-safe 语义与全部判定规则不变。新增回归测试 release v0.1.2 #9(mock 对 runs GET 先回两次 500 再回 200 → dry-run 通过;旧代码第一次 500 就 exit 1,测试有牙)。本地验证:node --import tsx --test tests/release-ci-gate.test.ts 9/9 通过,单文件 strict tsc 通过,diff 仍只有 2 个文件。
  3. 排查了追加 commit 后 CI 变红的原因(见下),并立项 #2697(带来源标记)。

结构化八问

  1. 是什么问题:四个发布渠道缺少统一的「发布 sha 上全套 CI 必须全绿才能 publish」硬门——v0.1.192(fix(#2658): dsh native-compaction rebase fallback on anthropic/google lanes #2664)证明切香肠/一键渠道可以在发布 sha 上零 e2e 覆盖的情况下照常发布,当时靠人工核对回归证据放行。
  2. 什么原因导致的:e2e workflow 不触发发布渠道的 push 事件(bugfix-release/** push、GITHUB_TOKEN 直推 master 无事件),而各渠道自身没有任何机制要求「发布 sha 全 lane 绿」;流程漏洞在机制层,不在某个渠道的实现细节。
  3. 影响范围与严重程度:四个发布渠道(release / bugfix / kernel / manual-direct)。修复前:完全可用但存在质量风险(特定条件下——走无 PR 渠道发布时——发布 sha 无任何 e2e 覆盖);修复后:publish 被阻塞直到 9 条 lane 在发布 sha 上全绿。
  4. 怎么修复的:新增 scripts/release-ci-gate.mjs,两个子命令——--dispatch(对发布 sha 上没有 run 的 lane 逐个 workflow_dispatch,幂等,不可 dispatch 硬失败)+ --wait(轮询直到每 lane 在发布 sha 上的最新 run = success,任何失败形态阻塞 publish,默认 60min 超时也阻塞)。复用规则严格单向:PR-head(HEAD^2)的绿 run 只在发布 sha 完全没有 run 时替代,发布 sha 上有 red 时永不被覆盖。四个 workflow 统一接入,步骤均插在 publish 之前;release.yml/kernel 用 EXTRA_MATCH_SHAS=HEAD^2 → 常规 PR 发布零额外 CI 成本(与分支保护 required checks 语义一致)。
  5. 是否有回归问题:逐条过过——四渠道既有步骤/触发器/prerelease/tag/publish/GH-release 逻辑字节级未动,纯增量(actions: write 权限 + 两个带条件的步骤);kernel/、wire、persistence、config surface、自更新路径均未触碰。有意行为变更(旧→新):① 所有渠道 publish 新增前置条件「9 条 lane 在发布 sha 上全绿」(旧:仅内嵌 pre-flight;bugfix/manual-direct 此前发布 sha 零 e2e);② 常规 PR 发布 ≈0 额外成本(复用 PR-head 绿 run),切香肠/一键渠道每次发布多 ~10min(lane 与 pre-flight 并行起跑)。⚠️ 当前 CI 红的原因(重要):GitHub 对 pull_request 事件跑的是 merge ref(head + 最新 master)。本 PR base 之后,master 先后并入 refactor(#2607): remove compress.stripImages — default media folding replaces it #2688(删除 compress.stripImages 字段)与 fix: 让压缩图片历史先减量,再检查发送字节预算 #2613(新增 tests/image-request-budget.test.ts,引用该已删字段)→ master 自身干净 checkout typecheck 必红;我在本地 clean worktree @ 6064a0e7a 按 CI 同法复现,错误逐字一致(stripImages does not exist in type 'CompressSettings & ...')。你原始 commit 的 CI 绿是因为其 checkout 早于这两个合并;我追加 commit 的 CI 红是因为 merge ref 继承了坏的 master——与本 PR 内容无关(diff 与出错文件零交集)。已立项 #2697(根因是 fix: 让压缩图片历史先减量,再检查发送字节预算 #2613×refactor(#2607): remove compress.stripImages — default media folding replaces it #2688 合并顺序交互,建议更新该测试文件到 refactor(#2607): remove compress.stripImages — default media folding replaces it #2688 后 API)。**master 修好后本 PR 重跑 CI 即可转绿,分支无需改动。**另注:master 近期 push 事件 CI 显示绿与干净复现矛盾,疑似 runner 缓存掩盖,master typecheck 损坏:tests/image-request-budget.test.ts 引用已被 #2688 删除的 compress.stripImages(#2613×#2688 合并顺序交互) #2697 里已注明建议重跑确认。
  6. 是否破坏缓存:不涉及(不触碰任何缓存/重试/增量游标/去重策略;自更新与 prefix-cache 路径未动)。
  7. 是否改了设计方向:不涉及(纯 CI 流程门禁,不改架构/边界/数据流)。
  8. 是否引入了新的配置:仅 CI 内部 env,非用户配置面(不动 BILI_* / billion-context.json):CI_GATE_TIMEOUT_MIN(默认 60)、CI_GATE_POLL_SEC(默认 20)、REQUIRED_CI_WORKFLOWS(覆盖必跑 lane 集)、EXTRA_MATCH_SHAS(复用额外 sha 绿 run)、DRY_RUN=1(演练)、API_BASE(仅测试钩子)。

一个额外观察(不影响本 PR 正确性):6 条 every-PR e2e lane(ci-e2e-fake 等)在本 PR 分支上从未自动触发过(相邻 PR 的 13 条 workflow 均正常触发,触发器配置核实为裸 pull_request+workflow_dispatch)——原因不明,值得单独看一眼;这也恰好演示了门的价值:缺什么 --dispatch 补什么,发布照样被正确门禁。

判定:可合(代码/测试/diff 全部过关;当前红为继承自 master 的损坏,与 PR 无关——#2697 修复后重跑 CI 即可)。人类合并,机器人不合并。

@ranxianglei
ranxianglei merged commit a24f6b6 into master Oct 11, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.240-master.a24f6b6 (rolling master tag).

npm install -g billion-context@0.0.240-master.a24f6b6  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

1 participant