Skip to content

🙌 OpenHands: AI-Driven Development

fix(settings): preserve application edits after a failed save (#18372)

Engel Nyst9b90c48f5a8f
diff --git a/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md b/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md
index c9da669f93..ab84f38705 100644
--- a/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md
+++ b/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md
@@ -25,7 +25,7 @@ Source: `src/routes/app-settings.tsx`, `src/components/features/settings/app-set
- `F16.voice-endpoint`: Voice input Base URL, API Key (masked) and Model save on every keystroke in this browser only, independently of Save; the key lives in session storage.
- `F16.git-identity`: Git Username and Git Email save with the form, persist after a reload, and are what the agent's commits use.
- `F16.git-identity-validation`: an email without `@` is refused by native validation; empty fields save the defaults `openhands` / `[email protected]`.
-- `F16.save-states`: Save is enabled only while a saved field differs from the stored value; while a save is pending the whole form, Save included, is replaced by the `app-settings-skeleton` (so the "Saving..." label in the source never shows); success toasts "Settings saved", failure toasts the server's message (`An error occurred` when it has none) and should keep the user's edits for a retry.
+- `F16.save-states`: Save is enabled only while a saved field differs from the stored value; while a save is pending the form stays mounted with a disabled fieldset and a "Saving..." button; success toasts "Settings saved", failure toasts an error and keeps the user's edits and Save enabled for a retry.
- `F16.keyboard`: every control, including the three switches, is reachable with Tab and exposed to assistive technology.
- `F16.phone`: the form fits a 390 px viewport without horizontal overflow and Save is reachable by scrolling.
- `F16.title-model-clear`: the Title generation model combobox has a clear (×) button, shown on hover; it resets the choice to Automatic (recommended).
@@ -67,7 +67,44 @@ Preconditions:
- **Voice input endpoint (`F16.voice-endpoint`).** Run `control-openhands browser fill 'testid=transcription-base-url-input' http://127.0.0.1:9/v1`, `control-openhands browser fill 'testid=transcription-api-key-input' qa-dummy-key`, `control-openhands browser fill 'testid=transcription-model-input' qa-whisper`, then `control-openhands browser enabled 'testid=submit-button'` (`false`) and `control-openhands browser attr 'testid=transcription-api-key-input' type` (`password`). After `control-openhands browser reload`, `control-openhands browser value 'testid=transcription-model-input'` is `qa-whisper` (same for the other two). `control-openhands browser eval "localStorage.getItem('openhands-transcription-endpoint') + ' | session=' + sessionStorage.getItem('openhands-transcription-api-key')"` reads `{"baseUrl":"http://127.0.0.1:9/v1","model":"qa-whisper"} | session=qa-dummy-key`; the API body has no `qa-whisper`. Clear each with `control-openhands browser fill 'testid=transcription-base-url-input' ''` (and the other two). Using the endpoint from the composer microphone is not driven here (needs microphone capture and a transcription server).
- **Git identity (`F16.git-identity`).** Run `control-openhands browser fill 'testid=git-user-name-input' 'QA Tester'`, `control-openhands browser fill 'testid=git-user-email-input' '[email protected]'`, `control-openhands browser click 'testid=submit-button'`, `control-openhands browser wait-text 'Settings saved'`, `control-openhands browser reload`, then `control-openhands browser value 'testid=git-user-name-input'` (`QA Tester`) and `control-openhands api GET /api/settings` (`git_user_name`, `git_user_email` set). Agent half: `control-openhands conversation start --prompt "Run exactly this command and reply with only its output: env | grep -c '^GIT_'; git init -q qa_t && cd qa_t && git commit --allow-empty -qm x; git log -1 --format='%an <%ae>'" --wait --timeout 240`, then `control-openhands conversation events <id> --kinds ObservationEvent,MessageEvent` with the `id` from the start output. Expected: `QA Tester <[email protected]>`. **Known failure:** the observation is `0 Author identity unknown ...`: the identity is stored only in `misc_settings.app_preferences` and never reaches the agent.
- **Git validation and defaults (`F16.git-identity-validation`).** Run `control-openhands browser fill 'testid=git-user-email-input' 'not-an-email'`, `control-openhands browser click 'testid=submit-button'`, then `control-openhands browser eval "document.querySelector('[data-testid=git-user-email-input]').validationMessage"` (`Please include an '@' in the email address. ...`); the API email is unchanged. Then `control-openhands browser fill 'testid=git-user-email-input' ''`, `control-openhands browser fill 'testid=git-user-name-input' ''`, click submit, `control-openhands browser wait-text 'Settings saved'`, `control-openhands browser reload`: the inputs read `openhands` and `[email protected]`, which also restores the baseline.
-- **Save button states (`F16.save-states`).** Click the analytics label once: `control-openhands browser enabled 'testid=submit-button'` is `true`; click it again: `false` (back to the stored value). Each successful save above made while the UI is in English shows the toast found by `control-openhands browser wait-text 'Settings saved'`; the Arabic save and the English restore in `F16.language` are made from a French and an Arabic UI and toast `Paramètres enregistrés` and `تم حفظ الإعدادات` instead (see Gotchas). Pending and failure: run `control-openhands service stop agent-server` (the open page keeps its form), click `testid=app-settings-screen >> text=Sound Notifications`, start a sampler with `control-openhands browser eval "(() => { window.__seen = []; window.__iv = setInterval(() => { const s = document.querySelector('[data-testid=submit-button]'); const k = (s ? s.textContent : '-') + ' skeleton=' + !!document.querySelector('[data-testid=app-settings-skeleton]'); if (window.__seen.at(-1) !== k) window.__seen.push(k); }, 10); return 'started'; })()"`, click `testid=submit-button`, `control-openhands browser wait-text 'An error occurred'` (after three `PATCH /api/settings` attempts answer `502`, `browser network --filter /api/settings` shows them; the ingress's plain-text 502 body carries no server message, so the toast is the generic one, #18051), then `control-openhands browser eval "(() => { clearInterval(window.__iv); return window.__seen.join(' -> '); })()"`: it starts with `Save Changes skeleton=false -> - skeleton=true`, i.e. the form and its Save button are replaced by the skeleton while pending; `Saving...` never appears. By the time the failure toast is read the form has usually come back, adding `-> Save Changes skeleton=false`; assert the prefix. Expected after the failure: the Sound switch stays on so the user can retry. **Known failure:** `control-openhands browser eval "document.querySelector('[data-testid=enable-sound-notifications-switch]').checked"` is `false` and Save is disabled: the edit is silently discarded. Bring the backend back with `control-openhands restart`, `control-openhands doctor`, `control-openhands browser goto /settings/app`.
+- **Save button states (`F16.save-states`).** Click the analytics label once: `control-openhands browser enabled 'testid=submit-button'` is `true`; click it again: `false` (back to the stored value). With the backend healthy, successful saves toast `Settings saved` in English (see the translated-toast gotcha). For a failed save, stop only this run's Agent Server after the page loads, edit Sound Notifications and Git Username, then Save. The error toast is `An error occurred`; both edits remain and Save stays enabled. Restart and doctor without navigating away, then retry: the same edits persist in `misc_settings.app_preferences` and after reload. To inspect the pending state without racing a fast response, pause this run's Agent Server immediately before the retry, inspect the mounted fieldset and `Saving...`, then resume promptly. Resume before stopping the run. A pending Save disables the native fields and never substitutes `app-settings-skeleton`. The recording may pause only while the owned stack restarts.
+
+ ```sh
+ control-openhands restart
+ control-openhands doctor
+ control-openhands browser viewport desktop
+ control-openhands browser goto /settings/app
+ control-openhands browser wait 'testid=submit-button'
+ control-openhands assert --field value --equals false -- browser eval "document.querySelector('[data-testid=enable-sound-notifications-switch]').checked"
+ control-openhands service stop agent-server
+ control-openhands browser record start --feature F16.save-states --name failed-save-desktop
+ control-openhands browser click 'testid=app-settings-screen >> text=Sound Notifications'
+ control-openhands browser click 'testid=submit-button'
+ control-openhands browser wait-text 'An error occurred'
+ control-openhands browser screenshot --feature F16.save-states --name failed-save-desktop
+ control-openhands browser record stop --gif
+ control-openhands restart
+ control-openhands assert --field value --equals true -- browser eval "document.querySelector('[data-testid=enable-sound-notifications-switch]').checked"
+ ```
+
+ ```sh
+ control-openhands restart
+ control-openhands doctor
+ control-openhands browser viewport phone
+ control-openhands browser goto /settings/app
+ control-openhands browser wait 'testid=submit-button'
+ control-openhands assert --field value --equals false -- browser eval "document.querySelector('[data-testid=enable-sound-notifications-switch]').checked"
+ control-openhands service stop agent-server
+ control-openhands browser record start --feature F16.save-states --name failed-save-phone
+ control-openhands browser click 'testid=app-settings-screen >> text=Sound Notifications'
+ control-openhands browser click 'testid=submit-button'
+ control-openhands browser wait-text 'An error occurred'
+ control-openhands browser screenshot --feature F16.save-states --name failed-save-phone
+ control-openhands browser record stop --gif
+ control-openhands restart
+ control-openhands assert --field value --equals true -- browser eval "document.querySelector('[data-testid=enable-sound-notifications-switch]').checked"
+ ```
+
- **Keyboard and screen readers (`F16.keyboard`).** Run `control-openhands browser focus 'testid=color-theme-input'`, then repeat `control-openhands browser press Tab` and `control-openhands browser eval "(document.activeElement.getAttribute('data-testid')||'') + ' ' + document.activeElement.tagName"`. Expected (the acceptance criterion): focus visits the three switches before `title-llm-profile-input`. The first Tab lands on `enable-analytics-switch`, followed by `enable-sound-notifications-switch` and `show-getting-started-checklist-switch`; Space toggles the focused checkbox. `control-openhands browser snapshot 'testid=app-settings-screen' --feature F16.keyboard --name aria` exposes each checkbox label and checked state. The label draws a visible focus outline.
```sh
@@ -120,6 +157,6 @@ Preconditions:
- The Title generation model combobox has a clear (×) button with no accessible name (`- button` in the snapshot, visible as × at phone width). At desktop width it only takes clicks after `browser hover` on the input (`F16.title-model-clear`); otherwise use the Automatic option.
- `browser eval` wraps its argument as an expression: statements separated by `;` fail with `SyntaxError: Unexpected token ';'`; wrap them in `(() => { ...; return x; })()`.
- With `service stop agent-server`, a `browser reload` of `/settings/app` shows the backend-unavailable screen (`agent-server-onboarding-screen`, Manage backends), not the form: stop the service only after the page is loaded, and `restart` afterwards.
-- Known product bugs (repro candidates): git identity never reaches the agent (#17899); a failed save discards the user's edits (`F16.save-states`) (#17927).
+- Known product bugs (repro candidates): git identity never reaches the agent (#17899).
- The harness builds with `VITE_DO_NOT_TRACK=1`, so PostHog never starts: `browser network --filter 'posthog|z\.openhands\.dev'` reports `total` `0`, also after analytics consent is granted (#18086). A browser-only Do Not Track setting is outside this recipe. Consent reversal requires the explicit non-DNT build and loopback-only analytics configuration described above, served with `launch --build never` (`F16.analytics`).
- The title model's clear button has no test id: the recipe's xpath relies on DOM nesting to skip the unnamed `Show suggestions` button. If both ever match, Playwright's strict mode fails the click instead of pressing the wrong one; report it as harness drift.
diff --git a/__tests__/routes/app-settings.test.tsx b/__tests__/routes/app-settings.test.tsx
index aaa8c7f27d..0bfb04a817 100644
--- a/__tests__/routes/app-settings.test.tsx
+++ b/__tests__/routes/app-settings.test.tsx
@@ -7,6 +7,15 @@ import SettingsService from "#/api/settings-service/settings-service.api";
import { MOCK_DEFAULT_USER_SETTINGS } from "#/mocks/handlers";
import { Settings } from "#/types/settings";
import ProfilesService from "#/api/profiles-service/profiles-service.api";
+import {
+ displayErrorToast,
+ displaySuccessToast,
+} from "#/utils/custom-toast-handlers";
+
+vi.mock("#/utils/custom-toast-handlers", () => ({
+ displayErrorToast: vi.fn(),
+ displaySuccessToast: vi.fn(),
+}));
const activeBackendState = vi.hoisted(() => ({
id: "local",
@@ -73,6 +82,69 @@ describe("AppSettingsScreen", () => {
activeBackendState.kind = "local";
});
+ it("keeps edits after a failed save and lets the user retry successfully", async () => {
+ // Arrange: a real save mutation remains pending until the service rejects.
+ const user = userEvent.setup();
+ let storedSettings = buildSettings({ enable_sound_notifications: false });
+ vi.spyOn(SettingsService, "getSettings").mockImplementation(
+ async () => storedSettings,
+ );
+ let rejectSave!: (error: Error) => void;
+ const save = vi
+ .spyOn(SettingsService, "saveSettings")
+ .mockImplementationOnce(
+ () =>
+ new Promise((_resolve, reject) => {
+ rejectSave = reject;
+ }),
+ );
+ renderAppSettingsScreen();
+ const sound = await screen.findByTestId(
+ "enable-sound-notifications-switch",
+ );
+ const name = screen.getByTestId("git-user-name-input");
+
+ // Act: edit both a switch and an uncontrolled text input, then save.
+ await user.click(sound);
+ await user.clear(name);
+ await user.type(name, "QA Tester");
+ await user.click(screen.getByTestId("submit-button"));
+
+ // Assert: inputs remain mounted during the request, with a pending button.
+ expect(sound).toBeInTheDocument();
+ expect(screen.getByTestId("submit-button")).toHaveTextContent(
+ "SETTINGS$SAVING",
+ );
+ expect(screen.getByTestId("submit-button")).toBeDisabled();
+ rejectSave(new Error("Save failed"));
+ await waitFor(() =>
+ expect(displayErrorToast).toHaveBeenCalledWith("Save failed"),
+ );
+ expect(sound).toBeChecked();
+ expect(name).toHaveValue("QA Tester");
+ expect(screen.getByTestId("submit-button")).toBeEnabled();
+
+ // Act: retry; the service persists the submitted values and refetches them.
+ save.mockImplementationOnce(async (settings) => {
+ storedSettings = buildSettings(settings);
+ return true;
+ });
+ await user.click(screen.getByTestId("submit-button"));
+
+ // Assert: the retry sends the same edit, then the form is clean.
+ await waitFor(() =>
+ expect(displaySuccessToast).toHaveBeenCalledWith("SETTINGS$SAVED"),
+ );
+ expect(save).toHaveBeenLastCalledWith(
+ expect.objectContaining({
+ enable_sound_notifications: true,
+ git_user_name: "QA Tester",
+ }),
+ );
+ expect(screen.getByTestId("submit-button")).toBeDisabled();
+ expect(sound).toBeChecked();
+ });
+
it("renders the OSS application settings form", async () => {
vi.spyOn(SettingsService, "getSettings").mockResolvedValue(
buildSettings({
diff --git a/src/routes/app-settings.tsx b/src/routes/app-settings.tsx
index 3ffda1ef40..639a21dfd1 100644
--- a/src/routes/app-settings.tsx
+++ b/src/routes/app-settings.tsx
@@ -100,6 +100,7 @@ function AppSettingsForm() {
[llmProfiles?.profiles, freeModels, t],
);
+ // @spec APS-001 — Clear the application draft only after a successful save.
const formAction = (formData: FormData) => {
const languageLabel = formData.get("language-input")?.toString();
const languageValue = AvailableLanguages.find(
@@ -133,12 +134,6 @@ function AppSettingsForm() {
onSuccess: () => {
void setTelemetryConsent(enableAnalytics ? "granted" : "denied");
displaySuccessToast(t(I18nKey.SETTINGS$SAVED));
- },
- onError: (error) => {
- const errorMessage = retrieveAxiosErrorMessage(error);
- displayErrorToast(errorMessage || t(I18nKey.ERROR$GENERIC));
- },
- onSettled: () => {
setLanguageInputHasChanged(false);
setAnalyticsSwitchHasChanged(false);
setSoundNotificationsSwitchHasChanged(false);
@@ -146,6 +141,10 @@ function AppSettingsForm() {
setGitUserEmailHasChanged(false);
setTitleLlmProfileInput(undefined);
},
+ onError: (error) => {
+ const errorMessage = retrieveAxiosErrorMessage(error);
+ displayErrorToast(errorMessage || t(I18nKey.ERROR$GENERIC));
+ },
},
);
};
@@ -192,18 +191,20 @@ function AppSettingsForm() {
!gitUserNameHasChanged &&
!gitUserEmailHasChanged;
- const shouldBeLoading =
- !settings || isLoading || areLlmProfilesLoading || isPending;
+ const shouldBeLoading = !settings || isLoading || areLlmProfilesLoading;
return (
<form
data-testid="app-settings-screen"
- action={formAction}
+ onSubmit={(event) => {
+ event.preventDefault();
+ if (!isPending) formAction(new FormData(event.currentTarget));
+ }}
className="flex flex-col gap-6"
>
{shouldBeLoading && <AppSettingsInputsSkeleton />}
{!shouldBeLoading && (
- <div className="flex flex-col gap-6">
+ <fieldset disabled={isPending} className="flex min-w-0 flex-col gap-6">
<LanguageInput
name="language-input"
defaultKey={settings.language}
@@ -318,7 +319,7 @@ function AppSettingsForm() {
</BrandButton>
</div>
</div>
- </div>
+ </fieldset>
)}
</form>
);