Skip to content

refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) - #1443

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-27_dead-code-cleanup
Oct 7, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-27_dead-code-cleanup

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

v2 note (2026-10-06) — regenerated on current master (d1d24ba6).
This branch had drifted 727 commits behind master with conflicts across 15 files, so instead of force-resolving the stale hunks I re-ran the same pass fresh: used this PR's own gate (scripts/check-unused-exports.mjs) to flag today's tree, then applied every verdict — 14 DEAD declarations deleted, 255 INTERNAL_ONLY exports demoted (87 files, +358/−352). Two deliberate gate adaptations for post-kernel-vendor master: (1) the scan corpus excludes kernel/** (vendored package behind the human-gated kernel boundary — unscoped it would flag 22 findings there); (2) ENTRY_FILES gains src/agent/dsh-native-client.ts (second tsup entry since #1590). Every deleted/export-stripped symbol was verified zero-reference repo-wide (rg -w, including docs/ and hermes-plugin/) before removal. Local verification: gate clean, tsc --noEmit clean, tsup build OK, focused suites green (wire-contract / web-sessions / dsh-settings-ui / advisory-parity, 41/41); full matrix delegated to CI. One judgment call flagged for review: Locale in src/web/i18n.ts is demoted — reference/architecture.md mentions it in prose description only, not as an API-surface nomination (and the gate has no exemption list, so leaving it exported keeps CI red).


Rebuild v3 (new base 9f82bbed) — 2026-10-07

Master moved 15 commits after this branch's original base; rebuilt on top of 9f82bbed (clean cherry-pick of both commits):

Rebuild v4 (253bbfa1) — lane-guard (#2170) compliance

  • The lane-guard job (side-lane test discipline, dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170) fails on ANY hunk in src/server/side-request.ts unless a pinned side-lane suite moves with it. This pass had demoted three type-exports there; those three demotions are reverted (exports restored verbatim, diff vs master now zero for that file) — churning truth-table-pinned suites purely for export hygiene is exactly what the guard exists to prevent.
  • The gate script gains a small, explicit WAIVERS list (file → symbols, each with its reason written right there) so those three exports stay waived by documented decision instead of being re-demoted in a future pass. Waivers print as ~ waived … lines on every run. Paired fix: the scanner no longer counts self-references (naming a symbol inside the gate script itself previously counted as "used", which would have masked any waiver). Detection sanity-checked: removing one waiver entry makes the gate fail as expected.

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_dead-code-cleanup (253bbfa)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2398-pr.1443.846d640

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title refactor: drop 8 dead declarations + demote 174 internal-only exports (#1440) refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) Sep 26, 2026
@ranxianglei
ranxianglei force-pushed the 2026-09-27_dead-code-cleanup branch from 62f20dd to 2cdbaa6 Compare September 26, 2026 16:59
ranxianglei pushed a commit that referenced this pull request Sep 26, 2026
The gate commit accidentally re-indented a pre-existing line in the
version-guard job (10 -> 11 leading spaces). Functionally inert, but it
muddied the diff; restore the original bytes so ci.yml changes are
purely additive.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable (human merge required per §7.4; see below). Full verification against rebased head, including a force-push that landed mid-review (old head 62f20dda → current 2cdbaa6c + my fix commit 6cdad1c5).

① Direction (original issue #1440)

Batch 1 targets #1440's P4 (dead code) + P6 (export-bloat root cause). The direction is right: removing the 8 dead declarations fixes the instances, and the new mechanical gate attacks the producer of future bloat rather than masking symptoms — root-cause, not symptom (§7.3). Verified the audit's claims independently rather than trusting them:

  • All 8 "dead" symbols are genuinely dead: full-corpus word-boundary verification over src/, tests/, scripts/, root *.ts (word-boundary matching also covers string literals, closing the dynamic-dispatch blind spot the PR notes as theoretical) — zero references anywhere for all 8.
  • All 183 demotions are genuinely internal-only: 174 in src/ (hunk-level classified: interface 70, type 41, function 37, const 26) + 9 in tests/ added by the force-push (ChatRelay, ChatRelayOptions, FakeUpstream, GoldenSpec, RegistryFixture, WireRule, validateAnthropicBody, validateGoogleBody, validateResponsesBody). Every one has zero references outside its own file. Live siblings confirmed intact: PLUGIN_BYPASS_HEADER (4 refs), _resetWireDropWarningsForTest (used by tests/fix-1205-file-parts.test.ts), tls import (still used at src/upstream-proxy.ts:379).
  • Diff hygiene: every one of the 226 deleted lines classifies as export-strip or dead-deletion — no unrelated edits, no whitespace churn in the refactor commit itself.

② Regression review (existing-behavior ledger)

Existing behavior Conclusion
Wire protocol / message shape (reasoned in BOTH compression modes per §6) Preserved — zero wire-path edits; every hunk classified
Config schema / persistence format Preserved — no config or persist-path edits
CLI surface Preserved — no user-facing command changes
dist named-export surface One intended delta, disclosed below
Auto-update logic (src/update.ts) Preserved — only the zero-reference stopAutoUpdate() removed; update flow untouched
CI version-guard job Preserved — byte-identical after my fix commit (see ⑤)

Behavior-change disclosure (Deliverables #4): empirical build comparison, master vs PR head, all 15 dist bundles: 14 have byte-identical named-export sets; the single delta is dist/agent/dsh-native.js no longer exporting _stateToolsReadyForTest (the deleted dead symbol leaked into the bundle's export list). Old → new: exported → not exported. Reason: dead-code deletion. Risk: negligible — test-only helper, zero references in-repo, no known external consumer.

③ Code review (gate script, scripts/check-unused-exports.mjs)

Design is sound and deliberately conservative: token-frequency counting where comments/strings count as used (false positives require out-of-corpus dynamic dispatch — none exists); misses are safe-direction (same-name merges across modules, re-export chains never flagged); ENTRY_FILES hardcoded set verified identical to tsup.config.ts's 15 entries, with documented asymmetric-drift safety; zero deps (plain node, no install step). Teeth verified both ways: run against the master baseline tree → ✗ 190 unused export(s), exit 1; run on the PR head → ✓ clean, exit 0. It fails where it should and passes where it should.

④ Test validity

No new tests (nothing behavioral to pin — correct call). Existing suite + the full e2e matrix (real codex/pi/opencode/dsh lanes vs fake upstream, hermetic registry e2e) all green via CI.

⑤ Diff cleanliness — one nit found, fixed directly

The gate commit had incidentally re-indented a pre-existing line in the version-guard job (echo "✓ version field untouched...", 10→11 leading spaces — functionally inert, but unrelated to the PR's purpose). Fixed on the branch: commit 6cdad1c5 restores the original bytes; the ci.yml diff is now purely additive.

Scope note (for owner awareness, not a blocker)

#1440 floor 10 promised the gate as a separate small PR; it landed inside this one instead. Defensible — cleanup and its anti-regression gate are one logical unit — but flagging since it changes the sequencing of the remaining #1440 batches (Batch 3 server.ts cut #1 can proceed regardless).

§7.4 auto-merge gate

Not eligible — refactor: scope, CI infrastructure addition, and a touch to load-bearing src/update.ts. Human merge required; the author already self-flagged stopAutoUpdate() for exactly this reason, and my independent verification confirms zero references.

CI status: 14/14 green at 6cdad1c5 (one investigated flake)

Original run at 6cdad1c5: 13/14 green; test (windows-latest, 22) red. Investigation: the failure was not ok 266 - resolveClaudeCli... (tests/claude-native.test.ts:555, assert.match(resolved, /where\.exe$/i) got 'where', duration_ms 5124 ≈ the 5000ms spawnSync timeout at src/plugin-install.ts:654 — the where.exe spawn itself timed out under runner load). Proven unrelated to this PR: (a) the failing code path has no reference from any changed symbol (corpus-verified), (b) the identical matrix passed ~4h earlier on this same PR's previous head 2cdbaa6c, (c) the same job failed at master @ 0d39b64 the same morning on a different timing-sensitive test (logger-epipe #1233 tick-count assertion) — a pre-existing flake pattern, filed as #1445. Reran the failed job on the same code → success. Head is now fully green.

Local pre-flight (rebased head)

npm run typecheck clean · npm run build success + dist-import-annotations: OK · full suite via CI (ubuntu+windows × node22/24) · gate teeth check above.


中文摘要:审核了 PR #1443(dead-code 清理 + unused-export 门禁):8 个死符号与 183 个内部导出全部独立复核为零外部引用、无行为变更(唯一 dist 导出面变化是 dsh-native.js 移除死符号,已披露),顺手修掉了 ci.yml 里一处无关缩进漂移(已补 commit 6cdad1c5),win22 一次红为与 PR 无关的既有 flaky(已另立 issue #1445,rerun 转绿)——可以合并(按 §7.4 需人工合并)。

ranxianglei pushed a commit that referenced this pull request Sep 30, 2026
…s; re-export symbols master now consumes (AffinitySnapshotEntry, UpstreamFailureKind)
ranxianglei added a commit that referenced this pull request Oct 6, 2026
…esh #1440 pass)

Regenerates PR #1443's batch-1 against current master (d1d24ba): the
original branch became unrebasable after master evolved (kernel/ vendored in-repo
and 15 conflicted files). Fresh textual gate run: 269 findings — 14 DEAD
declarations deleted (incl. test seams with no remaining consumer) and 255
INTERNAL_ONLY symbols demoted by stripping the export keyword. No behavioral
change; tsc/build/focused e2e suites green.
ranxianglei added a commit that referenced this pull request Oct 6, 2026
Ports the gate from PR #1443 to current master: npm script check:unused-exports
plus a zero-dep CI job. Adapted since the original: scans exclude kernel/ (its
own package with its own suite and human-gated boundary) and the entry list
gains src/agent/dsh-native-client.ts to match the second tsup.config.ts entry.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_dead-code-cleanup branch from a44609e to e89a4bb Compare October 6, 2026 15:32
ranxianglei added a commit that referenced this pull request Oct 6, 2026
…esh #1440 pass)

Regenerates PR #1443's batch-1 against current master (d1d24ba): the
original branch became unrebasable after master evolved (kernel/ vendored in-repo
and 15 conflicted files). Fresh textual gate run: 269 findings — 14 DEAD
declarations deleted (incl. test seams with no remaining consumer) and 255
INTERNAL_ONLY symbols demoted by stripping the export keyword. No behavioral
change; tsc/build/focused e2e suites green.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_dead-code-cleanup branch from e89a4bb to ec30f04 Compare October 6, 2026 16:14
ranxianglei added a commit that referenced this pull request Oct 6, 2026
Ports the gate from PR #1443 to current master: npm script check:unused-exports
plus a zero-dep CI job. Adapted since the original: scans exclude kernel/ (its
own package with its own suite and human-gated boundary) and the entry list
gains src/agent/dsh-native-client.ts to match the second tsup.config.ts entry.
…esh #1440 pass)

Regenerates PR #1443's batch-1 against current master (d1d24ba): the
original branch became unrebasable after master evolved (kernel/ vendored in-repo
and 15 conflicted files). Fresh textual gate run: 269 findings — 14 DEAD
declarations deleted (incl. test seams with no remaining consumer) and 255
INTERNAL_ONLY symbols demoted by stripping the export keyword. No behavioral
change; tsc/build/focused e2e suites green.
Ports the gate from PR #1443 to current master: npm script check:unused-exports
plus a zero-dep CI job. Adapted since the original: scans exclude kernel/ (its
own package with its own suite and human-gated boundary) and the entry list
gains src/agent/dsh-native-client.ts to match the second tsup.config.ts entry.
@ranxianglei
ranxianglei force-pushed the 2026-09-27_dead-code-cleanup branch from ec30f04 to 253bbfa Compare October 6, 2026 16:37
@ranxianglei
ranxianglei merged commit 0be9e83 into master Oct 7, 2026
36 of 37 checks passed
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.94-master.0be9e83 (rolling master tag).

npm install -g billion-context@0.0.94-master.0be9e83  # 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.

ranxianglei pushed a commit that referenced this pull request Oct 7, 2026
…ate)

Labeled in-passing fix found while reviewing #2303: the new unused-exports
gate (master-only, post-#1443) flags src/launcher.ts codexRewriteInsertionIndex
as INTERNAL_ONLY on current master itself, which kept every rebased PR red.
All references are file-local (call site + doc comment); dropping the export
keyword is behavior-neutral.
ranxianglei pushed a commit that referenced this pull request Oct 7, 2026
…dex (#1443 residue)

In-passing gate fix during #2307 review: the unused-export check fails on
master itself (INTERNAL_ONLY src/launcher.ts: codexRewriteInsertionIndex),
blocking every PR's unused-exports job. The function is used only inside
launcher.ts (:980); the export keyword is dead surface left by the #1443
cleanup pass. One-word removal; no behavior, wire, or cache impact.
ranxianglei added a commit that referenced this pull request Oct 7, 2026
ranxianglei added a commit that referenced this pull request Oct 7, 2026
@github-actions github-actions Bot mentioned this pull request Oct 8, 2026
@ranxianglei
ranxianglei deleted the 2026-09-27_dead-code-cleanup branch October 15, 2026 05:32
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