Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(web-app): show a session the background migration gave up on as not imported

thinhlpg2737ce8b59c8
diff --git a/web-app/src/lib/__tests__/coworkSync.test.ts b/web-app/src/lib/__tests__/coworkSync.test.ts
index 93b5095d9..d7b20fe38 100644
--- a/web-app/src/lib/__tests__/coworkSync.test.ts
+++ b/web-app/src/lib/__tests__/coworkSync.test.ts
@@ -502,6 +502,33 @@ describe('coworkSync', () => {
expect(backend.threads.has('b')).toBe(true)
})
+ it('a session the background run gives up on turns read-only with its reason', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+ putBlob(legacy('a'), legacy('b'))
+ let release!: () => void
+ const gate = new Promise<void>((r) => (release = r))
+ backend.hooks.before = async (cmd) => {
+ if (cmd === 'replace_thread_messages') await gate
+ }
+ agentTools.copySessionWorkspaceToThread.mockRejectedValueOnce(
+ new Error('PERMANENT: a already holds files of its own')
+ )
+ const started = startCoworkSync()
+ await vi.advanceTimersByTimeAsync(COWORK_MIGRATION_BUDGET_MS + 100)
+ await started
+ expect(useCoworkSessions.getState().sessions.find((s) => s.id === 'a')!.unavailable).toBeUndefined()
+ release()
+ await vi.advanceTimersByTimeAsync(200)
+ await flushCowork()
+ const a = useCoworkSessions.getState().sessions.find((s) => s.id === 'a')!
+ expect([a.unavailable, a.importError]).toEqual([
+ 'not-imported',
+ 'PERMANENT: a already holds files of its own',
+ ])
+ expect(backend.threads.has('a')).toBe(false)
+ expect(backend.threads.has('b')).toBe(true)
+ })
+
it('a session deleted while the migration was still running does not come back', async () => {
vi.useFakeTimers({ shouldAdvanceTime: true })
putBlob(legacy('a'), legacy('b'))
diff --git a/web-app/src/lib/coworkSync.ts b/web-app/src/lib/coworkSync.ts
index a60ee6b55..b714e38d3 100644
--- a/web-app/src/lib/coworkSync.ts
+++ b/web-app/src/lib/coworkSync.ts
@@ -432,6 +432,27 @@ async function finishLateMigration(
(s) => !inStore.has(s.id) && !seen.has(s.id) && !deleted.has(s.id)
)
if (fresh.length > 0) mergeLoaded(fresh, null)
+ // A session shown as legacy before the background run finished may have been
+ // abandoned by it: show it read-only with the reason, as a fresh launch would.
+ const placeholders = new Map(
+ loaded.sessions
+ .filter(
+ (s) =>
+ inStore.has(s.id) &&
+ (s.unavailable === 'not-imported' || s.unavailable === 'id-collision')
+ )
+ .map((s) => [s.id, s])
+ )
+ if (placeholders.size > 0) {
+ useCoworkSessions.setState((s) => ({
+ sessions: s.sessions.map((x) => {
+ const p = placeholders.get(x.id)
+ return p && !x.unavailable
+ ? { ...x, unavailable: p.unavailable, importError: p.importError }
+ : x
+ }),
+ }))
+ }
for (const t of loaded.threads) {
if (!deleted.has(t.id) && (!seen.has(t.id) || inStore.has(t.id))) upsertThread(t)
}