Skip to content

fix(acp): wait for providers to load before accepting requests#1171

Closed
chaodu-agent wants to merge 2 commits into
XiaomiMiMo:mainfrom
chaodu-agent:fix/acp-cold-start-migration-race
Closed

fix(acp): wait for providers to load before accepting requests#1171
chaodu-agent wants to merge 2 commits into
XiaomiMiMo:mainfrom
chaodu-agent:fix/acp-cold-start-migration-race

Conversation

@chaodu-agent

@chaodu-agent chaodu-agent commented Jun 21, 2026

Copy link
Copy Markdown

Summary

After DB migration, the SDK server may not have fully indexed providers before the first ACP request arrives. Add a readiness check before accepting connections.

Current Behavior

┌─── mimo acp cold start ─────────────────────────────────────────┐
│                                                                  │
│  t0  DB migration runs (rewrites SQLite tables)                  │
│  t1  migration done                                              │
│  t2  Server.listen()                                             │
│  t3  ACP agent created ← IMMEDIATELY accepts stdin               │
│  t4  1st request arrives                                         │
│       ├─ sdk.config.providers()                                  │
│       │   └─ [xiaomi] ← mimo provider NOT YET INDEXED   ❌       │
│       ├─ defaultModel() → Provider.sort()                        │
│       │   └─ picks mimo-v2.5-pro-ultraspeed (paid)      ❌       │
│       └─ 0 tokens → "(no response)"                             │
│                                                                  │
│  t5  2nd request → providers fully loaded → works        ✅      │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

Expected Behavior

┌─── mimo acp cold start (with fix) ──────────────────────────────┐
│                                                                  │
│  t0  DB migration runs                                           │
│  t1  migration done                                              │
│  t2  Server.listen()                                             │
│  t3  readiness loop: poll providers every 500ms (max 5s)         │
│       └─ waits until providers.length > 0                        │
│  t4  providers loaded → ACP agent created → accepts stdin        │
│  t5  1st request arrives                                         │
│       ├─ sdk.config.providers()                                  │
│       │   └─ [mimo, xiaomi, ...]                         ✅      │
│       ├─ defaultModel() → mimo/mimo-auto                 ✅      │
│       └─ works on first try!                                     │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

Relationship to #865

Belt-and-suspenders with PR #1170:

Fixes #866

After DB migration, the SDK server may not have fully indexed
providers before the first ACP request arrives. This causes
defaultModel() to miss the user's configured provider and fall
through to Provider.sort(), picking an unintended paid model.

Add a readiness loop (up to 5s) that waits for at least one
provider to be available before creating the ACP agent.

Fixes XiaomiMiMo#866
If providers don't load within 5s, log a warning so operators can
diagnose cold-start issues instead of silently proceeding.
@chaodu-agent

Copy link
Copy Markdown
Author

Superseded by #1172 (combined with #1170, added unit tests)

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.

First ACP request after cold start returns empty (DB migration race)

1 participant