Skip to content

Commit 3d7bc2d

Browse files
committed
fix(ui): surface the autosave reconnect latch instead of silently never saving
When a gateway connection is replaced while a config form draft is dirty, autosave intentionally latches off (autoSaveRequiresExplicitSubmit) until an explicit Save — but the latch was invisible: the indicator rendered nothing on idle, form mode has no Save button, and every subsequent edit (plus the dispose-time teardown flush) silently never saved. A recorded fact existed in the coordinator with no read where the operator needed it. The latch now projects a visible "paused" autosave status owned by the same arm/clear transitions (conflict outranks it; local edits cannot clear it), and the save indicator renders "Autosave paused after reconnect" with a Save action reusing the existing retry plumbing.
1 parent 641821f commit 3d7bc2d

6 files changed

Lines changed: 48 additions & 7 deletions

File tree

‎ui/src/components/settings-save-indicator.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ class SettingsSaveIndicator extends LitElement {
8888
>
8989
${t("configView.retry")}
9090
</button>`;
91+
} else if (props.status === "paused") {
92+
// Reconnect latch: autosave is off for this draft until an explicit
93+
// Save; without this row the form silently never saves again.
94+
content = html` <span>${t("configView.autoSavePaused")}</span>
95+
<button
96+
class="btn btn--xs settings-save-indicator__action"
97+
type="button"
98+
@click=${props.onRetry}
99+
>
100+
${t("configView.saveNow")}
101+
</button>`;
91102
} else if (props.status === "conflict") {
92103
modifier = " settings-save-indicator--danger";
93104
content = html` <span>${t("configView.autoSaveConflict")}</span>

‎ui/src/i18n/locales/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,8 @@ export const en: TranslationMap = {
16541654
applying: "Applying…",
16551655
autoSaveSaving: "Saving…",
16561656
autoSaveSaved: "Saved",
1657+
autoSavePaused: "Autosave paused after reconnect",
1658+
saveNow: "Save",
16571659
autoSaveFailed: "Save failed",
16581660
autoSaveConflict: "Settings changed elsewhere",
16591661
retry: "Retry",

‎ui/src/lib/config/config-draft-model.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,17 @@ function syncConfigDraft(state: RuntimeConfigState, nextForm: Record<string, unk
393393
/**
394394
* Any mutation invalidates a lingering "Saved"/"Save failed" indicator: a
395395
* dirty edit is about to reschedule, and a clean revert makes the old
396-
* failure moot (its error is cleared too). Two states persist regardless:
397-
* "saving" reports the in-flight request, and "conflict" marks the snapshot
398-
* itself stale — only a reload clears it, no local edit can.
396+
* failure moot (its error is cleared too). Three states persist regardless:
397+
* "saving" reports the in-flight request, "conflict" marks the snapshot
398+
* itself stale, and "paused" marks the reconnect latch — only an explicit
399+
* Save/Apply or discard clears it, no local edit can.
399400
*/
400401
function resetStaleAutoSaveStatus(state: RuntimeConfigState) {
401-
if (state.configAutoSaveStatus === "saving" || state.configAutoSaveStatus === "conflict") {
402+
if (
403+
state.configAutoSaveStatus === "saving" ||
404+
state.configAutoSaveStatus === "conflict" ||
405+
state.configAutoSaveStatus === "paused"
406+
) {
402407
return;
403408
}
404409
if (!state.configFormDirty && state.configAutoSaveStatus === "error") {

‎ui/src/lib/config/config-state-model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { ConfigSnapshot, ConfigUiHints } from "../../api/types.ts";
77
import type { ApplicationGatewayPhase } from "../../app/gateway.ts";
88
import { normalizeAgentId } from "../sessions/session-key.ts";
99

10-
export type ConfigAutoSaveStatus = "idle" | "saving" | "saved" | "error" | "conflict";
10+
export type ConfigAutoSaveStatus = "idle" | "saving" | "saved" | "error" | "conflict" | "paused";
1111
export type RuntimeConfigState = {
1212
client: GatewayBrowserClient | null;
1313
connected: boolean;

‎ui/src/lib/config/config-write-coordinator.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export function createConfigWriteCoordinator({
112112
const clearAutoSaveDraftConnection = () => {
113113
autoSaveDraftConnection = null;
114114
autoSaveRequiresExplicitSubmit = false;
115+
if (state.configAutoSaveStatus === "paused") {
116+
state.configAutoSaveStatus = "idle";
117+
}
115118
};
116119
const captureAutoSaveDraftConnection = () => {
117120
if (
@@ -138,6 +141,9 @@ export function createConfigWriteCoordinator({
138141
epoch: currentConfigConnectionEpoch(state),
139142
};
140143
autoSaveRequiresExplicitSubmit = false;
144+
if (state.configAutoSaveStatus === "paused") {
145+
state.configAutoSaveStatus = "idle";
146+
}
141147
};
142148
const canAutoSaveDraftOnCurrentConnection = () =>
143149
!autoSaveRequiresExplicitSubmit &&
@@ -396,8 +402,14 @@ export function createConfigWriteCoordinator({
396402
if (draftBelongsToPreviousConnection) {
397403
// A retained draft belongs to the Gateway connection where the edit
398404
// began. Preserve it across replacement, but require an explicit
399-
// Save/Apply or reload before the new Gateway may receive it.
405+
// Save/Apply or reload before the new Gateway may receive it. The
406+
// latch must be visible: without a rendered state the form looks
407+
// normal while every subsequent edit silently never saves.
400408
autoSaveRequiresExplicitSubmit = true;
409+
// Conflict outranks the latch: that snapshot is stale regardless.
410+
if (state.configAutoSaveStatus !== "conflict") {
411+
state.configAutoSaveStatus = "paused";
412+
}
401413
}
402414
if (autoSaveInFlight !== null || manualSubmitInFlight !== null) {
403415
// The epoch guard already blocks these flights from mutating state;

‎ui/src/lib/config/runtime-config-capability.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,24 @@ describe("runtime config capability", () => {
321321
await vi.advanceTimersByTimeAsync(CONFIG_FORM_AUTO_SAVE_DEBOUNCE_MS * 2);
322322
expect(server.submissions).toHaveLength(0);
323323
expect(runtimeConfig.state.configFormDirty).toBe(true);
324+
// The latch must be operator-visible: without a rendered state the form
325+
// looks normal while every subsequent edit silently never saves.
326+
expect(runtimeConfig.state.configAutoSaveStatus).toBe("paused");
327+
328+
// Further edits do not clear the latch state.
329+
runtimeConfig.patchForm(["count"], 3);
330+
await vi.advanceTimersByTimeAsync(CONFIG_FORM_AUTO_SAVE_DEBOUNCE_MS * 2);
331+
expect(server.submissions).toHaveLength(0);
332+
expect(runtimeConfig.state.configAutoSaveStatus).toBe("paused");
324333

325334
await expect(runtimeConfig.save()).resolves.toBe(true);
326335
expect(server.submissions).toEqual([
327-
{ method: "config.set", raw: '{\n "count": 2\n}\n', baseHash: "hash-1" },
336+
{ method: "config.set", raw: '{\n "count": 3\n}\n', baseHash: "hash-1" },
328337
]);
329338
expect(runtimeConfig.state.configFormDirty).toBe(false);
330339
expect(runtimeConfig.state.configNeedsApply).toBe(true);
340+
// Explicit save rebinds the draft and clears the paused indicator.
341+
expect(runtimeConfig.state.configAutoSaveStatus).not.toBe("paused");
331342
runtimeConfig.dispose();
332343
});
333344

0 commit comments

Comments
 (0)