fix: make sessionExists() async with SDK verification on SQLite

sessionExists() previously returned unconditional true on SQLite,
preventing ralph-loop orphaned-session cleanup from triggering.
Now uses sdkClient.session.messages() to verify session actually
exists. Callers updated to await the async result.

Addresses Cubic review feedback on PR #1837.
This commit is contained in:
YeonGyu-Kim
2026-02-15 19:23:05 +09:00
parent 3bbe0cbb1d
commit 11586445cf
4 changed files with 16 additions and 8 deletions
+10 -2
View File
@@ -138,8 +138,16 @@ export function getMessageDir(sessionID: string): string | null {
return null
}
export function sessionExists(sessionID: string): boolean {
if (isSqliteBackend()) return true
export async function sessionExists(sessionID: string): Promise<boolean> {
if (isSqliteBackend() && sdkClient) {
try {
const response = await sdkClient.session.messages({ path: { id: sessionID } })
const messages = response.data as unknown[] | undefined
return Array.isArray(messages) && messages.length > 0
} catch {
return false
}
}
return getMessageDir(sessionID) !== null
}