Skip to content

Commit 05c3e40

Browse files
authored
fix(app): tolerate null session archive times (anomalyco#36999)
1 parent b6478dc commit 05c3e40

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/app/src/context/global-sync/home-session-index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, test } from "bun:test"
2+
import type { SessionV2Info } from "@opencode-ai/sdk/v2/client"
23
import {
34
applyHomeSessionEvent,
45
appendHomeSessionEvent,
@@ -72,8 +73,13 @@ describe("Home V2 session index", () => {
7273
})
7374

7475
test("maps visible roots to Home session summaries", () => {
76+
const activeNull = {
77+
...session({ id: "active-null", updated: 20 }),
78+
time: { created: 1, updated: 20, archived: null },
79+
} as unknown as SessionV2Info
7580
const result = parseHomeSessionIndex([
7681
session({ id: "root", updated: 30 }),
82+
activeNull,
7783
session({ id: "child", parentID: "root", updated: 40 }),
7884
session({ id: "archived", archived: 50, updated: 50 }),
7985
])
@@ -88,6 +94,10 @@ describe("Home V2 session index", () => {
8894
title: "root",
8995
time: { created: 1, updated: 30 },
9096
}),
97+
expect.objectContaining({
98+
id: "active-null",
99+
time: { created: 1, updated: 20, archived: null },
100+
}),
91101
])
92102
})
93103

packages/app/src/context/global-sync/home-session-index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function createHomeSessionIndexCache(queryClient: QueryClient, server: st
132132
// parentID: null, order: "desc" }), then remove this adapter and its V1 fields.
133133
export function parseHomeSessionIndex(sessions: SessionV2Info[]): Session[] {
134134
return sessions.flatMap((item) => {
135-
if (item.parentID || item.time.archived !== undefined) return []
135+
if (item.parentID || typeof item.time.archived === "number") return []
136136
return [toLegacySummary(item)]
137137
})
138138
}
@@ -145,7 +145,7 @@ export function retainHomeSessions(sessions: Session[], limit: number, now: numb
145145
export function applyHomeSessionEvent(sessions: Session[], event: HomeSessionEvent) {
146146
const info = event.properties.info
147147
const index = sessions.findIndex((session) => session.id === info.id)
148-
if (event.type === "session.deleted" || info.parentID || info.time.archived !== undefined) {
148+
if (event.type === "session.deleted" || info.parentID || typeof info.time.archived === "number") {
149149
if (index === -1) return sessions
150150
return sessions.toSpliced(index, 1)
151151
}

0 commit comments

Comments
 (0)