Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

## [Unreleased]

- **First-sight mass digestion now drains in one batched call (#2326)**: hosts that hand bili a pre-inflated history (dsh plugin mode after its own digestion, CLI hand-off, resumed rollout) make the first requests see a large ready mass with zero growth baseline; the kernel marks those nudges ` [first-sight mass]` and re-arms after every successful fold, and the model folded the backlog one small call per request — each front-positioned fold rewrites the request prefix, so every piecemeal landing re-pays the ENTIRE remaining tail to the prefix cache (measured 2.29×/tok re-pay for a 5-fold cascade vs 0.032×/tok for one big fold, ~70×; issue log eb985b31 vs 5c5c26d1). Root constraint: a one-call batch is physically unexecutable when the model must write N summaries in one response — the per-response output budget caps how many 20K-char summaries fit, so the existing batching hints (SUMMARY_BUDGET_NOTE, ONE_CALL_HINT) degrade to piecemeal folds on big masses. `withFirstSightDrain(text, reason, external)` now keys on the kernel marker at all 12 nudge injection points (4 adapters × advisory/decide-directive): during digestion it appends a byte-stable "First-sight digestion" note (drain the WHOLE backlog in ONE batched compress call; split oversized spans into multiple ranges at logical boundaries but submit them all together in the same call; keep draining while the nudge repeats — it stops when the backlog is gone) and SUPPRESSES the smooth-transition staged note, whose smaller/tail-biased steering is exactly wrong for a backlog that must be drained; the decide-directive path carries an explicit precedence sentence over the stock "exactly this span" wording. No marker → byte-identical to the legacy staged path (steady-state guidance unchanged); no new config surface. The external variant of the note additionally tells the model that with `compress.externalSummary` enabled the independent summary service writes the summaries, so its own response-length budget is not a limit — combining the note with external summaries (targets may even point back at the same endpoint+key: the win comes from the channel — disjoint side requests, one landing — not the author) makes the batched instruction executable for arbitrarily large backlogs. Tests: `tests/first-sight-drain.test.ts` (marker keying, byte-identity outside digestion, staged suppression inside it, external variant, byte-stability).

- **Proxy spawn under GUI/Electron hosts finds Node without a full PATH (#1429)**: `resolveNodeRuntime()` (#819) resolved the executable that runs the spawned proxy as live Node → `BILLION_CONTEXT_NODE` override → PATH search → throw. GUI-launched hosts have a minimal PATH (launchd on macOS, the Windows GUI session) that omits normal install locations, so native plugins bootstrapped inside such hosts (e.g. deepseek-harness desktop's Electron process) threw before spawning and every session silently degraded to direct send (no compression), traceable only in bili.log (#1158 shape). Resolution now continues into well-known install locations the minimal PATH omits (`/usr/local/bin`, `/opt/homebrew/bin`, `/opt/local/bin`, Volta, `~/.local/bin`; on Windows `C:/Program Files/nodejs`, `%LOCALAPPDATA%/Programs/nodejs`, Volta), and as a last resort under an Electron host returns the host's own binary — which runs as plain Node when `ELECTRON_RUN_AS_NODE=1` is honored (the runAsNode fuse is on by default in standard builds); `ensureProxyRunning` forces that variable into the child env so the child runs Node instead of relaunching the desktop app. A real node always wins over the Electron-binary-as-node fallback; non-Electron behavior is unchanged (the env spread adds nothing outside Electron, the throw path is untouched). Entry backfilled here — PR #1436 shipped without a changelog line (#1576).

- **PR builds publish under one rolling `pr` tag with globally monotonic versions — per-PR dist-tag growth stops (#1385)**: the registry's `pr-N` dist-tags grew unboundedly (~595 live, +~40/day) because every PR push created/refreshed its own tag. `pr-artifact.yml` now publishes each build as `0.0.<run_number>-pr.<PR>.<sha7>[-a<attempt>]` under the SINGLE rolling `pr` tag — new dist-tag growth is exactly zero, and the legacy `pr-N` tags are frozen in place (still resolvable/installable, they just stop moving). PR bot comments switch Option A from `npm install -g billion-context@pr-N` to the EXACT immutable version string of that build (reproducible install, per #1108's exact-pin conclusion); `@pr` means "newest test build across ALL PRs" (semantics change: old `pr-N` meant "latest build of THAT PR"). The `0.0.x-pr.*` prerelease form is unchanged in properties: no semver range can ever resolve a PR build; `github.run_number` is unique+monotonic **per workflow** (gaps allowed) and `pr-artifact.yml` is the sole 0.0.x publisher, so concurrent publishes cannot collide, and `-a<attempt>` makes a rerun of one run publish a fresh version instead of failing E409. Release drift guards (`release-manual.yml` Drift guard, `release.yml` Read version) now abort any target version `< 0.1.0`, enforcing that official releases always sort above the PR-build line. Instances explicitly configured with `ACP_UPDATE_TAG=pr-N` freeze at that tag's final build (no forced migration; see CONFIGURATION.md).
Expand Down
41 changes: 41 additions & 0 deletions src/compress-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,47 @@ export function withStagedCompressGuidance(text: string): string {
return text + STAGED_COMPRESS_GUIDANCE;
}

// #2326 first-sight mass digestion. When a host hands bili a pre-inflated
// history (dsh plugin mode after its own digestion, CLI hand-off, resumed
// rollout), the first requests see a large ready mass with zero growth
// baseline: the kernel marks those nudges " [first-sight mass]" and re-arms
// after every SUCCESSFUL fold, so the backlog gets folded one small call per
// request. Each front-positioned fold rewrites the request prefix, so every
// piecemeal landing re-pays the ENTIRE remaining tail to the prefix cache —
// measured 2.29x/tok re-pay for a 5-fold cascade vs 0.032x/tok for one big
// fold (issue log: eb985b31 vs 5c5c26d1, ~70x). This note tells the model,
// at the moment of the nudge, that the ranges are a pre-existing backlog to
// drain in ONE batched call — split oversized spans into multiple ranges at
// logical boundaries (each under its per-summary cap, per the budget note
// above) but submit them ALL together in the same call — instead of piecemeal
// front folds. It deliberately REPLACES withStagedCompressGuidance during
// digestion: the smooth-transition note (smaller, tail-biased, keep the
// prefix intact) is exactly wrong for a backlog that must be drained. The
// closing precedence sentence keeps it correct on #2228 decide-directive
// injections, whose stock text pins ONE span. Byte-stable constants (like
// the notes above) so the prefix-cache anchor stays intact.
const FIRST_SIGHT_DRAIN_NOTE =
"\n\n[First-sight digestion: the compressible ranges above are a pre-existing backlog this session arrived with, not growth from your current task. Drain the backlog in ONE batched compress call — cover EVERY ready range, splitting oversized spans into multiple smaller ranges at logical boundaries (each summary within its cap), and submit them all together in the same call (content: [{startId,endId,summary}, {…}]). Do NOT fold piecemeal across turns: every small front fold re-bills the whole remaining tail to the prefix cache, while one batched call lands once. Keep draining while the nudge repeats — it stops when the backlog is gone. Where this conflicts with a single-span directive above, this takes precedence: the cited span is the starting point of the batch, not its limit.]";
const FIRST_SIGHT_DRAIN_NOTE_EXTERNAL =
"\n\n[First-sight digestion: the compressible ranges above are a pre-existing backlog this session arrived with, not growth from your current task. The independent summary service writes the summaries — you only select the ranges (plus optional topic hints), so your own response-length budget is not a limit here. Drain the backlog in ONE batched compress call — cover EVERY ready range, splitting oversized spans into multiple smaller ranges at logical boundaries, and submit them all together in the same call (content: [{startId,endId,summary}, {…}]). Do NOT fold piecemeal across turns: every small front fold re-bills the whole remaining tail to the prefix cache, while one batched call lands once. Keep draining while the nudge repeats — it stops when the backlog is gone. Where this conflicts with a single-span directive above, this takes precedence: the cited span is the starting point of the batch, not its limit.]";

/** True when the kernel flagged the nudge reason with the first-sight mass
* marker (kernel/src/compress.ts appends " [first-sight mass]" while a
* pre-inflated backlog is still being digested — the marker re-rides every
* re-armed nudge until the mass drops below the growth floor). */
export function firstSightDrainActive(reason: string | undefined): boolean {
return reason !== undefined && reason.includes("[first-sight mass]");
}

/** Nudge range guidance, first-sight aware (#2326): during first-sight mass
* digestion append the batched-drain note (and drop the smooth-transition
* note, which would steer the opposite direction); otherwise behave exactly
* like withStagedCompressGuidance. */
export function withFirstSightDrain(text: string, reason: string | undefined, external: boolean): string {
if (!firstSightDrainActive(reason)) return withStagedCompressGuidance(text);
return text + (external ? FIRST_SIGHT_DRAIN_NOTE_EXTERNAL : FIRST_SIGHT_DRAIN_NOTE);
}

// #717 anti-forgery rule for ACP confirmation markers. Under sustained
// context pressure a model was observed writing the proxy's own marker format
// ("📦 [ACP] Compressed …") as plain assistant text — 17 fake compressions,
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {
type GoogleSystemInstruction,
type GoogleTool,
} from "acp-kernel/wire";
import { ABSORB_TOOL_NAME, COMPRESS_TOOL, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_ANTHROPIC_NO_RANGE, BILI_ACP_TOOLS_GOOGLE, BILI_ACP_TOOLS_GOOGLE_NO_RANGE, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_OPENAI_NO_RANGE, BILI_ACP_TOOLS_RESPONSES, BILI_ACP_TOOLS_RESPONSES_NO_RANGE, BILI_ACP_READONLY_TOOLS_RESPONSES, BILI_ACP_READONLY_TOOLS_RESPONSES_NO_RANGE, COMPRESS_TOOL_NAME, IMAGE_FULL_TOOL, IMAGE_FULL_TOOL_GOOGLE, IMAGE_FULL_TOOL_OPENAI, IMAGE_FULL_TOOL_RESPONSES, RULE_TOOL, RULE_TOOL_GOOGLE, RULE_TOOL_OPENAI, RULE_TOOL_RESPONSES, absorbToolsFor, retrieveToolsFor, buildAcpTagsOnlyPrompt, withStagedCompressGuidance } from "./compress-tool.js";
import { ABSORB_TOOL_NAME, COMPRESS_TOOL, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_ANTHROPIC_NO_RANGE, BILI_ACP_TOOLS_GOOGLE, BILI_ACP_TOOLS_GOOGLE_NO_RANGE, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_OPENAI_NO_RANGE, BILI_ACP_TOOLS_RESPONSES, BILI_ACP_TOOLS_RESPONSES_NO_RANGE, BILI_ACP_READONLY_TOOLS_RESPONSES, BILI_ACP_READONLY_TOOLS_RESPONSES_NO_RANGE, COMPRESS_TOOL_NAME, IMAGE_FULL_TOOL, IMAGE_FULL_TOOL_GOOGLE, IMAGE_FULL_TOOL_OPENAI, IMAGE_FULL_TOOL_RESPONSES, RULE_TOOL, RULE_TOOL_GOOGLE, RULE_TOOL_OPENAI, RULE_TOOL_RESPONSES, absorbToolsFor, retrieveToolsFor, buildAcpTagsOnlyPrompt } from "./compress-tool.js";
import { absorbEnabled, storeEffectiveAbsorb } from "./absorb.js";
import { ccrEnabled, ccrLoopConfig, ccrPluginWireOk, contentStoreOf, executeRetrieve, pruneExpiredRetrievals, reconcileReloadedRetrievals, renderRetrievalNotes, retrieveToolName, snapshotPendingRetrievals, snapshotRetrievalNotes, storeEffectiveCcr, type CcrSettings } from "./store.js";
import { buildIncomingImageIndex, foldAnchoredCutoff, pruneRetrieveImgExports } from "./image-restore.js";
Expand Down
8 changes: 4 additions & 4 deletions src/server/prepare-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcil
import { nudgeSuppressed } from "../session-self-heal.js";
import { compressBreakerArmed } from "../stream.js";
import { applyCompactionArchive, detectUnannouncedHistoryRewrite, foldCoverage, markCompactionBoundary, markDirty, REWRITE_MIN_INCOMING_TOTAL, snapshotMessages, type PendingRetrieval, type Session } from "../session.js";
import { ABSORB_TOOL_NAME, IMAGE_FULL_TOOL, RULE_TOOL, absorbToolsFor, retrieveToolsFor, withMarkerIntegrityNote, withStagedCompressGuidance, withSummaryBudgetNote } from "../compress-tool.js";
import { ABSORB_TOOL_NAME, IMAGE_FULL_TOOL, RULE_TOOL, absorbToolsFor, retrieveToolsFor, withFirstSightDrain, withMarkerIntegrityNote, withSummaryBudgetNote } from "../compress-tool.js";
import { applyAbsorbView, storeEffectiveAbsorb } from "../absorb.js";
import { adoptContentStore, ccrEnabled, ccrLoopConfig, contentStoreOf, dropRetrievals, pruneExpiredRetrievals, reconcileReloadedRetrievals, renderRetrievalNotes, retrieveToolName, snapshotPendingRetrievals, snapshotRetrievalNotes } from "../store.js";
import { applyImageCompressionPass, imageCompressionEnabled, imageFullTrailingNote } from "../image-compress.js";
Expand Down Expand Up @@ -269,7 +269,7 @@ export async function prepareAnthropic(
const rendered = renderNudgeText(turn.nudge, prompts, surface?.nudgeSections);
const renderedWithPayload = rendered.text;
if (rendered.text) {
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withStagedCompressGuidance(renderedWithPayload), externalSummaryEnabled(config)), visibilityMarkers) }];
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withFirstSightDrain(renderedWithPayload, turn.nudge.reason, externalSummaryEnabled(config)), externalSummaryEnabled(config)), visibilityMarkers) }];
}
} catch {
}
Expand All @@ -281,7 +281,7 @@ export async function prepareAnthropic(
if (outcome.kind === "yes") {
const span = resolveDecisionRange(outcome, ranges);
if (span) {
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withStagedCompressGuidance(buildDirectiveText(span.startRef, span.endRef, outcome.topic)), externalSummaryEnabled(config)), visibilityMarkers) }];
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withFirstSightDrain(buildDirectiveText(span.startRef, span.endRef, outcome.topic), turn.nudge.reason, externalSummaryEnabled(config)), externalSummaryEnabled(config)), visibilityMarkers) }];
} else {
log("info", `[${sessionId}] [acp-decide] yes but no live range left to target — skipping injection`);
}
Expand All @@ -291,7 +291,7 @@ export async function prepareAnthropic(
const rendered = renderNudgeText(turn.nudge, prompts, surface?.nudgeSections);
const renderedWithPayload = rendered.text;
if (rendered.text) {
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withStagedCompressGuidance(renderedWithPayload), externalSummaryEnabled(config)), visibilityMarkers) }];
rebuiltMessages = [...rebuiltMessages, { role: "user", content: withMarkerIntegrityNote(withSummaryBudgetNote(withFirstSightDrain(renderedWithPayload, turn.nudge.reason, externalSummaryEnabled(config)), externalSummaryEnabled(config)), visibilityMarkers) }];
}
} catch {
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/prepare-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcil
import { nudgeSuppressed } from "../session-self-heal.js";
import { compressBreakerArmed } from "../stream.js";
import { applyCompactionArchive, foldCoverage, markDirty, REWRITE_MIN_INCOMING_TOTAL, snapshotMessages, type Session } from "../session.js";
import { ABSORB_TOOL_NAME, IMAGE_FULL_TOOL_GOOGLE, RULE_TOOL_GOOGLE, absorbToolsFor, buildAbsorbSystemPrompt, buildAcpTagsOnlyPrompt, buildCompressSystemPrompt, retrieveToolsFor, withMarkerIntegrityNote, withStagedCompressGuidance, withSummaryBudgetNote } from "../compress-tool.js";
import { ABSORB_TOOL_NAME, IMAGE_FULL_TOOL_GOOGLE, RULE_TOOL_GOOGLE, absorbToolsFor, buildAbsorbSystemPrompt, buildAcpTagsOnlyPrompt, buildCompressSystemPrompt, retrieveToolsFor, withFirstSightDrain, withMarkerIntegrityNote, withSummaryBudgetNote } from "../compress-tool.js";
import { absorbToolName, applyAbsorbView, storeEffectiveAbsorb } from "../absorb.js";
import { adoptContentStore, ccrEnabled, ccrLoopConfig, contentStoreOf, retrieveToolName } from "../store.js";
import { applyImageCompressionPass, imageCompressionEnabled, imageFullTrailingNote } from "../image-compress.js";
Expand Down Expand Up @@ -197,7 +197,7 @@ export async function prepareGoogle(
const rendered = renderNudgeText(turn.nudge, prompts, surface?.nudgeSections);
const renderedWithPayload = rendered.text;
if (rendered.text) {
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withStagedCompressGuidance(renderedWithPayload), visibilityMarkers));
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withFirstSightDrain(renderedWithPayload, turn.nudge.reason, externalSummaryEnabled(config)), visibilityMarkers));
}
} catch {
}
Expand All @@ -208,7 +208,7 @@ export async function prepareGoogle(
if (outcome.kind === "yes") {
const span = resolveDecisionRange(outcome, ranges);
if (span) {
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withStagedCompressGuidance(buildDirectiveText(span.startRef, span.endRef, outcome.topic)), visibilityMarkers));
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withFirstSightDrain(buildDirectiveText(span.startRef, span.endRef, outcome.topic), turn.nudge.reason, externalSummaryEnabled(config)), visibilityMarkers));
} else {
log("info", `[${sessionId}] [acp-decide] yes but no live range left to target — skipping injection`);
}
Expand All @@ -218,7 +218,7 @@ export async function prepareGoogle(
const rendered = renderNudgeText(turn.nudge, prompts, surface?.nudgeSections);
const renderedWithPayload = rendered.text;
if (rendered.text) {
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withStagedCompressGuidance(renderedWithPayload), visibilityMarkers));
rebuiltContents = appendGoogleNudge(rebuiltContents, withMarkerIntegrityNote(withFirstSightDrain(renderedWithPayload, turn.nudge.reason, externalSummaryEnabled(config)), visibilityMarkers));
}
} catch {
}
Expand Down
Loading
Loading