fix(ui): generation-guard the remaining async loads and polls (#1754)
Quality / check (push) Canceled after 7m38s
deploy / gate (push) Successful in 4m51s
deploy / archied-image (push) Successful in 3m26s
deploy / agent-image (push) Successful in 12s
deploy / dist-zip (push) Skipped

Schedules, command palette, skills, repos, services, secret engines,
captures, event types, curators, sources, channels, mappings (list and
preview), dispatch links and workflow history now capture a generation
at request start and drop their writes unless still latest — the guard
logs/state.ts already used. A failed schedules poll keeps the last good
rows beside the inline error instead of replacing the table, and a
failed skills/secret-engines poll no longer clears the list.
This commit is contained in:
sam committed 2026-11-06 23:40:03 +11:00
1 parent 0b08fc5242
commit 029198ff61
14 files changed
+76 -14

No files matched your search

+6 -1
View File
@@ -27,14 +27,19 @@ const props = defineProps<{
const dispatches = ref<Dispatch[]>([]);
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<Dispatch[]>(props.kind, props.id);
const res = await api.dispatches<Dispatch[]>(props.kind, props.id);
if (current !== generation) return;
dispatches.value = res;
} catch {
if (current !== generation) return;
dispatches.value = [];
failed.value = true;
}
+4
View File
@@ -49,14 +49,18 @@ export const draft = ref<Draft | null>(null);
export const saving = ref(false);
export const saveError = ref<string | null>(null);
let generation = 0;
export async function loadEventTypes(): Promise<void> {
const current = ++generation;
try {
const res = await api.eventTypes<EventTypesResponse>(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;
+4
View File
@@ -61,13 +61,17 @@ export const selected = ref<Capture | null>(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<void> {
const current = ++generation;
try {
const res = await api.captures<CapturesResponse>(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);
+8
View File
@@ -73,13 +73,17 @@ const instance = computed(() => useSessionStore().sections?.settings !== false);
const identities = useOrgStore();
const agents = ref<Identity[]>([]);
const agentsError = ref("");
let agentsGeneration = 0;
async function loadAgents(): Promise<void> {
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<ChannelStatus[]>([]);
// 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;
}
}
@@ -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<void> {
const current = ++entriesGeneration;
const [taskPage, workflowList] = await Promise.all([
api.taskPage<TaskEntry>({ 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;
+4
View File
@@ -69,12 +69,16 @@ watch(() => store.applyStatusFor(KIND).map(row => row.version).join(","), () =>
const curators = ref<Curator[]>([]);
const loadError = ref<string | null>(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);
}
}
+11 -2
View File
@@ -136,7 +136,9 @@ function blankDraft(): MappingDraft {
};
}
let loadGeneration = 0;
export async function loadMappings(): Promise<void> {
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<void> {
.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<void> {
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<void> {
return;
}
try {
current.preview = await api.mappingPreview<Preview>(
const preview = await api.mappingPreview<Preview>(
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);
}
}
+6 -2
View File
@@ -51,13 +51,17 @@ const schedules = ref<Schedule[] | null>(null);
const loadError = ref("");
const actionError = ref("");
let timer: ReturnType<typeof setInterval> | undefined;
let loadGeneration = 0;
async function load(): Promise<void> {
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 = () =>
<Section>
<Alert v-if="loadError" variant="destructive"><AlertDescription>{{ loadError }}</AlertDescription></Alert>
<div v-else-if="!schedules" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
<div v-if="!schedules" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
<DataTable
v-else
v-if="schedules"
:columns="columns"
:rows="schedules"
:row-key="(s) => s.id"
+4
View File
@@ -91,11 +91,15 @@ const reasons = (service: Service) => {
return found.length || !service.detail ? found : [service.detail];
};
let loadGeneration = 0;
async function load(): Promise<void> {
const current = ++loadGeneration;
try {
services.value = await api.services<Service[]>();
if (current !== loadGeneration) return;
error.value = null;
} catch (err) {
if (current !== loadGeneration) return;
error.value = String((err as Error).message || err);
}
}
+10 -7
View File
@@ -67,14 +67,17 @@ const { catalog, catalogError } = storeToRefs(store);
const organisation = useOrgStore();
const agents=ref<Identity[]>([]);
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));
+4 -1
View File
@@ -20,13 +20,16 @@ const skills = ref<Skill[]>([]);
const search = ref("");
const loadError = ref<string | null>(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);
}
}
+4
View File
@@ -24,17 +24,21 @@ export function useSources() {
return err instanceof Error && err.message ? err.message : String(err);
}
let generation = 0;
async function load(): Promise<void> {
const current = ++generation;
try {
const res = await api.sources<{
sources?: Source[];
refusals?: Record<string, SourceRefusals>;
}>(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);
}
}
+4 -1
View File
@@ -7,12 +7,15 @@ export interface SecretEngine { name: string; version?: string; source: string }
export const useSecretEnginesStore = defineStore("secret-engines", () => {
const engines = ref<SecretEngine[] | null>(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);
}
}
+4
View File
@@ -11,11 +11,15 @@ export function useWorkflowHistory(id: Ref<string>) {
const all = ref<ResourceRevision[]>([]);
const error = ref("");
let generation = 0;
async function reload(): Promise<void> {
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";
}
}