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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

### Fixes

- **Bump acp-kernel 0.0.74 → 0.0.77; `acp_cache` held off every wire surface until adoption (#800)**: the pin jumps three kernel releases — 0.0.75 (cache-reconciliation core: `acp_cache` tool + `buildCacheReport`; recommend tail-below-gate fix), 0.0.76 (Google/Gemini wire codec; recommend range integrity), 0.0.77 (nudge ranges ordered/merged by position instead of ref number — fixes #887). Kernel ≥0.0.75 ships a fifth proxy tool, `acp_cache`, but this proxy has no execution path for it: an intercepted call fell through `executeProxyTool` into the unknown-tool branch, which reports SUCCESS with `[Unknown proxy tool: acp_cache]` — a model calling it would get a plausible-looking result that did nothing. Until adoption lands (feature #800, owner decision pending), `src/compress-tool.ts` derives `PROXY_TOOL_NAMES` and the four `BILI_ACP_TOOLS_*` arrays from the kernel constants minus `UNADOPTED_KERNEL_TOOLS` (`{acp_cache}`) — the single choke point every serving surface consumes (Responses/OpenAI/Anthropic tool arrays, plugin manifest + allowed list, absorb gate, Responses-adapter classification), so the tool stays off the wire everywhere without touching call sites. `MUTATING_PROXY_TOOLS`/`READONLY_PROXY_TOOLS` stay raw re-exports (classification sets only; `acp_cache` is correctly classified readonly and no serving surface reads them). The #841 parity test (`tests/search-context-cross-session.test.ts`) extends the "no other tool may change" contract against the FILTERED kernel side only, so a future BILI-side leak of an unadopted tool still fails.
- **A render tag wrapped around the model's whole turn no longer reaches the client as orphan markup (PR #872)**: a model imitating the render tag can write its entire turn — tool call included — where the opening's attributes are still open (recorded shape: `<acp tokens="1" text="text` immediately followed by the turn's own markup). The span escapes every tag pattern at once: an attribute class stops at `<`, and the value opened with `"` is never closed, so no close tag is ever written. The filter dropped the opening and released the payload, and the agent received a completed turn of orphan `parameter`/`invoke`/`calls` closers with no tool call in it — it stalled until nudged by hand. The stripper now recognises the wrapped shape by form (the attribute list runs into a `<`, or carries an odd number of quotes) and swallows the span whole, to a loose close tag or to the end of the turn, in `stripAcpTags` and in the streaming filter alike; the turn then reaches the client empty, which the degenerate-turn retry (#870, PR #871) re-asks for. The #644 rule is unchanged: an over-long tail after a *plain* opening is still released as content.

- **Preflight fold budget raised 8 → 16: a payload far over the window can now be brought under it (#868, PR #869)**: one range folds per round and both per-invocation budgets were 8, so the loop gave up before finishing even when every fold succeeded. A live Gemini session (1.39M-token payload against a 1,048,576 window) folded 8 ranges, saved ~329k tokens, landed ~8k short of the window, and then fail-fast 502'd with `the compress budget was exhausted after 8 rounds` — a message that also read misleadingly, because it quoted the ORIGINAL context rather than the folded size. `MAX_PREFLIGHT_ROUNDS` and `MAX_SUMMARY_CALLS_PER_PREFLIGHT` are now 16 (`src/preflight.ts`, both exported so budget tests derive from them); the fail-fast 502 now reports the post-fold size ("~N tokens (down from ~M before preflight)") and the remaining compressible-range count (`result.rangesRemaining`) instead of only the original token count; the fold-depth coverage bound (best case ~9.6x-window overshoot, lower in practice) is documented beside the constants. `tests/preflight-round-budget.test.ts` pins the behaviour on the openai wire: an ~83k-token fixture against a 30k window is refused at 8 rounds and forwarded at 16, using more than 8 summary calls; a second case scales the same history past the 16-round bound and pins the honest 502 (post-fold size, remaining-range count, exactly 16 summary calls); the #574 budget-cap case in `tests/preflight-multi-range.test.ts` no longer re-pins the literal 8.
Expand Down
8 changes: 4 additions & 4 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"@types/node": "^22.0.0",
"@types/node-forge": "^1.3.14",
"acp-kernel": "0.0.74",
"acp-kernel": "0.0.77",
"fzstd": "0.1.1",
"jsonc-parser": "^3.3.1",
"node-forge": "^1.4.0",
Expand Down
24 changes: 17 additions & 7 deletions src/compress-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* The schemas, prompt builders, text tags and parseCompressInput moved to
* acp-kernel `src/compress-tools.ts` verbatim; this module keeps the proxy's
* historical import paths and names stable:
* - PROXY_TOOL_NAMES / MUTATING_PROXY_TOOLS / READONLY_PROXY_TOOLS alias the
* kernel's ACP_* names ("proxy" is a misnomer once shared);
* - MUTATING_PROXY_TOOLS / READONLY_PROXY_TOOLS alias the kernel's ACP_* names
* ("proxy" is a misnomer once shared); PROXY_TOOL_NAMES is a filtered copy
* of kernel ACP_TOOL_NAMES — see UNADOPTED_KERNEL_TOOLS below;
* - parseCompressInput wires the kernel's onWarn hook into the proxy logger.
* (The #603 single-quote salvage lives in the kernel ladder since 0.0.59;
* this wrapper only surfaces its diagnostics.)
Expand All @@ -21,6 +22,8 @@ import {
ACP_TOOLS_OPENAI,
ACP_TOOLS_RESPONSES,
ACP_READONLY_TOOLS_RESPONSES,
ACP_CACHE_TOOL_NAME,
ACP_TOOL_NAMES,
} from "acp-kernel";
import { log as loggerLog } from "./logger.js";
import { maxShrinkPerCompress } from "./fetch-util.js";
Expand Down Expand Up @@ -63,7 +66,14 @@ export {
buildAbsorbSystemPrompt,
} from "acp-kernel";
export type { ParsedRange, AbsorbConfig } from "acp-kernel";
export { ACP_TOOL_NAMES as PROXY_TOOL_NAMES, ACP_MUTATING_TOOLS as MUTATING_PROXY_TOOLS, ACP_READONLY_TOOLS as READONLY_PROXY_TOOLS } from "acp-kernel";
// #800: acp-kernel >=0.0.75 ships acp_cache (prompt-cache reconciliation report)
// but this proxy has no execution path for it yet — executeProxyTool would answer
// a call with "[Unknown proxy tool: acp_cache]" reported as success. Keep it off
// every wire surface until adoption lands (kernel constants are shared and never
// mutated; the filtered copies below are the single choke point all injection consumes).
export const UNADOPTED_KERNEL_TOOLS: ReadonlySet<string> = new Set([ACP_CACHE_TOOL_NAME]);
export const PROXY_TOOL_NAMES: ReadonlySet<string> = new Set([...ACP_TOOL_NAMES].filter((n) => !UNADOPTED_KERNEL_TOOLS.has(n)));
export { ACP_MUTATING_TOOLS as MUTATING_PROXY_TOOLS, ACP_READONLY_TOOLS as READONLY_PROXY_TOOLS } from "acp-kernel";

// #841: host-side conversation_id extension of search_context. Kernel constants
// are shared and never mutated; ALL wire-mode injection points must use these
Expand Down Expand Up @@ -102,10 +112,10 @@ export const BILI_SEARCH_CONTEXT_TOOL_RESPONSES = {
parameters: withConversationId(SEARCH_CONTEXT_TOOL_RESPONSES.parameters),
};

export const BILI_ACP_TOOLS_ANTHROPIC = ACP_TOOLS_ANTHROPIC.map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL : t));
export const BILI_ACP_TOOLS_OPENAI = ACP_TOOLS_OPENAI.map((t) => (t.function.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_OPENAI : t));
export const BILI_ACP_TOOLS_RESPONSES = ACP_TOOLS_RESPONSES.map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_RESPONSES : t));
export const BILI_ACP_READONLY_TOOLS_RESPONSES = ACP_READONLY_TOOLS_RESPONSES.map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_RESPONSES : t));
export const BILI_ACP_TOOLS_ANTHROPIC = ACP_TOOLS_ANTHROPIC.filter((t) => !UNADOPTED_KERNEL_TOOLS.has(t.name)).map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL : t));
export const BILI_ACP_TOOLS_OPENAI = ACP_TOOLS_OPENAI.filter((t) => !UNADOPTED_KERNEL_TOOLS.has(t.function.name)).map((t) => (t.function.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_OPENAI : t));
export const BILI_ACP_TOOLS_RESPONSES = ACP_TOOLS_RESPONSES.filter((t) => !UNADOPTED_KERNEL_TOOLS.has(t.name)).map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_RESPONSES : t));
export const BILI_ACP_READONLY_TOOLS_RESPONSES = ACP_READONLY_TOOLS_RESPONSES.filter((t) => !UNADOPTED_KERNEL_TOOLS.has(t.name)).map((t) => (t.name === SEARCH_CONTEXT_TOOL_NAME ? BILI_SEARCH_CONTEXT_TOOL_RESPONSES : t));

// The kernel ships no Responses-format absorb const (the four ACP tools have
// *_RESPONSES variants; absorb is host-registered opt-in). Synthesize it in
Expand Down
8 changes: 4 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ServerResponse } from "node:http";
import fs from "node:fs";
import path from "node:path";
import { acquireInFlight, effectiveConfig, findSessionByCanonicalId, listSessions, markCompactionBoundary, markDirty, peekSession, releaseInFlight, withSessionLock, type Session } from "./session.js";
import { ABSORB_TOOL, ABSORB_TOOL_NAME, ABSORB_TOOL_OPENAI, ABSORB_TOOL_RESPONSES, ACP_TOOLS_ANTHROPIC, ACP_TOOLS_OPENAI, ACP_TOOLS_RESPONSES, PROXY_TOOL_NAMES, SEARCH_CONTEXT_CONVERSATION_ID_PARAM, SEARCH_CONTEXT_TOOL_NAME } from "./compress-tool.js";
import { ABSORB_TOOL, ABSORB_TOOL_NAME, ABSORB_TOOL_OPENAI, ABSORB_TOOL_RESPONSES, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES, PROXY_TOOL_NAMES, SEARCH_CONTEXT_CONVERSATION_ID_PARAM, SEARCH_CONTEXT_TOOL_NAME } from "./compress-tool.js";
import { effectiveAbsorbConfig, isProxyToolFor } from "./absorb.js";
import { executeProxyTool } from "./loop/core.js";
import { normalizeSseLineEndings } from "./sse-util.js";
Expand Down Expand Up @@ -405,9 +405,9 @@ export function handlePluginManifest(res: import("node:http").ServerResponse): v
// manifest has no request context to know which route will win.
toolNames: [...PROXY_TOOL_NAMES, ABSORB_TOOL_NAME],
tools: {
anthropic: withSearchContextConversationDescription([...ACP_TOOLS_ANTHROPIC, ABSORB_TOOL].map(withConversationIdParam)),
openai: withSearchContextConversationDescription([...ACP_TOOLS_OPENAI, ABSORB_TOOL_OPENAI].map(withConversationIdParam)),
responses: withSearchContextConversationDescription([...ACP_TOOLS_RESPONSES, ABSORB_TOOL_RESPONSES].map(withConversationIdParam)),
anthropic: withSearchContextConversationDescription([...BILI_ACP_TOOLS_ANTHROPIC, ABSORB_TOOL].map(withConversationIdParam)),
openai: withSearchContextConversationDescription([...BILI_ACP_TOOLS_OPENAI, ABSORB_TOOL_OPENAI].map(withConversationIdParam)),
responses: withSearchContextConversationDescription([...BILI_ACP_TOOLS_RESPONSES, ABSORB_TOOL_RESPONSES].map(withConversationIdParam)),
},
headers: { agent: PLUGIN_AGENT_HEADER, conversation: PLUGIN_CONVERSATION_HEADER, contextWindow: PLUGIN_CONTEXT_WINDOW_HEADER },
toolEndpoint: "/__bili/plugin/tool",
Expand Down
12 changes: 10 additions & 2 deletions tests/search-context-cross-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
import { createHash } from "node:crypto";
import { ACP_READONLY_TOOLS_RESPONSES, ACP_TOOLS_ANTHROPIC, ACP_TOOLS_OPENAI, ACP_TOOLS_RESPONSES, SEARCH_CONTEXT_TOOL_NAME, createCore, createInitialState, defaultConfig } from "acp-kernel";
import { anthropicToCore, type AnthropicRequestBody } from "acp-kernel/wire";
import { BILI_ACP_READONLY_TOOLS_RESPONSES, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES } from "../src/compress-tool.ts";
import { BILI_ACP_READONLY_TOOLS_RESPONSES, BILI_ACP_TOOLS_ANTHROPIC, BILI_ACP_TOOLS_OPENAI, BILI_ACP_TOOLS_RESPONSES, UNADOPTED_KERNEL_TOOLS } from "../src/compress-tool.ts";
import { SessionStore, _setStoreForTest } from "../src/persist.ts";
import { _resetSessionsForTest, getSession, type Session } from "../src/session.ts";
import { executeSearchContext, executeSearchContextTarget } from "../src/decompress-shared.ts";
Expand Down Expand Up @@ -78,8 +78,16 @@ test("#841 schema: BILI arrays add optional conversation_id to search_context on
const kernelProps = paramsOf(kernelEntry!).properties as Record<string, unknown>;
assert.equal(kernelProps.conversation_id, undefined, "kernel constant must not be mutated");

// The kernel may ship tools the host has not adopted yet (acp_cache, #800);
// those are intentionally absent from the BILI arrays, so drop them from the
// kernel side only — a BILI-side leak of an unadopted tool must still fail.
const adoptedInKernel = (t: unknown): boolean => {
const e = t as FlatTool;
const name = shape === "openai" ? e.function?.name : e.name;
return !UNADOPTED_KERNEL_TOOLS.has(name as string);
};
const biliRest = bili.filter((t) => t !== entry);
const kernelRest = kernel.filter((t) => t !== kernelEntry);
const kernelRest = kernel.filter((t) => t !== kernelEntry && adoptedInKernel(t));
assert.deepEqual(biliRest, kernelRest, "no other tool may change");
}
const ro = searchEntry(BILI_ACP_READONLY_TOOLS_RESPONSES, "flat")!;
Expand Down
Loading