Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b59767d
chore: empty PR (no changes)
Oct 25, 2026
cd48d6d
Merge ci-fixes 18f514667: re-pin storage-lane proofs onto #4316 one-t…
Oct 25, 2026
4ca2a21
fix(ci): restore the Ensure jq bootstrap in release-bugfix.yml
Oct 25, 2026
557d24b
chore: sync plugin manifests to 0.1.207
Oct 25, 2026
041c32b
fix(preflight): stop folding when the payload already fits its own wi…
Oct 22, 2026
0b9fe76
fix(preflight): never emit sub-minimum chunk fragments when a single …
Oct 25, 2026
6aad27e
fix: fork row clone uses last live seq, not row count (#4730)
Oct 25, 2026
293ae65
kernel: skip null/negative covered-seq sentinels (PR #4725 N1)
Oct 25, 2026
a6b7d98
fix(storage): store the -1 no-claim sentinel for unresolvable coverag…
Oct 25, 2026
740c4e6
fix(render): keep the anchor when a fold covers the render window's t…
Oct 25, 2026
e253a29
fix(cache-ledger): read the wire fold-attribution pair from the ALS c…
Oct 25, 2026
a4a17cb
fix(kernel): re-key the CCR content store onto the restamped ref map …
Oct 25, 2026
b97807f
fix(loop): make the loop lane's upstream sends feed the 429 governor
Oct 25, 2026
23310dd
fix(preflight): target-aware fit exit (#4288) + coverage-aware fragme…
Oct 25, 2026
62a598b
merge ci-fixes into 2026-10-25_empty-pr (#4599 help-merge sweep)
Oct 25, 2026
de5e036
fix(review round-2): F1-F7 — text-to-text #4288 exit, sentinel fold-c…
Oct 25, 2026
5f62598
fix(storage): hoist the covered-id array out of the mysql span-query …
Oct 25, 2026
6e7e274
merge ci-fixes into 2026-10-25_empty-pr (#4599 help-merge sweep)
Oct 25, 2026
785af36
fix(preflight): an overflow-arm baseline keeps the floored exit — #11…
Oct 26, 2026
f3a3816
Merge master into 2026-10-25_empty-pr — resolve #4725 base conflict
Oct 26, 2026
4e0c773
Merge branch 'master' into 2026-10-25_empty-pr
ranxianglei Oct 26, 2026
ec3576b
fix(review round-3 leftovers): manifest-check coverage on the bugfix …
Oct 26, 2026
825fd2c
Merge branch 'master' into 2026-10-25_empty-pr
ranxianglei Oct 26, 2026
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: 1 addition & 1 deletion .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plugins": [
{
"name": "billion-context",
"version": "0.1.205",
"version": "0.1.207",
"source": {
"source": "local",
"path": "./plugins/codex"
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "billion-context",
"source": "./",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"version": "0.1.205",
"version": "0.1.207",
"author": {
"name": "ranxianglei"
},
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.205",
"version": "0.1.207",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"author": {
"name": "ranxianglei"
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/release-bugfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ jobs:
id-token: write
actions: write
steps:
- name: Ensure jq (2026-10 runner images are unreliable about it — always install our own)
run: |
type -a jq || true
mkdir -p "$HOME/.local/bin"
curl -fsSL "https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-linux-amd64" -o "$HOME/.local/bin/jq"
chmod +x "$HOME/.local/bin/jq"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
"$HOME/.local/bin/jq" --version

- name: Validate trigger + resolve the publish ref
id: resolve
run: |
Expand Down Expand Up @@ -120,6 +129,24 @@ jobs:
[ -z "$SHA" ] && SHA="$(git rev-parse HEAD)"
echo "::notice::Publishing carve-out from '$REF' @ ${SHA:0:12} -> v$V (master NOT involved)"

- name: Verify plugin manifests match package.json (#4449)
# The four plugin manifests carry their own version fields — the
# marketplaces use them for UPDATE DETECTION, so a release whose
# manifests disagree with package.json ships a plugin that never
# prompts users to upgrade. Drift = red release, nothing shipped.
# See reference/release.md.
if: steps.resolve.outputs.proceed == 'true'
# #4576 follow-up: lanes cut from a pre-#4449 tag do not carry the
# manifest sync script at all -- fail-open with a notice there instead
# of MODULE_NOT_FOUND (same existence-guard philosophy as release-manual's
# lane guard).
run: |
if [ -f scripts/sync-codex-plugin-version.mjs ]; then
node scripts/sync-codex-plugin-version.mjs --check
else
echo "::notice::this tree predates #4449 (no scripts/sync-codex-plugin-version.mjs) — manifest sync check skipped for the pre-#4449 lane"
fi

- name: Publish guard (monotonic + not-already-live)
if: steps.resolve.outputs.proceed == 'true'
run: |
Expand Down
2 changes: 2 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,8 @@ Interaction with the budget: the achievable fold rate of a batch is bounded by h

Two optional knobs turn the chain into a **proxy-driven auto-folder** (`autoFold`): with `"autoFold": true` the proxy stops waiting for the model to call the compression tool at all — the same zero-model folding engine that guards the overflow window also folds the conversation down to `autoFoldTargetTokens` (default: half the model window) *before* forwarding, using the external chain and kernel-chosen ranges. The model never sees a nudge and never spends thinking tokens drafting compression plans. The knob rides whole-chain replace semantics like the rest of the block; it only takes effect while the chain itself is enabled — setting either knob on a disabled (or omitted-`enabled`) chain has no effect and is logged once as a warning rather than failing silently. `autoFoldTargetTokens` must be an integer in `[8192, 10000000]`. Failure is fail-open: if the chain errors at fold time, the request forwards as-is, a 10-minute backoff suppresses auto-folding, and classic advisory nudges return for that window. One exception (#2662): a zero-progress fold caused purely by queue drops — batches submitted but no summary call ever dispatched because the shared pool is saturated — does not arm the backoff, since that is scheduler congestion rather than a chain failure; auto-fold simply retries on the next turn.

Auto-fold growth triggers are benefit-gated (#3444), not bare threshold crossings: a growth fold arms only when the text channel exceeds the effective target budget by at least **4096 tokens** — payloads sitting at (or barely past) the target forward as-is instead of burning a full external-summary round trip to save less than its fixed cost. The same gate applies post-fold: a growth fold that ends up saving fewer than 4096 tokens arms the 10-minute backoff exactly like a zero-progress pass. Image-dominant payloads are exempt (images are not foldable, so their overage is never "expected benefit"), and classic overflow folding is untouched — there, firing is mandatory. Additionally, the effective target has a **measured floor**: when the session's irreducible baseline (system prompt + tool definitions + live tail) is larger than the configured `autoFoldTargetTokens`, the target is raised to that measured size and a warning names the real number — an unreachable target would otherwise re-arm a futile fold on every request. The floor never lifts the target above the model window.

#### Agent-reported providers (fallback layer)

An ACP-native agent (currently the `pi` extension) reports its own configured providers to the proxy once per process (`POST /__bili/agent-providers`): provider name, base URL, wire protocol, resolved API key, and model list. These recipes form a **fallback layer** — a chain may reference `"zhipu/glm-5"` without the dial fields being duplicated in the file, so a provider configured once in the agent's own config is directly usable as a summary target. Merge order is **file wins**: a file recipe with the same name shadows the agent's contribution for that provider entirely (including its models). The agent layer never persists to disk: keys live only in proxy process memory, are never returned by the configuration API, and never appear in logs. Skip rules on the reporting side: OAuth-authenticated providers, `auth.json` ("stored") credentials, providers whose endpoint points back at the proxy itself, and wire protocols without a summary dial (`bedrock`, `vertex`, `mistral`, `pi-messages`) are not reported; plain-HTTP non-loopback baseUrls are not sent either (the server would refuse them — the inline apiKey must not travel over plaintext, #2585). Intake is per-entry: a refused entry is logged and named in the response's `skipped` list instead of discarding the whole report — the remaining entries register normally. The Web UI marks agent-reported models with an `(agent)` badge in the target dropdown.
Expand Down
2 changes: 2 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ URL 键通道(或带 `bind` 的命名条目)可以向上游发送**自己的

两个可选旋钮可把这条链升级为**代理驱动的自动折叠器**(`autoFold`):`"autoFold": true` 后代理不再等模型调压缩工具 —— 原本只守溢出窗口的零模型折叠引擎同样会在转发前把对话折到 `autoFoldTargetTokens`(默认:模型窗口的一半)以下,范围由内核选定、摘要由外部链完成。主模型完全看不到 nudge,也不会把思考预算花在起草压缩方案上。该旋钮随整链替换语义生效,且只在链本身启用时才起作用——在链未启用(或省略 `enabled`)时设置任一旋钮均无效,并会记录一次警告而非静默失效;`autoFoldTargetTokens` 必须是 `[8192, 10000000]` 内的整数。失败时 fail-open:链在折叠时出错则照常转发请求,退避 10 分钟内暂停自动折叠并恢复经典 advisory nudge。一个例外(#2662):若零进展完全由队列丢弃造成——批次已提交但因共享池饱和、没有任何一次摘要调用真正派发——则不触发退避(那是调度拥塞而非链故障),auto-fold 在下一轮直接重试。

auto-fold 的增长触发是**收益门槛制**(#3444),不是裸阈值:只有文本通道超出有效目标预算至少 **4096 token** 才会武装增长折叠——已坐在目标上(或刚刚过线)的载荷会直接照常转发,不会为了省不到固定成本的量去烧一整轮外部摘要往返。折叠后同一道门槛再算一次:一场增长折叠实际省下不足 4096 token,就按零进展同样处理,武装 10 分钟退避。图片主导的载荷豁免(图片不可折叠,其超出量永远算不上“预期收益”);经典溢出折叠不受影响——那是必须触发的。另外,有效目标有一个**实测下限**:当会话不可压缩的基线(系统提示词 + 工具定义 + 存活尾巴)大于配置的 `autoFoldTargetTokens` 时,目标会被抬到实测值并告警提示真实数字——否则一个永远够不着的目标会在每轮请求上重复武装注定徒劳的折叠。下限永远不会把目标抬过模型窗口。

#### Agent 上报的 providers(兜底层)

ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报自己已配置的 providers(`POST /__bili/agent-providers`):provider 名、base URL、线上协议、已解析的 API key 与模型清单。这些 recipes 构成一个**兜底层** —— 链可以直接引用 `"zhipu/glm-5"`,无需在文件里重复拨号字段;在 agent 自身配置过的 provider 可直接用作摘要目标。合并序为**文件优先**:同名 file recipe 会完全遮蔽 agent 对该 provider 的贡献(含模型清单)。agent 层永不落盘:key 只存在于代理进程内存,配置 API 不返回,也不进日志。上报侧的跳过规则:OAuth 认证的 provider、`auth.json`(“stored”)凭据、端点指回代理自身的 provider、以及没有摘要拨号协议的 provider(`bedrock`、`vertex`、`mistral`、`pi-messages`)都不会上报;plain-HTTP 非回环 baseUrl 同样不会发送(服务端会拒绝——内联 apiKey 不能走明文,#2585)。接收按条目隔离:被拒的条目只会被记录并出现在响应的 `skipped` 列表里,不再丢弃整份上报——其余条目照常注册。Web 面板的目标下拉里 agent 上报的模型带 `(agent)` 标记。
Expand Down
4 changes: 2 additions & 2 deletions kernel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kernel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acp-kernel",
"version": "0.0.163",
"version": "0.0.165",
"description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
"license": "MIT",
"author": "ranxianglei",
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,9 @@ function resolveCoverageInterval(
!consumed ||
typeof consumed.startSeq !== "number" ||
typeof consumed.endSeq !== "number" ||
consumed.endSeq < consumed.startSeq
consumed.endSeq < consumed.startSeq ||
consumed.startSeq < 0 ||
consumed.endSeq < 0
) {
return undefined; // unbounded consumed block (or legacy) — never guess
}
Expand Down
46 changes: 46 additions & 0 deletions kernel/src/content-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,52 @@ export function hasStoredRef(store: MessageContentStore, ref: string): boolean {
return store.byRef[ref] !== undefined;
}

/** #4733: re-key a CCR content store onto the post-restamp ref map.
* restampRefsToLedger renumbers messageRefs (ref = seq+1) but the store's
* byRef keys stay frozen at store-time refs — after the stamp the two views
* disagree: a stored entry sits under a number the ref map now vends to a
* DIFFERENT message (silent misattribution on retrieveByRef), and host
* consistency gates that check byRaw[entry.rawId] === ref reject the whole
* session. Re-key every entry whose rawId holds a live numeric ref in the
* new map; entries for unmapped raw ids (dead/pruned) keep their old key
* (the store's byRef index remains their retrieval path, per the frozen-alias
* invariant); entries for BLOCKED raw ids keep theirs too (no numeric ref).
* Collisions merge — one entry per rawId under its current ref, first
* content wins (append-only/first-write-wins preserved). */
export function restampContentStore(
store: MessageContentStore,
byRaw: Record<string, string>,
): MessageContentStore {
const next: Record<string, StoredEntry> = {};
// Live mappings claim their keys first; a dead raw id's frozen alias may
// never shadow a live mapping that now owns that number.
for (const entry of Object.values(store.byRef)) {
const live = byRaw[entry.rawId];
if (live === undefined || live === "BLOCKED") continue;
if (next[live] === undefined) next[live] = entry;
}
let changed = Object.keys(next).length !== Object.keys(store.byRef).length;
for (const [ref, entry] of Object.entries(store.byRef)) {
const live = byRaw[entry.rawId];
if (live !== undefined && live !== "BLOCKED") continue;
if (next[ref] === undefined) {
next[ref] = entry;
} else {
changed = true; // frozen alias shadowed by a live mapping — dropped
}
}
if (!changed) {
for (const [ref, entry] of Object.entries(store.byRef)) {
if (next[ref] !== entry) {
changed = true;
break;
}
}
}
if (!changed) return store;
return { ...store, byRef: next };
}

export interface ContentStoreStats {
/** Number of stored refs. */
entries: number;
Expand Down
1 change: 1 addition & 0 deletions kernel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export {
createContentStore,
hashContent,
storeOriginal,
restampContentStore,
retrieveByRef,
hasStoredRef,
contentStoreStats,
Expand Down
9 changes: 9 additions & 0 deletions kernel/src/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export function isCovered(id: string, coveredBases: Set<string>): boolean {
* Blocks without bounds contribute nothing; messages without stamps are
* decided by the id path alone. Both paths run in parallel (union): the id
* path stays byte-identical for unstamped traffic.
*
* The -1/-1 "no claim" sentinel (PR #4725 N1: storage writes it when a
* block's covered ids cannot be resolved to transcript rows, e.g. migrated
* pre-unified-storage folds) contributes nothing — with the historical
* endSeq >= startSeq guard alone it would pass as a REAL interval and, for
* the [0,0] placeholder it replaces, suppress the seq-0 message as already
* folded. [0,0] itself stays a legitimate claim: a block can genuinely
* cover just seq 0.
*/
export function coveredSeqIntervals(
state: CompressionState,
Expand All @@ -62,6 +70,7 @@ export function coveredSeqIntervals(
if (
typeof block.startSeq === "number" &&
typeof block.endSeq === "number" &&
block.startSeq >= 0 &&
block.endSeq >= block.startSeq
) {
intervals.push({ start: block.startSeq, end: block.endSeq });
Expand Down
5 changes: 4 additions & 1 deletion kernel/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import type { CompressionState, CoreMessage } from "./types.js";

/** #4316 layer 3: true when any visible message's ledgerSeq stamp falls
* inside the block's exact interval claim. Unbounded blocks and unstamped
* views answer false — the id path decides those. */
* views answer false — the id path decides those. The -1/-1 "no claim"
* sentinel (PR #4725 N1) also answers false: it is absence of evidence, not
* a positional claim (a [0,0] row IS a real claim over seq 0). */
function blockSeqPresent(
block: { startSeq?: number; endSeq?: number },
messages: CoreMessage[],
): boolean {
if (
typeof block.startSeq !== "number" ||
typeof block.endSeq !== "number" ||
block.startSeq < 0 ||
block.endSeq < block.startSeq
) {
return false;
Expand Down
66 changes: 66 additions & 0 deletions kernel/tests/ccr-restamp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import assert from "node:assert/strict";
import test from "node:test";

import {
createContentStore,
restampContentStore,
retrieveByRef,
storeOriginal,
type MessageContentStore,
} from "../src/content-store.js";

// #4733: restampRefsToLedger renumbers messageRefs (ref = seq+1) but the CCR
// content store's byRef keys stay frozen at store-time refs. After a restamp
// the two disagree: the stored original for message A sits under the number
// the ref map now vends to message B (silent misattribution on retrieveByRef),
// and host consistency gates that assert byRaw[entry.rawId] === ref reject
// the whole session (plugin fork 409). restampContentStore re-keys the store
// onto the post-restamp map: live raw ids move to their new refs, dead ids
// keep their frozen aliases, and a dead id's alias never shadows a live
// mapping that now owns that number.

function spec(ref: string, rawId: string, text: string) {
return { ref, rawId, kind: "shell output", tokens: Math.ceil(text.length / 4), text, head: text.slice(0, 24) };
}

test("restampContentStore re-keys live entries and never misattributes", () => {
let store: MessageContentStore = createContentStore();
// Store-time aliases: rawA→m00002, rawB→m00003, rawD→m00004 (rawD dies later)
store = storeOriginal(store, spec("m00002", "rawA", "AAA original"));
store = storeOriginal(store, spec("m00003", "rawB", "BBB original"));
store = storeOriginal(store, spec("m00004", "rawD", "DDD original"));

// Post-restamp map: rawA lands on seq+1 = m00003, rawB on m00005; rawD unmapped.
// Note rawA's NEW ref collides with rawB's store-time alias.
const byRaw: Record<string, string> = { rawA: "m00003", rawB: "m00005" };

const next = restampContentStore(store, byRaw);

// Live mappings claim their keys: m00003 → rawA's original (NOT rawB's).
const a = retrieveByRef(next, "m00003");
assert.ok(a.ok && a.entry.rawId === "rawA" && a.text === "AAA original", "new ref resolves to its own raw id's original");
const b = retrieveByRef(next, "m00005");
assert.ok(b.ok && b.entry.rawId === "rawB" && b.text === "BBB original", "rawB re-keyed to its new ref");
// Dead rawD keeps its frozen alias m00004…
const d = retrieveByRef(next, "m00004");
assert.ok(d.ok && d.entry.rawId === "rawD", "dead id keeps its frozen alias");
// …but its alias was m00004 — no collision here; assert the collision case below.
assert.equal(next.byRef["m00002"], undefined, "rawA's old key vacated");
});

test("restampContentStore: a dead id's frozen alias never shadows a live mapping", () => {
let store: MessageContentStore = createContentStore();
store = storeOriginal(store, spec("m00004", "rawD", "DDD original")); // rawD dies
store = storeOriginal(store, spec("m00009", "rawA", "AAA original")); // rawA lands on m00004 after restamp
const byRaw: Record<string, string> = { rawA: "m00004" };
const next = restampContentStore(store, byRaw);
const r = retrieveByRef(next, "m00004");
assert.ok(r.ok && r.entry.rawId === "rawA" && r.text === "AAA original", "live mapping wins the contested number");
});

test("restampContentStore: aligned store is returned unchanged (identity, no copy)", () => {
let store: MessageContentStore = createContentStore();
store = storeOriginal(store, spec("m00002", "rawA", "AAA original"));
const byRaw: Record<string, string> = { rawA: "m00002" };
assert.equal(restampContentStore(store, byRaw), store, "no-op when already aligned");
});
Loading
Loading