perf(agent-server): cut redundant calls from boot critical path#2150
Draft
tatoalo wants to merge 2 commits into
Draft
perf(agent-server): cut redundant calls from boot critical path#2150tatoalo wants to merge 2 commits into
tatoalo wants to merge 2 commits into
Conversation
Cloud agent server boot was waiting on the synchronous /v1/models gateway call inside createSession before /health flips hasSession=true, even when the caller already pinned a model (which cloud always does). Each new sandbox = new process = cold cache = one extra round trip. When meta?.model or settings.model is set, return a single-entry options list immediately and warm the gateway cache from deferBackgroundFetches. The available-models dropdown updates after init, getContextWindowForModel falls back to the 200k default until the warmup completes (which fires within ~10ms of session creation). When neither is set we still wait — there's no other source for the default model id.
sendInitialTaskMessage re-fetched the task via getTask() even though _doInitializeSession had already fetched it milliseconds earlier in the same boot path (preTask). Each getTask is a sandbox->PostHog round trip on the critical path that gates /health hasSession=true. Pass preTask through as prefetchedTask and reuse it, falling back to the API call when it is absent (the catch path in _doInitializeSession can still yield null). Pure within-boot dedupe: no staleness risk since it re-uses a value fetched in the same function.
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.
Problem
The cloud
start_agent_serveractivity gates on the agent-server's/healthreturninghasSession:true, which only happens after_doInitializeSessionfinishes. Two things on that path do avoidable network work that sits directly on the boot critical path:createSessionawaits a synchronous gateway callgetTask()is called twice during boot and each call is a sandbox→PostHog round trip through the egress pathChanges
meta.model/ settings model is set,createSessionreturns a minimal single-entry options list immediately and warms the real gateway models cache indeferBackgroundFetchessendInitialTaskMessagenow takes the already-fetchedpreTaskand only falls back togetTask()when it is absent