





















@@ -274,7 +274,7 @@ describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
274274config: {
275275tools: {
276276loopDetection: {
277-postCompactionGuard: { enabled: true, windowSize: 2 },
277+postCompactionGuard: { windowSize: 2 },
278278},
279279},
280280} as never,
@@ -322,7 +322,7 @@ describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
322322config: {
323323tools: {
324324loopDetection: {
325-postCompactionGuard: { enabled: true, windowSize: 2 },
325+postCompactionGuard: { windowSize: 2 },
326326},
327327},
328328agents: {
@@ -345,6 +345,54 @@ describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
345345expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
346346});
347347348+it("does not arm the post-compaction guard when loop detection is disabled", async () => {
349+const overflowError = makeOverflowError();
350+351+mockedRunEmbeddedAttempt.mockImplementationOnce(async () =>
352+makeAttemptResult({ promptError: overflowError }),
353+);
354+mockedRunEmbeddedAttempt.mockImplementationOnce(async (attemptParams: unknown) => {
355+const onToolOutcome = (attemptParams as { onToolOutcome?: ToolOutcomeObserver })
356+.onToolOutcome;
357+for (let i = 0; i < 3; i += 1) {
358+await executeWrappedToolOutcome(
359+"gateway",
360+{ action: "lookup", path: "x" },
361+"identical-result",
362+onToolOutcome,
363+);
364+}
365+return makeAttemptResult({
366+promptError: null,
367+toolMetas: [{ toolName: "gateway" }, { toolName: "gateway" }, { toolName: "gateway" }],
368+});
369+});
370+371+mockedCompactDirect.mockResolvedValueOnce(
372+makeCompactionSuccess({
373+summary: "Compacted session",
374+firstKeptEntryId: "entry-5",
375+tokensBefore: 150000,
376+}),
377+);
378+379+const result = await runEmbeddedPiAgent({
380+ ...baseParams,
381+config: {
382+tools: {
383+loopDetection: {
384+enabled: false,
385+postCompactionGuard: { windowSize: 2 },
386+},
387+},
388+} as never,
389+});
390+391+expect(result.meta.error).toBeUndefined();
392+expect(mockedCompactDirect).toHaveBeenCalledTimes(1);
393+expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
394+});
395+348396it("aborts post-compaction loop from the live tool path even when toolCallHistory is at its trim cap", async () => {
349397// Long-running sessions accumulate up to historySize (default 30) records
350398// in toolCallHistory. The live observer must still see the new outcome
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。