Skip to content

Import LiteLLM on first use — at module scope it broke the wakeup - #278

Merged
Sbussiso merged 1 commit into
masterfrom
agent-lazy-litellm
Sep 9, 2026
Merged

Import LiteLLM on first use — at module scope it broke the wakeup#278
Sbussiso merged 1 commit into
masterfrom
agent-lazy-litellm

Conversation

@Sbussiso

@Sbussiso Sbussiso commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Caught by measuring the cold-start path in production right after #277 deployed, rather than assuming it was fine.

20:23:07  Preparing to run: python -m app.sentinel_agent
20:23:15  proxy: gave up after 15 attempts (8.48s)   ← webhook got RemoteDisconnected
20:23:23  Uvicorn running on 0.0.0.0:8080           ← 16s after start

The machine started in 928ms. The Python process then took 16s to bind, because litellm pulls boto3, tokenizers, openai and ~20 more and a cold shared-cpu-1x is much slower at it than a warm laptop. I measured 2.08s locally and reported that as the cost — it understated the real thing by roughly 5×.

Fly's proxy waits ~8.5s for the port, so it declared the machine it had just auto-started unreachable. Since the agent scales to zero, this hit every wakeup.

Deferring the import takes it off the critical path: agent boot goes ~2.1s → 0.33s locally, the server binds and answers /wakeup immediately, and litellm's ~2s is paid inside the drain where it sits beside a 270s budget and an LLM round-trip.

The failure would have been survivable but expensive — the webhook is fire-and-forget with a re-fire loop, so runs get picked up eventually while every wakeup pays a cold start and times out.

864 tests pass, ruff clean.

🤖 Generated with Claude Code

Importing litellm at module scope made the agent unreachable on cold
start. Measured in production immediately after the previous deploy:

  20:23:07  Preparing to run: python -m app.sentinel_agent
  20:23:15  proxy: gave up after 15 attempts (8.48s)
  20:23:23  Uvicorn running on 0.0.0.0:8080

The machine itself started in 928ms. The Python process then took 16s to
bind, because litellm pulls boto3, tokenizers, openai and ~20 more, and a
cold shared-cpu-1x is far slower at it than a warm laptop — I measured
2.08s locally and took that as the cost, which understated it by roughly
a factor of five.

Fly's proxy waits ~8.5s for the port, so it declared the machine it had
just auto-started unreachable and Command Center's webhook came back
RemoteDisconnected. The agent had scaled to zero, so this hit every
wakeup, not just the first.

Deferring the import drops agent boot from ~2.1s to 0.33s locally and
takes litellm off the critical path entirely: the server binds and
answers /wakeup immediately, and the ~2s is paid inside the drain, where
it sits next to a 270s budget and an LLM round-trip.

Worth noting the failure would have been survivable but expensive — the
webhook is fire-and-forget with a re-fire loop, so runs would have been
picked up eventually while every wakeup paid a cold start and timed out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Sbussiso
Sbussiso merged commit 715fc7e into master Sep 9, 2026
12 checks passed
@Sbussiso
Sbussiso deleted the agent-lazy-litellm branch September 9, 2026 20:26
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