fix: hide synthetic untrusted metadata in chat history

This commit is contained in:
Peter Steinberger
2026-02-21 19:25:57 +01:00
parent afa22acc4a
commit 9fc6c8b713
8 changed files with 168 additions and 12 deletions

View File

@@ -3,12 +3,14 @@ import path from "node:path";
import readline from "node:readline";
import type { NormalizedUsage, UsageLike } from "../agents/usage.js";
import { normalizeUsage } from "../agents/usage.js";
import { stripInboundMetadata } from "../auto-reply/reply/strip-inbound-meta.js";
import type { OpenClawConfig } from "../config/config.js";
import {
resolveSessionFilePath,
resolveSessionTranscriptsDirForAgent,
} from "../config/sessions/paths.js";
import type { SessionEntry } from "../config/sessions/types.js";
import { stripEnvelope, stripMessageIdHints } from "../shared/chat-envelope.js";
import { countToolResults, extractToolCallNames } from "../utils/transcript-tools.js";
import { estimateUsageCost, resolveModelCostConfig } from "../utils/usage-format.js";
import type {
@@ -941,6 +943,13 @@ export async function loadSessionLogs(params: {
if (!content) {
continue;
}
content = stripInboundMetadata(content);
if (role === "user") {
content = stripMessageIdHints(stripEnvelope(content)).trim();
}
if (!content) {
continue;
}
// Truncate very long content
const maxLen = 2000;