mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:31:25 +00:00
fix(agents): re-run tool_use pairing repair after history truncation (#13926)
Co-authored-by: 0xRaini <0xRaini@users.noreply.github.com>
This commit is contained in:
@@ -44,6 +44,7 @@ import { createOpenClawCodingTools } from "../pi-tools.js";
|
|||||||
import { resolveSandboxContext } from "../sandbox.js";
|
import { resolveSandboxContext } from "../sandbox.js";
|
||||||
import { repairSessionFileIfNeeded } from "../session-file-repair.js";
|
import { repairSessionFileIfNeeded } from "../session-file-repair.js";
|
||||||
import { guardSessionManager } from "../session-tool-result-guard-wrapper.js";
|
import { guardSessionManager } from "../session-tool-result-guard-wrapper.js";
|
||||||
|
import { sanitizeToolUseResultPairing } from "../session-transcript-repair.js";
|
||||||
import { acquireSessionWriteLock } from "../session-write-lock.js";
|
import { acquireSessionWriteLock } from "../session-write-lock.js";
|
||||||
import { detectRuntimeShell } from "../shell-utils.js";
|
import { detectRuntimeShell } from "../shell-utils.js";
|
||||||
import {
|
import {
|
||||||
@@ -429,10 +430,16 @@ export async function compactEmbeddedPiSessionDirect(
|
|||||||
const validated = transcriptPolicy.validateAnthropicTurns
|
const validated = transcriptPolicy.validateAnthropicTurns
|
||||||
? validateAnthropicTurns(validatedGemini)
|
? validateAnthropicTurns(validatedGemini)
|
||||||
: validatedGemini;
|
: validatedGemini;
|
||||||
const limited = limitHistoryTurns(
|
const truncated = limitHistoryTurns(
|
||||||
validated,
|
validated,
|
||||||
getDmHistoryLimitFromSessionKey(params.sessionKey, params.config),
|
getDmHistoryLimitFromSessionKey(params.sessionKey, params.config),
|
||||||
);
|
);
|
||||||
|
// Re-run tool_use/tool_result pairing repair after truncation, since
|
||||||
|
// limitHistoryTurns can orphan tool_result blocks by removing the
|
||||||
|
// assistant message that contained the matching tool_use.
|
||||||
|
const limited = transcriptPolicy.repairToolUseResultPairing
|
||||||
|
? sanitizeToolUseResultPairing(truncated)
|
||||||
|
: truncated;
|
||||||
if (limited.length > 0) {
|
if (limited.length > 0) {
|
||||||
session.agent.replaceMessages(limited);
|
session.agent.replaceMessages(limited);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import { resolveSandboxContext } from "../../sandbox.js";
|
|||||||
import { resolveSandboxRuntimeStatus } from "../../sandbox/runtime-status.js";
|
import { resolveSandboxRuntimeStatus } from "../../sandbox/runtime-status.js";
|
||||||
import { repairSessionFileIfNeeded } from "../../session-file-repair.js";
|
import { repairSessionFileIfNeeded } from "../../session-file-repair.js";
|
||||||
import { guardSessionManager } from "../../session-tool-result-guard-wrapper.js";
|
import { guardSessionManager } from "../../session-tool-result-guard-wrapper.js";
|
||||||
|
import { sanitizeToolUseResultPairing } from "../../session-transcript-repair.js";
|
||||||
import { acquireSessionWriteLock } from "../../session-write-lock.js";
|
import { acquireSessionWriteLock } from "../../session-write-lock.js";
|
||||||
import { detectRuntimeShell } from "../../shell-utils.js";
|
import { detectRuntimeShell } from "../../shell-utils.js";
|
||||||
import {
|
import {
|
||||||
@@ -556,10 +557,16 @@ export async function runEmbeddedAttempt(
|
|||||||
const validated = transcriptPolicy.validateAnthropicTurns
|
const validated = transcriptPolicy.validateAnthropicTurns
|
||||||
? validateAnthropicTurns(validatedGemini)
|
? validateAnthropicTurns(validatedGemini)
|
||||||
: validatedGemini;
|
: validatedGemini;
|
||||||
const limited = limitHistoryTurns(
|
const truncated = limitHistoryTurns(
|
||||||
validated,
|
validated,
|
||||||
getDmHistoryLimitFromSessionKey(params.sessionKey, params.config),
|
getDmHistoryLimitFromSessionKey(params.sessionKey, params.config),
|
||||||
);
|
);
|
||||||
|
// Re-run tool_use/tool_result pairing repair after truncation, since
|
||||||
|
// limitHistoryTurns can orphan tool_result blocks by removing the
|
||||||
|
// assistant message that contained the matching tool_use.
|
||||||
|
const limited = transcriptPolicy.repairToolUseResultPairing
|
||||||
|
? sanitizeToolUseResultPairing(truncated)
|
||||||
|
: truncated;
|
||||||
cacheTrace?.recordStage("session:limited", { messages: limited });
|
cacheTrace?.recordStage("session:limited", { messages: limited });
|
||||||
if (limited.length > 0) {
|
if (limited.length > 0) {
|
||||||
activeSession.agent.replaceMessages(limited);
|
activeSession.agent.replaceMessages(limited);
|
||||||
|
|||||||
Reference in New Issue
Block a user