Skip to content

[bugfix] providers: derive initial chat service fields from its preset - #459

Open
wuli666 wants to merge 1 commit into
ThinkFlowLab:mainfrom
wuli666:fix/chat-service-default-preset
Open

wuli666 wants to merge 1 commit into
ThinkFlowLab:mainfrom
wuli666:fix/chat-service-default-preset

Conversation

@wuli666

@wuli666 wuli666 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

When opening Settings → Model connections → Chat (agent) → Add service (or the first-run language-model form), ModelServiceForm defaulted presetId to "custom" (OpenAI compatible), but initialized the form state with connectionType: "self_hosted", authMode: "none", and an empty url instead of the preset's values (connectionType: "api", authMode: "bearer", url: "https://api.openai.com/v1").

Because http_settings.trust_environment() always bypasses system proxies for connectionType == "self_hosted" origins, users configuring an OpenAI-compatible chat service behind a system proxy hit ConnectError even after explicitly selecting Follow system proxy (proxyMode: "system")—whereas the Image tab worked because users had to manually switch from vllm-omni-image to OpenAI compatible, which invoked chooseProvider("custom") and set connectionType: "api".

  • Add a shared servicePresetDefaults() helper in src/canvas/providerPresets.ts and use it for both initial state and chooseProvider() in src/canvas/ModelServiceForm.tsx, keeping video/image/audio self-hosted defaults unchanged while aligning new agent forms with the "custom" preset.
  • Clear stale discoveryError when proxyMode changes.
  • Add unit tests in tests/providerPresetDefaults.test.ts and real-browser assertions in tests/browser/provider_settings.mjs and tests/browser/first_run.mjs verifying the initial URL, Bearer auth state, and persisted connectionType: "api" / authMode: "bearer".

Linked issue

No existing issue applies (discovered and reproduced locally when configuring an OpenAI chat API behind a system proxy).

  • Fixes #N or Refs #N is included, or no issue applies

Labels

Requested labels: type:bug, area:provider (fork authors cannot apply repository labels directly; left for repository automation / maintainer).

  • Labels applied

Test plan

  • Local:
    • npm test (959 passed, 0 failed, including tests/providerPresetDefaults.test.ts)
    • npm run build (tsc --noEmit && vite build)
    • npm run check:i18n, npm run check:browser-locale, npm run check:browser-manifest
    • .venv/bin/python -m pytest tests/test_self_hosted_proxy.py tests/test_model_configs.py (42 passed)
    • Isolated browser tests with local Chrome + tests/browser/creation_server.py: tests/browser/provider_settings.mjs and tests/browser/first_run.mjs (both passed)
    • Pre-commit hooks (check-merge-conflict, end-of-file-fixer, mixed-line-ending, trailing-whitespace) passed on commit
  • Left to CI:
    • Full Python suite, full Release checks browser matrix, and CodeQL

Evidence that it works

  • Media attached, or N/A because: verified via both isolated browser tests (provider_settings.mjs and first_run.mjs) asserting initial OpenAI compatible URL (https://api.openai.com/v1), unchecked "No key required" checkbox, and persisted connectionType: "api" / authMode: "bearer" receipt, plus local reproduction of trust_environment() returning True for api + system vs False for self_hosted + system. No layout or visual design changed.

Provider verification

  • Real-provider calls are described honestly, or none were made
    • No paid model inference calls were made. All automated tests used local fixtures/doubles (creation_server.py and in-memory HTTP mocks). A local unauthenticated GET https://api.openai.com/v1/models probe confirmed ConnectError under direct vs HTTP 401 under system proxy (127.0.0.1:7897).

Bilingual UI

  • Both locales are updated, or no user-facing copy changed (npm run check:i18n passed with 0 issues)

## summary

- Derive initial new-service fields in ModelServiceForm from the
  selected default preset through a shared servicePresetDefaults helper
  also used by chooseProvider.
- Fix new chat (agent) services starting with preset "custom"
  (OpenAI compatible) while keeping connectionType="self_hosted",
  authMode="none", and an empty URL, which caused trust_environment to
  bypass the system proxy even when proxyMode="system" was selected.
- Clear stale model discovery errors when switching proxyMode.
- Add unit and isolated browser assertions covering default chat preset
  fields and persisted connectionType/authMode.

## validation

- npm test: 959 passed, 0 failed.
- npm run build, npm run check:i18n, npm run check:browser-locale,
  npm run check:browser-manifest: all passed.
- pytest tests/test_self_hosted_proxy.py tests/test_model_configs.py:
  42 passed.
- Isolated browser tests (Chrome + creation_server.py):
  tests/browser/provider_settings.mjs and tests/browser/first_run.mjs
  passed.
@github-actions github-actions Bot added area:provider Model providers and generation protocols type:bug Something is broken labels Nov 23, 2026
@Zhangbo-cn

Copy link
Copy Markdown
Contributor

PASS 421680e (no linked issue)

  • the bug is real and the cause is right: the custom preset id was shown while the state started as self_hosted/none/empty URL, so trust_environment() followed the machine proxy and ConnectError surfaced as a connect failure
  • both paths now derive from servicePresetDefaults() — the initial state and chooseProvider() — which is what removes the divergence instead of patching one call site
  • checked for drift in the other presets: vllm-omni-image/-speech are ""/self_hosted/none with protocol openai, vllm-omni-video is vllm_omni; both equal the previous initialProtocol/self_hosted/none values, so image, video and audio initial state is unchanged and only the chat custom preset actually moves
  • setDiscoveryError("") fires only when proxyMode is patched, so a real discovery error is not swallowed by unrelated edits
  • the user-visible outcome is asserted, not just described: provider_settings.mjs and first_run.mjs check the prefilled https://api.openai.com/v1, "No key required" unchecked, and the saved connectionType: "api" / authMode: "bearer" receipt

Ran: Release checks green on 421680e (13/13, including browser (isolated)); local node --test tests/providerPresetDefaults.test.ts → 2 passed
Not run: local browser lane

Non-blocking: no issue is linked and the template line is unfilled, so there is no acceptance text to check this against — worth opening one so the regression has a home. Also note the product consequence: a new custom chat service now opens prefilled with a remote OpenAI URL, so anyone adding a self-hosted OpenAI-compatible endpoint has to overwrite it. That matches what chooseProvider() already did, so it is consistent rather than new, but it is a visible default change and a screenshot in the PR would close the media item.

Coordinator: ping after this Reviewer PASS and green CI on this SHA. This skill does not merge.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider Model providers and generation protocols type:bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants