Skip to content

fix: robust provider handling when credentials are misconfigured#10080

Merged
catrielmuller merged 5 commits intomainfrom
foam-log
May 8, 2026
Merged

fix: robust provider handling when credentials are misconfigured#10080
catrielmuller merged 5 commits intomainfrom
foam-log

Conversation

@catrielmuller
Copy link
Copy Markdown
Contributor

@catrielmuller catrielmuller commented May 8, 2026

Context

https://kilo-code.slack.com/archives/C09GD7US2UB/p1778004884354009

When a provider (e.g. Kilo Gateway) is configured with wrong credentials, the CLI was printing raw error messages to stdout before the TUI started, and the /connect dialog was hiding the failed provider so users couldn't reconnect with new credentials.

Three problems are fixed:

  1. Errors from provider/model fetching were printed to the terminal instead of going to the log file.
  2. When the Kilo Gateway org-scoped endpoint returned 401 (wrong kilocodeOrganizationId), models were silently empty and the provider was dropped from the UI entirely.
  3. /connect didn't show already-connected providers that had failed, making it impossible to re-enter credentials.

Implementation

Silent errors (packages/kilo-gateway/)

  • fetchKiloModels now returns a typed KiloModelsResult = { models, error? } instead of throwing or calling console.error. Network/auth failures are surfaced as a discriminated error kind without printing to stdout.
  • modes.ts: removed all console.warn calls — failures silently return [].
  • bootstrap.ts: downgraded the "bootstrapping" log from logInfo to logDebug so it no longer appears in the TUI on every startup.

401 fallback (packages/kilo-gateway/src/api/models.ts)

  • When the org-scoped authenticated request returns 401, fetchKiloModels automatically retries against the public unauthenticated endpoint. The provider stays usable with the public model list while the user re-authenticates.

Per-provider failure state (packages/opencode/src/provider/model-cache.ts)

  • ModelCache tracks which providers have a fetch error via failedProviders() / getFailure().
  • clear() also resets failure state.

Provider list route (provider.ts + httpapi handler)

  • Connected providers with 0 models are no longer filtered out — a provider in a failed-auth state stays in provider_next.all so /connect can list it.
  • Response now includes failed: string[] (provider IDs with fetch errors).
  • Provider.ListResult schema updated; both Hono and Effect HttpApi routes updated for parity.

/connect dialog TUI

  • Failed providers show a red ! gutter indicator and (reconnect) description suffix, implemented in the Kilo-isolated override (src/kilocode/cli/cmd/tui/component/dialog-provider.tsx) and consumed via a single kilocode_change in the upstream file.

SDK + story fixture

  • packages/sdk/js/src/gen/types.gen.ts: added failed: Array<string> to ProviderListResponses.
  • packages/kilo-vscode/webview-ui/src/stories/history.stories.tsx: added failed: [] to the story fixture to match the updated type.

Tests

  • packages/kilo-gateway/test/api/models.test.ts — 5 tests for typed result and 401 fallback (lives in gateway package to avoid Bun mock.module cross-contamination).
  • packages/opencode/test/kilocode/kilo-models-401-fallback.test.ts — integration: ModelCache correctly surfaces 401 errors from the gateway.
  • packages/opencode/test/kilocode/provider-list-failed-state.test.ts — 5 tests for failedProviders() / getFailure() lifecycle.
  • Updated stubs in kilo-loader-auth.test.ts and model-cache-org.test.ts to use the new { models } return shape.

packages/opencode/AGENTS.md — added Fork Isolation Rule documenting the mirror-file pattern.

Screenshots

before after
Terminal shows raw errors + provider missing from /connect Errors go to log; failed provider shows with ! and (reconnect) in /connect

How to Test

  1. Configure Kilo Gateway with a bad kilocodeOrganizationId (e.g. via kilo.json provider.kilo.options.kilocodeOrganizationId = "bad-org").
  2. Start kilo — no error output should appear in the terminal on startup.
  3. Open /connect — the Kilo provider should appear with a red ! and (reconnect) description.
  4. Select it and enter valid credentials — it should reconnect and the ! should disappear.
  5. With a valid token but bad org ID, models should still load (from the public fallback endpoint).

Get in Touch

catrielmuller on Discord.

Comment thread packages/opencode/src/server/routes/instance/provider.ts Outdated
Comment thread packages/opencode/src/server/routes/instance/httpapi/handlers/provider.ts Outdated
Comment thread packages/kilo-gateway/src/api/models.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 8, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

No new inline issues found in the incremental diff.

Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
packages/kilo-gateway/src/api/modes.ts 94 Organization mode fetch failures still call console.warn, which can reintroduce the raw terminal/TUI output this PR is trying to avoid.

Fix these issues in Kilo Cloud

Files Reviewed (8 files)
  • packages/opencode/src/project/bootstrap.ts - 0 issues
  • packages/opencode/src/provider/model-cache.ts - 0 issues
  • packages/opencode/src/server/routes/instance/httpapi/handlers/provider.ts - 0 issues
  • packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts - 0 issues
  • packages/opencode/src/server/routes/instance/project.ts - 0 issues
  • packages/opencode/src/session/instruction.ts - 0 issues
  • packages/opencode/test/config/agent-color.test.ts - 0 issues
  • packages/ui/src/components/provider-icons/types.ts - 0 issues

Reviewed by gpt-5.5-2026-04-23 · 970,621 tokens

@catrielmuller catrielmuller merged commit 8628793 into main May 8, 2026
16 checks passed
@catrielmuller catrielmuller deleted the foam-log branch May 8, 2026 19:46
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.

2 participants