perf(kiro): cache provider-scoped model catalog to avoid per-account fetches#145
Open
tonybase wants to merge 1 commit into
Open
perf(kiro): cache provider-scoped model catalog to avoid per-account fetches#145tonybase wants to merge 1 commit into
tonybase wants to merge 1 commit into
Conversation
…fetches Kiro model registration called ListAvailableModels once per account on every registration cycle (startup, config reload, 3h catalog refresh). With a fleet of accounts this amplified into N upstream requests each cycle. The Kiro model catalog is provider-scoped (identical for every account; profileArn only routes billing), so cache the base (pre-agentic) catalog in a small TTL cache shared across all Kiro auths. The mutex is held across the fetch so a concurrent burst of accounts collapses into a single upstream call; the TTL collapses repeat fetches across registration cycles. Agentic variants are derived per read since they depend on a runtime flag, not the account. Failed and empty fetches are not cached so a later caller can retry. Result: N accounts trigger at most one ListAvailableModels call per TTL instead of one per account per cycle. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
When managing many Kiro accounts, model registration called
ListAvailableModelsonce per account on every registration cycle — startup, config reload, and the 3-hour catalog refresh. With N accounts this amplified into N upstream requests per cycle (thekiro: fetched N models from APIlog line fires per account).The Kiro model catalog is provider-scoped — identical for every account;
profileArnonly routes billing. So this PR caches the catalog once and shares it across all Kiro auths.What changed
kiroModelsCache) onServicefor the Kiro base (pre-agentic) model list.fetchKiroModelsnow: cache lookup → single upstreamListAvailableModels(fetchKiroBaseModelsFromAPI) → per-read agentic variant generation.kiro-system-prompt-inject-enableruntime flag rather than the account.registry.GetKiroModels()).Result
N Kiro accounts trigger at most one
ListAvailableModelscall per TTL, instead of one per account per registration cycle.Notes / scope
cursor,github-copilot,kilo,qoder, andantigravity— if this approach is acceptable, it can be extended in a follow-up.generateKiroAgenticVariants,applyExcludedModels,applyModelPrefixesall build new slices / clone before edits), so sharing is safe.Testing
service_kiro_models_cache_test.gocovering: concurrent coalescing (50 callers → 1 fetch), TTL reuse + expiry refresh, failures not cached, empty results not cached. All pass under-race.gofmt -w .,go build ./cmd/server, andgo test ./sdk/cliproxy/...all pass.🤖 Generated with Claude Code