Skip to content

feat(cloud-agent): build reusable environment snapshots - #8886

Open
eshurakov wants to merge 6 commits into
mainfrom
eshurakov/environment-snapshot-builds-pr
Open

eshurakov wants to merge 6 commits into
mainfrom
eshurakov/environment-snapshot-builds-pr

Conversation

@eshurakov

@eshurakov eshurakov commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Repository environments can build reusable snapshots in dedicated builders. New sessions restore an eligible snapshot, then run setup with their admitted configuration. Refreshes keep the current snapshot until a replacement succeeds; restore failures fall back to a fresh sandbox once.

The environment editor separates the current snapshot from build progress. Snapshots use capture dates and times in UTC in settings and session startup. Details show clone/setup duration, and logs open in a dialog with live output and retry controls.

Verification

  • Checked the running local editor, log dialog, details, refresh, failure, and cancellation at 375, 900, and 1440 pixels.
  • The GIF uses browser-only simulated build responses. Its final frame demonstrates startup copy covered by backend tests. It does not prove native Cloudflare capture or restore.

Visual Changes

environment-snapshots-demo.gif

Reviewer Notes

Local checks pass: 5,544 Worker unit tests, 642 Workers-runtime integration tests, 118 focused web tests, and 18 environment-builder tests. Coverage includes catalog consistency, real Git authentication, downloaded startup, billing cancellation, large scripts, log batching, runner redelivery, restore failure limits, and concurrent environment edits. Web, Worker, and wrapper type checks, full lint, migration metadata checks, and formatting pass.

The UI follows the Kilo Cloud overlay and interaction-quality guidance, using existing dialog and popover components. There is no snapshot-specific design recipe.

Build admission and publication recheck access and configuration. Builders remove managed credentials before capture. Snapshot files can retain values written by setup scripts; the UI keeps that notice visible.

This PR includes the environment snapshot implementation already prepared on this branch. Its database migration was regenerated after current main. Native Cloudflare capture, restore, and production rollout remain unverified.

Comment thread services/cloud-agent-next/src/shared/environment-build-protocol.ts Outdated
Comment thread services/cloud-agent-next/src/shared/environment-build-protocol.ts Outdated
Comment thread services/cloud-agent-next/src/environment-build/coordinator.ts Outdated
Comment thread services/cloud-agent-next/src/environment-build/coordinator.ts
Comment thread apps/web/src/hooks/useCloudAgentEnvironments.ts Outdated
Comment thread apps/web/src/components/cloud-agent-next/EnvironmentBuildPanel.tsx Outdated
Comment thread apps/web/src/components/cloud-agent-next/EnvironmentBuildPanel.tsx Outdated
Comment thread apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx Outdated
Comment thread packages/cloud-agent-profile/src/environment-service.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental changes from d10b7aa9d (setup-script and reporter bounds, allocation-first billing admission, queued retry backoff, runner re-delivery with a consumption marker, snapshot start-failure cap, tail log reads, retained UI data, and consistent environment reads) resolve the previously reported findings and introduce no new defects at review confidence.

Assumptions: [INFERENCE] Native Cloudflare capture/restore and production rollout remain unverified, as the PR states. The snapshot start-failure counter is stored in the per-container Durable Object; whether every new isolated session (fresh sandbox id) still retries a broken snapshot with a fresh counter, which would preserve the 5-minute restore wait across sessions, was not verified. Tests and type checks were not executed in this read-only review.

Files Reviewed (23 files)
  • apps/web/src/components/cloud-agent-next/EnvironmentBuildPanel.tsx
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx
  • apps/web/src/hooks/useCloudAgentEnvironments.ts
  • apps/web/src/lib/cloud-agent-next/environment-build-client.ts
  • apps/web/src/routers/cloud-environments-router.ts
  • apps/web/src/tests/cloud-agent-profile/environment-service.test.ts
  • packages/cloud-agent-profile/src/environment-service.ts
  • services/cloud-agent-next/docs/control-plane.md
  • services/cloud-agent-next/src/environment-build/coordinator.ts
  • services/cloud-agent-next/src/environment-build/environment-build-do.ts
  • services/cloud-agent-next/src/environment-build/store.ts
  • services/cloud-agent-next/src/router/handlers/environment-build.ts
  • services/cloud-agent-next/src/sandbox-containers/SandboxContainers.ts
  • services/cloud-agent-next/src/sandbox-containers/native-start.ts
  • services/cloud-agent-next/src/sandbox-containers/sandbox-containers.test.ts
  • services/cloud-agent-next/src/sandbox-containers/snapshot-start-failures.ts
  • services/cloud-agent-next/src/shared/environment-build-protocol.ts
  • services/cloud-agent-next/test/integration/environment-build.test.ts
  • services/cloud-agent-next/wrapper/src/environment-builder/reporter.ts
  • services/cloud-agent-next/wrapper/src/environment-builder/run.test.ts
  • services/cloud-agent-next/wrapper/src/environment-builder/runner-file.test.ts
  • services/cloud-agent-next/wrapper/src/environment-builder/runner-file.ts
  • services/kilo-mcp/catalog.json (generated; cursor default removed in step with the request schema)
Previous Review Summary (commit d10b7aa)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d10b7aa)

Status: 11 Issues Found | Recommendation: Address before merge

Executive Summary

The build-input schema rejects setup scripts longer than 500 characters, deterministically breaking snapshot builds for a common environment configuration; several durability and retry gaps (billing admission ordering, snapshot-start failure tracking, runner delivery, alarm hot loop) also need attention.

Assumptions: [INFERENCE] Native Cloudflare capture/restore and the production rollout remain unverified, as the PR states. An apparent race where a stop-requested arriving during the up-to-15s snapshot lookup in sandbox-do.ts could launch a container after the stop was considered but not confirmed, so it is omitted from the findings rather than asserted. Generated files and lock files were not reviewed line by line.

Overview

Severity Count
CRITICAL 1
WARNING 6
SUGGESTION 4
Issue Details (click to expand)

CRITICAL

File Line Issue
services/cloud-agent-next/src/shared/environment-build-protocol.ts 56 Build-input schema caps setup commands at 500 characters while the contract allows 16,000, so longer scripts always fail input_unavailable

WARNING

File Line Issue
services/cloud-agent-next/src/shared/environment-build-protocol.ts 75 Log events cap 512 lines but the reporter batches only by 64 KiB, so valid batches get 400 and stall the heartbeat
services/cloud-agent-next/src/environment-build/coordinator.ts 758 Billing admission issued before the allocation id is persisted; a cancel race leaves an untracked admission
services/cloud-agent-next/src/environment-build/coordinator.ts 749 Git-source unavailability re-arms the alarm at now, producing a hot retry loop for up to 30 minutes
services/cloud-agent-next/src/sandbox-containers/SandboxContainers.ts 412 A running builder record is treated as runner-delivered, so a crash between start and delivery strands the build
services/cloud-agent-next/src/sandbox-containers/SandboxContainers.ts 594 Failed snapshot starts are not recorded, so a broken snapshot is retried by every allocation
apps/web/src/hooks/useCloudAgentEnvironments.ts 174 Build logs always request cursor: 0, so output past the first 500 lines is unreachable

SUGGESTION

File Line Issue
apps/web/src/components/cloud-agent-next/EnvironmentBuildPanel.tsx 75 A transient poll error hides retained status data (same pattern in the log dialog at line 403)
apps/web/src/components/cloud-agent-next/EnvironmentBuildPanel.tsx 413 Truncation notice says earlier output was dropped, but the store drops later output
apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx 1025 Reuse notice is gated on profile var counts and misses environment vars/secrets/commands
packages/cloud-agent-profile/src/environment-service.ts 710 Environment row and variables are read in separate statements, so values can be tagged with an older revision
Files Reviewed (137 files)
  • services/cloud-agent-next/src/environment-build/* (coordinator, store, DO, policy, access, reference, routes, provider, credential, schema) - 6 issues
  • services/cloud-agent-next/src/shared/environment-build-protocol.ts - 2 issues
  • services/cloud-agent-next/src/sandbox-containers/* (SandboxContainers, native start/capture, main process) - 2 issues
  • services/cloud-agent-next/src/sandbox-control/* (providers, runtime bootstrap, startup, paths) - none
  • services/cloud-agent-next/src/control-plane/sandbox/* and session/* (sandbox DO, snapshot launch, routes, migrations, registration) - none confirmed
  • services/cloud-agent-next/wrapper/src/control-plane/* and environment-builder/* - none confirmed
  • apps/web/src/components/cloud-agent-next/*, cloud-agent/*, hooks, client, router - 4 issues
  • packages/cloud-agent-profile/src/* - 1 issue
  • packages/db/src/schema.ts, migration 0302 and journal - none
  • services/kilo-mcp/catalog.json - none (new environment build tools expose no credential, secret or membership writes)
  • Worker wiring (wrangler.jsonc, wrangler.test.jsonc, index.ts, router.ts, server.ts) and docs - none

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 86.7K · Output: 56.4K · Cached: 5.1M

Review guidance: REVIEW.md from base branch main

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.

1 participant