Skip to content

fix(#3516): keep jimp out of dist (P0 release blocker) + wire pi/omp guardrail knobs - #3524

Merged
ranxianglei merged 4 commits into
masterfrom
2026-10-17_fix-p0-jimp-zod-dist
Oct 17, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-10-17_fix-p0-jimp-zod-dist

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: vllm-qwen/qwen3.8-27b)

Resolves P0 and P1-3 of #3516 (v0.1.198 release blockers found in the #3511 final pre-release review). One PR per issue per loop-guard; the remaining #3516 checklist items stay tracked there.

What & why

P0 — jimp dragged zod into dist (availability-level). #3425's image-rescale swap put jimp in noExternal, so tsup inlined it — carrying jimp's transitive import { z } from "zod" verbatim into dist/index.js and dist/agent/pi-native.js (16 static imports each, verified by building master). Installs without a node_modules tree (dsh profile bundles — the mainstream plugin install path) then crash at startup with ERR_MODULE_NOT_FOUND: zod while model traffic silently bypasses compression. Violates AGENTS.md KDD#1 (dist entries dependency-free; only opencode-native may touch zod, lazily).

Fix:

  • jimp removed from tsup noExternal + added to explicit external (tsup only auto-externalizes dependencies/peerDeps — an optionalDependency would still be bundled); src/image-rescale.ts resolves jimp once at first use; a failed resolution is permanent per process and degrades rescaling to pass-through (originals forwarded untouched, one warn log).
  • jimp moved devDependencies → optionalDependencies (the sharp precedent): installed where possible, silently skipped where not.
  • New build gate scripts/check-dist-no-zod.mjs (chained into npm run build) fails on ANY static zod import in dist — the offender class is now structurally impossible to re-land.

P1-3 — guardrail knobs dead in production. createBiliPlugin called wireToolGuardrails(pi) with no opts, so the owner-approved #3066/#3331 defaults never reached production: bash 60s timeout injection never fired, and every documented BILI_GUARDRAIL_* / guardrails.* switch was inert. The call site now passes guardrailBashTimeout() / guardrailMaxOutputBytes() ?? 0 / guardrailRepetition() (the ?? 0 maps knob-undefined(disabled) → wireToolGuardrails' 0(no-cap); undefined there means its 50KB default). Also registers the existing FileConfig.guardrails field in KNOWN_TOP_LEVEL_KEYS (it was missing, so correctly-spelled user configs got unknown-key warnings).

Verification (local, on this head)

  • Isolated P0 repro (dist copied to a dir with NO node_modules): before — node index.js --version → ERR_MODULE_NOT_FOUND: zod; after — prints version, exit 0.
  • Fresh npm run build: both gates pass (dist-import-annotations: OK, dist-no-zod: OK); dist/index.js + dist/agent/pi-native.js each carry exactly one DYNAMIC import("jimp"); zero static zod anywhere in dist.
  • npm run typecheck clean; targeted suites green: tests/issue3400-image-rescale.test.ts + tests/tool-guardrails-pi.test.ts + tests/config-surface-guard.test.ts + tests/knobs-config-precedence.test.ts = 78/78.
  • Full-suite verdict = CI lanes on this head (§7.2).

Behavior changes (flagged per policy)

  1. Packaging: jimp devDependency → optionalDependency. Normal registry installs now download jimp (a few MB) — rescale stays ENABLED there as intended; file-copy installs (dsh profile bundles) lose rescale but the proxy boots (previously: the proxy did not boot at all). Old → new: crash → graceful pass-through + one warn log.
  2. pi/omp guardrails (intended 迁移billion-context-pi中的timeout 输出截断后自动dump到临时文件到本仓库 #3066/197-master range review | 197-master区间审查 #3331 owner defaults, previously inert): bash calls without an explicit timeout now get a 60s injected timeout (old: none — unsupervised bash could hang a session a day); identical-call breaker warn@3/abort@5 now active; BILI_GUARDRAIL_BASH_TIMEOUT=0 / guardrails.* now genuinely disable each piece (old: switches had no effect in either direction).
  3. Config surface: NO new keys. guardrails.* / BILI_GUARDRAIL_* were already documented in CONFIGURATION.md en+zh — they simply work now; no migration needed. No config-shape invention.

Closes: n/a (checklist issue #3516 stays open for the remaining items)
Fixes: #3516 P0 + #3516 P1-3 items
Source review: #3511

awork added 2 commits October 17, 2026 16:26
…l dep + dist-no-zod build gate

#3516 P0 (from #3511 final pre-release review): #3425's jimp swap was
inlined via noExternal, carrying jimp's transitive zod import verbatim into
dist/index.js & dist/agent/pi-native.js (16 static imports each). Installs
without a node_modules tree (dsh profile bundles) then die at startup with
ERR_MODULE_NOT_FOUND while model traffic silently bypasses compression.

- jimp removed from tsup noExternal and added to explicit external (tsup
  only auto-externalizes dependencies/peerDeps, not optionalDependencies)
- src/image-rescale.ts resolves jimp once at first use; a failed resolution
  is permanent per process and degrades rescaling to pass-through
- jimp moved devDependencies -> optionalDependencies (sharp precedent:
  installed where possible, silently skipped where not)
- new build gate scripts/check-dist-no-zod.mjs fails the build on any static
  zod import in dist (the original offender class, forever)
createBiliPlugin called wireToolGuardrails(pi) with no opts, so the
owner-approved #3066/#3331 defaults never reached production: bash 60s
timeout injection never fired, and the documented BILI_GUARDRAIL_* /
guardrails.* switches had zero effect (disable switches dead too —
wireToolGuardreads treats undefined as its 50KB default, so the knob's
undefined(disabled) maps to 0(no cap)). Also register the existing
FileConfig.guardrails field in KNOWN_TOP_LEVEL_KEYS so a user spelling it
right is no longer flagged as an unknown key.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_fix-p0-jimp-zod-dist (146e2f8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4170-pr.3524.f73953e

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

Install instructions are refreshed on each push.

awork and others added 2 commits October 17, 2026 16:36
…ernal-zod build gate

Conflict resolution (#3519 vs #3524, same P0, two designs):

- tsup.config.ts: keep jimp EXTERNAL + lazy-load degrade (this branch's
  design). Master's noExternal:["zod"] is dropped as moot — with jimp out
  of the bundle nothing statically imports zod, so bundling it had no
  effect anymore. dist/index.js shrinks 7.1MB -> 4.8MB.
- package.json build line: keep master's check-dist-external-zod.mjs gate
  (stricter: flags literal import("zod") too, catches any future static
  zod leak). This branch's check-dist-no-zod.mjs + tests/dist-no-zod.test.ts
  removed as the weaker duplicate.
- ework's optionalDependencies jimp + guardrail knob wiring unchanged.

Verified: npm run build + dist-external-zod gate OK; thin install
(bare dist, no node_modules) `node dist/index.js --version` exit 0;
issue3400-image-rescale 18 + check-dist-external-zod 3 + opencode-native-v1 28
= 49 pass; typecheck clean.
@ranxianglei
ranxianglei merged commit 6dc41f6 into master Oct 17, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.530-master.6dc41f6 (rolling master tag).

npm install -g billion-context@0.0.530-master.6dc41f6  # 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.

v0.1.198 release blockers found in final pre-release review | v0.1.198 发版前终审发现的阻塞项清单

1 participant