Skip to content

fix(settings): reduce settings desync — single source of truth + atomic writes - #249

Open
pnewsam wants to merge 2 commits into
stagingfrom
paul/eng-941-settings-desync-server
Open

fix(settings): reduce settings desync — single source of truth + atomic writes#249
pnewsam wants to merge 2 commits into
stagingfrom
paul/eng-941-settings-desync-server

Conversation

@pnewsam

@pnewsam pnewsam commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description

Saving user settings has been a source of many bugs. We've applied many patches but there are some root causes that have gone unaddressed, as described in ENG-941. This makes a first pass at improving some of the settings code design.

This PR is paired with the frontend PR. It includes two changes:

  • Single source of truth for settings schema and default values The mapping from .env file to SQLite DB and the provider normalization logic existed in multiple places that had drifted apart; this creates one definition in UserSettings; parity tests fail CI if they drift again.
  • New bulk update endpoint Added PUT /settings which writes all keys in an all-or-nothing transaction, to prevent partial writes
  • Fix /test request to read only: removes the update block fromPOST /test-providers, so that it's read-only (note: a stored green dot could outlive a revoked key or drained wallet)

References

pnewsam and others added 2 commits July 28, 2026 12:40
…rmalization (ENG-1125)

Server foundation for the ENG-941 settings-CRUD refactor (PR1). Collapses the
duplicated pieces of the settings contract into single definitions on/near
UserSettings so the client can stop restating them in copies that drift.

- Add SETTING_ENV_ALIASES + ENV_ALIAS_TO_SETTING: one canonical .env<->DB key
  map. migrations._ENV_TO_SETTING now derives from it instead of keeping a
  hand-maintained copy (the client's syncSettings.ts copy had already drifted,
  silently omitting gemini/openai-compatible/router/memory/act_first/etc.).
- Add normalize_provider_value(): one home for the hyphen->underscore +
  minds_cloud detection previously reimplemented in migrations,
  syncSettings.ts, and settingsTransform.js. migrations._normalize_provider_value
  now delegates to it.
- Parity tests so future drift between the alias map, the model, and the
  migration fails CI (incl. pinning the canonical show_dots default that the
  client had wrong).

Client consumes the existing GET /settings/ (already returns every field's
resolved default + options), so no new endpoint is added — the single source is
the server the client already talks to. No storage or auth change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Server half of the ENG-941 settings-CRUD refactor (PR2). Two write-honesty fixes.

Atomic saves: add PUT /settings (bulk), backed by SettingService.save_all, which
validates every key and writes them in one transaction — all-or-nothing. The
Settings form will move onto this from the per-key PUT /{key} loop, which could
leave the DB half-written when one key in a logical save failed. Extracts a
shared _encode_for_store/_write_row helper so upsert_setting and save_all share
one encode path.

No silent write on test: POST /test-providers no longer persists provider_status.
A "test" is a read; persisting it made a stale green dot outlive a revoked key or
a drained wallet and still read as passing (ENG-335). Callers render the returned
results directly.

No storage or auth change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

No PR environment for this pull request

Add the deploy label and push to create one. It is torn down when the label is removed or the PR closes, so any URL you saw here earlier is gone.

Updated on every push to this PR.

@pnewsam
pnewsam marked this pull request as ready for review July 29, 2026 00:26
@pnewsam pnewsam changed the title fix(settings): reduce settings desync — single source of truth + atomic writes [server] (ENG-941) fix(settings): reduce settings desync — single source of truth + atomic writes Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant