Skip to content

fix: fallback header preservation, kimi credential pool, TUI stale model display - #6754

Merged
teknium1 merged 4 commits into
mainfrom
hermes/hermes-f409204f
Apr 9, 2026
Merged

fix: fallback header preservation, kimi credential pool, TUI stale model display#6754
teknium1 merged 4 commits into
mainfrom
hermes/hermes-f409204f

Conversation

@teknium1

@teknium1 teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Salvage of PRs #6076, #6399 by @SeeYangZhi (PR #5797 superseded by #6076).

Three related fallback fixes:

1. Fallback drops provider-specific headers (from #6076)

_try_activate_fallback() saved _client_kwargs with only api_key and base_url, dropping default_headers. Every subsequent API call via _create_request_openai_client() rebuilt a headerless client, causing 403s from providers like Kimi that require User-Agent: KimiCLI/x.x.

Fix: Extract _custom_headers from the fallback client and include them in _client_kwargs.

2. Auxiliary client custom endpoint missing headers (from #6076/#5797)

resolve_provider_client() created bare OpenAI() clients in the custom endpoint branch without header injection. Also bumps all KimiCLI version strings from 1.0 to 1.3. Adds kimi-coding base_url resolution in credential pool seeding.

3. TUI status bar shows stale model after fallback (from #6399)

_get_status_bar_snapshot() read self.model (CLI instance, set at init) instead of agent.model (updated live by fallback). Fix: read agent.model first, fall back to self.model.

Files changed

  • run_agent.py — preserve fallback client headers in _client_kwargs
  • agent/auxiliary_client.py — KimiCLI 1.0→1.3, header injection in custom endpoint branch
  • agent/credential_pool.py — kimi-coding base_url resolution in pool seeding
  • hermes_cli/auth.py — comment fix (platform.kimi.ai → kimi.com/code)
  • cli.py — status bar reads live agent.model

Test results

  • 205 passed, 3 pre-existing failures (unrelated TestCLIUsageReport mock gap)
  • E2E validated: header preservation, version bumps, credential pool, status bar

Attribution

All commits cherry-picked from @SeeYangZhi with original authorship preserved.

…lback

When _try_activate_fallback() swaps to a new provider (e.g.
kimi-coding), resolve_provider_client() correctly injects
provider-specific default_headers (like KimiCLI User-Agent) into the
returned OpenAI client. However, _client_kwargs was saved with only
api_key and base_url, dropping those headers.

Every subsequent API call rebuilds the client from _client_kwargs via
_create_request_openai_client(), producing a bare OpenAI client without
the required headers. Kimi Coding rejects this with 403; Copilot would
lose its auth headers similarly.

This patch reads _custom_headers from the fallback client (where the
OpenAI SDK stores the default_headers kwarg) and includes them in
_client_kwargs so any client rebuild preserves provider-specific headers.

Fixes #6075
…ding pool

The credential pool seeder (_seed_from_env) hardcoded the base URL
for API-key providers without running provider-specific auto-detection.
For kimi-coding, this caused sk-kimi- prefixed keys to be seeded with
the legacy api.moonshot.ai/v1 endpoint instead of api.kimi.com/coding/v1,
resulting in HTTP 401 on the first request.

Import and call _resolve_kimi_base_url for kimi-coding so the pool
uses the correct endpoint based on the key prefix, matching the
runtime credential resolver behavior.

Also fix a comment: sk-kimi- keys are issued by kimi.com/code,
not platform.kimi.ai.

Fixes #5561
…sync clients

When  is explicitly set to ,
the custom-endpoint path in  creates a plain
client without provider-specific headers. This means sync vision calls (e.g.
) use the generic  User-Agent and get rejected by
Kimi's coding endpoint with a 403:

    'Kimi For Coding is currently only available for Coding Agents such as Kimi CLI...'

The async converter  already injects , and the
auto-detected API-key provider path also injects it, but the explicit custom
endpoint shortcut was missing it entirely.

This patch adds the same  injection to the custom endpoint
branch, and updates all existing Kimi header sites to  for
consistency.

Fixes <issue number to be filled in>
The status bar reads self.model from the CLI class, which is set once
at init and never updated when _try_activate_fallback() switches to a
backup provider/model in run_agent.py. This causes the TUI to display
the original model name while context_length_max changes, creating a
confusing mismatch.

Read the model name from agent.model (live, updated by fallback) with
self.model as fallback before the agent is created. Remove the
redundant getattr(self, 'agent') call that was already done above.
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