fix(ui): generation-guard the remaining async loads and polls (#1754)
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:
14 files changed
+76
-14
No files matched your search
@@ -27,14 +27,19 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const dispatches = ref<Dispatch[]>([]);
|
const dispatches = ref<Dispatch[]>([]);
|
||||||
const failed = ref(false);
|
const failed = ref(false);
|
||||||
|
let generation = 0;
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [props.kind, props.id],
|
() => [props.kind, props.id],
|
||||||
async () => {
|
async () => {
|
||||||
|
const current = ++generation;
|
||||||
failed.value = false;
|
failed.value = false;
|
||||||
try {
|
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 {
|
} catch {
|
||||||
|
if (current !== generation) return;
|
||||||
dispatches.value = [];
|
dispatches.value = [];
|
||||||
failed.value = true;
|
failed.value = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,14 +49,18 @@ export const draft = ref<Draft | null>(null);
|
|||||||
export const saving = ref(false);
|
export const saving = ref(false);
|
||||||
export const saveError = ref<string | null>(null);
|
export const saveError = ref<string | null>(null);
|
||||||
|
|
||||||
|
let generation = 0;
|
||||||
export async function loadEventTypes(): Promise<void> {
|
export async function loadEventTypes(): Promise<void> {
|
||||||
|
const current = ++generation;
|
||||||
try {
|
try {
|
||||||
const res = await api.eventTypes<EventTypesResponse>(useEventsStore().workspace);
|
const res = await api.eventTypes<EventTypesResponse>(useEventsStore().workspace);
|
||||||
|
if (current !== generation) return;
|
||||||
eventTypesEnabled.value = res.enabled !== false;
|
eventTypesEnabled.value = res.enabled !== false;
|
||||||
eventTypes.value = res.event_types || [];
|
eventTypes.value = res.event_types || [];
|
||||||
proposals.value = res.proposals || [];
|
proposals.value = res.proposals || [];
|
||||||
eventTypesError.value = null;
|
eventTypesError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== generation) return;
|
||||||
eventTypesError.value = (err as Error).message || String(err);
|
eventTypesError.value = (err as Error).message || String(err);
|
||||||
} finally {
|
} finally {
|
||||||
eventTypesLoading.value = false;
|
eventTypesLoading.value = false;
|
||||||
|
|||||||
@@ -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
|
* 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.
|
* would replace the rows an operator is reading several times a minute.
|
||||||
*/
|
*/
|
||||||
|
let generation = 0;
|
||||||
export async function load(): Promise<void> {
|
export async function load(): Promise<void> {
|
||||||
|
const current = ++generation;
|
||||||
try {
|
try {
|
||||||
const res = await api.captures<CapturesResponse>(LIST_LIMIT);
|
const res = await api.captures<CapturesResponse>(LIST_LIMIT);
|
||||||
|
if (current !== generation) return;
|
||||||
enabled.value = res.enabled !== false;
|
enabled.value = res.enabled !== false;
|
||||||
captures.value = res.captures || [];
|
captures.value = res.captures || [];
|
||||||
error.value = null;
|
error.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== generation) return;
|
||||||
// The server's own message is the only part of a failure an operator can
|
// 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.
|
// act on, so it is what the list says instead of the captures.
|
||||||
error.value = (err as Error).message || String(err);
|
error.value = (err as Error).message || String(err);
|
||||||
|
|||||||
@@ -73,13 +73,17 @@ const instance = computed(() => useSessionStore().sections?.settings !== false);
|
|||||||
const identities = useOrgStore();
|
const identities = useOrgStore();
|
||||||
const agents = ref<Identity[]>([]);
|
const agents = ref<Identity[]>([]);
|
||||||
const agentsError = ref("");
|
const agentsError = ref("");
|
||||||
|
let agentsGeneration = 0;
|
||||||
async function loadAgents(): Promise<void> {
|
async function loadAgents(): Promise<void> {
|
||||||
|
const current = ++agentsGeneration;
|
||||||
agentsError.value = "";
|
agentsError.value = "";
|
||||||
try {
|
try {
|
||||||
await identities.loadOrg();
|
await identities.loadOrg();
|
||||||
const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg);
|
const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg);
|
||||||
|
if (current !== agentsGeneration) return;
|
||||||
agents.value = response.agents.filter((agent) => agent.lifecycle === "active");
|
agents.value = response.agents.filter((agent) => agent.lifecycle === "active");
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
|
if (current !== agentsGeneration) return;
|
||||||
agentsError.value = String((cause as Error).message || cause);
|
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
|
// 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".
|
// transient failure neither clears every badge nor passes as "all idle".
|
||||||
const statusError = ref(false);
|
const statusError = ref(false);
|
||||||
|
let statusGeneration = 0;
|
||||||
async function loadStatus() {
|
async function loadStatus() {
|
||||||
|
const current = ++statusGeneration;
|
||||||
try {
|
try {
|
||||||
statuses.value = (await api.channels<{ channels?: ChannelStatus[] }>())?.channels ?? [];
|
statuses.value = (await api.channels<{ channels?: ChannelStatus[] }>())?.channels ?? [];
|
||||||
|
if (current !== statusGeneration) return;
|
||||||
statusError.value = false;
|
statusError.value = false;
|
||||||
} catch {
|
} catch {
|
||||||
|
if (current !== statusGeneration) return;
|
||||||
statusError.value = true;
|
statusError.value = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,13 +50,16 @@ const showWorkflows = computed(() => !props.hidden.includes("/workflows"));
|
|||||||
// missing group: the pages still work either way.
|
// missing group: the pages still work either way.
|
||||||
const tasksError = ref(false);
|
const tasksError = ref(false);
|
||||||
const workflowsError = ref(false);
|
const workflowsError = ref(false);
|
||||||
|
let entriesGeneration = 0;
|
||||||
async function loadEntries(): Promise<void> {
|
async function loadEntries(): Promise<void> {
|
||||||
|
const current = ++entriesGeneration;
|
||||||
const [taskPage, workflowList] = await Promise.all([
|
const [taskPage, workflowList] = await Promise.all([
|
||||||
api.taskPage<TaskEntry>({ limit: 100 }).catch(() => null),
|
api.taskPage<TaskEntry>({ limit: 100 }).catch(() => null),
|
||||||
showWorkflows.value
|
showWorkflows.value
|
||||||
? api.workflows<{ definitions?: { id: string }[] }>().catch(() => null)
|
? api.workflows<{ definitions?: { id: string }[] }>().catch(() => null)
|
||||||
: null,
|
: null,
|
||||||
]);
|
]);
|
||||||
|
if (current !== entriesGeneration) return;
|
||||||
tasksError.value = taskPage === null;
|
tasksError.value = taskPage === null;
|
||||||
tasks.value = taskPage?.tasks ?? [];
|
tasks.value = taskPage?.tasks ?? [];
|
||||||
workflowsError.value = showWorkflows.value && workflowList === null;
|
workflowsError.value = showWorkflows.value && workflowList === null;
|
||||||
|
|||||||
@@ -69,12 +69,16 @@ watch(() => store.applyStatusFor(KIND).map(row => row.version).join(","), () =>
|
|||||||
const curators = ref<Curator[]>([]);
|
const curators = ref<Curator[]>([]);
|
||||||
const loadError = ref<string | null>(null);
|
const loadError = ref<string | null>(null);
|
||||||
|
|
||||||
|
let loadGeneration = 0;
|
||||||
async function load() {
|
async function load() {
|
||||||
|
const current = ++loadGeneration;
|
||||||
try {
|
try {
|
||||||
const res = await api.curators<{ curators?: Curator[] }>();
|
const res = await api.curators<{ curators?: Curator[] }>();
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
curators.value = res?.curators || [];
|
curators.value = res?.curators || [];
|
||||||
loadError.value = null;
|
loadError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
loadError.value = String((err as Error).message || err);
|
loadError.value = String((err as Error).message || err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ function blankDraft(): MappingDraft {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let loadGeneration = 0;
|
||||||
export async function loadMappings(): Promise<void> {
|
export async function loadMappings(): Promise<void> {
|
||||||
|
const current = ++loadGeneration;
|
||||||
listLoading.value = true;
|
listLoading.value = true;
|
||||||
try {
|
try {
|
||||||
// Capture storage is optional infrastructure -- a deployment can serve
|
// Capture storage is optional infrastructure -- a deployment can serve
|
||||||
@@ -149,6 +151,7 @@ export async function loadMappings(): Promise<void> {
|
|||||||
.catch(() => null),
|
.catch(() => null),
|
||||||
api.eventTypes<{ event_types?: EventType[] }>().catch(() => null),
|
api.eventTypes<{ event_types?: EventType[] }>().catch(() => null),
|
||||||
]);
|
]);
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
mappings.value = listed.mappings || [];
|
mappings.value = listed.mappings || [];
|
||||||
eventTypes.value = types?.event_types || [];
|
eventTypes.value = types?.event_types || [];
|
||||||
captures.value = captured?.captures || [];
|
captures.value = captured?.captures || [];
|
||||||
@@ -157,9 +160,10 @@ export async function loadMappings(): Promise<void> {
|
|||||||
eventTypesError.value = types === null;
|
eventTypesError.value = types === null;
|
||||||
loadError.value = null;
|
loadError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
loadError.value = String((err as Error).message || err);
|
loadError.value = String((err as Error).message || err);
|
||||||
} finally {
|
} finally {
|
||||||
listLoading.value = false;
|
if (current === loadGeneration) listLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,12 +255,17 @@ export async function runPreview(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
current.preview = await api.mappingPreview<Preview>(
|
const preview = await api.mappingPreview<Preview>(
|
||||||
current.captureId,
|
current.captureId,
|
||||||
current.fields,
|
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;
|
actionError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (draft.value !== current) return;
|
||||||
actionError.value = classifyActionError(err);
|
actionError.value = classifyActionError(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,17 @@ const schedules = ref<Schedule[] | null>(null);
|
|||||||
const loadError = ref("");
|
const loadError = ref("");
|
||||||
const actionError = ref("");
|
const actionError = ref("");
|
||||||
let timer: ReturnType<typeof setInterval> | undefined;
|
let timer: ReturnType<typeof setInterval> | undefined;
|
||||||
|
let loadGeneration = 0;
|
||||||
|
|
||||||
async function load(): Promise<void> {
|
async function load(): Promise<void> {
|
||||||
|
const current = ++loadGeneration;
|
||||||
try {
|
try {
|
||||||
const response = await api.schedules<{ schedules?: Schedule[] }>();
|
const response = await api.schedules<{ schedules?: Schedule[] }>();
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
schedules.value = response.schedules ?? [];
|
schedules.value = response.schedules ?? [];
|
||||||
loadError.value = "";
|
loadError.value = "";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
loadError.value = err instanceof Error ? err.message : String(err);
|
loadError.value = err instanceof Error ? err.message : String(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,9 +164,9 @@ const remove = () =>
|
|||||||
|
|
||||||
<Section>
|
<Section>
|
||||||
<Alert v-if="loadError" variant="destructive"><AlertDescription>{{ loadError }}</AlertDescription></Alert>
|
<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
|
<DataTable
|
||||||
v-else
|
v-if="schedules"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:rows="schedules"
|
:rows="schedules"
|
||||||
:row-key="(s) => s.id"
|
:row-key="(s) => s.id"
|
||||||
|
|||||||
@@ -91,11 +91,15 @@ const reasons = (service: Service) => {
|
|||||||
return found.length || !service.detail ? found : [service.detail];
|
return found.length || !service.detail ? found : [service.detail];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let loadGeneration = 0;
|
||||||
async function load(): Promise<void> {
|
async function load(): Promise<void> {
|
||||||
|
const current = ++loadGeneration;
|
||||||
try {
|
try {
|
||||||
services.value = await api.services<Service[]>();
|
services.value = await api.services<Service[]>();
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
error.value = null;
|
error.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
error.value = String((err as Error).message || err);
|
error.value = String((err as Error).message || err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,14 +67,17 @@ const { catalog, catalogError } = storeToRefs(store);
|
|||||||
const organisation = useOrgStore();
|
const organisation = useOrgStore();
|
||||||
const agents=ref<Identity[]>([]);
|
const agents=ref<Identity[]>([]);
|
||||||
const agentError=ref("");
|
const agentError=ref("");
|
||||||
|
let agentsGeneration=0;
|
||||||
onMounted(async()=>{
|
onMounted(async()=>{
|
||||||
void store.load();
|
void store.load();
|
||||||
try {
|
const current=++agentsGeneration;
|
||||||
await organisation.loadOrg();
|
try {
|
||||||
const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg);
|
await organisation.loadOrg();
|
||||||
agents.value=response.agents.filter((agent)=>agent.lifecycle==="active");
|
const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg);
|
||||||
} catch(cause) {agentError.value=String((cause as Error).message || cause)}
|
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 resources = computed(() => resourcesForPage(catalog.value, "repositories"));
|
||||||
const form = computed(() => store.formFor(KIND));
|
const form = computed(() => store.formFor(KIND));
|
||||||
|
|||||||
@@ -20,13 +20,16 @@ const skills = ref<Skill[]>([]);
|
|||||||
const search = ref("");
|
const search = ref("");
|
||||||
const loadError = ref<string | null>(null);
|
const loadError = ref<string | null>(null);
|
||||||
|
|
||||||
|
let loadGeneration = 0;
|
||||||
async function load() {
|
async function load() {
|
||||||
|
const current = ++loadGeneration;
|
||||||
try {
|
try {
|
||||||
const res = await api.skills<{ skills?: Skill[] }>();
|
const res = await api.skills<{ skills?: Skill[] }>();
|
||||||
|
if (current !== loadGeneration) return;
|
||||||
skills.value = res?.skills || [];
|
skills.value = res?.skills || [];
|
||||||
loadError.value = null;
|
loadError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
skills.value = [];
|
if (current !== loadGeneration) return;
|
||||||
loadError.value = String((err as Error).message || err);
|
loadError.value = String((err as Error).message || err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,17 +24,21 @@ export function useSources() {
|
|||||||
return err instanceof Error && err.message ? err.message : String(err);
|
return err instanceof Error && err.message ? err.message : String(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let generation = 0;
|
||||||
async function load(): Promise<void> {
|
async function load(): Promise<void> {
|
||||||
|
const current = ++generation;
|
||||||
try {
|
try {
|
||||||
const res = await api.sources<{
|
const res = await api.sources<{
|
||||||
sources?: Source[];
|
sources?: Source[];
|
||||||
refusals?: Record<string, SourceRefusals>;
|
refusals?: Record<string, SourceRefusals>;
|
||||||
}>(useEventsStore().workspace);
|
}>(useEventsStore().workspace);
|
||||||
|
if (current !== generation) return;
|
||||||
sources.value = res.sources || [];
|
sources.value = res.sources || [];
|
||||||
refusals.value = res.refusals || {};
|
refusals.value = res.refusals || {};
|
||||||
failure.value = null;
|
failure.value = null;
|
||||||
loadError.value = null;
|
loadError.value = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== generation) return;
|
||||||
loadError.value = message(err);
|
loadError.value = message(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ export interface SecretEngine { name: string; version?: string; source: string }
|
|||||||
export const useSecretEnginesStore = defineStore("secret-engines", () => {
|
export const useSecretEnginesStore = defineStore("secret-engines", () => {
|
||||||
const engines = ref<SecretEngine[] | null>(null);
|
const engines = ref<SecretEngine[] | null>(null);
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
|
let generation = 0;
|
||||||
async function load() {
|
async function load() {
|
||||||
|
const current = ++generation;
|
||||||
try {
|
try {
|
||||||
engines.value = (await api.secretEngines<{ engines: SecretEngine[] }>()).engines;
|
engines.value = (await api.secretEngines<{ engines: SecretEngine[] }>()).engines;
|
||||||
|
if (current !== generation) return;
|
||||||
error.value = "";
|
error.value = "";
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
engines.value = null;
|
if (current !== generation) return;
|
||||||
error.value = String((cause as Error).message || cause);
|
error.value = String((cause as Error).message || cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ export function useWorkflowHistory(id: Ref<string>) {
|
|||||||
const all = ref<ResourceRevision[]>([]);
|
const all = ref<ResourceRevision[]>([]);
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
|
|
||||||
|
let generation = 0;
|
||||||
async function reload(): Promise<void> {
|
async function reload(): Promise<void> {
|
||||||
|
const current = ++generation;
|
||||||
try {
|
try {
|
||||||
all.value = await store.history(KIND);
|
all.value = await store.history(KIND);
|
||||||
|
if (current !== generation) return;
|
||||||
error.value = "";
|
error.value = "";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (current !== generation) return;
|
||||||
error.value = err instanceof Error ? err.message : "Could not load history";
|
error.value = err instanceof Error ? err.message : "Could not load history";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user