Skip to content

fix(cloud-agent-next): skip sandbox delete cleanup when container is stopped - #8147

Merged
eshurakov merged 2 commits into
mainfrom
kilo/capable-packet-kc1
Oct 19, 2026
Merged

eshurakov merged 2 commits into
mainfrom
kilo/capable-packet-kc1

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Summary

Retention cleanup for a session on a shared sandbox ran rm -rf inside the sandbox, waking a stopped container once per expired session. With thousands of expired sessions per shared sandbox, each TTL cohort kept containers awake with no active work.

CloudflareAgentSandbox.delete now reuses the existing non-waking isSandboxContainerRunning probe before getSession, cleanupWorkspace, or deleteSession. When the container is confirmed stopped, cleanup is skipped and logged as sandbox_delete_cleanup_skipped with the sandbox ID and deletion reason. Unknown state stays fail-safe and keeps the existing cleanup path. The recovery branch is unchanged.

Tests

  • Stopped container: delete('retention-expired') does not call getSession, cleanupWorkspace (via exec), or deleteSession.
  • Running container: cleanup and deleteSession still run.
  • Unknown container state: cleanup still runs.
  • Existing missing-exec-session behavior still passes.

Verified with:

  • pnpm exec vitest run src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.test.ts --config vitest.config.ts
  • pnpm run typecheck
  • oxfmt --check and oxlint on the changed files

Out of scope

  • The cloudflare-containers runtime (SandboxContainers).
  • Retiring the shared allocation.
  • Changing SESSION_TTL_MS.

@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change scopes the stopped-container cleanup skip to retention-expired, so explicit deletes still reclaim the workspace and session home (including auth.json); the added test covers that path and the prior warning is resolved.

Files Reviewed (2 files)
  • services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.ts
  • services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.test.ts
Previous Review Summary (commit c28f0d9)

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

Previous review (commit c28f0d9)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The stopped-container fast path correctly avoids wakes, but it also skips workspace and session-home cleanup for explicit deletes, leaving user data and credentials on the shared sandbox disk.

Overview

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

WARNING

File Line Issue
services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.ts 566 Early return skips cleanupWorkspace/deleteSession for all non-recovery reasons, including explicit deletes, leaving the session workspace and /home/<sessionId> (with auth.json) on the shared sandbox's persistent disk. Consider limiting the skip to retention-expired or reclaiming skipped paths on the next real wake.
Files Reviewed (2 files)
  • services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.ts - 1 issue
  • services/cloud-agent-next/src/agent-sandbox/cloudflare/cloudflare-agent-sandbox.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 35K · Output: 3.6K · Cached: 306.4K

Review guidance: REVIEW.md from base branch main

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.

2 participants