Conversation
kumare3
reviewed
May 21, 2026
| # reference (see Python's background-tasks idiom) so the task can't be | ||
| # GC'd mid-execution; in this short driver the local frame is alive for | ||
| # the whole duration so it's safe to discard. | ||
| asyncio.create_task(heavy_env.prewarm()) # noqa: RUF006 |
Contributor
There was a problem hiding this comment.
looks cool, but you need to have one await before it really triggers sometime
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.
Motivation
When a reusable
TaskEnvironmentis first invoked, the backend lazily spawns its actor pool — pulling images, running init containers, starting workers. Subsequent tasks land on the warm pool, but the first one pays the full cold start. Users who know they'll hit a reusable env later in a workflow have no way to ask the SDK to start that pool earlier; today they have to author a hand-rolled dummy task and fire it from the driver. SE-760 adds a first-class API for it.Summary
Adds
TaskEnvironment.prewarm()(async) andTaskEnvironment.prewarm_sync()(matchingdownload_sync/load_syncconvention). Calling either submits a hidden no-op sub-action on the reusable env, which triggersGetOrCreateEnvironmenton the backend and spins upmin_replica_countworkers. The heavy task — invoked later in the driver — lands on the warm pool instead of paying the cold start.await env.prewarm()blocks until the noo HEALTHY on return) — standard Python async semantics.asyncio.create_task(env.prewarm())is the pool warms concurrently with whatever async work the driver does next.env.prewarm_sync()blocks until completiions.The synthesized no-op is a real task registen time (
__post_init__calls_register_prewarm_taskwhenreusable is not None). It shares the env's image,ReusePolicy, env_ve so its actorversionhash matches the env's real tasks — without this match, the warm-up would land on a different pool aPrewarmTaskResolvermaterializes the task on the worker without touching user code, so the no-op is loadable even when thee bundle that doesn't define it explicitly.Per-env naming (
<env>.prewarm_<env>, prefix form) makes prewarm sub-actions sort together in the UI.prewarm()logs thfired so users can see the warm window they're operating in.No-op cases (all warn and return):
prewarm()on a non-reusable envExample Executions
Without Prewarm: https://union-internal.hosted.unionai.cloud/v2/domain/development/project/flytesnacks/runs/ux2bz5jljgkhlrxqt9st
With Prewarm: https://union-internal.hosted.unionai.cloud/v2/domain/development/project/flytesnacks/runs/uff6qnnx59wjzvx5f6kz