mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:32:43 +00:00
fix(agents): skip compaction API call when session has no real messages (#36451)
Merged via squash.
Prepared head SHA: 52dd631789
Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
@@ -132,6 +132,10 @@ type CompactionMessageMetrics = {
|
||||
contributors: Array<{ role: string; chars: number; tool?: string }>;
|
||||
};
|
||||
|
||||
function hasRealConversationContent(msg: AgentMessage): boolean {
|
||||
return msg.role === "user" || msg.role === "assistant" || msg.role === "toolResult";
|
||||
}
|
||||
|
||||
function createCompactionDiagId(): string {
|
||||
return `cmp-${Date.now().toString(36)}-${generateSecureToken(4)}`;
|
||||
}
|
||||
@@ -663,6 +667,17 @@ export async function compactEmbeddedPiSessionDirect(
|
||||
);
|
||||
}
|
||||
|
||||
if (!session.messages.some(hasRealConversationContent)) {
|
||||
log.info(
|
||||
`[compaction] skipping — no real conversation messages (sessionKey=${params.sessionKey ?? params.sessionId})`,
|
||||
);
|
||||
return {
|
||||
ok: true,
|
||||
compacted: false,
|
||||
reason: "no real conversation messages",
|
||||
};
|
||||
}
|
||||
|
||||
const compactStartedAt = Date.now();
|
||||
const result = await compactWithSafetyTimeout(() =>
|
||||
session.compact(params.customInstructions),
|
||||
|
||||
Reference in New Issue
Block a user