Skip to content

Commit 8e115ac

Browse files
committed
test(agents): remove duplicate ceiling coverage
1 parent f4680dd commit 8e115ac

2 files changed

Lines changed: 2 additions & 134 deletions

File tree

‎src/agents/embedded-agent-runner/run/overflow-context-recovery.test.ts‎

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it, vi } from "vitest";
22
import type { ToolResultPromptProjectionState } from "../session-prompt-state.js";
3-
import type { recoverEmbeddedRunOverflow as recoverEmbeddedRunOverflowType } from "./overflow-context-recovery.js";
43
import type { EmbeddedRunAttemptResult } from "./types.js";
54

65
const truncateOversizedToolResultsInActiveTargetMock = vi.hoisted(() =>
@@ -195,135 +194,4 @@ describe("recoverEmbeddedRunOverflow", () => {
195194
userText: expect.stringContaining("Completed tool actions were not replayed"),
196195
});
197196
});
198-
199-
// Groq refuses an oversized single request with a 413 that names TPM and states both numbers.
200-
// Requested above Limit cannot be admitted by any bucket state, and compaction budgets against
201-
// the model's 131k context window rather than the provider's 8k per-request ceiling, so the
202-
// recovery owner must stop the run instead of compacting, adopting, truncating, or retrying.
203-
const GROQ_REQUEST_CEILING_413 =
204-
"413 Request too large for model `openai/gpt-oss-120b` in organization `org_x` " +
205-
"service tier `on_demand` on tokens per minute (TPM): Limit 8000, Requested 8098, " +
206-
"please reduce your message size and try again.";
207-
208-
function buildCeilingRecoveryInput(promptError: Error, overrides: Record<string, unknown>) {
209-
return {
210-
runParams: {
211-
runId: "run-ceiling",
212-
sessionId: "session-1",
213-
sessionKey: "agent:main:session-1",
214-
config: {},
215-
workspaceDir: "/tmp/workspace",
216-
prompt: "continue",
217-
timeoutMs: 1_000,
218-
},
219-
state: {
220-
autoCompactionCount: 0,
221-
lastCompactionTokensAfter: undefined,
222-
lastContextBudgetStatus: undefined,
223-
// Zero attempts means generic recovery would compact if it were allowed to.
224-
overflowCompactionAttempts: 0,
225-
timeoutCompactionAttempts: 0,
226-
toolResultTruncationAttempted: false,
227-
},
228-
contextTokenBudget: 131_072,
229-
genericCompactionRecoveryAllowed: true,
230-
aborted: false,
231-
signalOwnedInterruption: false,
232-
promptError,
233-
attempt: {
234-
terminal: { kind: "failed", source: "prompt", error: promptError },
235-
messagesSnapshot: [],
236-
replayMetadata: { replaySafe: false, hadPotentialSideEffects: false },
237-
itemLifecycle: { startedCount: 0, completedCount: 0, activeCount: 0 },
238-
} as unknown as EmbeddedRunAttemptResult,
239-
toolResultPromptProjectionState: {
240-
replacements: new Map(),
241-
frozen: new Set(),
242-
ambiguousBaseKeys: new Set(),
243-
sourceTextByKey: new Map(),
244-
},
245-
attemptCompactionCount: 0,
246-
runtimeAuthPlan: {},
247-
resolvedSessionKey: "agent:main:session-1",
248-
sessionAgentId: "main",
249-
agentDir: "/tmp/agent",
250-
workspaceDir: "/tmp/workspace",
251-
provider: "mock-groq",
252-
modelId: "openai/gpt-oss-120b",
253-
harnessRuntime: "embedded",
254-
thinkLevel: "off",
255-
authProfileIdSource: "auto",
256-
resolveContextEnginePluginId: () => undefined,
257-
buildRuntimeSettings: () => ({}),
258-
onCompactionHookMessages: async () => {},
259-
runOwnsCompactionAfterHook: async () => {},
260-
getActiveSession: () => ({ id: "session-1", file: "agent:main:session-1" }),
261-
prepareCurrentTranscriptRetry: () => {},
262-
armPostCompactionGuard: () => {},
263-
...overrides,
264-
} as unknown as Parameters<typeof recoverEmbeddedRunOverflowType>[0];
265-
}
266-
267-
it("surfaces reset guidance without compacting when the provider states a request-size ceiling", async () => {
268-
const { recoverEmbeddedRunOverflow } = await import("./overflow-context-recovery.js");
269-
const compact = vi.fn(async () => ({ ok: true as const, compacted: true as const }));
270-
const adoptCompactionTranscript = vi.fn(async () => undefined);
271-
const prepareCompactedTranscriptRetry = vi.fn(async () => {});
272-
const runOwnsCompactionBeforeHook = vi.fn(async () => {});
273-
truncateOversizedToolResultsInActiveTargetMock.mockClear();
274-
sessionLikelyHasOversizedToolResultsMock.mockReturnValue(true);
275-
276-
const result = await recoverEmbeddedRunOverflow(
277-
buildCeilingRecoveryInput(new Error(GROQ_REQUEST_CEILING_413), {
278-
contextEngine: {
279-
info: { id: "legacy", name: "Legacy" },
280-
ingest: async () => ({ ingested: true }),
281-
assemble: async ({ messages }: { messages: [] }) => ({ messages, estimatedTokens: 0 }),
282-
compact,
283-
},
284-
adoptCompactionTranscript,
285-
prepareCompactedTranscriptRetry,
286-
runOwnsCompactionBeforeHook,
287-
}),
288-
);
289-
290-
expect(result).toMatchObject({ action: "surface", kind: "context_overflow" });
291-
expect((result as { userText: string }).userText).toContain("/reset");
292-
// Terminal: none of the generic recovery machinery may run for an unsatisfiable request.
293-
expect(compact).not.toHaveBeenCalled();
294-
expect(runOwnsCompactionBeforeHook).not.toHaveBeenCalled();
295-
expect(adoptCompactionTranscript).not.toHaveBeenCalled();
296-
expect(prepareCompactedTranscriptRetry).not.toHaveBeenCalled();
297-
expect(truncateOversizedToolResultsInActiveTargetMock).not.toHaveBeenCalled();
298-
});
299-
300-
it("leaves ordinary TPM throttling to the rate-limit owner instead of overflow recovery", async () => {
301-
const { recoverEmbeddedRunOverflow } = await import("./overflow-context-recovery.js");
302-
const compact = vi.fn(async () => ({ ok: true as const, compacted: false as const }));
303-
truncateOversizedToolResultsInActiveTargetMock.mockClear();
304-
305-
const result = await recoverEmbeddedRunOverflow(
306-
buildCeilingRecoveryInput(
307-
new Error(
308-
"429 Rate limit reached for model `openai/gpt-oss-120b` in organization `org_x` " +
309-
"service tier `on_demand` on tokens per minute (TPM): Limit 8000, Used 7500, " +
310-
"Requested 1000, please try again in 3.5s.",
311-
),
312-
{
313-
contextEngine: {
314-
info: { id: "legacy", name: "Legacy" },
315-
ingest: async () => ({ ingested: true }),
316-
assemble: async ({ messages }: { messages: [] }) => ({ messages, estimatedTokens: 0 }),
317-
compact,
318-
},
319-
adoptCompactionTranscript: async () => undefined,
320-
prepareCompactedTranscriptRetry: async () => {},
321-
runOwnsCompactionBeforeHook: async () => {},
322-
},
323-
),
324-
);
325-
326-
expect(result).toEqual({ action: "none" });
327-
expect(compact).not.toHaveBeenCalled();
328-
});
329197
});

‎src/agents/failover/context-overflow.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ function readStatedTokenCount(digits: string | undefined): number | undefined {
4242
*
4343
* The ceiling belongs to the request and to the refusing provider's quota, not to the model's
4444
* context window, so compaction budgeted against that window cannot satisfy it either. Overflow
45-
* recovery declines it and failover keeps advancing candidates, because a differently
46-
* provisioned one may still admit the request.
45+
* Embedded recovery surfaces reset guidance without retrying. If a transport-owning harness
46+
* bypasses that recovery, model failover may advance to a differently provisioned candidate.
4747
*/
4848
export function isProviderRequestSizeCeilingError(errorMessage?: string): boolean {
4949
if (!errorMessage || !hasRateLimitTpmHint(errorMessage)) {

0 commit comments

Comments
 (0)