refactor(tools): remove artificial analysis ceilings

This commit is contained in:
morluto
2026-09-29 16:29:23 +08:00
parent 36aeec9586
commit 2f08c7c932
202 changed files with 2314 additions and 3072 deletions
-1
View File
@@ -255,7 +255,6 @@ const activityDetails = (activity: HopperRequestActivity): JsonValue => ({
request_id: activity.requestId,
operation: activity.operation,
elapsed_ms: activity.elapsedMs,
timeout_ms: activity.timeoutMs,
caller_state: activity.callerState,
queued_requests: activity.queuedRequests,
});
+1 -8
View File
@@ -57,7 +57,6 @@ const SESSION_ROOT = process.platform === "darwin" ? "/tmp" : tmpdir();
export interface HopperClientOptions {
readonly launcher: BridgeLauncher;
readonly runId?: string;
readonly requestTimeoutMs?: number;
readonly startupTimeoutMs?: number;
readonly onDiagnostic?: (event: HopperDiagnostic) => void;
readonly logger?: Logger;
@@ -78,9 +77,7 @@ type HopperClientCloseOptions = {
* Hopper launcher does not confer ownership of the GUI application.
*/
export class HopperClient {
readonly #options: Required<
Pick<HopperClientOptions, "requestTimeoutMs" | "startupTimeoutMs">
> &
readonly #options: Required<Pick<HopperClientOptions, "startupTimeoutMs">> &
HopperClientOptions;
readonly #requests: HopperRequestQueue;
readonly #responses: HopperResponseStream;
@@ -112,7 +109,6 @@ export class HopperClient {
this.#logger = options.logger ?? silentLogger;
this.#options = {
...options,
requestTimeoutMs: options.requestTimeoutMs ?? 30_000,
startupTimeoutMs: options.startupTimeoutMs ?? 120_000,
};
this.#requests = new HopperRequestQueue(
@@ -284,7 +280,6 @@ export class HopperClient {
arguments_: Readonly<Record<string, JsonValue>> = {},
options: {
readonly signal?: AbortSignal;
readonly timeoutMs?: number;
readonly progress?: ProgressReporter;
} = {},
): Promise<Result<JsonValue, AnalysisError>> {
@@ -432,9 +427,7 @@ export class HopperClient {
if (options.signal?.aborted === true)
return err(new HopperCancelledError());
const startedAt = performance.now();
const timeoutMs = options.timeoutMs ?? this.#options.requestTimeoutMs;
const result = await this.#requests.run(id, method, params, {
timeoutMs,
...(options.signal === undefined ? {} : { signal: options.signal }),
...(options.progress !== undefined ? { progress: options.progress } : {}),
});
-1
View File
@@ -246,7 +246,6 @@ export class HopperProvider implements AnalysisProviderCandidate {
requestId: activity.requestId,
operation: activity.operation,
elapsedMs: activity.elapsedMs,
timeoutMs: activity.timeoutMs,
callerState: activity.callerState,
},
queuedRequests: activity?.queuedRequests ?? 0,
+5 -60
View File
@@ -1,5 +1,3 @@
import { performance } from "node:perf_hooks";
import type {
ProgressReporter,
ProgressUpdate,
@@ -11,7 +9,6 @@ import {
HopperProcessError,
HopperProtocolError,
HopperRemoteError,
HopperTimeoutError,
} from "../domain/errors.js";
import type { JsonValue } from "../domain/jsonValue.js";
import { err, type Result } from "../domain/result.js";
@@ -20,7 +17,6 @@ export type HopperRequestResult = Result<JsonValue, HopperError>;
export interface HopperRequestQueueOptions {
readonly signal?: AbortSignal;
readonly timeoutMs: number;
readonly progress?: ProgressReporter;
}
@@ -28,8 +24,7 @@ export interface HopperRequestActivity {
readonly requestId: number;
readonly operation: string;
readonly elapsedMs: number;
readonly timeoutMs: number;
readonly callerState: "waiting" | "timed_out" | "cancelled";
readonly callerState: "waiting" | "cancelled";
readonly queuedRequests: number;
}
@@ -47,13 +42,10 @@ interface QueuedRequest {
readonly method: string;
readonly params: JsonValue;
readonly signal: AbortSignal | undefined;
readonly timeoutMs: number;
readonly deadline: number;
readonly progress: ProgressReporter | undefined;
readonly resolve: (result: HopperRequestResult) => void;
readonly timer: NodeJS.Timeout;
readonly onAbort: (() => void) | undefined;
callerState: "waiting" | "timed_out" | "cancelled";
callerState: "waiting" | "cancelled";
callerSettled: boolean;
startedAt: number | undefined;
heartbeat: NodeJS.Timeout | undefined;
@@ -66,7 +58,7 @@ export class HopperRequestQueue {
constructor(private readonly send: RequestSender) {}
/** Queue one request, counting queue wait against its caller deadline. */
/** Queue one request until Hopper replies or the caller cancels it. */
run(
id: number,
method: string,
@@ -75,25 +67,17 @@ export class HopperRequestQueue {
): Promise<HopperRequestResult> {
if (options.signal?.aborted === true)
return Promise.resolve(err(new HopperCancelledError()));
if (options.timeoutMs <= 0)
return Promise.resolve(
err(new HopperTimeoutError(options.timeoutMs, method, id)),
);
return new Promise((resolve) => {
let entry: QueuedRequest;
const onAbort =
options.signal === undefined ? undefined : () => this.#cancel(entry);
const timer = setTimeout(() => this.#timeout(entry), options.timeoutMs);
entry = {
id,
method,
params,
signal: options.signal,
timeoutMs: options.timeoutMs,
deadline: performance.now() + options.timeoutMs,
progress: options.progress,
resolve,
timer,
onAbort,
callerState: "waiting",
callerSettled: false,
@@ -190,7 +174,6 @@ export class HopperRequestQueue {
requestId: active.id,
operation: active.method,
elapsedMs: Math.max(0, Math.round(performance.now() - active.startedAt)),
timeoutMs: active.timeoutMs,
callerState: active.callerState,
queuedRequests: this.#queue.length,
};
@@ -214,17 +197,8 @@ export class HopperRequestQueue {
if (this.#active !== undefined) return;
const entry = this.#queue.shift();
if (entry === undefined) return;
const remaining = entry.deadline - performance.now();
if (entry.signal?.aborted === true || remaining <= 0) {
this.#settleCaller(
entry,
entry.signal?.aborted === true
? err(new HopperCancelledError())
: err(
new HopperTimeoutError(entry.timeoutMs, entry.method, entry.id),
),
entry.signal?.aborted === true ? "cancelled" : "timed_out",
);
if (entry.signal?.aborted === true) {
this.#settleCaller(entry, err(new HopperCancelledError()), "cancelled");
this.#drain();
return;
}
@@ -252,33 +226,6 @@ export class HopperRequestQueue {
}
}
#timeout(entry: QueuedRequest): void {
if (entry.callerSettled) return;
if (this.#active === entry) {
this.#settleCaller(
entry,
err(
new HopperTimeoutError(
entry.timeoutMs,
entry.method,
entry.id,
"busy",
),
),
"timed_out",
);
return;
}
const index = this.#queue.indexOf(entry);
if (index < 0) return;
this.#queue.splice(index, 1);
this.#settleCaller(
entry,
err(new HopperTimeoutError(entry.timeoutMs, entry.method, entry.id)),
"timed_out",
);
}
#cancel(entry: QueuedRequest): void {
if (entry.callerSettled) return;
if (this.#active === entry) {
@@ -303,7 +250,6 @@ export class HopperRequestQueue {
clearInterval(entry.heartbeat);
entry.heartbeat = undefined;
}
clearTimeout(entry.timer);
if (entry.signal !== undefined && entry.onAbort !== undefined)
entry.signal.removeEventListener("abort", entry.onAbort);
entry.resolve(result);
@@ -312,7 +258,6 @@ export class HopperRequestQueue {
#releaseWire(entry: QueuedRequest): void {
if (entry.heartbeat !== undefined) clearInterval(entry.heartbeat);
entry.heartbeat = undefined;
clearTimeout(entry.timer);
if (entry.signal !== undefined && entry.onAbort !== undefined)
entry.signal.removeEventListener("abort", entry.onAbort);
}
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { HopperResponseStream } from "./HopperResponseStream.js";
describe("Hopper response stream", () => {
it("accepts complete responses larger than the former 10 MiB ceiling", () => {
const messages: unknown[] = [];
const failures: string[] = [];
const stream = new HopperResponseStream({
accept: (message) => {
messages.push(message);
return true;
},
hasQueued: () => false,
nextRequestId: () => 2,
abort: (message) => failures.push(message),
});
const line = `{"id":1,"result":"${"x".repeat(10 * 1024 * 1024 + 1)}"}`;
stream.push(`${line}\n`);
expect(failures).toEqual([]);
expect(messages).toHaveLength(1);
});
});
+1 -10
View File
@@ -3,8 +3,6 @@ import {
type HopperBridgeMessage,
} from "./protocol.js";
const MAX_LINE_BYTES = 10 * 1024 * 1024;
export interface HopperResponseStreamOptions {
readonly accept: (message: HopperBridgeMessage) => boolean;
readonly hasQueued: (id: number) => boolean;
@@ -12,7 +10,7 @@ export interface HopperResponseStreamOptions {
readonly abort: (message: string, cause?: Error) => void;
}
/** Incrementally validates bounded Hopper NDJSON response frames. */
/** Incrementally validates Hopper NDJSON response frames. */
export class HopperResponseStream {
#buffer = "";
@@ -24,16 +22,9 @@ export class HopperResponseStream {
while (newline >= 0) {
const line = this.#buffer.slice(0, newline).trim();
this.#buffer = this.#buffer.slice(newline + 1);
if (Buffer.byteLength(line) > MAX_LINE_BYTES) {
this.options.abort("Hopper response exceeded the maximum line size");
return;
}
if (line.length > 0 && !this.#acceptLine(line)) return;
newline = this.#buffer.indexOf("\n");
}
if (Buffer.byteLength(this.#buffer) > MAX_LINE_BYTES) {
this.options.abort("Hopper response exceeded the maximum line size");
}
}
reset(): void {