You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(router-provider): fetch model metadata before context management decisions (#1053)
* fix(router-provider): fetch model metadata before context management decisions
Router providers (zoo-gateway, kimi-code) that are auth-scoped skip the
model cache entirely. On a fresh handler instance getModel() falls back
to hardcoded defaults (e.g. 200k context window) because the real model
list has not been fetched yet. Context management runs before
createMessage() which is where fetchModel() normally happens, so
condensing/truncation decisions use the wrong context window.
Add ensureModelFetched() to RouterProvider that fetches once when the
instance model map is empty. Call it in Task before context management
so getModel() returns accurate metadata from the API.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(router-provider): single-flight ensureModelFetched and earlier call site
Make ensureModelFetched single-flight so concurrent callers share a
single in-flight fetch instead of firing duplicates. Move the call site
before the cachedStreamingModel snapshot so the model info is accurate
from the start of the streaming session, not just for context management.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(router-provider): address review feedback on fetch failures and double-fetch
Make fetchModel single-flight and short-circuit once models are loaded so
auth-scoped providers do not hit the models endpoint twice per request.
Catch ensureModelFetched failures in Task via safeEnsureModelFetched so a
metadata fetch error falls back to defaults instead of ending the task.
Add reject-then-recover coverage and Task tests for the new call sites.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(test): spy private addToApiConversationHistory via TaskTestAccess
vi.spyOn on the private method fails check-types; route it through the
existing test access cast like the other private helpers.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
0 commit comments