Skip to content

perf(agent-server): cut redundant calls from boot critical path#2150

Draft
tatoalo wants to merge 2 commits into
mainfrom
perf/start-agent-server-speedup
Draft

perf(agent-server): cut redundant calls from boot critical path#2150
tatoalo wants to merge 2 commits into
mainfrom
perf/start-agent-server-speedup

Conversation

@tatoalo
Copy link
Copy Markdown
Contributor

@tatoalo tatoalo commented May 15, 2026

Problem

The cloud start_agent_server activity gates on the agent-server's /health returning hasSession:true, which only happens after _doInitializeSession finishes. Two things on that path do avoidable network work that sits directly on the boot critical path:

  1. createSession awaits a synchronous gateway call
  2. getTask() is called twice during boot and each call is a sandbox→PostHog round trip through the egress path

Changes

  • when meta.model / settings model is set, createSession returns a minimal single-entry options list immediately and warms the real gateway models cache in deferBackgroundFetches
  • sendInitialTaskMessage now takes the already-fetched preTask and only falls back to getTask() when it is absent

tatoalo added 2 commits May 15, 2026 15:45
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.
@tatoalo tatoalo self-assigned this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant