fix(client): register running sessions missed while disconnected (#53012)

This commit is contained in:
Kit Langton
2026-10-25 15:54:33 -07:00
committed by GitHub
Unverified
parent 8b813d362c
commit f6991636a5
2 changed files with 23 additions and 1 deletions
+5
View File
@@ -652,6 +652,11 @@ export function createData(config: CreateDataInput) {
})
activeUpdates = undefined
setStore("session", "active", reconcile(Object.fromEntries(snapshot)))
// Sessions created before this connection (while disconnected, or before the client started)
// never delivered `session.created`; without their info a running child never joins its root's family.
snapshot.forEach((status, id) => {
if (status === "running" && !store.session.info[id]) refresh(() => result.session.sync(id))
})
})
.catch(() => {
if (activeUpdates === updates) activeUpdates = undefined
+18 -1
View File
@@ -1186,6 +1186,21 @@ test.each([
}
})
test("adds running sessions created while disconnected to their family", async () => {
const root = { ...session(0), id: "ses_root" }
const child = { ...session(0), id: "ses_child", parentID: "ses_root" }
const setup = activityFixture(() => Response.json({ data: { ses_child: { type: "running" } } }), [child])
try {
setup.data.session.remember(root)
setup.emit({ type: "server.connected", data: {} })
await wait(() => setup.data.session.family("ses_root").includes("ses_child"))
expect(setup.data.session.status("ses_child")).toBe("running")
} finally {
setup.dispose()
}
})
test("ignores activity snapshots from an older connection", async () => {
const reads: ReturnType<typeof Promise.withResolvers<Response>>[] = []
const setup = activityFixture(() => {
@@ -1257,7 +1272,7 @@ function modelInfo(name: string): ModelInfo {
}
}
function activityFixture(read: () => Response | Promise<Response>) {
function activityFixture(read: () => Response | Promise<Response>, sessions: SessionInfo[] = []) {
const listeners = new Set<Parameters<CreateDataInput["event"]["listen"]>[0]>()
const api = OpenCode.make({
baseUrl: "http://opencode.local",
@@ -1265,6 +1280,8 @@ function activityFixture(read: () => Response | Promise<Response>) {
const request = input instanceof Request ? input : new Request(input, init)
const path = new URL(request.url).pathname
if (path === "/api/session/active") return read()
const known = sessions.find((item) => path === `/api/session/${item.id}`)
if (known) return Response.json({ data: known })
if (path === "/api/project") return Response.json([])
if (path === "/api/location") return Response.json({ directory: "/project" })
return Response.json({ location: { directory: "/project" }, data: { branch: "main" } })