Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
18f5146
test: re-pin storage-lane proofs onto the #4316 one-time ledger align…
Oct 25, 2026
93cd238
Merge remote-tracking branch 'origin/master' into HEAD
ranxianglei Oct 25, 2026
d58df2b
test: re-pin storage-lane proofs onto the #4316 one-time ledger align…
Oct 25, 2026
6a1871a
fix(storage): unresolvable block interval bounds become the -1/-1 no-…
ranxianglei Oct 25, 2026
fa4d11e
fix(plugin-render): emit the acp_summary anchor when block coverage e…
ranxianglei Oct 25, 2026
f47aa8a
fix(fold-reconcile): stored-decomposition lookup rebuilds ordered row…
ranxianglei Oct 25, 2026
3b772a3
fix(cache): #3307 fold re-pay measurement reads pending evidence thro…
ranxianglei Oct 25, 2026
4c6aefe
fix(persist): remap token snapshot onto ledger-aligned refs; align-le…
ranxianglei Oct 25, 2026
dcd2dbc
chore(release): port the Ensure-jq bootstrap back into release-bugfix…
ranxianglei Oct 25, 2026
ab6a7f1
fix(wiring): degenerate-turn continuation retry joins the 429 governo…
ranxianglei Oct 25, 2026
1863a23
test: re-pin storage-render goldens after #4741/#4742 (metadata secti…
ranxianglei Oct 25, 2026
6ad09a0
test(plugin-fork): wait for the async compress fold before asserting …
ranxianglei Oct 25, 2026
8082ee8
test(plugin-fork): also bounded-wait for the ledger-aligned flag (#4599)
ranxianglei Oct 25, 2026
1b317de
fix(web): blog frontmatter survives CRLF checkouts (#4599)
ranxianglei Oct 25, 2026
081206e
test(plugin-fork): type-clean the ledger-flag wait
ranxianglei Oct 25, 2026
1fa9373
test(plugin-fork): refLedgerAligned is unified-mode-only — mirror the…
ranxianglei Oct 25, 2026
783c34c
test(storage): align the #4316 gap-case pin with the -1/-1 no-claim s…
Oct 25, 2026
d87774c
merge: converge inherited storage-lane reds via ci-fixes 1fa93735d (#…
Oct 25, 2026
4fcd6cc
test(storage): re-pin google lane stateDigestAligned for the merged a…
Oct 25, 2026
c496cfb
test(launcher): opencode-inline spawn expectation follows the #679 co…
Oct 26, 2026
dfeea8a
fix(launcher): COMSPEC lookup must survive sanitized env copies (#4599)
ranxianglei Oct 26, 2026
729c117
fix(preflight): stop the post-model-switch folding ladder on fitting …
ranxianglei Oct 26, 2026
d0166c9
test(launcher): opencode-inline spawn expectations mirror the #4599 C…
Oct 26, 2026
4d7f5a3
Merge remote-tracking branch 'origin/2026-10-25_review-fixes' into fi…
ranxianglei Oct 26, 2026
6475f7e
merge ci-fixes into 2026-10-25_review-fixes (#4599 help-merge sweep)
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
10 changes: 10 additions & 0 deletions .github/workflows/release-bugfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ jobs:
contents: write
id-token: write
actions: write
pull-requests: write # annotate the ship PR + auto-open the alignment PR (#4744 note)
steps:
- name: Ensure jq (2026-10 runner images are unreliable about it — always install our own; ported back from v0.1.208, #4744)
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
2 changes: 1 addition & 1 deletion plugins/codex/.codex-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 Codex — small context windows (100K is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and high compression quality.",
"author": {
"name": "ranxianglei"
Expand Down
10 changes: 8 additions & 2 deletions src/cache-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,10 +1291,16 @@ export function recordCacheSample(
if (pending.length > 0 && known && s.input > 0) {
const rawMissed = s.input - effCached;
if (rawMissed > 8192 && rawMissed > 0.3 * s.input) {
const curB = session.transient?.sentBody;
// #4748: read the CURRENT send through pendingCapture — the relay
// lane keeps pending evidence in the AsyncLocalStorage capture
// (#4430), so transient.sentBody is undefined there and this
// measurement (whose target scenario IS the relay lane) never
// fired. prev reads stay on transient: settled evidence is moved
// OUT of the capture at settle time.
const curB = pendingCapture(session).sentBody ?? session.transient?.sentBody;
const prevB = session.transient?.settledBody;
if (curB !== undefined && prevB !== undefined && curB.bytes <= SEAM_BODY_CAP && prevB.bytes <= SEAM_BODY_CAP) {
const curIn = session.transient?.inBody;
const curIn = pendingCapture(session).inBody ?? session.transient?.inBody;
const prevIn = session.transient?.settledInBody;
const clientBreak = curIn !== undefined && prevIn !== undefined && curIn.msgs <= INBOUND_MSG_CAP && prevIn.msgs <= INBOUND_MSG_CAP && (() => {
const k = firstDivergentInboundMsg(prevIn, curIn);
Expand Down
15 changes: 15 additions & 0 deletions src/degenerate-retry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetchWithTimeout } from "./fetch-util.js";
import { noteUpstreamThrottle429, noteUpstreamThrottleResolved, upstreamThrottleLocalReject } from "./upstream-throttle.js";
import { hasCompactionTrigger } from "./codex-compact.js";
import { proxyDispatcher } from "./upstream-proxy.js";
import type { WireProtocol } from "./util.js";
Expand Down Expand Up @@ -82,6 +83,17 @@ export function makeContinuationRefetch(opts: ContinuationRetryOpts): () => Prom
const wireRetryBody = opts.wrapBody ? opts.wrapBody(retryBody) : retryBody;
try {
opts.resign?.(opts.reqHeaders, wireRetryBody);
// #4743: the retry is an egress send like any other — feed the 429
// governor (observe only, no local gate: the retry is bounded by
// the degenerate-turn ladder, and holding IT locally would strand
// the client's already-open response stream). A 429 verdict arms
// the hold for the NEXT main-lane send; any other resolved status
// clears it — same one-observation-per-request discipline as relay.
const throttleReject = upstreamThrottleLocalReject(opts.upstreamUrl, opts.reqHeaders);
if (throttleReject !== undefined) {
opts.log("info", `[${opts.label}] [plugin] degenerate-terminal retry answered locally by the 429 hold (#4204) — passing the empty turn through`);
return null;
}
const r = await fetchWithTimeout(
opts.upstreamUrl,
{
Expand All @@ -95,9 +107,12 @@ export function makeContinuationRefetch(opts: ContinuationRetryOpts): () => Prom
);
if (!r.response.ok || !r.response.body) {
r.clearTimer();
if (r.response.status === 429) noteUpstreamThrottle429(opts.upstreamUrl, opts.reqHeaders, r.response.headers.get("retry-after"));
else noteUpstreamThrottleResolved(opts.upstreamUrl, opts.reqHeaders, r.response.status);
opts.log("warn", `[${opts.label}] [plugin] degenerate-terminal retry rejected (HTTP ${r.response.status}); passing the empty turn through`);
return null;
}
noteUpstreamThrottleResolved(opts.upstreamUrl, opts.reqHeaders, r.response.status);
const body = r.response.body as ReadableStream<Uint8Array>;
// The retry stream is spliced into a response the caller already
// owns, so its own idle timer is dropped — a stalled retry then ends
Expand Down
5 changes: 4 additions & 1 deletion src/dsh-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ export function planDshSpawn(
"Set BILI_DSH_BIN to the dsh executable, or reword the argument.",
);
});
const comspec = env.COMSPEC?.trim() || "cmd.exe";
// #4599: sanitized env copies keep original key casing (`ComSpec`) — an
// exact `env.COMSPEC` probe misses it on plain objects.
const comspecRaw = env.COMSPEC ?? env.ComSpec ?? env.comspec;
const comspec = comspecRaw?.trim() || "cmd.exe";
const line = `"${[command, ...args].map(quoteWinToken).join(" ")}"`;
return { command: comspec, args: ["/d", "/s", "/c", line], windowsVerbatimArguments: true };
}
Expand Down
25 changes: 12 additions & 13 deletions src/fold-decomposition-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface StoredRow {
content: string;
}

interface DecompositionSource {
export interface DecompositionSource {
/** null = no index available (legacy/shadow/degraded); [] = index has none of them. */
rows(sessionId: string, msgIds: readonly string[]): StoredRow[] | null;
}
Expand Down Expand Up @@ -89,10 +89,13 @@ export function resolveStoredDecompositions(
// Latest seq per id wins (edits append rows); neighbors stay in so rc
// pairs keep adjacency for turn-key derivation. Unparseable rows are
// auxiliary-evidence misses, not errors — count them, don't throw.
// #4747: no in-loop index maintenance — interleaved rows (A1,B1,A2,B2 —
// the append shape for edits, exactly this lookup's target scenario)
// desynced a per-id index map on every splice, deleting the wrong
// element and silently dropping another id's LATEST row. Collect
// per-id latest now; rebuild + sort once at the end.
let skipped = 0;
const latestSeq = new Map<string, number>();
const ordered: { seq: number; m: CoreMessage }[] = [];
const orderedIdx = new Map<string, number>();
const latestById = new Map<string, { seq: number; m: CoreMessage }>();
for (const row of rows) {
let parsed: unknown;
try {
Expand All @@ -110,16 +113,12 @@ export function resolveStoredDecompositions(
skipped++;
continue;
}
const prev = latestSeq.get(row.msgId);
if (prev !== undefined && prev >= row.seq) continue;
latestSeq.set(row.msgId, row.seq);
const prevIdx = orderedIdx.get(row.msgId);
if (prevIdx !== undefined) ordered.splice(prevIdx, 1);
ordered.push({ seq: row.seq, m });
orderedIdx.set(row.msgId, ordered.length - 1);
const prev = latestById.get(row.msgId);
if (prev !== undefined && prev.seq >= row.seq) continue;
latestById.set(row.msgId, { seq: row.seq, m });
}
if (skipped > 0) loggerLog("debug", `[fold-reconcile] stored decomposition: ${skipped} unparseable row(s) skipped`);
if (ordered.length === 0) return undefined;
ordered.sort((a, b) => a.seq - b.seq);
if (latestById.size === 0) return undefined;
const ordered = [...latestById.values()].sort((a, b) => a.seq - b.seq);
return ordered.map((o) => o.m);
}
7 changes: 6 additions & 1 deletion src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5418,7 +5418,12 @@ export function planClientSpawn(
"Set BILI_CLIENT_BIN to the native executable (e.g. the real codex.exe) or to a script entry run under node, or reword the argument.",
);
});
const comspec = nonEmpty(env.COMSPEC) ? env.COMSPEC : "cmd.exe";
// #4599: Windows env vars are case-insensitive, but sanitized copies
// (spread objects, e.g. stripInheritedProxy's inlineEnv) keep the original
// key casing — `ComSpec` — where an exact `env.COMSPEC` probe misses it
// and silently degrades to the bare-name fallback. Probe every spelling.
const comspecRaw = env.COMSPEC ?? env.ComSpec ?? env.comspec;
const comspec = nonEmpty(comspecRaw) ? comspecRaw : "cmd.exe";
return {
command: comspec,
args: ["/d", "/s", "/c", buildWindowsCommandLine(cmd, args)],
Expand Down
24 changes: 24 additions & 0 deletions src/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,30 @@ export class SessionStore {
if (outcome.superseded.size > 0) {
session.restampSuperseded = outcome.superseded;
}
// The token snapshot is keyed by ref (#3488 render-refs): renumbered
// refs would otherwise inherit the stale count of whichever message
// held the new number pre-alignment — the wire tag then disagrees
// with the legacy-restart leg beyond citation renumbering (storage
// engine-proofs wire-parity, #4599). Two-pass moves: stage all
// (oldRef → newRef → count) first, then delete, then write — a
// single-pass swap would lose entries whose newRef is another
// move's oldRef.
const snap = (state as { tokenSnapshot?: Record<string, number> }).tokenSnapshot;
if (snap && outcome.superseded.size > 0) {
const byRawNow = state.messageRefs.byRaw;
const moves: Array<[oldRef: string, newRef: string, count: number]> = [];
for (const [oldRef, rawId] of outcome.superseded) {
const count = snap[oldRef];
const newRef = byRawNow[rawId];
if (count === undefined || newRef === undefined || newRef === oldRef) continue;
moves.push([oldRef, newRef, count]);
}
if (moves.length > 0) {
for (const [oldRef] of moves) delete snap[oldRef];
for (const [, newRef, count] of moves) snap[newRef] = count;
this.log("info", `[persist] remapped ${moves.length} token-snapshot entries onto ledger-aligned refs for ${session.id} (#4599)`);
}
}
state.refLedgerAligned = true;
this.log("info", `[persist] ledger-aligned refs for ${session.id}: kept=${outcome.kept} restamped=${outcome.restamped} rehomed=${outcome.rehomed} blocked=${outcome.blocked} superseded=${outcome.superseded.size} (#4316 PR3/3)`);
this.scheduleSave(session);
Expand Down
17 changes: 15 additions & 2 deletions src/plugin-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ export async function handlePluginRender(req: http.IncomingMessage, res: http.Se
if (blockSeqs.length === 0) continue;
for (const s of blockSeqs) coveredSeqs.add(s);
const maxCover = Math.max(...blockSeqs);
// #4746: the anchor's slot is the first view row PAST the block's
// coverage — when the coverage ends at (or beyond) the window's last
// row there IS no later row, and the anchor belongs at the very end
// (mirror of snapshot-render.ts's `let at = d` default + its tail
// flush). Skipping it (the old `continue`) suppressed the covered
// rows AND emitted no acp_summary anchor: the model silently lost
// the fold's context while the log still counted folded=N.
const pos = viewRows.findIndex((r) => r.seq > maxCover);
if (pos === -1) continue; // the fold extends past the requested window
anchors.push({ pos, msg: { id: `acp_summary_${block.blockId}`, role: "system", contentType: "text", text: "" } as BiliMessage });
anchors.push({ pos: pos === -1 ? viewRows.length : pos, msg: { id: `acp_summary_${block.blockId}`, role: "system", contentType: "text", text: "" } as BiliMessage });
}
anchors.sort((a, b) => a.pos - b.pos);
const merged: BiliMessage[] = [];
Expand All @@ -119,6 +125,13 @@ export async function handlePluginRender(req: http.IncomingMessage, res: http.Se
}
if (!coveredSeqs.has(viewRows[i].seq)) merged.push(prefix[i]);
}
// #4746: anchors slotted past the last view row (coverage reached the
// window's end) must still be flushed — the loop above never reaches
// their index (mirror of snapshot-render.ts's tail flush).
while (ai < anchors.length) {
merged.push(anchors[ai].msg);
ai++;
}

const system = loadSystem(sessionId);
// v1 renders the prefix WITHOUT cache-control marks: marks are per-turn
Expand Down
34 changes: 34 additions & 0 deletions src/preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ export interface PreflightDeps {
upstreamOrigin?: string;
/** #2133: compress.streamSummary resolved true for this request (three-level cascade). The self-learn flag only sees 400 "stream required" rejections, so gateways that time out long non-streaming completions (Cloudflare 524) can never self-heal — this forces SSE from the first attempt instead. */
forceStreamSummary?: boolean;
/** #4288 rework: true ONLY when this invocation re-runs after the upstream
* PROVED an overflow (the #1195/#3787 refold lanes pass the stated or
* armed window as a per-call override). There the usage baseline carries
* the upstream's own stated number (armOverflowShrink ran before us), so
* it is EVIDENCE, not staleness — the own-estimate round exit must stay
* off and folding judges on the floored quantity exactly as before.
* Absent (the normal growth/window path): a mid-session model switch
* leaves a stale baseline measured under the prior wider window, and the
* own-estimate exit stops the summarization ladder on payloads that
* already fit (#4288). */
upstreamProvedOverflow?: boolean;
/** One external-summary deadline shared by every range/chunk in this invocation. */
externalSummary?: ConfiguredSummaryPlan;
/** #2155: compress.streamSummary resolved FALSE for this request (explicit operator opt-out anywhere in the cascade). Neither learn path (400 "stream required" nor the 524/504 gateway-timeout first-hit learn) may arm, and an already-armed session flag is ignored — the operator said this upstream must never stream summaries. */
Expand Down Expand Up @@ -2049,6 +2060,29 @@ export async function preflightCompress(deps: PreflightDeps, messages: CoreMessa
// (the floor can be stale — see PreflightResult.payloadEstimate).
result.payloadEstimate = roundText + imageReserve;
if (startTokens < 0) startTokens = currentTokens;
// #4288: the round-boundary exit must judge on the payload's OWN
// estimate — the same floorless quantity the caller's forward gate
// trusts (#1839/#1492) — NOT on decisionTokens, which is floored by
// the session's usage baseline. After a mid-session switch to a
// smaller-window model that baseline was measured under the prior
// (wider) model and sits above the new target, so a floored
// comparison never trips and the loop burns the whole slow
// summarization ladder on a payload that already fits (the client
// then times out mid-ladder and the session appears stuck).
// EXCEPTION (#4288 rework): when the upstream PROVED the overflow
// (#1195/#3787 refold lanes — upstreamProvedOverflow), the baseline
// carries the upstream's stated number and outranks our own estimate:
// a locally-fitting payload was just rejected by the real window, so
// folding must continue on the floored quantity exactly as before
// (the original #4294 exit without this guard killed the #1195
// rescue: the mock upstream's stated 130k made a 17k payload look
// fitting and preflight returned an unchanged body).
if (deps.upstreamProvedOverflow !== true && result.payloadEstimate < limit) {
if (baselineFloor >= limit) {
deps.log("info", `[preflight] payload fits by its own estimate (~${Math.round(result.payloadEstimate)}/${limit}); stopping instead of folding further despite a higher usage baseline (~${Math.round(baselineFloor)} tok measured under a prior model/route) — forwarding (#4288)`);
}
break;
}
if (decisionTokens < textTarget) break;
// #847: drop sub-minimum ranges at list level too — every chunk of a
// sub-min range fails the apply-side gate, so walking them only burns
Expand Down
4 changes: 4 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,9 @@ export async function preflightCompressIfNeeded(
anonymous: boolean,
log: (level: string, msg: string) => void,
instanceId: string,
/** #4288 rework: true only on the #1195/#3787 refold lanes (the upstream
* PROVED the overflow); see PreflightDeps.upstreamProvedOverflow. */
upstreamProvedOverflow?: boolean,
): Promise<Prepared | PreflightFailFast> {
const session = prepared.session;
// #3450: when an upstream-stated overflow proved this provider bills the
Expand Down Expand Up @@ -3733,6 +3736,7 @@ export async function preflightCompressIfNeeded(
upstreamOrigin: currentOrigin,
forceStreamSummary,
streamSummaryOff,
...(upstreamProvedOverflow === true ? { upstreamProvedOverflow: true } : {}),
},
prepared.originalMessages,
);
Expand Down
Loading
Loading