fix(sleeptime): trigger compaction reflection for legacy summary format (#1090)
This commit is contained in:
@@ -451,6 +451,13 @@ function extractTextPart(v: unknown): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
function markCompactionCompleted(ctx?: ContextTracker): void {
|
||||
if (!ctx) return;
|
||||
ctx.pendingCompaction = true;
|
||||
ctx.pendingSkillsReinject = true;
|
||||
ctx.pendingReflectionTrigger = true;
|
||||
}
|
||||
|
||||
function resolveLineIdForKind(
|
||||
b: Buffers,
|
||||
canonicalId: string,
|
||||
@@ -787,6 +794,9 @@ export function onChunk(
|
||||
phase: "finished",
|
||||
summary: compactionSummary,
|
||||
}));
|
||||
// Legacy servers may emit compaction completion as a user_message
|
||||
// system alert instead of summary_message.
|
||||
markCompactionCompleted(ctx);
|
||||
}
|
||||
// If not a summary, ignore it (user messages aren't rendered during streaming)
|
||||
break;
|
||||
@@ -1131,11 +1141,7 @@ export function onChunk(
|
||||
// Set here (not in event_message) because summary_message arrives after
|
||||
// compaction completes, guaranteeing the next usage_statistics has the
|
||||
// reduced token count.
|
||||
if (ctx) {
|
||||
ctx.pendingCompaction = true;
|
||||
ctx.pendingSkillsReinject = true;
|
||||
ctx.pendingReflectionTrigger = true;
|
||||
}
|
||||
markCompactionCompleted(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,30 @@ describe("accumulator usage statistics", () => {
|
||||
expect(tracker.pendingReflectionTrigger).toBe(true);
|
||||
});
|
||||
|
||||
test("sets reflection trigger for legacy compaction summary user_message", () => {
|
||||
const buffers = createBuffers("agent-1");
|
||||
const tracker = createContextTracker();
|
||||
const legacySummary = JSON.stringify({
|
||||
type: "system_alert",
|
||||
message:
|
||||
"The following prior messages have been hidden due to the conversation context window being reached.\nThe following is a summary of the previous messages: compact summary",
|
||||
});
|
||||
|
||||
onChunk(
|
||||
buffers,
|
||||
{
|
||||
message_type: "user_message",
|
||||
id: "legacy-compaction-1",
|
||||
content: legacySummary,
|
||||
} as unknown as LettaStreamingResponse,
|
||||
tracker,
|
||||
);
|
||||
|
||||
expect(tracker.pendingCompaction).toBe(true);
|
||||
expect(tracker.pendingSkillsReinject).toBe(true);
|
||||
expect(tracker.pendingReflectionTrigger).toBe(true);
|
||||
});
|
||||
|
||||
test("accumulates assistant messages when otid is missing but id is present", () => {
|
||||
const buffers = createBuffers();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user