Skip to content

Commit 17faddd

Browse files
committed
fix(bench): close the eight gaps the benchmark self-audit surfaced
Scoring OpenCodex against its own sixteen benchmark categories exposed holes the phase reviews had each individually accepted: bodies were admitted after allocation, management routes parsed unbounded JSON, preflight heartbeats accumulated without cap, spill publication never fsynced the directory entry, the provider and crash rings lacked boundary tests, the periodic sweeper missed the continuation and replay stores, a stale Grok flight could block applies until it settled, the pinned headroom above the eviction target had no proven ceiling, and a timed-out ACL hardening still published the secret. All eight now have finite contracts with boundary tests, including a 512 MiB worst-case pinned ceiling computed from the per-store caps themselves.
1 parent ff09467 commit 17faddd

41 files changed

Lines changed: 1510 additions & 452 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/adapters/anthropic-image-normalize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type ProcessResult =
9999
* not entry count. Entries are immutable snapshots — demotions write NEW tier-suffixed
100100
* keys, never mutate stored values.
101101
*/
102-
const CACHE_BYTE_CAP = 64 * MiB;
102+
export const IMAGE_NORMALIZE_CACHE_MAX_BYTES = 64 * MiB;
103103
const CACHE_MAX_ENTRIES = 4_096;
104104
const CACHE_MAX_ENTRY_BYTES = 20 * MiB;
105105
// "pass" = validated pass-through; "miss" = this position's ladder cannot meet its hard
@@ -117,7 +117,7 @@ interface NormalizeCacheLimits {
117117
maxEntryBytes: number;
118118
}
119119
const DEFAULT_CACHE_LIMITS: NormalizeCacheLimits = {
120-
maxBytes: CACHE_BYTE_CAP,
120+
maxBytes: IMAGE_NORMALIZE_CACHE_MAX_BYTES,
121121
maxEntries: CACHE_MAX_ENTRIES,
122122
maxEntryBytes: CACHE_MAX_ENTRY_BYTES,
123123
};

src/adapters/cursor/framing.ts

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ interface CopyReservation {
3131
release(): void;
3232
}
3333

34+
interface InspectedConnectFrame {
35+
flags: number;
36+
length: number;
37+
payloadStart: number;
38+
readBytes: number;
39+
}
40+
3441
export class ConnectFrameError extends Error {
3542
constructor(
3643
public readonly code: ConnectFrameErrorCode,
@@ -77,36 +84,26 @@ export function tryDecodeConnectFrame(
7784
reservePayloadCopy?: (bytes: number) => CopyReservation | undefined,
7885
): DecodedConnectFrame | null {
7986
assertOffset(input, offset);
80-
if (input.length - offset < CONNECT_FRAME_HEADER_BYTES) return null;
81-
82-
const view = new DataView(input.buffer, input.byteOffset + offset, input.byteLength - offset);
83-
const flags = view.getUint8(0);
84-
const length = view.getUint32(1, false);
85-
if (length > maxPayloadBytes) {
86-
throw new ConnectFrameError("payload_too_large", `Connect frame payload too large: ${length}`);
87-
}
88-
const readBytes = CONNECT_FRAME_HEADER_BYTES + length;
89-
if (input.length - offset < readBytes) return null;
90-
91-
const payloadStart = offset + CONNECT_FRAME_HEADER_BYTES;
92-
const payloadEnd = payloadStart + length;
93-
const reservation = reservePayloadCopy?.(length);
87+
const inspected = inspectConnectFrame(input, offset, maxPayloadBytes);
88+
if (!inspected) return null;
89+
const payloadEnd = inspected.payloadStart + inspected.length;
90+
const reservation = reservePayloadCopy?.(inspected.length);
9491
let payload: Uint8Array;
9592
try {
96-
payload = input.slice(payloadStart, payloadEnd);
93+
payload = input.slice(inspected.payloadStart, payloadEnd);
9794
reservation?.commitRetained();
9895
} catch (error) {
9996
reservation?.release();
10097
throw error;
10198
}
10299
return {
103100
frame: {
104-
flags,
101+
flags: inspected.flags,
105102
payload,
106-
compressed: isConnectFrameCompressed(flags),
107-
endStream: isConnectFrameEndStream(flags),
103+
compressed: isConnectFrameCompressed(inspected.flags),
104+
endStream: isConnectFrameEndStream(inspected.flags),
108105
},
109-
readBytes,
106+
readBytes: inspected.readBytes,
110107
};
111108
}
112109

@@ -135,28 +132,57 @@ export function decodeAvailableConnectFrames(
135132
availableFrameSlots = Number.POSITIVE_INFINITY,
136133
reservePayloadCopy?: (bytes: number) => CopyReservation | undefined,
137134
): DecodedConnectFrames {
138-
const frames: ConnectFrame[] = [];
135+
const planned: Array<InspectedConnectFrame & { reservation?: CopyReservation }> = [];
139136
let offset = 0;
140-
while (offset < input.length && frames.length < availableFrameSlots) {
141-
const decoded = tryDecodeConnectFrame(input, offset, maxPayloadBytes, reservePayloadCopy);
142-
if (!decoded) break;
143-
frames.push(decoded.frame);
144-
offset += decoded.readBytes;
145-
}
146-
const remainderBytes = offset === input.length ? 0 : bufferedPayloadBytes(input, offset);
147-
const remainderReservation = reservePayloadCopy?.(remainderBytes);
148-
let remainder: Uint8Array;
137+
let remainderReservation: CopyReservation | undefined;
149138
try {
150-
remainder = offset === input.length ? new Uint8Array() : input.slice(offset);
139+
while (offset < input.length && planned.length < availableFrameSlots) {
140+
const inspected = inspectConnectFrame(input, offset, maxPayloadBytes);
141+
if (!inspected) break;
142+
const reservation = reservePayloadCopy?.(inspected.length);
143+
planned.push({ ...inspected, reservation });
144+
offset += inspected.readBytes;
145+
}
146+
const remainderBytes = offset === input.length ? 0 : bufferedPayloadBytes(input, offset);
147+
remainderReservation = reservePayloadCopy?.(remainderBytes);
148+
149+
// Keep every reservation transient until every batch allocation succeeds. A later admission
150+
// failure can then roll the entire batch back without needing ownership of unreturned frames.
151+
const frames = planned.map(({ flags, length, payloadStart }) => {
152+
const payload = input.slice(payloadStart, payloadStart + length);
153+
return {
154+
flags,
155+
payload,
156+
compressed: isConnectFrameCompressed(flags),
157+
endStream: isConnectFrameEndStream(flags),
158+
};
159+
});
160+
const remainder = offset === input.length ? new Uint8Array() : input.slice(offset);
161+
for (const entry of planned) entry.reservation?.commitRetained();
151162
remainderReservation?.commitRetained();
163+
return { frames, remainder };
152164
} catch (error) {
165+
for (const entry of planned) entry.reservation?.release();
153166
remainderReservation?.release();
154167
throw error;
155168
}
156-
return {
157-
frames,
158-
remainder,
159-
};
169+
}
170+
171+
function inspectConnectFrame(
172+
input: Uint8Array,
173+
offset: number,
174+
maxPayloadBytes: number,
175+
): InspectedConnectFrame | null {
176+
if (input.length - offset < CONNECT_FRAME_HEADER_BYTES) return null;
177+
const view = new DataView(input.buffer, input.byteOffset + offset, input.byteLength - offset);
178+
const flags = view.getUint8(0);
179+
const length = view.getUint32(1, false);
180+
if (length > maxPayloadBytes) {
181+
throw new ConnectFrameError("payload_too_large", `Connect frame payload too large: ${length}`);
182+
}
183+
const readBytes = CONNECT_FRAME_HEADER_BYTES + length;
184+
if (input.length - offset < readBytes) return null;
185+
return { flags, length, payloadStart: offset + CONNECT_FRAME_HEADER_BYTES, readBytes };
160186
}
161187

162188
function bufferedPayloadBytes(input: Uint8Array, start: number): number {

src/adapters/cursor/native-exec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function cursorUnsafeNativeLocalExecEnabled(input: Pick<CursorNativeExecC
8787
const BLOB_TTL_MS = 15 * 60_000;
8888
const BLOB_MAX_ENTRIES = 4_096;
8989
const BLOB_MAX_ENTRY_BYTES = 16 * 1024 * 1024;
90-
const BLOB_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
90+
export const CURSOR_BLOB_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
9191

9292
type CursorBlobProvenance = "local-regenerated" | "remote-setBlobArgs";
9393
export type CursorBlobRequestScopeToken = symbol;
@@ -121,7 +121,7 @@ const DEFAULT_BLOB_LIMITS: CursorBlobLimits = {
121121
ttlMs: BLOB_TTL_MS,
122122
maxEntries: BLOB_MAX_ENTRIES,
123123
maxEntryBytes: BLOB_MAX_ENTRY_BYTES,
124-
maxTotalBytes: BLOB_MAX_TOTAL_BYTES,
124+
maxTotalBytes: CURSOR_BLOB_MAX_TOTAL_BYTES,
125125
};
126126

127127
const blobs = new Map<string, CursorBlobEntry>();

src/adapters/google-antigravity-replay.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ interface ReplayEntry {
2828

2929
const MIN_SIGNATURE_LEN = 16;
3030
const REPLAY_TTL_MS = 60 * 60 * 1000; // 1h
31-
const REPLAY_MAX_ENTRIES = 10_240;
31+
export const ANTIGRAVITY_REPLAY_MAX_ENTRIES = 10_240;
3232
const REPLAY_EVICT_BATCH = 128;
3333
const REPLAY_MAX_CALLS_PER_SESSION = 256;
34-
const REPLAY_MAX_BYTES_PER_SESSION = 2 * 1024 * 1024;
34+
export const ANTIGRAVITY_REPLAY_MAX_BYTES_PER_SESSION = 2 * 1024 * 1024;
35+
export const ANTIGRAVITY_REPLAY_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
3536
const REPLAY_MAX_SIGNATURE_BYTES = 64 * 1024;
3637

3738
interface ReplayLimits {
@@ -42,7 +43,7 @@ interface ReplayLimits {
4243

4344
const DEFAULT_REPLAY_LIMITS: ReplayLimits = {
4445
maxCallsPerSession: REPLAY_MAX_CALLS_PER_SESSION,
45-
maxBytesPerSession: REPLAY_MAX_BYTES_PER_SESSION,
46+
maxBytesPerSession: ANTIGRAVITY_REPLAY_MAX_BYTES_PER_SESSION,
4647
maxSignatureBytes: REPLAY_MAX_SIGNATURE_BYTES,
4748
};
4849

@@ -122,6 +123,12 @@ function deleteExpiredReplaySessions(now: number): void {
122123
for (const [key, entry] of replayCache) if (entry.expiresAtMs <= now) deleteReplaySession(key);
123124
}
124125

126+
export function sweepExpiredAntigravityReplay(now = Date.now()): number {
127+
const before = replayCache.size;
128+
deleteExpiredReplaySessions(now);
129+
return before - replayCache.size;
130+
}
131+
125132
function deleteReplayCall(entry: ReplayEntry, callKey: string): number {
126133
const call = entry.byCall.get(callKey);
127134
if (!call) return 0;
@@ -143,11 +150,18 @@ function evictInnerCalls(entry: ReplayEntry): void {
143150
}
144151

145152
function evictIfNeeded(): void {
146-
if (replayCache.size <= REPLAY_MAX_ENTRIES) return;
147-
const oldest = [...replayCache.entries()]
148-
.sort((a, b) => a[1].expiresAtMs - b[1].expiresAtMs)
149-
.slice(0, REPLAY_EVICT_BATCH);
150-
for (const [key] of oldest) deleteReplaySession(key);
153+
if (replayCache.size > ANTIGRAVITY_REPLAY_MAX_ENTRIES) {
154+
const oldest = [...replayCache.entries()]
155+
.sort((a, b) => a[1].expiresAtMs - b[1].expiresAtMs)
156+
.slice(0, REPLAY_EVICT_BATCH);
157+
for (const [key] of oldest) deleteReplaySession(key);
158+
}
159+
while (replayBytes > ANTIGRAVITY_REPLAY_MAX_TOTAL_BYTES) {
160+
const oldestKey = [...replayCache.entries()]
161+
.sort((a, b) => a[1].expiresAtMs - b[1].expiresAtMs)[0]?.[0];
162+
if (oldestKey === undefined) return;
163+
deleteReplaySession(oldestKey);
164+
}
151165
}
152166

153167
/** Gemini/Flash/Agent use the replay cache; Claude does not (inline sanitization instead). */

0 commit comments

Comments
 (0)