
























@@ -4,7 +4,10 @@ import type {
44getDiagnosticSessionState as GetDiagnosticSessionStateType,
55SessionState,
66} from "../../logging/diagnostic-session-state.js";
7-import type { hashToolCall as HashToolCallType } from "../tool-loop-detection.js";
7+import type {
8+recordToolCall as RecordToolCallType,
9+recordToolCallOutcome as RecordToolCallOutcomeType,
10+} from "../tool-loop-detection.js";
811import type { PostCompactionLoopPersistedError as PostCompactionLoopPersistedErrorType } from "./post-compaction-loop-guard.js";
912import {
1013makeAttemptResult,
@@ -30,7 +33,8 @@ let runEmbeddedPiAgent: typeof import("./run.js").runEmbeddedPiAgent;
3033// vi.resetModules() inside the harness invalidates any earlier import.
3134let diagnosticSessionStates: typeof DiagnosticSessionStatesType;
3235let getDiagnosticSessionState: typeof GetDiagnosticSessionStateType;
33-let hashToolCall: typeof HashToolCallType;
36+let recordToolCall: typeof RecordToolCallType;
37+let recordToolCallOutcome: typeof RecordToolCallOutcomeType;
3438let PostCompactionLoopPersistedError: typeof PostCompactionLoopPersistedErrorType;
35393640// Mirror the production trim cap (resolveLoopDetectionConfig default
@@ -42,26 +46,20 @@ function recordToolOutcome(
4246state: SessionState,
4347toolName: string,
4448toolParams: unknown,
45-resultHash: string,
49+result: unknown,
4650runId?: string,
4751): void {
48-if (!state.toolCallHistory) {
49-state.toolCallHistory = [];
50-}
51-state.toolCallHistory.push({
52+const toolCallId = `${toolName}-${state.toolOutcomeSeq ?? 0}`;
53+recordToolCall(state, toolName, toolParams, toolCallId, undefined, {
54+ ...(runId ? { runId } : {}),
55+});
56+recordToolCallOutcome(state, {
5257 toolName,
53-argsHash: hashToolCall(toolName, toolParams),
54-resultHash,
55-timestamp: Date.now(),
58+ toolParams,
59+toolCallId,
60+result,
5661 ...(runId ? { runId } : {}),
5762});
58-if (state.toolCallHistory.length > HISTORY_TRIM_CAP) {
59-state.toolCallHistory.splice(0, state.toolCallHistory.length - HISTORY_TRIM_CAP);
60-}
61-// Mirror recordToolCallOutcome's unmatched-push branch: bump the monotonic
62-// outcome seq the runner uses to detect new records without an absolute
63-// index into the (trim-prone) toolCallHistory array.
64-state.toolOutcomeSeq = (state.toolOutcomeSeq ?? 0) + 1;
6563}
66646765describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
@@ -71,7 +69,7 @@ describe("post-compaction loop guard wired into runEmbeddedPiAgent", () => {
7169// the runner. The runner imports both modules through its own graph.
7270({ diagnosticSessionStates, getDiagnosticSessionState } =
7371await import("../../logging/diagnostic-session-state.js"));
74-({ hashToolCall } = await import("../tool-loop-detection.js"));
72+({ recordToolCall, recordToolCallOutcome } = await import("../tool-loop-detection.js"));
7573({ PostCompactionLoopPersistedError } = await import("./post-compaction-loop-guard.js"));
7674});
7775此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。