fix(hub): archive active sessions with stale metadata (#1170)

This commit is contained in:
Junmo Kim
2026-07-26 15:03:24 +08:00
committed by GitHub
parent c305c5ce31
commit 60d7489a59
2 changed files with 23 additions and 1 deletions
+22
View File
@@ -1167,6 +1167,28 @@ describe('sessions routes', () => {
expect(calls).toEqual(['session-1'])
})
it('archives an active session with stale archived lifecycle metadata', async () => {
const calls: string[] = []
const session = createSession({
active: true,
metadata: {
path: '/tmp/project',
host: 'localhost',
flavor: 'codex',
lifecycleState: 'archived'
}
})
const { app } = createApp(session, {
archiveSession: async (sessionId: string) => { calls.push(sessionId) }
})
const response = await app.request('/api/sessions/session-1/archive', { method: 'POST' })
expect(response.status).toBe(200)
expect(calls).toEqual(['session-1'])
expect(await response.json()).toEqual({ ok: true })
})
it('returns 2xx and skips archiveSession when the row is already archived (idempotent)', async () => {
let called = false
const session = createSession({
+1 -1
View File
@@ -339,7 +339,7 @@ export function createSessionsRoutes(getSyncEngine: () => SyncEngine | null): Ho
}
const lifecycleState = sessionResult.session.metadata?.lifecycleState
if (lifecycleState === 'archived') {
if (!sessionResult.session.active && lifecycleState === 'archived') {
return c.json({ ok: true, alreadyArchived: true })
}