fix(app): tolerate null session archive times (#36999)

This commit is contained in:
Brendan Allan
2026-07-15 03:02:49 +00:00
committed by GitHub
parent b6478dcebf
commit 05c3e40a4e
2 changed files with 12 additions and 2 deletions
@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test" import { describe, expect, test } from "bun:test"
import type { SessionV2Info } from "@opencode-ai/sdk/v2/client"
import { import {
applyHomeSessionEvent, applyHomeSessionEvent,
appendHomeSessionEvent, appendHomeSessionEvent,
@@ -72,8 +73,13 @@ describe("Home V2 session index", () => {
}) })
test("maps visible roots to Home session summaries", () => { test("maps visible roots to Home session summaries", () => {
const activeNull = {
...session({ id: "active-null", updated: 20 }),
time: { created: 1, updated: 20, archived: null },
} as unknown as SessionV2Info
const result = parseHomeSessionIndex([ const result = parseHomeSessionIndex([
session({ id: "root", updated: 30 }), session({ id: "root", updated: 30 }),
activeNull,
session({ id: "child", parentID: "root", updated: 40 }), session({ id: "child", parentID: "root", updated: 40 }),
session({ id: "archived", archived: 50, updated: 50 }), session({ id: "archived", archived: 50, updated: 50 }),
]) ])
@@ -88,6 +94,10 @@ describe("Home V2 session index", () => {
title: "root", title: "root",
time: { created: 1, updated: 30 }, time: { created: 1, updated: 30 },
}), }),
expect.objectContaining({
id: "active-null",
time: { created: 1, updated: 20, archived: null },
}),
]) ])
}) })
@@ -132,7 +132,7 @@ export function createHomeSessionIndexCache(queryClient: QueryClient, server: st
// parentID: null, order: "desc" }), then remove this adapter and its V1 fields. // parentID: null, order: "desc" }), then remove this adapter and its V1 fields.
export function parseHomeSessionIndex(sessions: SessionV2Info[]): Session[] { export function parseHomeSessionIndex(sessions: SessionV2Info[]): Session[] {
return sessions.flatMap((item) => { return sessions.flatMap((item) => {
if (item.parentID || item.time.archived !== undefined) return [] if (item.parentID || typeof item.time.archived === "number") return []
return [toLegacySummary(item)] return [toLegacySummary(item)]
}) })
} }
@@ -145,7 +145,7 @@ export function retainHomeSessions(sessions: Session[], limit: number, now: numb
export function applyHomeSessionEvent(sessions: Session[], event: HomeSessionEvent) { export function applyHomeSessionEvent(sessions: Session[], event: HomeSessionEvent) {
const info = event.properties.info const info = event.properties.info
const index = sessions.findIndex((session) => session.id === info.id) const index = sessions.findIndex((session) => session.id === info.id)
if (event.type === "session.deleted" || info.parentID || info.time.archived !== undefined) { if (event.type === "session.deleted" || info.parentID || typeof info.time.archived === "number") {
if (index === -1) return sessions if (index === -1) return sessions
return sessions.toSpliced(index, 1) return sessions.toSpliced(index, 1)
} }