perf: avoid duplicate transcript idempotency scans

This commit is contained in:
Shakker
2026-05-25 21:41:58 +01:00
committed by Shakker
parent a9e51732db
commit dc692aa6f6
3 changed files with 8 additions and 3 deletions

View File

@@ -186,6 +186,7 @@ export async function mirrorCodexAppServerTranscript(params: {
const { messageId, message: appendedMessage } = await appendSessionTranscriptMessage({
transcriptPath: params.sessionFile,
message: messageToAppend,
idempotencyLookup: idempotencyKey ? "caller-checked" : "scan",
config: params.config,
});
if (appendedMessage.role === "user") {

View File

@@ -241,6 +241,8 @@ type AppendSessionTranscriptMessageParams<TMessage = unknown> = {
sessionId?: string;
cwd?: string;
useRawWhenLinear?: boolean;
/** Use only when the caller already checked this idempotency key under the session write lock. */
idempotencyLookup?: "scan" | "caller-checked";
config?: OpenClawConfig;
};
@@ -305,9 +307,10 @@ async function appendSessionTranscriptMessageLocked<TMessage>(
...(params.cwd ? { cwd: params.cwd } : {}),
});
const idempotencyKey = readMessageIdempotencyKey(params.message);
const existing = idempotencyKey
? await findTranscriptMessageByIdempotencyKey<TMessage>(params.transcriptPath, idempotencyKey)
: undefined;
const existing =
idempotencyKey && params.idempotencyLookup !== "caller-checked"
? await findTranscriptMessageByIdempotencyKey<TMessage>(params.transcriptPath, idempotencyKey)
: undefined;
if (existing) {
return { ...existing, appended: false };
}

View File

@@ -353,6 +353,7 @@ export async function appendExactAssistantMessageToSessionTranscript(params: {
return await appendSessionTranscriptMessage({
transcriptPath: sessionFile,
message,
idempotencyLookup: explicitIdempotencyKey ? "caller-checked" : "scan",
config: params.config,
});
},