fix(acp): resolve cold-start race with belt-and-suspenders defense#1172
Open
chaodu-agent wants to merge 1 commit into
Open
fix(acp): resolve cold-start race with belt-and-suspenders defense#1172chaodu-agent wants to merge 1 commit into
chaodu-agent wants to merge 1 commit into
Conversation
Two complementary fixes for the ACP cold-start race condition where DB migration delays provider loading, causing defaultModel() to fall through to Provider.sort() and pick a paid model. Proactive fix (acp.ts): - Poll providers endpoint (max 10x, 500ms intervals) before accepting requests, ensuring providers are loaded post-migration - Log warning if providers don't load within 5s Defensive fix (agent.ts): - When user specifies a model in config.json but the provider is not yet loaded (or provider loaded but model not indexed), return the user's explicit choice instead of falling through to Provider.sort() Extracted testable modules: - resolve-model.ts: pure resolution logic (6 unit tests) - wait-for-providers.ts: polling loop with configurable retry (4 unit tests) Fixes XiaomiMiMo#865, Fixes XiaomiMiMo#866
This was referenced Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Belt-and-suspenders fix for the ACP cold-start race condition where DB migration delays provider loading, causing
defaultModel()to fall through toProvider.sort()and pick a paid model.Supersedes #1170 and #1171 (combined into one PR with unit tests).
Proactive Fix (
acp.ts)Poll providers endpoint (max 10× at 500ms intervals) before accepting requests:
Defensive Fix (
agent.ts)When user specifies a model in
config.jsonbut:Instead of falling through to
Provider.sort()which may pick an unintended paid model.Tests
10 new unit tests covering both paths:
test/acp/default-model.test.ts(6 tests): resolution logic for all provider/model statestest/acp/wait-for-providers.test.ts(4 tests): polling retry, immediate success, timeoutDesign
Extracted testable pure functions:
resolve-model.ts— stateless model resolution (no SDK, no side effects)wait-for-providers.ts— configurable polling with log.warn on timeoutVerification
bun test test/acp/— ✅ 21 passbun run typecheck— ✅ cleanFixes #865, Fixes #866