惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
罗磊的独立博客
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
V
V2EX
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
量子位
MyScale Blog
MyScale Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
B
Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(agents): recover message-tool mirror replay poison (#...
anyech · 2026-06-23 · via Recent Commits to openclaw:main

@@ -39,7 +39,11 @@ import {

3939

} from "../session-transcript-repair.js";

4040

import type { SessionManager } from "../sessions/index.js";

4141

import { STREAM_ERROR_FALLBACK_TEXT } from "../stream-message-shared.js";

42-

import { sanitizeToolCallIdsForCloudCodeAssist } from "../tool-call-id.js";

42+

import {

43+

extractToolCallsFromAssistant,

44+

extractToolResultId,

45+

sanitizeToolCallIdsForCloudCodeAssist,

46+

} from "../tool-call-id.js";

4347

import type { TranscriptPolicy } from "../transcript-policy.js";

4448

import {

4549

providerRequiresSignedThinking,

@@ -588,6 +592,78 @@ function isSameModelSnapshot(a: ModelSnapshotEntry, b: ModelSnapshotEntry): bool

588592

);

589593

}

590594595+

function formatOpenAIResponsesReplayInvariantError(params: {

596+

reason: "dangling_tool_call" | "orphan_tool_result";

597+

toolCallId?: string;

598+

messageIndex: number;

599+

}): Error {

600+

const toolCallId = params.toolCallId ? ` toolCallId=${params.toolCallId}` : "";

601+

return new Error(

602+

`invalid_replay_transcript: OpenAI Responses replay contains ${params.reason}${toolCallId} at message index ${params.messageIndex}`,

603+

);

604+

}

605+606+

function assertOpenAIResponsesToolUseResultInvariant(messages: AgentMessage[]): AgentMessage[] {

607+

const pending = new Map<string, { messageIndex: number }>();

608+609+

for (let i = 0; i < messages.length; i += 1) {

610+

const message = messages[i];

611+

const role = (message as { role?: unknown } | undefined)?.role;

612+613+

if (pending.size > 0 && role !== "toolResult") {

614+

const [toolCallId, meta] = pending.entries().next().value as [

615+

string,

616+

{ messageIndex: number },

617+

];

618+

throw formatOpenAIResponsesReplayInvariantError({

619+

reason: "dangling_tool_call",

620+

toolCallId,

621+

messageIndex: meta.messageIndex,

622+

});

623+

}

624+625+

if (!message || typeof message !== "object") {

626+

continue;

627+

}

628+629+

if (role === "toolResult") {

630+

const toolCallId = extractToolResultId(

631+

message as Extract<AgentMessage, { role: "toolResult" }>,

632+

);

633+

if (!toolCallId || !pending.has(toolCallId)) {

634+

throw formatOpenAIResponsesReplayInvariantError({

635+

reason: "orphan_tool_result",

636+

...(toolCallId ? { toolCallId } : {}),

637+

messageIndex: i,

638+

});

639+

}

640+

pending.delete(toolCallId);

641+

continue;

642+

}

643+644+

if (role !== "assistant") {

645+

continue;

646+

}

647+648+

for (const toolCall of extractToolCallsFromAssistant(

649+

message as Extract<AgentMessage, { role: "assistant" }>,

650+

)) {

651+

pending.set(toolCall.id, { messageIndex: i });

652+

}

653+

}

654+655+

if (pending.size > 0) {

656+

const [toolCallId, meta] = pending.entries().next().value as [string, { messageIndex: number }];

657+

throw formatOpenAIResponsesReplayInvariantError({

658+

reason: "dangling_tool_call",

659+

toolCallId,

660+

messageIndex: meta.messageIndex,

661+

});

662+

}

663+664+

return messages;

665+

}

666+591667

/**

592668

* Applies the generic replay-history cleanup pipeline before provider-owned

593669

* replay hooks run.

@@ -749,6 +825,9 @@ export async function sanitizeSessionHistory(params: {

749825

providerSanitized = providerResult ?? undefined;

750826

}

751827

const sanitizedWithProvider = providerSanitized ?? sanitizedCompactionUsage;

828+

const responsesInvariantChecked = isOpenAIResponsesApi

829+

? assertOpenAIResponsesToolUseResultInvariant(sanitizedWithProvider)

830+

: sanitizedWithProvider;

752831753832

if (hasSnapshot && (!priorSnapshot || modelChanged)) {

754833

appendModelSnapshot(params.sessionManager, {

@@ -760,7 +839,7 @@ export async function sanitizeSessionHistory(params: {

760839

}

761840762841

if (!policy.applyGoogleTurnOrdering) {

763-

return sanitizedWithProvider;

842+

return responsesInvariantChecked;

764843

}

765844766845

// Strict OpenAI-compatible providers (vLLM, Gemma, etc.) also reject

@@ -769,7 +848,10 @@ export async function sanitizeSessionHistory(params: {

769848

// provider-owned ordering rewrite above; keep this generic fallback for the

770849

// strict OpenAI-compatible path and for any provider that leaves assistant-

771850

// first repair to core. See #38962.

772-

return sanitizeGoogleTurnOrdering(sanitizedWithProvider);

851+

const googleOrdered = sanitizeGoogleTurnOrdering(responsesInvariantChecked);

852+

return isOpenAIResponsesApi

853+

? assertOpenAIResponsesToolUseResultInvariant(googleOrdered)

854+

: googleOrdered;

773855

}

774856775857

/**