perf(core): parallelize resolveTier's independent storage reads - #6441
Open
pedrofrxncx wants to merge 1 commit into
Open
perf(core): parallelize resolveTier's independent storage reads#6441pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
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.
Source: storage-ports latency-investigation hunt (issue #2995 — "DB latency amplifies significantly across MCP tool calls").
resolveTier(apps/api/src/core/resolve-tier.ts) is on the model-resolution path for interactive chat and every automation/task-board/review-judge call that picks a tier — it runs on essentially every agent turn.Payoff: the function issued three independent DB reads back-to-back with
await: org settings, the per-user model-preference override, and the AI provider key list. None of the three depends on another's result, so serializing them adds up to two extra round-trips of latency to every tier resolution for no reason. This change fetches all three concurrently withPromise.all, same conditional skip for the user-prefs read (still not issued whenapplyUserPrefsis off).Behavior: unchanged — same three conditions gate the user-prefs read, same values feed
orgSlot/userSlot/keysafterward, only the await ordering changed from serial to parallel.How a reviewer confirms: run
bun test apps/api/src/core/resolve-tier.test.ts(all 10 cases still pass, including the one assertinguserModelPreferences.getis NOT called whenapplyUserPrefsis unset).Checks run locally:
bun run fmt,cd apps/api && bunx tsc --noEmit(clean),bun test apps/api/src/core/resolve-tier.test.ts(10/10 pass),bunx oxlint apps/api/src/core/resolve-tier.ts(0 warnings/errors). Full CI validates the rest.Summary by cubic
Parallelizes resolveTier’s independent storage reads to reduce per-turn latency in model resolution. Previously, org settings, user model preferences (conditionally), and AI provider keys were read sequentially; they now load in parallel with unchanged behavior, including skipping the user-preferences read when it does not apply. This supports issue #2995 on DB latency across MCP tool calls.
applyUserPrefsis set, the tier is a chat tier, and auserIdexists; the read is skipped otherwise.bun test apps/api/src/core/resolve-tier.test.ts(ensures the skip behavior and overall resolution logic remain intact).Written for commit f1f9afa. Summary will update on new commits.