feat(webui): show which process is running which settings version

The settings page now reads apply status beside each resource: every known
process with the version it applied, its error if it rejected the edit, and
whether it is still reporting at all. It re-reads after each save, so the page
reflects what the processes did with an edit rather than what was stored.

The server derives liveness only, because it knows whether a record went stale
but not which version the page is showing. The client compares against the
resource it is rendering, which is what turns a live record on an older
version into a pending restart.

A process that stopped re-stamping and one that never reported are separate
rows with separate wording, and neither is an error: the setting may be fine
and the process simply absent, which an operator acts on differently. A failed
apply-status read leaves the previous rows rather than taking the settings
page down with it.

state-store-contract.md gains the pair in its inventory and its count moves
from 45 to 47, with the note that this read is a list rather than the
config-snapshot pair's found=false singleton.

Closes archie-core-pskb.
This commit is contained in:
sam committed 2026-09-21 15:57:46 +10:00
1 parent 48367151f3
commit dcdaa9f451
10 files changed
+358 -5

No files matched your search

+75 -1
View File
@@ -22,6 +22,55 @@ export interface ControlPlaneResource {
interface ResourceResponse { resource: ControlPlaneResource }
/** One process's report about one resource kind, as the server derives it.
* `state` is liveness only: the server knows whether a record went stale, not
* which version the page is showing. */
export interface ApplyStatusRecord {
process: string;
kind: string;
applied_version: number;
error?: string;
reported_at: string;
state: "current" | "failed" | "unknown";
}
export interface ApplyStatusResponse {
records: ApplyStatusRecord[];
processes: string[];
}
/** What the settings page says about one process for one resource. */
export type ApplyState = "running" | "pending-restart" | "failed" | "unknown" | "not-reporting";
export interface ApplyStatusRow {
process: string;
state: ApplyState;
version: number;
error: string;
}
/** applyStatusForKind reads every known process against the stored version, so
* a process that has never reported is a row saying so rather than a missing
* one. Staleness wins over the version comparison: a record that stopped being
* re-stamped describes a process that may no longer exist, so it can never
* read as running. */
export function applyStatusForKind(
records: ApplyStatusRecord[],
processes: string[],
kind: string,
storedVersion: number,
): ApplyStatusRow[] {
return processes.map((process) => {
const record = records.find((entry) => entry.process === process && entry.kind === kind);
if (!record) return { process, state: "not-reporting" as const, version: 0, error: "" };
const row = { process, version: record.applied_version, error: record.error ?? "" };
if (record.state === "unknown") return { ...row, state: "unknown" as const };
if (record.state === "failed") return { ...row, state: "failed" as const };
if (record.applied_version < storedVersion) return { ...row, state: "pending-restart" as const };
return { ...row, state: "running" as const };
});
}
/** One entry of a resource's audit trail. `value` is what that version held,
* which is also the payload a restore replays through the replace command. */
export interface ResourceRevision {
@@ -108,6 +157,7 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
const catalogError = ref("");
const states = reactive<Record<string, ResourceState>>({});
const streams = new Map<string, EventSource>();
const applyStatus = ref<ApplyStatusResponse>({ records: [], processes: [] });
const genericResources = computed(() => catalog.value.filter((item) =>
item.apply_mode !== "domain-managed" && !item.query_service && item.commands.includes("replace"),
@@ -150,11 +200,31 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
streams.set(kind, stream);
}
/** Re-read on every load and after each save, so the page reflects what the
* processes did with the edit rather than what was stored. A failure leaves
* the previous rows: apply status is a diagnostic, and losing it must not
* take the settings page with it. */
async function loadApplyStatus(): Promise<void> {
try {
applyStatus.value = await request<ApplyStatusResponse>("/api/control-plane/apply-status");
} catch {
// Keep whatever was last read.
}
}
/** Rows for one resource, every known process included. */
function applyStatusFor(kind: string): ApplyStatusRow[] {
return applyStatusForKind(
applyStatus.value.records, applyStatus.value.processes, kind, stateFor(kind).resource?.version ?? 0,
);
}
async function load(): Promise<void> {
try {
const response = await request<{ resources?: ResourceDescriptor[] }>("/api/control-plane/catalog");
catalog.value = response.resources ?? [];
catalogError.value = "";
await loadApplyStatus();
await Promise.all(genericResources.value.map(async ({ kind }) => {
await loadResource(kind);
watchResource(kind);
@@ -176,6 +246,7 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
{ method: "POST", body: commandBody(value, state.resource.version) },
);
apply(response.resource);
await loadApplyStatus();
return true;
} catch (error) {
if (error instanceof ControlPlaneError && error.status === 409) {
@@ -207,5 +278,8 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
}
}
return { catalog, catalogError, states, genericResources, history, load, replace, shippedWorkflows, stateFor };
return {
applyStatusFor, catalog, catalogError, states, genericResources,
history, load, loadApplyStatus, replace, shippedWorkflows, stateFor,
};
});