The first commit regenerated the corpus after stripping the legacy
image keys, so tests/storage-corpus.test.ts asserted 'keys must NOT
materialize' against a fixture that never carried them — a vacuous pin
while the PR body claimed the corpus pinned back-compat.
The generator now re-injects the pre-#3266 keys into the on-disk record
after the normal write (writeAndPin mutateFiles hook), so the fixture
carries exactly what an older version persisted. Verified load behavior
pins honestly: whitelisted readers DROP stats.imageShrunk*/imageFull*
and state.imageShrinks/imageFullRestored; metadata is an opaque host
bag and passes THROUGH (legacy imageShrinks survives as inert data —
the digest covers the loaded view, so it pins that split). All case
digests shift because the kernel state.stats blob lost its three image
fields; folded/zstd pair stays byte-identical.
The opt-in compress.imageCompression pass and its image_full restore
channel are structurally broken where they matter most:
- hosts that reject bili-injected tools (codex) can never deliver the
restore call — the downscale is permanent for them (#3270 disarmed
the lane, which proved the tool was dead weight there);
- where the tool IS injectable, the model has no reliable way to learn
the ref of the downscaled message (no ref annotations on the wire),
producing the 38-round guess-reject-resend loop from #3266 (cache
hit 75% -> 28%).
Remove the whole feature from host and kernel: arrival-time downscale
pass, image_full injection + sticky restore + fail-streak guardrail,
image stats, persistence keys, wire-contract tool variants, config
schema, docs, and the sharp optional dependency. Every image now passes
through byte-identical at original resolution.
Sessions persisted by older versions load unchanged; legacy
imageShrinks/imageFullRestored state keys and imageShrunk* stats are
ignored on load (storage corpus pins that as a fixture).
kernel 0.0.126.
- scripts/check-unused-exports.mjs: git ls-files --cached --others
--exclude-standard — a brand-new module is exactly where INTERNAL_ONLY
leaks happen, and a tracked-only scan passed locally right before CI
failed on the same tree (the fresh src/agent/incremental-client.ts was
untracked at the local gate run on #3273).
- src/agent/incremental-client.ts: IncrementalPlan / PlanArgs keep their
leading export off (module-internal shapes; callers infer).
Root cause of the 7-red test matrix: #3145 sharding concentrated the port
families into shards 2/3 while #2816 concurrency let them bind
simultaneously on one runner — cross-file 18787 collisions and shared
ephemeral-port TOCTOU.
Fixes:
- scripts/live-files.mjs: shared LIVE_FILES table + zonePortForSlot bands
(18787+(slot+1)*32; first band above the default base so bare 18787 is
never a CI target)
- tests/preload-zone-slot.mjs: CI-only preload assigns each live file its
band via BILI_ZONE_PORT (product support already in src/config.ts)
- run-ci-tests.mjs: preload injected for live suites
- port-zone-live: band-aware base + waitForBandFree at sandbox entry
(teardown SIGKILL returns before kernel release) + full XDG isolation
(a dev box's real config/index.db makes children queue on real locks —
the #3044 fail-fast then never fires) + squatter leak closes on failure
- claude-native: band-aware helpers (ZONE_BAND_BASE from process.env;
planClaudeNativeBootstrap({}) stays on the exported default), squatter
test flipped to the #2877 own-lane refusal contract (was in the original
red set — #2877 superseded #1660's attach-by-default), foreign-listener
squatter kills connections (unhandled ECONNRESET crashed the runner),
freePort TOCTOU bounded retry
- auto-restart: stubs exit 91 on EADDRINUSE with bounded scenario retries;
SIGTERM-survivor escalation test is POSIX-only (Windows terminates
uncatchably — was a w24 red)
- ensureDistBuilt (claude-native/port-zone-live/index-entry-guard): rebuild
when src is newer than dist — a stale dist exercises last week's product
code (the #3044 'hang' was exactly this)
The suite outgrew one runner: ~656 top-level files (~190k LOC) serialized
through --test-concurrency=4 on a single 4-core leg took ~17-20 min (windows
slowest; measured 1225s on the last full green run). Add a `shard` matrix
dimension to the test job so each leg runs a balanced slice; run-ci-tests.mjs
now partitions deterministically + totally (LPT bin-packing over file size)
so the union of all shards == allFiles and no test is skipped. Same tests,
assertions, env, OS and node versions — zero coverage loss. Wall drops ~3x
(~20 -> ~7 min).
Two concurrent full `npm test` runs on one machine corrupted each other:
cores-1 concurrency doubled the spawn/attach load so every 15s readiness
watchdog timed out (mass false-red), and daemons without a per-test
XDG_STATE_HOME shared ~/.local/state/billion-context (port-zone drift,
multi-instance alarms) — with ZERO detection of the sibling run.
Add scripts/test-suite-lock.mjs: an O_EXCL ("wx") lock at
$XDG_CACHE_HOME/billion-context/test-suite.lock holding {pid,ts,cmdline,cwd},
with liveness-only stale steal (kill(pid,0); never steal a live suite; no age
timeout — a local full run can exceed any fixed budget; a corrupt/truncated
file left by a SIGKILLed writer is reclaimable, not a permanent wedge).
`pretest` now prepends a non-owning `gate` so a second run refuses within
milliseconds BEFORE the build; `test` becomes an owning `run` wrapper that
holds the lock across the real suite and releases it on exit (plus a sync
backstop in the exit handler). BILI_TEST_FORCE=1 is the documented escape hatch.
Single-run behavior is unchanged: the wrapper reproduces the exact old
`node --import … --test tests/*.test.ts` invocation (same file set, no
concurrency cap added). Regression suite tests/test-suite-lock.test.ts pins
free / live-block / dead-steal / corrupt-reclaim, the <2s fail-fast acceptance,
force bypass, and release-on-exit.
memoryReport and residentBreakdown have cross-file references (admin.ts
imports memoryReport; tests import both), so the gate does not flag them.
Only the structurally-consumed interfaces need waiving.
- session.ts: extract deepSizeOf; add residentBreakdown(session) and
memoryReport() — per-session resident bytes split across lastMessages,
pluginSnapshot, blockContents, contentStore, state, other (columns sum
to the revision-cached sessionWeight total).
- server/admin.ts: GET /__bili/memory (loopback-gated like all /__bili)
returns process memoryUsage + VmHWM peak plus the pool report, top 25
sessions by bytes.
- tests/memory-diagnostics.test.ts: field attribution, monotone scaling,
pool sorting/budget context.
- unused-export gate: reasoned waiver for the three test-consumed symbols.
This is the measurement half of the R3 memory plane: the numbers decide
which residents (blockContents originals, CCR store, lastMessages,
pluginSnapshot) become lazy DB-backed views.
When a test child dies silently (non-zero exit, no stderr — e.g. OOM kill, tsx/esbuild worker death, race exit under concurrency), node --test collapses it to one file-level 'not ok <file>' whose only payload is error:'test failed' and zero subtests; no reporter can surface an error the child never emitted. CI was left unable to attribute the failure (#3029).
run-ci-tests.mjs now, on failure:
- captures exit code + signal (previously discarded by an empty catch);
- logs a resource snapshot (free/total mem, loadavg, node version, platform);
- surfaces child stderr when present (may carry a V8/native fatal such as OOM 'Reached heap limit');
- detects the swallowed shape (top-level 'not ok … *.test.ts' + error:'test failed') and re-runs each such file in isolation for attribution;
- retries the whole phase ONCE and exits 0 only if that retry is green (a confirmed transient). Concrete assertion failures are NOT the swallowed shape and still fail hard immediately with no retry, so real regressions are never masked.
Behavior changes (flagged):
- The test step now forces --test-reporter=tap (Windows log format spec->tap; Linux was already tap). No test-semantics change.
- Swallowed-shape failures get one bounded recovery (isolated re-run + full retry -> exit 0 if green) instead of failing immediately. Concrete assertion failures are unchanged (fail immediately).
- No new config/env added; concurrency stays 4.
A green suite over a retired module guarantees nothing about the wired
path: #2988 finding ① shipped while every persona-anchor pin stayed
green. New zero-dep gate scripts/check-test-import-graph.mjs BFS-walks
the tsup entry set and fails on any tests/** import of an unreachable
src module unless whitelisted (test-only registries marker/spec.ts,
exit-matrix.ts) or the importing file carries a 'retired-module pin'
label. Wired into ci.yml as the test-import-graph leg gating both
test and static-gates.
resolveStorageMode now lands on 'shadow' when neither storage.unified nor
BILI_STORAGE_UNIFIED is set: the JSON envelope stays the sole source of
truth (zero behavior change) while every session write is mirrored into
index.db with digest reconciliation — fleet-wide parity telemetry before
the full-mode default flip. Explicit legacy opts out; garbage still
degrades to legacy; engine-less lanes stay legacy-only (#2825 contract).
The test corpus runs on an explicit legacy baseline
(tests/preload-storage-baseline.mjs wired into npm test and
scripts/run-ci-tests.mjs) so the 600-suite wire/e2e corpus keeps its
legacy dir-shape assumptions; the storage family pins and overrides its
own modes, the resolveStorageMode matrices pin the new default, and the
web-sessions stamp test now asserts shadow for absent-everywhere.
Freezes the manual v0.1.196 review pass (PR #2962) into one command for
operator machines with live models — the regression lane GitHub CI can
never run. Executed before each release (reference/release.md step 5.5).
Lanes (hermetic scratch: own DSH_HOME/BILI_CONFIG_FILE/sessions/XDG/ports;
never touches ~/.dsh or running proxies; missing prerequisites skip with
a warning, GATE_* knobs in the script header):
- A compression: real dsh session reads a marker corpus at the real
window, then the route window shrinks mid-session (the field-report
"switched to a smaller-window model" lane) -> nudge INJECT -> preflight
fold -> SAME session answers from folded context, cache recovers.
A fresh oversized read tool-result is NOT expected to fold (protected
recent zone, #2847 fail-fast) — asserted as such.
- B model switch: same session resumed on a different model/upstream;
same lineage across switch + proxy restart (dsh resume-replay fork
WITH fork-adoption of the parent's folded blocks passes; an orphaned
pfa fails), cross-upstream usage-baseline demoted to untrusted when
cited (#2283/#2867), cache cold -> hot on the new upstream.
- U --with-update: dsh-managed install detection (no in-place self
update) + latest read from the configured update registry.
Green on 0.1.196: A 8/8, B 6/6, U 2/2 (~4 min, sglang + z.ai relay).
Windows-only update lanes (global installer, desktop-profile in-place
swap + spec converge, doctor) stay on the Win10 VM checklist appended
to reference/release.md.
tests/hook-graceful-exit.test.ts spawns the real hook entry (node --import
tsx) for its integration subtest, so scripts/run-ci-tests.mjs' #1248
self-check would fail the test job once unused-exports unblocks it.
Concurrency review: the spawned child runs with BILI_NATIVE_ZCODE=0
(plan mode off -> earliest return), opens no port, touches no config or
proxy state, and is SIGKILL-bounded at 8s — no shared-resource contention
under c=4.
Pre-existing master gap, fixed in passing: c81be81ee (#2752, 2026-10-11) added a process-spawning suite before the #2816 LIVE_FILES tripwire landed (e6ba45cd8, 2026-10-12), so every test job has died at the tripwire since then and the full suite never ran in them. Concurrency assumptions reviewed: listen(0) ephemeral ports, BILI_MCP_PROXY env save/restore, stdio transport to the spawned src/mcp.ts child.
The #2816 tripwire requires every process-spawning suite to be listed in scripts/run-ci-tests.mjs before it may ride the c=4 pool (#1248 review). Concurrency assumptions reviewed: isolated mkdtemp dir, child-only env (BILI_PERSIST_ZSTD/BILI_SESSIONS_DIR), no port binding, one blocking spawnSync under a 128 MiB heap cap.
Baseline-log arithmetic (sum of per-test durations vs step wall) proves the
old runner default was already concurrent, so the two-phase split's serial
live phase only idled 3+ cores for 3-4 min without buying stability. Run the
whole suite at explicit concurrency=4 (keeps the LIVE_FILES tripwire), and
move typecheck/kernel/pi-subagents/build into a parallel static-gates job off
the test critical path.
execFileSync('npm.cmd', ...) fails with EINVAL on Windows: CreateProcess
cannot exec batch files without a shell. The first CI run showed both
windows legs dying at the pretest step before any test ran. shell:true
routes it through cmd.exe; args are fixed literals, no quoting surface.
The node built-in runner defaults file concurrency to availableParallelism()-1 == 1 on 2-vCPU runners, so the flat tests/*.test.ts glob ran all 600+ suites strictly serially, each paying a node+tsx spawn in turn. scripts/run-ci-tests.mjs splits the same suites into: live (process-spawning, concurrency=1 — #1248 requires quiet-machine conditions) and pool (everything else, concurrency=4 — no spawners by construction, listen(0) ports, XDG-isolated homes), with a self-check that fails the job when a new spawning suite lands unregistered. Same tests/assertions/env; local npm test untouched. Plus two targeted suite speedups: image-request-budget hoists the shared ~100MB body (5 builds -> 3) and claude-native pre-warms the Windows CA (existing #1807 pattern) in the three remaining fresh-home hook e2e tests.
Pre-refactor stakes for the unified storage layer (#2671):
- tests/golden-storage-render.test.ts + scripts/update-storage-render-goldens.ts:
byte-exact golden of per-turn outbound bodies AND the persisted end state
for chat/anthropic/responses/google — 15 turns each, one T1 fold at turn 9,
a mid-history client edit, and post-edit growth. The end-state digest goes
through the REAL shutdown path (flushAllSessions); the corpus pins the
renderer + fold semantics, not debounce timing.
- tests/storage-corpus.test.ts + scripts/update-storage-corpus.ts +
tests/golden/storage-corpus/: committed legacy-format sessions covering
every persisted-record branch (folded, tier-2 supersede with #401
normalization, deadRefs tombstones, fork receipt/retained asymmetry
(#2675 ②), images, CCR sibling store, twin-namespace files (#2671 ①),
zstd framing). The manifest pins write→loadSync round-trip digests; the
unified store must reproduce them bit-for-bit after migration.
- tests/pins-storage-refactor.test.ts / tests/pins-wire-id-mints.test.ts:
kernel invariants (I1–I7), scripted + seeded-random scenarios, wire id
minting contracts.
Regeneration is a migration-relevant event — commit the diff with a reason.
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.
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).
Review of #2651 found the existing scripts/check-unused-exports.mjs gate red on this PR's own new file: ConfigSurfaceReport in config-surface-guard.d.mts is exported but every reference sits inside the declaring file (INTERNAL_ONLY). It only serves as runChecks()'s return-type annotation, so dropping the leading export is sufficient and legal in a declaration file. Verified locally: unused-export gate clean, config-surface-guard check green (125 leaves / 24 flags), its test 5/5, full typecheck clean.
Closes#2643
The existing docs-coverage gate (#2107) only enforced BILI_*/ACP_* env vars
and FileConfig TOP-LEVEL keys. Two surfaces slipped through: nested
config-file leaf fields (a new network.newKnob passed silently because a
sibling network.* entry satisfied the top-level key) and CLI --flags
(never checked at all).
scripts/config-surface-guard.mjs closes both: it walks the FileConfig type
to enumerate every leaf path (resolving local named types; expanding
compress via the maintained COMPRESS_SETTING_FIELDS mirror; treating
open/Record/scheme-keyed maps as documented at their parent) and every
parseArgs --flag, then requires each to have a seed entry / be documented
in README.md or CONFIGURATION.md. Missing = red with names listed. A report
mode dumps the full inventory (the 盘查 ask). Zero-dep plain node, no install
step in CI. Not gated to pull_request so master pushes are held to the same
surface.
Baseline gaps found & fixed on current master:
- compress.search had no seed entry (only compress.search.planAware did) --
added the container entry + regenerated docs.
- --bin was documented nowhere -- added to README.md.
(--auto-restart-on-update was already in README; the guard checks the
README+CONFIGURATION union so it passes.)
tests/config-surface-guard.test.ts pins the extractors against golden
anchors and proves the red path fires (planted undocumented field + flag),
so the gate cannot silently go vacuous.
The #1440-P6 gate scans all tracked .ts via the *.ts pathspec but only
excludes kernel/. Vendoring pi-subagents/ (#2384) put the component's own
public API surface (a separately published npm package with its own test
suite and version discipline) under the root-package gate, which flagged
20 of its exports. Exclude it wholesale exactly as kernel/ is excluded;
the component imports nothing from the root src/, so no root symbol loses
its only references.
The semver alone cannot distinguish a locally-installed test build from the
npm release with the same version number (exactly the situation while trialing
an unmerged fix). Add BUILD_COMMIT and render it wherever a human reads a
version:
- bili --version → "0.1.187 (8f9faf9e)" (first token stays bare semver;
all in-repo consumers match by regex, none compare equality)
- /acp panel host line → billion-context 0.1.187 (8f9faf9e)
- web UI header + overview row → v0.1.187 (8f9faf9e) / "0.1.187 (8f9faf9e)"
- /__bili/health and /__bili/overview → additive "commit" field
Resolution: bundled code reads dist/build-info.json stamped by
scripts/write-build-info.mjs at build time ("-dirty" suffix when the worktree
has uncommitted changes); dev (tsx) asks git directly; "unknown" otherwise.
The updater, advisory watcher and MCP serverInfo keep comparing/announcing
bare package.json semver — display-only, zero update-path impact.
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.
When no level sets compress.priceProfile, the session stamp now falls back to the request model's models.dev price row (absolute $\/Mtok: w = cost.input, r = cost.cache_read ?? 0.1*input, q = cost.output ?? 1.5*input). Known-provider hosts get their own listing; unknown relays take the first matching listing with a one-time conflict warning. Live catalog.json wins when reachable, bundled snapshot is the offline floor (snapshot rebuilt to carry 7126 cost rows). User config at any level still wins wholesale; unresolvable models keep the kernel relative defaults.
Consolidates the #1301 served-surface gate and the #1302 kernel-export gate
into one wire-contract suite and extends it per owner decision on #1304
(items 1+2+3, plus the 4-protocol scripted-client matrix phase):
- tests/wire-contract-fakes.ts: WIRE_RULES ledger (WC-001..WC-006, each with
production/doc provenance) + strictest-known validation for all four wires
(anthropic /v1/messages, openai chat, responses, google v1beta) + four
validation-parity fake upstreams on listen(0) with canned per-wire replies.
- tests/wire-contract.test.ts: four layers — ledger self-check (every rule id
has a live enforcement clause), A kernel exports, B bili-built surfaces,
C plugin manifest (default + opt-in), D live proxy-mode forward of one
client-shaped turn per protocol through the matching fake (asserts the
forwarded tool set is exactly bili's intended surface and the fake's
strictest validation accepts it). The anthropic lane reproduces #1299
end-to-end. Supersedes tests/kernel-pin-wire-schema.test.ts and
tests/issue1299-anthropic-top-level.test.ts (all their assertions kept).
- tests/wire-contract-golden.test.ts + tests/golden/wire-contract/*.json:
byte-equal golden snapshots of every advertised tool schema at both layers
(kernel exports, bili surfaces, plugin manifest default+opt-in); manifest
version normalized to <VERSION> so release commits don't churn it.
- scripts/update-wire-contract-goldens.ts: explicit regeneration path.
- AGENTS.md §7.3: institutional rule — every upstream rejection/validation
constraint becomes a permanent wire-contract rule inside the fixing PR;
the ledger only grows.
Node resolves entry-point symlinks, so when the gate script is invoked through a symlink (pnpm-style symlinked trees, /tmp -> /private/tmp), process.argv[1] no longer string-matches import.meta.url and the main-module guard silently skipped the whole check (exit 0, no output) — a silent gate death of exactly the class this gate exists to prevent. Compare realpathSync(fileURLToPath(import.meta.url)) against realpathSync(argv[1]) instead. Verified: direct/symlink/copy invocations all run the check; negative case still fails loudly; unit tests pass.
Non-minified esbuild output keeps class-member JSDoc comments; undici's
{import('./client.js')}-style type annotations therefore survive into every
dist entry. Node's ESM loader ignores them, but opencode's plugin loader
resolves them as real files -> ENOENT -> 'failed to load plugin' -> silent
dead lane for all modern versions under opencode 1.x.
Set minifyWhitespace via tsup's esbuildOptions hook (drops non-legal
comments, keeps structure + license footers) and add a build gate that
fails if relative import()/require() text ever reappears in dist.
Headless, key-free verification for the real-machine gap in #686:
confirm that codex accepts the <CODEX_HOME>-bili overlay produced by
`bili codex` and registers the bili MCP server, on a hosted Windows
runner. Uses `codex mcp list` (reads config.toml only, never calls a
model) so no E2E_UPSTREAM_* secrets are needed.
Refs #686