
















@@ -285,6 +285,66 @@ describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
285285expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
286286});
287287288+it("uses the active agent post-compaction guard window over the global default", async () => {
289+const overflowError = makeOverflowError();
290+291+mockedRunEmbeddedAttempt.mockImplementationOnce(async () =>
292+makeAttemptResult({ promptError: overflowError }),
293+);
294+mockedRunEmbeddedAttempt.mockImplementationOnce(async (attemptParams: unknown) => {
295+const onToolOutcome = (attemptParams as { onToolOutcome?: ToolOutcomeObserver })
296+.onToolOutcome;
297+for (let i = 0; i < 3; i += 1) {
298+await executeWrappedToolOutcome(
299+"gateway",
300+{ action: "lookup", path: "x" },
301+"identical-result",
302+onToolOutcome,
303+);
304+}
305+return makeAttemptResult({
306+promptError: null,
307+toolMetas: [{ toolName: "gateway" }, { toolName: "gateway" }, { toolName: "gateway" }],
308+});
309+});
310+311+mockedCompactDirect.mockResolvedValueOnce(
312+makeCompactionSuccess({
313+summary: "Compacted session",
314+firstKeptEntryId: "entry-5",
315+tokensBefore: 150000,
316+}),
317+);
318+319+const result = await runEmbeddedPiAgent({
320+ ...baseParams,
321+agentId: "agent-a",
322+config: {
323+tools: {
324+loopDetection: {
325+postCompactionGuard: { enabled: true, windowSize: 2 },
326+},
327+},
328+agents: {
329+list: [
330+{
331+id: "agent-a",
332+tools: {
333+loopDetection: {
334+postCompactionGuard: { windowSize: 4 },
335+},
336+},
337+},
338+],
339+},
340+} as never,
341+});
342+343+expect(result.meta.error).toBeUndefined();
344+expect(mockedCompactDirect).toHaveBeenCalledTimes(1);
345+expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
346+});
347+288348it("aborts post-compaction loop from the live tool path even when toolCallHistory is at its trim cap", async () => {
289349// Long-running sessions accumulate up to historySize (default 30) records
290350// in toolCallHistory. The live observer must still see the new outcome
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。