The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
desktop: settle stale local-models owners without throwing in the jobs observer
ethernetda32e8596a11
diff --git a/apps/desktop/src/store/local-runtime-jobs.test.ts b/apps/desktop/src/store/local-runtime-jobs.test.tsindex a3b0236a45b..96ed890e0ba 100644--- a/apps/desktop/src/store/local-runtime-jobs.test.ts+++ b/apps/desktop/src/store/local-runtime-jobs.test.ts@@ -41,6 +41,7 @@ vi.mock('@/store/notifications', () => ({const { localModelsKey, localModelsOwner, watchLocalRuntimeJobs } = await import('./local-runtime-jobs')const { getLocalModelsJobs } = await import('@/hermes')+const { $connection } = await import('@/store/session')const { notify, notifyError } = await import('@/store/notifications')function job(overrides: Partial<LocalRuntimeJob>): LocalRuntimeJob {@@ -96,6 +97,31 @@ describe('local runtime jobs store — pause/settle contract', () => {expect(notify).not.toHaveBeenCalled()})+ it('a settle landing after the primary connection moved is bookkept silently, not thrown', async () => {+ const owner: LocalModelsOwner = localModelsOwner()+ const key: QueryKey = localModelsKey(owner, 'jobs')+ backend.jobs = [job({ done_bytes: 10 })]+ await pollTick()++ // The response was fetched for the old endpoint but its observer+ // notification fires after the connection re-homed (TanStack notifies in+ // a microtask). Published straight into the cache to hit exactly that+ // window; the poll itself would already reject the stale scope.+ ;($connection as { set: (value: unknown) => void }).set({ baseUrl: 'http://moved.example' })+ queryClient.setQueryData(key, [job({ done_bytes: 100, status: 'done' })])+ await settle(0)++ expect(notify).not.toHaveBeenCalled()+ expect(notifyError).not.toHaveBeenCalled()++ // Bookkeeping kept going: the job is remembered as settled, so coming+ // back to this endpoint does not re-announce it.+ ;($connection as { set: (value: unknown) => void }).set(null)+ queryClient.setQueryData(key, [job({ done_bytes: 100, status: 'done' })])+ await settle(0)+ expect(notify).not.toHaveBeenCalled()+ })+it('publishes a pinned job response into an injected QueryClient observer', async (): Promise<void> => {const client: QueryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })const owner: LocalModelsOwner = { connectionId: 'A', profile: 'work' }diff --git a/apps/desktop/src/store/local-runtime-jobs.ts b/apps/desktop/src/store/local-runtime-jobs.tsindex 991effcbae2..47fcacc65d2 100644--- a/apps/desktop/src/store/local-runtime-jobs.ts+++ b/apps/desktop/src/store/local-runtime-jobs.ts@@ -62,8 +62,14 @@ export function localModelsKey(owner: LocalModelsOwner, resource?: string): Quer]}+// A legacy (unpinned) owner is fenced by the endpoint it was minted for;+// once the primary connection moves, its requests and toasts must stop.+export function isLocalModelsOwnerLive(owner: LocalModelsOwner): boolean {+ return Boolean(owner.connectionId) || owner.legacyBaseUrl === ($connection.get()?.baseUrl ?? '')+}+export function localModelsRequestScope(owner: LocalModelsOwner): LocalModelsScope {- if (!owner.connectionId && owner.legacyBaseUrl !== ($connection.get()?.baseUrl ?? '')) {+ if (!isLocalModelsOwnerLive(owner)) {throw new Error('Local models connection changed')}@@ -194,7 +200,7 @@ export function localModelsJobsOptions(owner: LocalModelsOwner): UseQueryOptionsreturn [...jobs].sort((a: LocalRuntimeJob, b: LocalRuntimeJob): number => a.job_id.localeCompare(b.job_id))},refetchInterval: (query: Query<readonly LocalRuntimeJob[]>): number | false => {- if (!owner.connectionId && owner.legacyBaseUrl !== ($connection.get()?.baseUrl ?? '')) {+ if (!isLocalModelsOwnerLive(owner)) {return false}@@ -298,6 +304,9 @@ export function watchLocalRuntimeJobs()let changed: boolean = [...downloading].some((jobId: string): boolean => !nextDownloads.has(jobId))+ // A stale legacy owner still settles its bookkeeping; it just has no+ // toast to show — a throw here would abort the whole listener instead.+ const live: boolean = isLocalModelsOwnerLive(owner)for (const job of jobs) {if (isActive(job.status) || !active.has(job.job_id) || settledNotified.has(job.job_id)) {@@ -306,7 +315,10 @@ export function watchLocalRuntimeJobs(settledNotified.add(job.job_id)changed = true- notifySettled(owner, job)++ if (live) {+ notifySettled(owner, job)+ }}active = new Set(