Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(compact): the layer before a per-turn compaction ends before the open answer

purple2b52dcd83feb
diff --git a/src/lib/__tests__/auto-compact-wiring.test.ts b/src/lib/__tests__/auto-compact-wiring.test.ts
index 2a95a1aa..c0b73232 100644
--- a/src/lib/__tests__/auto-compact-wiring.test.ts
+++ b/src/lib/__tests__/auto-compact-wiring.test.ts
@@ -633,6 +633,18 @@ describe('Auto-Kompaktierung, die klappt, sagt es auch', () => {
expect(hinweise(id)).toHaveLength(0)
})
+ it('eine schon angelegte, leere Antwort gehoert nicht zum Stand davor', async () => {
+ // Mac-Lauf 28.10.: die Agent-Schleife legt die Antwort an, bevor sie
+ // verdichtet. Als Ende genommen zeigte die Ebene "vorher" die spaetere
+ // Antwort mit.
+ setzeSchwelle(0.5)
+ const id = vollesGespraech()
+ useChatStore.getState().addMessage(id, { id: 'offen', role: 'assistant', content: '', timestamp: 9999, agentBlocks: [] })
+ zusammenfassen.mockResolvedValue({ ok: true, summary: ZUSAMMENFASSUNG } as never)
+ const rec = await maybeAutoCompact({ conversationId: id, activeModel: MODELL })
+ expect(rec!.endMessageId).toBe('lang39')
+ })
+
it('die Linie steht NACH den Nachrichten, die sie ersetzt', async () => {
// Am Schnittpunkt, nicht am Anfang: sonst behauptet sie, das ganze
// Gespraech sei zusammengefasst. Was davor stand, liegt eine Ebene tiefer.
diff --git a/src/lib/run-compact-command.ts b/src/lib/run-compact-command.ts
index 2e35365b..f0ffeb49 100644
--- a/src/lib/run-compact-command.ts
+++ b/src/lib/run-compact-command.ts
@@ -272,7 +272,10 @@ export async function runCompactForConversation(opts: {
record.contextBefore = contextBefore
record.contextAfter = Math.max(0, contextBefore - Math.max(0, record.tokensBefore - record.tokensAfter))
}
- const newest = conv.messages[conv.messages.length - 1]
+ // The answer the agent loops have already opened (empty, no step yet) is
+ // not part of the stand before: what it will say comes after. Mac run
+ // 28.10.: with it as the end, the layer "before" showed the later answer.
+ const newest = conv.messages.findLast((m) => !(m.role === 'assistant' && !m.content && !m.agentBlocks?.length))
if (newest) record.endMessageId = newest.id
// Re-read the store: the conversation may have been deleted while the model
// was writing. recordCompaction is a no-op on a missing id, but reporting