Skip to content

fix(speech): show "Saved key kept" hint for equivalent OpenAI-compatible base URLs - #49231

Merged
nwparker merged 1 commit into
stablyai:mainfrom
YannVanneth:fix/openai-compatible-saved-key-hint
Nov 25, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
YannVanneth:fix/openai-compatible-saved-key-hint

Conversation

@YannVanneth

@YannVanneth YannVanneth commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When an API key is already saved for an OpenAI-compatible voice provider, the settings dialog shows "Saved key kept". That hint disappeared if you only added a trailing / or pasted the full transcription URL, as if the key would be lost. Saving actually kept it. The hint now matches what saving does.

What Changed

  • Before: the dialog compared the raw saved and typed base URLs (saved.baseUrl === baseUrl.trim()), so any change in spelling swapped "Saved key kept" for "Optional for local servers", while the store kept the key for any URL that resolves to the same transcription endpoint.
  • After: the dialog and the store both use one rule, isSameOpenAiCompatibleEndpoint, which compares the transcription endpoints the two URLs resolve to. An invalid or half-typed URL returns false instead of throwing.
  • Mechanism: openAiCompatibleTranscriptionUrl moved from the main-process store to src/shared/speech/openai-compatible-endpoint.ts so the renderer can use it, next to the new isSameOpenAiCompatibleEndpoint. The trailing-slash trim switched from the /\/+$/ regex to a linear scan, because that regex backtracks quadratically on long slash runs and the function now runs on every keystroke.

Why

The dialog and the store each had their own rule, and they disagreed. One shared helper keeps them in step without duplicating URL parsing in the renderer. Which keys are kept is unchanged: a different host, scheme, port or path still drops the saved key.

Linked Issue

Fixes #49201

Original fix by @YannVanneth in #49231; final version reworked during the bug bash.

Reported by @Minidoracat

Visual Proof

Saved base URL https://api.groq.com/openai/v1, then a trailing / typed. Screenshots from the original PR (the dialog change is unchanged):

Before After
before after

Testing

Repro: Settings → Voice → OpenAI-compatible provider with a saved key, then add a trailing / to the base URL or paste the full /audio/transcriptions URL.

Verification:

  • New src/shared/speech/openai-compatible-endpoint.test.ts covers equivalent forms (whitespace, trailing slashes, full transcriptions URL), a different endpoint, and invalid URLs without throwing. vitest run src/shared/speech src/main/speech: 7/7 passed.

  • A throwaway happy-dom probe (not committed) rendered the real dialog and checked the API key placeholder for 13 typed URLs. Trailing /, full and slash-terminated transcriptions URLs, padding, uppercase scheme/host and an explicit :443 all show "Saved key kept". /v2, http:, another host, embedded credentials, a missing scheme and an empty field all show "Optional for local servers". 13/13 passed.

  • oxfmt, oxlint, the anti-slop and code-quality oxlint configs, ast-grep and the changed-code quality gate are clean on the changed files.

  • Platforms: macOS (unit and component tests). The change is pure URL logic with no OS, path or shell dependence.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because this only runs in the voice provider settings dialog. Measured with Node 24: the per-keystroke check costs about 0.7 µs (before: about 0.01 µs for a string compare). For a URL with 20,000 trailing slashes it takes 25 µs, compared with 162 ms for the old regex in the store. A 100k-character path takes 111 µs. No new I/O, IPC, polling or subprocesses.

Risk

Level: Low

The shared function also builds the URL that receives the key. Apart from the trailing-slash trim, which gives the same result, its logic is unchanged. If the comparison were wrong, the hint would be wrong, or a blank key field would keep or drop the saved key incorrectly. The stored format and IPC contract are unchanged, so a plain revert backs it out.

Review

The store still refuses to reuse the saved key for a different host, scheme or path. UI copy and layout are unchanged.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No security, cross-platform, SSH/remote, mobile or backwards-compatibility impact: the logic is pure string/URL handling and the IPC contract and stored format are unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change moves OpenAI-compatible transcription URL normalization into a shared module and adds endpoint comparison. The provider store uses that comparison when retaining a saved key. The provider dialog uses the same comparison to determine whether to show the saved-key hint.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 28a6b

The provider dialog's saved-key hint now follows the same endpoint-equivalence rule the store uses when it retains a key. No new risk was identified, and the change is safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#49201] requires the OpenAI-compatible dialog saved-key hint to use the store's same-endpoint rule. At the reviewed head, OpenAiCompatibleProviderDialog.tsx uses isSameOpenAiCompatibleEndpoint(saved.…
Out of Scope Changes check Passed Each changed file supports the endpoint-equivalence rule. The dialog change implements the hint fix. The new shared module holds the URL logic moved from the store, plus isSameOpenAiCompatibleEndpoint…
Title check Passed The title names the main change: the dialog now shows the "Saved key kept" hint for base URLs that resolve to the same OpenAI-compatible transcription endpoint. The changeset adds the shared isSameOpe…
Description check Passed The description follows the repository template closely. It covers ELI5, What Changed (before and after with the mechanism), Why, Linked Issue (Fixes #49201), Visual Proof (before and after screenshot…
Full details: Linked Issues check

Explanation

[#49201] requires the OpenAI-compatible dialog saved-key hint to use the store's same-endpoint rule. At the reviewed head, OpenAiCompatibleProviderDialog.tsx uses isSameOpenAiCompatibleEndpoint(saved.baseUrl, baseUrl) instead of an exact string comparison. The shared function in src/shared/speech/openai-compatible-endpoint.ts normalizes both URLs with openAiCompatibleTranscriptionUrl and compares the results. A trailing '/' and a full '/audio/transcriptions' URL normalize to the same endpoint, so the hint stays. Invalid or partial input throws inside the helper, which catches it and returns false, so the hint hides. The store's savedKeyFor now calls the same helper. Its error paths return '' for a null saved provider, an invalid saved URL, or an invalid typed URL, as before, so the key-retention behavior is unchanged. The trailing-slash trim is now a linear loop instead of //+$/; it strips the same characters. Residual uncertainty: the Windows report in the issue was not reproduced. The PR reports Linux headless rendering checks, and the logic is platform-independent.

Full details: Out of Scope Changes check

Explanation

Each changed file supports the endpoint-equivalence rule. The dialog change implements the hint fix. The new shared module holds the URL logic moved from the store, plus isSameOpenAiCompatibleEndpoint. The store change replaces its inline comparison in savedKeyFor with the shared helper and updates a comment. The import-only changes in cloud-transcription-target.ts and openai-api-key-verification.ts keep those modules on the shared helper. The new test file covers the new helper. One small difference from the PR description: it says the moved function is unchanged, but the trailing-slash trim was rewritten as a linear loop. The commit message explains this as a per-keystroke performance choice, and the behavior is equivalent, so this is a justified supporting change, not unrelated work.

Full details: Title check

Explanation

The title names the main change: the dialog now shows the "Saved key kept" hint for base URLs that resolve to the same OpenAI-compatible transcription endpoint. The changeset adds the shared isSameOpenAiCompatibleEndpoint helper, moves openAiCompatibleTranscriptionUrl to a shared module, and updates the dialog and store to use the same rule. The title uses the conventional fix(speech) prefix and is 82 characters, which is slightly long but still specific and readable.

Full details: Description check

Explanation

The description follows the repository template closely. It covers ELI5, What Changed (before and after with the mechanism), Why, Linked Issue (Fixes #49201), Visual Proof (before and after screenshots), Testing with concrete steps and results, Performance with a measured justification, Risk with level and rollback, AI Disclosure, the agent skill boundary checkbox, and the checklist. Gaps: the Visual Proof screenshots are hosted on another contributor's fork and come from the original PR, not this branch. The unchecked 'manually tested' box and the unchecked lint/typecheck/test/build checklist item leave verification status unclear. The AI Disclosure section is left as the template placeholder. These are minor relative to the overall completeness.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05d8af38-2ff3-40d4-81fa-4a0e417a8982
Commits

Reviewing files that changed from the base of the PR and between 4301e40 and 28a6b6c.

Files selected for processing: 6

  • src/main/speech/cloud-transcription-target.ts
  • src/main/speech/openai-api-key-verification.ts
  • src/main/speech/openai-compatible-speech-provider-store.ts
  • src/renderer/src/components/settings/voice/OpenAiCompatibleProviderDialog.tsx
  • src/shared/speech/openai-compatible-endpoint.test.ts
  • src/shared/speech/openai-compatible-endpoint.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…ble base URLs

The OpenAI-compatible provider dialog compared the raw saved and typed
base URLs, so a trailing slash or the full /audio/transcriptions URL hid
the "Saved key kept" hint even though the store keeps the key for any URL
that resolves to the same transcription endpoint.

Move openAiCompatibleTranscriptionUrl to a shared module next to a new
isSameOpenAiCompatibleEndpoint, and use it in both the dialog and the
store so they apply the same rule. Trailing slashes are trimmed with a
linear scan instead of a backtracking regex since the dialog now runs it
per keystroke.

Fixes stablyai#49201

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/openai-compatible-saved-key-hint branch from 4301e40 to 28a6b6c Compare November 25, 2026 20:25
@nwparker nwparker changed the title fix(voice): keep the saved-key hint when the base URL only changes form fix(speech): show "Saved key kept" hint for equivalent OpenAI-compatible base URLs Nov 25, 2026
@nwparker
nwparker merged commit 98014fe into stablyai:main Nov 25, 2026
57 of 58 checks passed
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.

[Bug]: OpenAI-compatible provider dialog drops the "Saved key kept" hint when only the base URL’s form changes

2 participants