Repository navigation
[PR] feat: async compression for Pi and Claude bridge - #3001
RodrigoHamuy wants to merge 3 commits into
Conversation
[bot] 🏷 Full review of #3001 complete (draft kept as-is — no merge/approve; human tier per §7.4). What I did
diff --git a/src/async-compress.ts b/src/async-compress.ts
--- a/src/async-compress.ts
+++ b/src/async-compress.ts
@@ -25,7 +25,7 @@ import type { WireProtocol } from "./util.js";
export const ASYNC_COMPRESS_CALL_ID_PREFIX = "async_compress_";
-export interface AsyncCompressPolicy {
+interface AsyncCompressPolicy {
captureTimeoutMs: number;
@@ -73,7 +73,7 @@ interface Note {
-export interface OutboundSend {
+interface OutboundSend {
url: string;
@@ -104,6 +104,12 @@ export function asyncCompressEnabled(): boolean {
return policy !== undefined;
}
+/** Request-level eligibility shared by the apply and note hooks: plain model POSTs only —
+ * not count-tokens, not codex compact-forge, and never side-lane traffic (side requests do not own compression). */
+export function asyncRequestGate(countTokens: boolean, responsesCompact: boolean, prepared: { sidePassthrough?: boolean } | null | undefined): boolean {
+ return policy !== undefined && !countTokens && !responsesCompact && prepared !== null && prepared !== undefined && prepared.sidePassthrough !== true;
+}
+
export function disposeAsyncCompress(reason = "disposed"): void {
@@ -371,12 +377,12 @@ function activeBlockKeys(session: Session): string[] {
-export interface FoldHint {
+interface FoldHint {
startRef: string;
endRef: string;
}
-export type FoldSuggestion = { hint: FoldHint; reason?: undefined } | { hint?: undefined; reason: "no-offer" | "stale-offer" | "none-offered" };
+type FoldSuggestion = { hint: FoldHint; reason?: undefined } | { hint?: undefined; reason: "no-offer" | "stale-offer" | "none-offered" };
@@ -495,7 +501,7 @@ function modelOf(protocol: WireProtocol, body: Record<string, unknown>, url: str
-export interface ForkCall { name: string; arguments: string }
+interface ForkCall { name: string; arguments: string }
@@ -608,10 +614,10 @@ export function mediaTypeClass(header: string | null): string {
-export type ReplyFraming = "sse" | "json" | "html" | "empty" | "other";
+type ReplyFraming = "sse" | "json" | "html" | "empty" | "other";
/** Classifies a decoded reply by its first non-blank characters (a BOM is already removed by TextDecoder). */
-export function replyFraming(text: string): ReplyFraming {
+function replyFraming(text: string): ReplyFraming {
@@ -730,7 +736,7 @@ function staleReason(capture: Capture, session: Session, messages: readonly Core
-export interface AsyncApplyContext {
+interface AsyncApplyContext {
core: CompressionCore;
diff --git a/src/server/handle.ts b/src/server/handle.ts
--- a/src/server/handle.ts
+++ b/src/server/handle.ts
@@ -64,7 +64,7 @@
-import { applyReadyAsyncCompress, asyncCompressEnabled, attachAsyncNote } from "../async-compress.js";
+import { applyReadyAsyncCompress, attachAsyncNote, asyncRequestGate } from "../async-compress.js";
@@ -2024,7 +2024,7 @@
prepared = await runPrepare();
- if (asyncCompressEnabled() && !countTokens && !responsesCompact && prepared && !prepared.sidePassthrough && applyReadyAsyncCompress(session, {
+ if (prepared && asyncRequestGate(countTokens, responsesCompact, prepared) && applyReadyAsyncCompress(session, {
core, config: reqConfig, protocol: prepared.protocol, upstreamUrl: forwardUpstreamUrl(req, opts, route), model: requestModel,
@@ -2141,7 +2141,7 @@
- if (asyncCompressEnabled() && !countTokens && !responsesCompact && !prepared!.sidePassthrough) prepared!.body = attachAsyncNote(prepared!, session, prepared!.protocol, prepared!.body);
+ if (asyncRequestGate(countTokens, responsesCompact, prepared)) prepared!.body = attachAsyncNote(prepared!, session, prepared!.protocol, prepared!.body);
logRequestCost(log, session.id, inboundMsgs, inboundBytes, reqT0, prepared!.body);Why each fix is right:
Structured eight questions (结构化八问)
Clear recommendations on the three owner questions (not a menu):
Remaining gaps before merge (your open checklist is honest; confirmed still needed):
Verdict: code quality is high, the feature is provably inert until enabled, and I found no regressions. Keep draft status: resolve the three owner decisions + the checklist above, then undraft for human review (wire-shape feat ⇒ auto-merge N/A; merge stays human-only regardless). |
|
@ranxianglei you mind if I add a new setting |
[bot] 🏷 Adding a config field is owner territory (AGENTS.md §3 Configuration Surface Discipline — a new key needs explicit owner sign-off in-thread BEFORE implementation), so I can't give that yes/no for you — @ranxianglei has to rule on As reviewer though: the shape you propose matches exactly what I recommended in the review (a key inside the existing
@ranxianglei — over to you: approve or decline |
…fault off)
An empty compress({"content": []}) queues a background job. The next
outbound request is captured and replayed once as a background request
(existing message content and tool declarations preserved, plus a
directive asking for exactly one compress call). The validated result is
applied through the existing atomic apply path at a later request; stale
or invalid results are dropped with a one-time note.
Default off: reachable only through the internal configureAsyncCompress
hook. No config key, env var or CLI flag. Enablement, Claude-bridge
routing, background-request accounting and credential policy await
owner decisions in the tracking issue.
107007c to
0b9f84f
Compare
|
8问 |
[bot] 🏷 当前状态的结构化八问(代码 @
待办三项:
判定:代码质量高、可证明默认惰性、未发现回归;维持 draft,上述清完再出 draft 走人审(wire-shape feat ⇒ auto-merge 不适用,合并始终人工)。 |
Resolve the src/server/relay.ts conflict with ranxianglei#3148's upstream circuit breaker: the breaker check runs before the async capture hook, so an open circuit fails fast without capturing a queued background job; a transport failure settles the async job, then throws master's failureDetail. Add a regression test: with the circuit open the queued job is neither captured nor left running, and it captures once the circuit closes.
🚨 Blocked pending approval: add
compress.async(default: off) using the existing global/provider/model settings. For now, tests enable it through an internal, default-off switch (configureAsyncCompress).Closes #3000.
✨ What this does
Safety: summaries are checked before applying. If a summary is no longer valid or a request can't be copied safely, background compression is skipped and the agent gets a short note.
⚙️ Config surface
No public settings added yet; the proposed
compress.asynckey is the approval request above.Notes: automatic Claude-bridge setup is still unfinished. Usage stats don't include these background requests, as they already don't for external-summary requests. A pending background summary is lost if bili restarts; the original conversation is preserved.