Skip to content

feat(kubernetes): add template-driven sandbox warm pools - #5518

Open
grs wants to merge 15 commits into
ai-openshell:mainfrom
grs:warm-pooling-2
Open

grs wants to merge 15 commits into
ai-openshell:mainfrom
grs:warm-pooling-2

Conversation

@grs

@grs grs commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Add template-driven warm pooling for Kubernetes sandboxes with dedicated or shared supervisors. Prepared runtimes wait for a claim, then receive their sandbox identity and credentials over existing supervisor connections, avoiding cold startup and claim-time Secret projection delays.

Related Issue

Closes #2157

Changes

  • Derive warm pools from template startup tuning (ready_within and max_burst), with pooling enabled by default and operator-configurable limits.
  • Coordinate preparation, capacity reservation, claims, refill, and retirement through durable records shared across gateway replicas.
  • Hold dedicated supervisors’ asynchronous RegisterSupervisor responses until claim; deliver shared-supervisor claims through the existing assignment stream.
  • Preserve physical runtime identity and validate credentials before activation, without adding a runtime-to-gateway bootstrap connection.
  • Restrict claims to the originating template and drain unclaimed capacity when a template is deleted or pooling is disabled.
  • Update Helm permissions, configuration documentation, and lifecycle coverage.

Release Notes

Kubernetes sandbox templates can request warm capacity using --ready-within and --max-burst. Pooling supports dedicated and shared supervisors and creates no spares for templates without startup tuning. Sandbox creation falls back to cold provisioning when no compatible spare is available.

Testing

  • Checks appropriate to the affected code and behavior pass

  • Unit tests added/updated

  • E2E tests added/updated

  • Manual basic operation verified with both supervisor topologies.

Checklist

@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@grs
grs force-pushed the warm-pooling-2 branch 2 times, most recently from 7ad90b9 to 5bde8ea Compare November 16, 2026 16:19
@FrostGod

Copy link
Copy Markdown
Contributor

taking a look!

@FrostGod
FrostGod self-requested a review November 16, 2026 18:46
Comment on lines +329 to +335
if state.revision > pool.revision
|| (state.revision == pool.revision && state.fingerprint != fingerprint)
{
return Err(invalid(
"warm pool configuration changed; increase its revision on all gateway replicas",
));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fingerprint hashes the whole driver config (L50), including the default supervisor and sandbox images, which are pinned to the gateway version. After an upgrade with an unchanged warm_pool.revision, this returns an error. The pool then stops refilling, aging out, and draining (even with enabled = false), and creates quietly go cold. Could a fingerprint change start a new pool generation and drain the old spares instead of erroring?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +115 to +138
let pools = self.template_warm_pools(Some(sandbox.id.clone())).await?;
let pools: Vec<_> = pools
.into_iter()
.filter(|pool| pool.workspace == sandbox.workspace && pool.target_size > 0)
.collect();
if pools.is_empty() {
return Ok(None);
}
let trust = supervision
.warm_runtime_trust()
.await
.map_err(KubernetesDriverError::Message)?;
let inventory = self.warm_runtime_inventory(&sandbox.workspace).await?;
for pool in &pools {
let Some(snapshot) = supervision
.warm_pool_state(&pool.workspace, &pool.name)
.await
.map_err(KubernetesDriverError::Message)?
else {
continue;
};
if snapshot.state.revision != pool.revision
|| snapshot.state.fingerprint
!= reconciler::fingerprint(&self.config, pool, &trust)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing has been claimed yet here, but any error (template lookup, trust, inventory, journal read, fingerprint) fails the whole create. The docs say creates fall back to cold creation. Could these return Ok(None), so a pool hiccup doesn't block creates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

impl Default for WarmPoolSettings {
fn default() -> Self {
Self {
enabled: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pooling defaults to on. Templates that already set --ready-within and --max-burst will start spare Pods after upgrading, and each dedicated spare costs two Pods. Since the docs call this experimental, should the default be false, or should the release notes call it out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --ready-within and --max-burst options were added specifically as a means to configure warm pooling. I suspect no one is 'using' them yet, since prior to this PR those option have no effect whatsoever.

() = &mut changed => {},
// Other replicas commit to the same durable store. This is
// server-side observation, not a registration retry.
() = tokio::time::sleep(std::time::Duration::from_secs(1)) => {},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each pending RegisterSupervisor stream polls once a second, with no deadline and no per-route cap. Every poll calls dedicated_registration, which loads launch material from the credential store (prepared.rs:584) before checking whether the spare is claimed. With N spares, that's N credential-store reads per second. Could the poll check the assignment record first, load material only once it's claimed, and cap streams per route?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

sandbox_id: String::new(),
generation: retirement.generation.to_string(),
workspace: retirement.workspace.clone(),
phase: RecordPhase::Retired,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retired tombstones are never deleted. That makes sense so a route can't be revived, but with a 1-hour max age they grow without limit and every reconcile pass scans them. Could they expire once the physical resource UID is confirmed gone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crates/openshell-supervisor/src/main.rs Resolved
@grs
grs force-pushed the warm-pooling-2 branch 2 times, most recently from 4f8dd24 to 810e1e5 Compare November 19, 2026 22:17
@grs
grs requested a review from FrostGod November 19, 2026 22:18
grs added 12 commits November 23, 2026 08:54
Fingerprint effective runtime inputs and retain compatible spares across
revision changes. Preserve cleanup during configuration mismatches and
persist drain decisions across replicas.

Update regression tests, operator guidance, and the stale packaging
driver-selection assertion.

Signed-off-by: Gordon Sim <[email protected]>
- Add warm_pool.refill_per_pass (default 4, 1..=64) to replace the fixed
  per-pass refill and operation burst.
- Record whether a pool is suspended in the journal and report target,
  ready, pending, retiring, revision, and suspended through
  GetSandboxTemplate and `openshell sandbox template get`.
- Export openshell_warm_pool_claims_total{outcome},
  openshell_warm_pool_claim_duration_seconds{outcome},
  openshell_warm_pool_spares{state}, and
  openshell_warm_pool_suspended_pools.

Signed-off-by: divesh <[email protected]>
Default warm_pool.enabled to false. A disabled reconciler drains only
pools that already have a journal and no longer writes journals for
templates that were never pooled. Once a disabled pass finds no
recorded pool, sandbox creates skip warm claim lookups and the cold
launch fence, so gateways that never enable pooling keep the existing
create path.

Signed-off-by: divesh <[email protected]>
@FrostGod

FrostGod commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

@grs can you PTAL again, I have added the following things on top of this feature

  • Configurable refill rate: new warm_pool.refill_per_pass setting (default 4, range 1–64) replaces the hardcoded 4 spares per pass. Changing it doesn't need a revision bump.
  • Pool status in CLI and API: openshell sandbox template get <name> now shows a warm pool section with target, ready, pending, retiring, revision, and suspended. The same data is in -o json and GetSandboxTemplate.
  • Metrics:
    • openshell_warm_pool_claims_total{outcome=warm|cold|error}: warm hits vs cold fallbacks
    • openshell_warm_pool_claim_duration_seconds: claim latency
    • openshell_warm_pool_spares{state=ready|pending|retiring}: spare counts
    • openshell_warm_pool_suspended_pools: pools that can't refill
  • Pooling off by default: warm_pool.enabled now defaults to false. A disabled gateway only drains pools that already exist and doesn't create pool journals. Once it confirms no pools exist, sandbox creates skip warm-pool lookups and the cold-launch DB write.
  • Main merged in: the branch is up to date with main via a merge commit; existing commits are not rewritten.
  • Docs, tests, e2e: updated the gateway configuration, templates, and metrics docs, the driver README, and the debug-openshell-cluster skill. Added unit tests for status, metrics, refill pacing, and the disabled path. The warm-pool e2e now asserts pool status, and values-warm-pool.yaml sets enabled: true.

and @drew for viz

This branch has not been deployed

No deployments
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.

feat: add warm-pool provisioning for Kubernetes sandboxes

2 participants