Skip to content

Serve known models right after a start: retry the catalog fetch, register models before listening - #7

Draft
t1sh0o wants to merge 4 commits into
mainfrom
fix/startup-model-readiness
Draft

t1sh0o wants to merge 4 commits into
mainfrom
fix/startup-model-readiness

Conversation

@t1sh0o

@t1sh0o t1sh0o commented Nov 6, 2026

Copy link
Copy Markdown

Story: none. Follow-up of the 1 Nov and 3 Nov 2026 CLIProxyAPI startup incidents on mm007.

Summary

The proxy answered 400 unknown provider for model for current models after two kinds of start. Three patches close both gaps. Upstream has not fixed either one in a release (issue #6702 was closed as not planned), so two patches are backports of open upstream PRs and one is ours.

start
 ├─ catalog fetch (background) ── fails? ── old: retry in 3 h   new: retry in 30 s        (Patch 5, upstream PR #6236)
 ├─ wait ≤10 s for the first fetch                                new                       (Patch 7, ours)
 ├─ register models of the loaded OAuth files                     moved before the listener (Patch 6, upstream PR #6464)
 └─ open :8317

Review guide

  1. internal/registry/model_updater.go: runModelCatalogUpdater (30 s retry after a failure, 3 h after a success), then WaitForStartupModelRefresh and the two process-wide channels.
  2. sdk/cliproxy/service_lifecycle.go: the wait plus syncPluginModelRuntime before server.Start, and the 10 s cap startupModelRefreshWait.
  3. internal/registry/model_updater_startup_wait_test.go, model_updater_retry_test.go, sdk/cliproxy/service_startup_models_test.go: the guards.
  4. Skim: codex_client_models_updater.go, devin_models_updater.go (same retry loop), their tests, README.md (patch list).

Evidence

Verdict: live-verified (independent verifier, own builds, port 18417)

Harness: the binary runs behind an HTTPS_PROXY that blocks the catalog hosts, with one fake Claude and one fake Codex OAuth file. Old = the production v0.1.6-ampeco release asset (same SHA-256 as on mm007).

Before: catalog hosts blocked at start and opened again at 20 s: claude-opus-5-5 and gpt-6.1-sol were still unknown after 150 s, with one fetch attempt at 0.1 s. The code waits 3 h for the next one. A burst of 20 requests every 20 ms from process start got 60 400 unknown provider per run (5 of 5 runs).

After:

Test old v0.1.6 Patches 5+6 this branch
Catalog blocked, opened at 20 s: first routable not in 150 s — 30.9 s / 32.0 s
Catalog blocked, opened at 75 s: first routable — — 91.0 s / 92.0 s
Burst, catalog-only models: 400s in 5 runs 300 300 0
Burst, models in the embedded catalog: 400s in 5 runs 320 0 0
Catalog black-holed: port opens after 0.98 s — 10.97 s (cap hit, warning logged)
--local-model: port opens after — — 0.06 s, no fetch
SIGTERM during the wait — — exits in 0.11 s, code 0
  • go vet ./... clean. go test ./...: only internal/runtime/executor fails (2 tests), and it fails the same way on main.
  • Red on old: the Patch 6 test fails on main. Mutations turn the Patch 5 and Patch 7 tests red.
  • Known gaps: removing the WaitForStartupModelRefresh call from Service.Run keeps every test green, so only the burst harness catches it. The Patch 6 test fails under -race. The race is an existing one in api.Server.Start/Stop, not in this change, and CI does not run -race. TestWaitForStartupModelRefresh cannot run with -count=2 because the channels close once per process.

Merge danger

Door: two-way. Nothing is deployed until a v0.1.7-ampeco tag is cut and cliproxyapi_binary_version is bumped in the Ansible role.
Blast radius: fleet. Every CODA worker goes through this proxy. Safe because the only new behaviour on a normal start is up to about 0.5 s more of "connection refused" before the port opens (the first fetch takes 0.3 s). Clients retry a refused connection, but they do not retry a 400. The worst case is 10 s when the network drops packets.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PSwp2RzGuRkZ8wKNtCnhxD

zhengzi and others added 4 commits November 6, 2026 12:37
…o Patch 5)

Backport of upstream PR router-for-me#6236 (open, not merged).
When the proxy starts before DNS works, all catalog URLs fail and upstream
waits the full 3 h interval, so models missing from the embedded catalog
get 400 unknown provider. Retry 30 s after a failed attempt; a successful
fetch, changed or not, goes back to the 3 h cadence.

Dropped two tests from the PR file that need v8-only fields.

Co-Authored-By: zhengzi <zhengzi@qcraft.ai>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PSwp2RzGuRkZ8wKNtCnhxD
…ampeco Patch 6)

Backport of upstream PR router-for-me#6464 (open, not merged;
upstream issue router-for-me#6702 was closed as not planned). Requests that arrive in
the first second after a restart got 400 unknown provider for models of
file-backed OAuth auths, because those models were registered only after
the watcher's first load, after the port opened. Register them first.

Co-Authored-By: lemon07r <12001338+lemon07r@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PSwp2RzGuRkZ8wKNtCnhxD
…e listening (ampeco Patch 7)

After a restart, requests for models newer than the embedded catalog got
400 unknown provider until the background catalog fetch finished and the
refresh callback re-registered the auths (3 Nov 2026: 9 requests in the
first second). Wait for the first fetch, success or failure, before the
startup model registration. A fetch takes well under a second; the cap
keeps a black-holed network from holding the port closed for 60 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PSwp2RzGuRkZ8wKNtCnhxD
@t1sh0o t1sh0o self-assigned this Nov 6, 2026
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