diff --git a/ui/src/bindings/DispatchLinks.vue b/ui/src/bindings/DispatchLinks.vue index c3eeb588b..16dd12202 100644 --- a/ui/src/bindings/DispatchLinks.vue +++ b/ui/src/bindings/DispatchLinks.vue @@ -27,14 +27,19 @@ const props = defineProps<{ const dispatches = ref([]); const failed = ref(false); +let generation = 0; watch( () => [props.kind, props.id], async () => { + const current = ++generation; failed.value = false; try { - dispatches.value = await api.dispatches(props.kind, props.id); + const res = await api.dispatches(props.kind, props.id); + if (current !== generation) return; + dispatches.value = res; } catch { + if (current !== generation) return; dispatches.value = []; failed.value = true; } diff --git a/ui/src/captures/event-type-state.ts b/ui/src/captures/event-type-state.ts index 2ec9b95a1..3ba25cb7e 100644 --- a/ui/src/captures/event-type-state.ts +++ b/ui/src/captures/event-type-state.ts @@ -49,14 +49,18 @@ export const draft = ref(null); export const saving = ref(false); export const saveError = ref(null); +let generation = 0; export async function loadEventTypes(): Promise { + const current = ++generation; try { const res = await api.eventTypes(useEventsStore().workspace); + if (current !== generation) return; eventTypesEnabled.value = res.enabled !== false; eventTypes.value = res.event_types || []; proposals.value = res.proposals || []; eventTypesError.value = null; } catch (err) { + if (current !== generation) return; eventTypesError.value = (err as Error).message || String(err); } finally { eventTypesLoading.value = false; diff --git a/ui/src/captures/state.ts b/ui/src/captures/state.ts index aa964e6b1..cee4cadb8 100644 --- a/ui/src/captures/state.ts +++ b/ui/src/captures/state.ts @@ -61,13 +61,17 @@ export const selected = ref(null); * are for a page with nothing on it yet, and a live refresh that put them back * would replace the rows an operator is reading several times a minute. */ +let generation = 0; export async function load(): Promise { + const current = ++generation; try { const res = await api.captures(LIST_LIMIT); + if (current !== generation) return; enabled.value = res.enabled !== false; captures.value = res.captures || []; error.value = null; } catch (err) { + if (current !== generation) return; // The server's own message is the only part of a failure an operator can // act on, so it is what the list says instead of the captures. error.value = (err as Error).message || String(err); diff --git a/ui/src/channels/ChannelsPage.vue b/ui/src/channels/ChannelsPage.vue index 9c1a19deb..7446543a5 100644 --- a/ui/src/channels/ChannelsPage.vue +++ b/ui/src/channels/ChannelsPage.vue @@ -73,13 +73,17 @@ const instance = computed(() => useSessionStore().sections?.settings !== false); const identities = useOrgStore(); const agents = ref([]); const agentsError = ref(""); +let agentsGeneration = 0; async function loadAgents(): Promise { + const current = ++agentsGeneration; agentsError.value = ""; try { await identities.loadOrg(); const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg); + if (current !== agentsGeneration) return; agents.value = response.agents.filter((agent) => agent.lifecycle === "active"); } catch (cause) { + if (current !== agentsGeneration) return; agentsError.value = String((cause as Error).message || cause); } } @@ -93,11 +97,15 @@ const statuses = ref([]); // A failed status read keeps the last known badges and flags the error, so a // transient failure neither clears every badge nor passes as "all idle". const statusError = ref(false); +let statusGeneration = 0; async function loadStatus() { + const current = ++statusGeneration; try { statuses.value = (await api.channels<{ channels?: ChannelStatus[] }>())?.channels ?? []; + if (current !== statusGeneration) return; statusError.value = false; } catch { + if (current !== statusGeneration) return; statusError.value = true; } } diff --git a/ui/src/components/command-palette/CommandPalette.vue b/ui/src/components/command-palette/CommandPalette.vue index 4c0a87ba2..ce8fa2c83 100644 --- a/ui/src/components/command-palette/CommandPalette.vue +++ b/ui/src/components/command-palette/CommandPalette.vue @@ -50,13 +50,16 @@ const showWorkflows = computed(() => !props.hidden.includes("/workflows")); // missing group: the pages still work either way. const tasksError = ref(false); const workflowsError = ref(false); +let entriesGeneration = 0; async function loadEntries(): Promise { + const current = ++entriesGeneration; const [taskPage, workflowList] = await Promise.all([ api.taskPage({ limit: 100 }).catch(() => null), showWorkflows.value ? api.workflows<{ definitions?: { id: string }[] }>().catch(() => null) : null, ]); + if (current !== entriesGeneration) return; tasksError.value = taskPage === null; tasks.value = taskPage?.tasks ?? []; workflowsError.value = showWorkflows.value && workflowList === null; diff --git a/ui/src/curators/CuratorsPage.vue b/ui/src/curators/CuratorsPage.vue index 42b7b3813..9f718f368 100644 --- a/ui/src/curators/CuratorsPage.vue +++ b/ui/src/curators/CuratorsPage.vue @@ -69,12 +69,16 @@ watch(() => store.applyStatusFor(KIND).map(row => row.version).join(","), () => const curators = ref([]); const loadError = ref(null); +let loadGeneration = 0; async function load() { + const current = ++loadGeneration; try { const res = await api.curators<{ curators?: Curator[] }>(); + if (current !== loadGeneration) return; curators.value = res?.curators || []; loadError.value = null; } catch (err) { + if (current !== loadGeneration) return; loadError.value = String((err as Error).message || err); } } diff --git a/ui/src/mappings/state.ts b/ui/src/mappings/state.ts index c5faa7899..e397e3951 100644 --- a/ui/src/mappings/state.ts +++ b/ui/src/mappings/state.ts @@ -136,7 +136,9 @@ function blankDraft(): MappingDraft { }; } +let loadGeneration = 0; export async function loadMappings(): Promise { + const current = ++loadGeneration; listLoading.value = true; try { // Capture storage is optional infrastructure -- a deployment can serve @@ -149,6 +151,7 @@ export async function loadMappings(): Promise { .catch(() => null), api.eventTypes<{ event_types?: EventType[] }>().catch(() => null), ]); + if (current !== loadGeneration) return; mappings.value = listed.mappings || []; eventTypes.value = types?.event_types || []; captures.value = captured?.captures || []; @@ -157,9 +160,10 @@ export async function loadMappings(): Promise { eventTypesError.value = types === null; loadError.value = null; } catch (err) { + if (current !== loadGeneration) return; loadError.value = String((err as Error).message || err); } finally { - listLoading.value = false; + if (current === loadGeneration) listLoading.value = false; } } @@ -251,12 +255,17 @@ export async function runPreview(): Promise { return; } try { - current.preview = await api.mappingPreview( + const preview = await api.mappingPreview( current.captureId, current.fields, ); + // A newer edit started while the preview was in flight; this response is + // for the old draft and must not overwrite it. + if (draft.value !== current) return; + current.preview = preview; actionError.value = null; } catch (err) { + if (draft.value !== current) return; actionError.value = classifyActionError(err); } } diff --git a/ui/src/schedules/SchedulesPage.vue b/ui/src/schedules/SchedulesPage.vue index b161d17f6..3c7e9c1b8 100644 --- a/ui/src/schedules/SchedulesPage.vue +++ b/ui/src/schedules/SchedulesPage.vue @@ -51,13 +51,17 @@ const schedules = ref(null); const loadError = ref(""); const actionError = ref(""); let timer: ReturnType | undefined; +let loadGeneration = 0; async function load(): Promise { + const current = ++loadGeneration; try { const response = await api.schedules<{ schedules?: Schedule[] }>(); + if (current !== loadGeneration) return; schedules.value = response.schedules ?? []; loadError.value = ""; } catch (err) { + if (current !== loadGeneration) return; loadError.value = err instanceof Error ? err.message : String(err); } } @@ -160,9 +164,9 @@ const remove = () =>
{{ loadError }} -
+
{ return found.length || !service.detail ? found : [service.detail]; }; +let loadGeneration = 0; async function load(): Promise { + const current = ++loadGeneration; try { services.value = await api.services(); + if (current !== loadGeneration) return; error.value = null; } catch (err) { + if (current !== loadGeneration) return; error.value = String((err as Error).message || err); } } diff --git a/ui/src/settings/SystemReposPage.vue b/ui/src/settings/SystemReposPage.vue index b5ea3131e..60afb873e 100644 --- a/ui/src/settings/SystemReposPage.vue +++ b/ui/src/settings/SystemReposPage.vue @@ -67,14 +67,17 @@ const { catalog, catalogError } = storeToRefs(store); const organisation = useOrgStore(); const agents=ref([]); const agentError=ref(""); +let agentsGeneration=0; onMounted(async()=>{ - void store.load(); - try { - await organisation.loadOrg(); - const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg); - agents.value=response.agents.filter((agent)=>agent.lifecycle==="active"); - } catch(cause) {agentError.value=String((cause as Error).message || cause)} -}); + void store.load(); + const current=++agentsGeneration; + try { + await organisation.loadOrg(); + const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg); + if(current!==agentsGeneration)return; + agents.value=response.agents.filter((agent)=>agent.lifecycle==="active"); + } catch(cause) {if(current===agentsGeneration)agentError.value=String((cause as Error).message || cause)} + }); const resources = computed(() => resourcesForPage(catalog.value, "repositories")); const form = computed(() => store.formFor(KIND)); diff --git a/ui/src/skills/SkillsPage.vue b/ui/src/skills/SkillsPage.vue index d9671350c..bc82a3493 100644 --- a/ui/src/skills/SkillsPage.vue +++ b/ui/src/skills/SkillsPage.vue @@ -20,13 +20,16 @@ const skills = ref([]); const search = ref(""); const loadError = ref(null); +let loadGeneration = 0; async function load() { + const current = ++loadGeneration; try { const res = await api.skills<{ skills?: Skill[] }>(); + if (current !== loadGeneration) return; skills.value = res?.skills || []; loadError.value = null; } catch (err) { - skills.value = []; + if (current !== loadGeneration) return; loadError.value = String((err as Error).message || err); } } diff --git a/ui/src/sources/use-sources.ts b/ui/src/sources/use-sources.ts index f63fa3169..ded37ac41 100644 --- a/ui/src/sources/use-sources.ts +++ b/ui/src/sources/use-sources.ts @@ -24,17 +24,21 @@ export function useSources() { return err instanceof Error && err.message ? err.message : String(err); } + let generation = 0; async function load(): Promise { + const current = ++generation; try { const res = await api.sources<{ sources?: Source[]; refusals?: Record; }>(useEventsStore().workspace); + if (current !== generation) return; sources.value = res.sources || []; refusals.value = res.refusals || {}; failure.value = null; loadError.value = null; } catch (err) { + if (current !== generation) return; loadError.value = message(err); } } diff --git a/ui/src/stores/secret-engines.ts b/ui/src/stores/secret-engines.ts index eb1c85663..d768cbfcd 100644 --- a/ui/src/stores/secret-engines.ts +++ b/ui/src/stores/secret-engines.ts @@ -7,12 +7,15 @@ export interface SecretEngine { name: string; version?: string; source: string } export const useSecretEnginesStore = defineStore("secret-engines", () => { const engines = ref(null); const error = ref(""); + let generation = 0; async function load() { + const current = ++generation; try { engines.value = (await api.secretEngines<{ engines: SecretEngine[] }>()).engines; + if (current !== generation) return; error.value = ""; } catch (cause) { - engines.value = null; + if (current !== generation) return; error.value = String((cause as Error).message || cause); } } diff --git a/ui/src/workflows/workflow-history.ts b/ui/src/workflows/workflow-history.ts index 1fe4c23d2..74f39777f 100644 --- a/ui/src/workflows/workflow-history.ts +++ b/ui/src/workflows/workflow-history.ts @@ -11,11 +11,15 @@ export function useWorkflowHistory(id: Ref) { const all = ref([]); const error = ref(""); + let generation = 0; async function reload(): Promise { + const current = ++generation; try { all.value = await store.history(KIND); + if (current !== generation) return; error.value = ""; } catch (err) { + if (current !== generation) return; error.value = err instanceof Error ? err.message : "Could not load history"; } }