fix(call-omo-agent): preserve reused session tracking

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-12 02:24:22 +09:00
parent e249333898
commit 7997606892
2 changed files with 27 additions and 1 deletions

View File

@@ -131,4 +131,28 @@ describe("executeSync session cleanup", () => {
expect(syncSubagentSessions.has(sessionID)).toBe(false)
})
})
describe("#given executeSync reuses an existing session", () => {
test("#when execution completes successfully #then the reused session stays tracked in both Sets", async () => {
// given
const sessionID = "ses-reused"
const args = { ...createArgs(), session_id: sessionID }
const toolContext = createToolContext()
const promptAsync = mock(async () => ({ data: {} }))
const deps = createDependencies({
createOrGetSession: mock(async () => ({ sessionID, isNew: false })),
})
subagentSessions.add(sessionID)
syncSubagentSessions.add(sessionID)
// when
const result = await executeSync(args, toolContext, createContext(promptAsync) as never, deps)
// then
expect(result).toContain(`session_id: ${sessionID}`)
expect(subagentSessions.has(sessionID)).toBe(true)
expect(syncSubagentSessions.has(sessionID)).toBe(true)
})
})
})

View File

@@ -46,10 +46,12 @@ export async function executeSync(
spawnReservation?: SpawnReservation,
): Promise<string> {
let sessionID: string | undefined
let createdSessionForExecution = false
try {
const session = await deps.createOrGetSession(args, toolContext, ctx)
sessionID = session.sessionID
createdSessionForExecution = session.isNew
if (session.isNew) {
spawnReservation?.commit()
@@ -100,7 +102,7 @@ export async function executeSync(
spawnReservation?.rollback()
throw error
} finally {
if (sessionID) {
if (sessionID && createdSessionForExecution) {
subagentSessions.delete(sessionID)
syncSubagentSessions.delete(sessionID)
}