|
1 | 1 | import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import type { ToolResultPromptProjectionState } from "../session-prompt-state.js"; |
3 | | -import type { recoverEmbeddedRunOverflow as recoverEmbeddedRunOverflowType } from "./overflow-context-recovery.js"; |
4 | 3 | import type { EmbeddedRunAttemptResult } from "./types.js"; |
5 | 4 |
|
6 | 5 | const truncateOversizedToolResultsInActiveTargetMock = vi.hoisted(() => |
@@ -195,135 +194,4 @@ describe("recoverEmbeddedRunOverflow", () => { |
195 | 194 | userText: expect.stringContaining("Completed tool actions were not replayed"), |
196 | 195 | }); |
197 | 196 | }); |
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 | | - }); |
329 | 197 | }); |
0 commit comments