fix: resolve #3124 #3125 #3127 session tools, cache priming, and compaction loop

- #3124: Session tools now merge SDK and file-backed sessions for SQLite backend
- #3125: Cache priming fixed for OpenCode >=1.3.14 empty workspace
- #3127: Activity-based progress detection prevents infinite compaction on Kimi/Minimax

All 29 new tests pass, 4885 total tests passing.
This commit is contained in:
YeonGyu-Kim
2026-04-05 09:30:19 +09:00
parent aeb9c97c30
commit 130f4ac080
22 changed files with 538 additions and 114 deletions
@@ -165,6 +165,58 @@ describe("pollSyncSession", () => {
expect(callCount).toBeGreaterThan(1)
})
test("keeps polling when finish is 'stop' but assistant still has tool-call parts", async () => {
//#given
const { pollSyncSession } = require("./sync-session-poller")
let callCount = 0
const mockClient = {
session: {
messages: async () => {
callCount++
if (callCount <= 1) {
return {
data: [
{ info: { id: "msg_001", role: "user", time: { created: 1000 } } },
{
info: { id: "msg_002", role: "assistant", time: { created: 2000 }, finish: "stop" },
parts: [{ type: "tool-call", text: "calling tool" }],
},
],
}
}
return {
data: [
{ info: { id: "msg_001", role: "user", time: { created: 1000 } } },
{
info: { id: "msg_002", role: "assistant", time: { created: 2000 }, finish: "stop" },
parts: [{ type: "tool-call", text: "calling tool" }],
},
{ info: { id: "msg_003", role: "user", time: { created: 3000 } } },
{
info: { id: "msg_004", role: "assistant", time: { created: 4000 }, finish: "stop" },
parts: [{ type: "text", text: "Done" }],
},
],
}
},
status: async () => ({ data: { "ses_test": { type: "idle" } } }),
},
}
//#when
const result = await pollSyncSession(createMockCtx(), mockClient, {
sessionID: "ses_test",
agentToUse: "test-agent",
toastManager: null,
taskId: undefined,
})
//#then
expect(result).toBeNull()
expect(callCount).toBeGreaterThan(1)
})
test("does not complete when assistant id < user id (user sent after assistant)", async () => {
//#given - assistant finished but user message came after it (agent still processing)
const { pollSyncSession } = require("./sync-session-poller")
@@ -421,6 +473,44 @@ describe("pollSyncSession", () => {
expect(result).toBe(false)
})
test("returns false when finish is stop but assistant has tool-call parts", () => {
const { isSessionComplete } = require("./sync-session-poller")
//#given - provider marks stop even though tool execution is still pending
const messages = [
{ info: { id: "msg_001", role: "user", time: { created: 1000 } } },
{
info: { id: "msg_002", role: "assistant", time: { created: 2000 }, finish: "stop" },
parts: [{ type: "tool-call", text: "calling tool" }],
},
]
//#when
const result = isSessionComplete(messages)
//#then - should return false because tool execution is still pending
expect(result).toBe(false)
})
test("returns false when finish is end_turn but assistant has tool-call parts", () => {
const { isSessionComplete } = require("./sync-session-poller")
//#given - assistant emitted a terminal finish but still contains pending tool calls
const messages = [
{ info: { id: "msg_001", role: "user", time: { created: 1000 } } },
{
info: { id: "msg_002", role: "assistant", time: { created: 2000 }, finish: "end_turn" },
parts: [{ type: "tool-call", text: "calling tool" }],
},
]
//#when
const result = isSessionComplete(messages)
//#then - should return false because tool execution is still pending
expect(result).toBe(false)
})
test("returns false when user message has missing info.id field", () => {
const { isSessionComplete } = require("./sync-session-poller")
@@ -438,7 +528,7 @@ describe("pollSyncSession", () => {
//#then - should return false (missing user id)
expect(result).toBe(false)
})
})
})
})
@@ -5,6 +5,7 @@ import { log } from "../../shared/logger"
import { normalizeSDKResponse } from "../../shared"
const NON_TERMINAL_FINISH_REASONS = new Set(["tool-calls", "unknown"])
const PENDING_TOOL_PART_TYPES = new Set(["tool", "tool_use", "tool-call"])
function wait(milliseconds: number): Promise<void> {
const sharedBuffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
@@ -35,6 +36,7 @@ export function isSessionComplete(messages: SessionMessage[]): boolean {
if (!lastAssistant?.info?.finish) return false
if (NON_TERMINAL_FINISH_REASONS.has(lastAssistant.info.finish)) return false
if (lastAssistant.parts?.some((part) => part.type && PENDING_TOOL_PART_TYPES.has(part.type))) return false
if (!lastUser?.info?.id || !lastAssistant?.info?.id) return false
return lastUser.info.id < lastAssistant.info.id
}