Skip to content

fix(platform): keep custom provider edits whole and version-checked - #3778

Merged
yannickmonney merged 5 commits into
mainfrom
fix/provider-credential-edit-save
Sep 29, 2026
Merged

yannickmonney merged 5 commits into
mainfrom
fix/provider-credential-edit-save

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Two defects in the edit dialog of an organization-defined ("custom") provider's credential. Both are reproduced on main in a real browser and fixed here as two distinct regression cases, plus one adjacent defect that the browser reproduction surfaced.

What changed

1. fix(platform): save a custom provider edit against the version it showed (#3663)

  • GET /api/app/providers/catalogs now gives each organization-defined provider a definitionHash: the hash of the file its facts were read from. loadOrgCustomProviderSnapshots takes the facts and the hash from the same bytes.
  • The dialog carries that version with the facts. If the definition has moved since, the hook refuses with CONFIG_VERSION_CONFLICT ("The provider changed since it was loaded. Reopen the dialog and try again."; the existing message, in all locales) and refetches the listing.
  • CredentialEditDialog stays mounted with its table row, so it now seeds its form when it opens rather than only at mount. It shows, and saves against, the listing as it is at that moment.

2. fix(platform): save custom provider credential and definition together (#3662)

  • New strict door POST /api/app/provider-credentials/{id}/with-definition, body {name?, modelAllowlist?, endpointUrl?, expectedHash, definition: {config, expectedHash}}. An unknown field gets a 400 rather than being dropped. The body is JSON-only with the definition door's duplicate-key refusal (now the shared parseNativeJsonBody).

  • updateCredentialWithDefinition runs both parts inside the definition save's transaction, under the providers config lock:

    1. the definition's compare-and-set;
    2. the credential row locked FOR UPDATE and updated through updateCredential against its own hash;
    3. the audit rows;
    4. the definition file, written last.

    A duplicate name, a stale definition or a stale credential is therefore refused before either part changes.

  • saveProviderDefinition gains an alongside hook. A file that fails its readback gets its reviewed preimage back while the lock still holds.

  • The hook sends one request with both reviewed hashes, and refetches the catalog and credential reads after a save or a refusal. The dialog shows the refusal inline, without the generic "Try again" toast.

  • The providers guide (EN/DE/FR) says a save changes both parts or neither. The manual layer gains SET-B21, updated error-code rows and an updated automation register row.

3. fix(platform): keep an open credential dialog across list refetches

Review: 90a6c5d18 fix(platform): preserve provider saves after uncertain commits (maintainer)

  • This supersedes this PR's first take-back of a published file after a failed COMMIT. A lost acknowledgement does not prove a rollback, and compensating outside the lock could undo a committed save.
  • A lost acknowledgement now rewinds nothing. The docs tell the reader to reload and check both parts before retrying.
  • The lane gains a check for a committed save behind an injected lost acknowledgement. 60eff1864 merges main.

Verification

All local checks below ran on the exact head 60eff1864 unless noted.

  • Unit / component:
    • Server project 322/322 across backend/domains/providers, provider_credentials, configuration-writes, core/lib/providers and the adapter-row suite.
    • UI project: the settings providers, credentials and connectors suites pass. Under this sandbox host's load (load average about 20), four typing-heavy add-flow tests hit the 5 s timeout and pass with --testTimeout 30000. On bd06d45da the same suites plus data-residency passed 192/192 at the default timeout, and CI's UI job passed there.
    • New suites:
  • Mutation checks (on bd06d45da): each mutation turns its guard test red:
    • the table columns rebuilt on every refetch;
    • no re-seed on open;
    • the hook saving against the hash read at Save;
    • the credential written after the file;
    • no take-back after a failed readback;
    • no definitionHash in the listing;
    • a non-strict door.
  • Real PostgreSQL: ITEST_LANES=checkProviderCredentials,checkProviderCredentialConfiguration,checkCustomProviderCredentialEdit bun run backend:integration on a disposable pgserver cluster passes 32/33. The one FAIL, knowledge BM25 indexes verified at boot (no pg_search in pgserver), also fails on main: the two existing lanes alone give 26/27 there. The lane's six checks, each with readback through the doors a reloaded page reads:
    • a successful edit saves both parts;
    • a native duplicate name → 409 CREDENTIAL_NAME_TAKEN, provider unchanged;
    • a definition moved through the native door → 409 CONFIG_VERSION_CONFLICT, newer base URL kept;
    • a credential renamed elsewhere → 409, rename kept;
    • a lost acknowledgement leaves the committed save in place;
    • a read-only providers directory → 500, with the credential UPDATE the transaction had already run rolled back.
  • Gates (on bd06d45da): type-aware oxlint on every changed file, oxfmt --check, local Opengrep (0 findings), lint:manual, check-guide on settings.md, and the docs locale/link/anchor suites. Type-aware oxlint was re-run on the files the review commit touched.

Browser evidence

This is the local stack (pgserver, backend and Vite) driven by Playwright, on a fresh organization per run. The screenshots and step logs are attached to the tracking task.

Case main e3943c5f5 This PR 60eff1864 (and bd06d45da)
#3662: Base URL v1→v2 plus a rename onto sibling B, Save, Cancel PUT definition → 200, POST credential → 409. The definition reads back as display name "B", base URL v2; a reload shows v2 One POST …/with-definition → 409, inline refusal only. The definition and credential are unchanged (same hash); a reload shows v1. A free name then saves both parts
#3663: editor opened at v1, v2 saved through the native door, name-only Save The older editor saves; v1 is back Refused inline with no write; v2 kept. Reopened, the editor shows v2 and the rename saves
#3663: v2 saved in another session's dialog The older editor is closed by the refetch. Reopened, it still shows v1; Save restores v1 The older editor stays open with its typed name. Save is refused; v2 kept. Reopen, and the rename saves

The visual-aspect-analyzer on the providers page, with and without the edit dialog open, gives the same result on main and on bd06d45da: score 98 from two pre-existing load-time layout shifts of the settings layout. Nothing is affected by this change, and no new defect appears.

Notes

  • No provider calls anywhere. Hosts are .invalid, catalog source is none, and credentials are synthetic TALE_PROVIDER_KEY_TALE77_* env references. The local stack's shipped catalog left out the two live-listing providers (OpenRouter, Vercel AI Gateway); the backend logs show no catalog fetch attempt.
  • Left as they were, and out of scope here:
    • An edit of a shipped provider's credential still saves last-writer-wins; the plain door takes an optional expectedHash the dialog does not send.
    • The create flow's rollback delete does not name the hash it created.

Closes #3662
Closes #3663

yannickmonney and others added 5 commits September 28, 2026 22:21
The edit dialog for an organization-defined provider's credential showed
the provider's facts from the catalog listing, then read the definition
again at Save and sent that fresh hash as the precondition. A dialog opened
before another administrator's save therefore wrote its older base URL or
API format back over theirs, and the native compare-and-set could not
refuse it (#3663).

The catalog listing now gives each organization-defined provider the hash
of the file its facts were read from, the dialog carries that version with
the facts, and the save names it: a definition that moved since is refused
with CONFIG_VERSION_CONFLICT ("The provider changed since it was loaded.
Reopen the dialog and try again.") instead of being overwritten, and the
listing refetches so the reopened dialog reads the newer version.

The shared edit dialog stays mounted with its table row, so it now seeds
its form on the open transition rather than only at mount: what it shows,
and the version it saves against, are the listing's when it opens.

Closes #3663
Editing an organization-defined provider's credential saved the provider
definition first and the credential second, as two independent writes.
When the credential was refused, for example because a sibling credential
already carried the new name (409 CREDENTIAL_NAME_TAKEN), the provider's
new base URL and display name had already landed and stayed after Cancel
(#3662).

The dialog now sends one request, POST
/api/app/provider-credentials/{id}/with-definition: the credential's
fields, its reviewed hash, and the definition with the hash its facts were
read at. The door is strict (an unknown field is refused, never dropped)
and takes JSON the way the definition door does. The server runs both
parts in the definition save's transaction under the providers lock: the
definition's compare-and-set first, then the credential row locked FOR
UPDATE and updated against its own hash, and the definition file written
last. A refused name, a definition or a credential saved since the dialog
read it therefore writes neither part. A file that fails its readback, or
a transaction that fails to commit after the file was written, puts the
reviewed preimage back, and only while the file still holds that save's
bytes, so a later writer is never undone.

The catalog listing's hash moves with every save, so the hook also
refetches the credential reads after a save or a refusal. The new
checkCustomProviderCredentialEdit lane proves the rollback on real
PostgreSQL, including a credential update undone when the definition
file cannot be written. The providers guide (EN/DE/FR) says a save
changes both or neither, and the manual layer gains SET-B21.

Closes #3662
The credential table rebuilt its column set whenever the credential list
changed, because the delete dialog's sibling count was read from a map
the columns memo depended on. TanStack renders a function cell as a
component, so every rebuilt column set remounted each row's actions, and
with them any edit, replace or delete dialog open on the row.

Another session's save of any credential in the organization hints the
list to refetch, so an administrator's edit in progress vanished,
typed input included. Observed while reproducing #3663 in a browser:
the older editor closed instead of reaching Save. The sibling count now
rides on the row data and the columns stay stable, so the open dialog
keeps what was typed, and a save against a moved provider gets its
refusal on screen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant