Skip to content

fix: bili pi launcher disables pi's native auto-compaction (#447) - #448

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-02_pi-disable-native-compaction
Sep 3, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-02_pi-disable-native-compaction

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (#447)

bili pi never disabled pi's own context compaction, so pi's native summarizer (shouldCompact, enabled: true by default) could fire ahead of / alongside bili's ACP compression and lossily rewrite the context bili is managing — losing the detailed history.

Fix

The pi overlay (<piHome>-bili) is now always built when the real pi home exists, and always carries a settings.json with compaction.enabled=false (merged over the user's real settings.json, which is never mutated). This makes bili's ACP compression the sole compression path under bili pi, mirroring how codex/claude already get their native auto-compact aligned (codex model_auto_compact_token_limit, claude CLAUDE_CODE_AUTO_COMPACT_WINDOW).

Changes:

Verification

  • npm run typecheck ✅
  • npm test — 899 pass, 0 fail ✅
  • npm run build ✅
  • Integration check: realistic pi home (HTTP vllm provider + user settings.json) → overlay settings.json = {packages, theme, compaction:{reserveTokens:16384, enabled:false}}, models.json baseUrl rewritten to /bili/, real settings.json untouched ✅

Launcher-only change (no request-pipeline change), so the codex E2E suite is not exercised by this diff.

The `bili pi` launcher never disabled pi's own context compaction, so pi's
native summarizer (shouldCompact, enabled by default) could fire ahead of /
alongside bili's ACP compression and lossily rewrite the context bili is
managing — losing the detailed history.

The pi overlay (<piHome>-bili) is now ALWAYS built when the real pi home
exists and always carries a settings.json with compaction.enabled=false
(merged over the user's real settings.json, which is never mutated). This
makes bili's ACP compression the sole compression path under `bili pi`,
mirroring how codex/claude already get their native auto-compact aligned.

- refreshOverlayHome / mergeOverlayEntry now accept a SET of generated files
  (models.json + settings.json) so both stay out of the real-home symlink and
  merge-back sets.
- models.json is still rewritten for HTTP/wrapped-HTTPS upstreams when present.
- preparePiHttpRewrite returns undefined only for a missing real home.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-02_pi-disable-native-compaction (037070d)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-448

Each push to this PR publishes a new version under the pr-448 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr448.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 Reviewed PR #448 (fixes #447). Verified and analyzed in detail — assessment below.

Verification (all green):

  • npm run typecheck ✅
  • npm test — 899 pass, 0 fail ✅
  • npm run build ✅

The root cause is real and the fix targets it correctly. For pi, raw-HTTPS providers (the common case) are classified into httpsDomains (cert-MITM), not into httpRewrites/httpsRewrites (discoverRoutes, src/launcher.ts:267-270). So for a typical HTTPS-only pi setup, preparePiHttpRewrite returned undefined, the <piHome>-bili overlay was never built, PI_CODING_AGENT_DIR was never set, and pi ran from its real home with native compaction left at its default (enabled: true). That's exactly the gap #447 describes. Making the overlay always build (when the real home exists) closes it. I reproduced both scenarios manually:

  • HTTPS-only providers (no rewrites) → overlay now built, settings.json = {"theme":"dark","compaction":{"enabled":false}}.
  • Realistic home (HTTP vllm provider + user settings.json) → settings.json = {packages, theme, compaction:{reserveTokens:16384, enabled:false}}, vllm baseUrl → /bili/…, openai (HTTPS) untouched, real settings.json byte-for-byte unchanged, auth.json symlinked.

The #410 guarantee now holds for both generated files. refreshOverlayHome/mergeOverlayEntry take a set (settings.json + models.json), so both stay out of the real-home symlink set and the merge-back set at any depth. isGeneratedDraft correctly matches .settings.json.<pid>.tmp / .models.json.<pid>.tmp. Clean generalization of the prior single-file logic; the omp/hermes/dsh call sites still pass a single string, which the Array.isArray guard handles.

writePiCompactionDisabledSettings is correct. Reads the real settings.json, shallow-copies the compaction object, sets enabled=false, writes to the overlay — preserving packages/theme/reserveTokens/etc. Real file is never mutated. Missing/malformed/non-object settings.json and non-object compaction are all handled gracefully (falls back to {} then forces enabled=false).

Consistent with codex/claude, with an intentional mechanism difference. Same goal (ACP is the sole compression path). codex's local compaction is benign (same-session truncation the kernel deactivates by message id), so codex gets threshold alignment (model_auto_compact_token_limit). pi's native summarizer is lossy — it rewrites the context bili manages — so pi gets full disable. That's the right call for pi.

Two small notes (non-blocking):

  1. The description says models.json is "copied verbatim otherwise," but the code re-serializes it via JSON.stringify(modelsRoot) whenever it's a present, valid object — even when no rewrite matched. For plain-JSON models.json the parsed content is identical (only whitespace/formatting differs), so it's harmless in practice. Either do a true byte-copy in the no-rewrite case or soften the description.
  2. The whole fix hinges on pi reading compaction.enabled (boolean) from settings.json to gate its native summarizer. That's pi-internal (separate repo) and isn't referenced anywhere in this codebase, so I'm taking the author's word for it — worth a one-line pointer to the pi source that confirms the exact key/shape before merge.

Bottom line: LGTM to merge. Correct fix, well-tested (the new/updated preparePiHttpRewrite tests cover the no-rewrite overlay build, the non-existent-home undefined, compaction disable, and key preservation), clean verification. Launcher-only, so no codex E2E needed. I'd only want the compaction.enabled key-shape confirmation (note 2) before merge; note 1 is optional polish.

@ranxianglei
ranxianglei merged commit cdbf2bc into master Sep 3, 2026
6 checks passed
ranxianglei added a commit that referenced this pull request Sep 26, 2026
- wire-contract goldens regenerated for acp-kernel 0.0.93→0.0.95 via
  scripts/update-wire-contract-goldens.ts: compress/decompress/search
  schemas gain explicit typed anyOf alternatives (kernel #448, the
  Copilot-Gemini portability fix). Reviewed: no unrelated drift.
- preflight e2e windows 10_600 → 12_000: the typed-alternative schema
  grew tool definitions by ~1.4KB (~340 tokens of wireOverhead, which
  every fit decision adds per #470). At 10_600 the recent zone no
  longer fit after folding — fold-all is correct behavior for a tight
  window, but these tests pin 'recent messages survive', so they need
  the headroom the pre-#448 schema size had. Payload still overflows
  12k (~13k-token history), so the preflight-fire premise is intact.
ranxianglei added a commit to InCerryGit/billion-context that referenced this pull request Sep 26, 2026
…chema (ranxianglei#1414)

Kernel ranxianglei#448 (acp-kernel 0.0.95) replaced the compress tool's union
type arrays and untyped anyOf fragments with explicit typed
alternatives; Bili bundles that schema at build time, so the exact
dev-dependency pin is the delivery path.

Adds tests/wire-schema-portable.test.ts walking Bili's full outgoing
ACP tool surface on all four wires (anthropic/openai/responses/google,
including withRangeParams rewrites): no union type arrays, every anyOf
alternative declares an explicit scalar type, top level stays a plain
object. Red against 0.0.93 (3/4 wires fail), green against 0.0.95.

Fixes ranxianglei#1414
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