Skip to content

feat(cloud-agent): clean up merged workspaces in the background - #8295

Open
eshurakov wants to merge 3 commits into
mainfrom
kilo/empty-field-74z
Open

eshurakov wants to merge 3 commits into
mainfrom
kilo/empty-field-74z

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Summary

  • Add a Cloud Agent sidebar action to clean up workspaces whose linked GitHub PRs are all verified as merged, with a destructive confirmation showing the count. Selection covers the current personal/organization scope independently of sidebar filters and pagination.
  • Run cleanup through a per-user/per-organization Durable Object with persisted item status, sequential alarms, eviction recovery, bounded automatic retries, and a retry-failed action. No browser tab or persisted bearer token is required.
  • Reuse normal worktree deletion and its session/cache/tab reconciliation: queued/deleting rows show the existing deletion indicator, completed rows disappear, selected deleted chats navigate away, and progress is restored on return.
  • Recheck authoritative PR eligibility before the deletion fence and again for discovered scope-linked or orphan children before runtime cleanup. Keep mixed, unverified, unknown, closed-but-unmerged, and non-GitHub PR workspaces out of cleanup. Individual deletion remains unrestricted.

Verification

  • Web backend: 386 focused tests passed across worktree, worker-client, token-source, and session-router suites.
  • UI: 36 tests passed across cleanup component/hook, layout integration, and existing sidebar regressions.
  • Cloud Agent: 207 focused unit tests and 3 real Workers-runtime coordinator tests passed.
  • Session ingest: 54 existing deletion-journal tests and 23 new PostgreSQL eligibility regression cases passed.
  • Scoped web, Cloud Agent, session-ingest, and contracts TypeScript checks passed. Changed-file lint, formatting, and git diff --check passed.
  • Browser walkthrough passed confirmation, deleting markers, incremental row removal, closing/reopening the tab, completion, and preservation of an unmerged workspace. Cleanup controls checked at 375px, 768px, and 1440px.

GIF Evidence

This is the actual local Cloud UI with deterministic API fixtures. The tab is closed between the 1/3 and 2/3 stages. It demonstrates UI behavior and restored progress, not an end-to-end sandbox deletion. Browser-independent persistence/recovery is covered separately by the Workers-runtime tests, and eligibility uses real PostgreSQL regression tests. No production resources were deleted or deployed.

An 18.5-second GIF was recorded, but uploading it is blocked by the sandbox credentials: current gh pr create --attach rejects the delegated credential type, and GitHub's user-attachment endpoint returns HTTP 404 with those credentials despite repository push access. The GIF and all capture artifacts remain outside the repository; none are committed. GIF attachment remains outstanding.

Rollout

Deploy session-ingest before cloud-agent-next, then web, so the optional merged-only RPC guard is understood before requests use it. cloud-agent-next includes the new WORKTREE_CLEANUP binding and SQLite Durable Object migration v12. No PostgreSQL schema migration or new secret is required.

Comment thread apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts
Comment thread apps/web/src/routers/cli-sessions-v2-router.ts
Comment thread services/cloud-agent-next/wrangler.jsonc
Comment thread services/kilo-mcp/catalog.json Outdated
Comment thread apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.tsx
Comment thread services/cloud-agent-next/src/router/handlers/worktree-deletion.ts
@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of 25d5925e1: every previously reported finding is fixed or verified as a false positive, and the follow-up changes introduce no new issues.

Files Reviewed (14 files)
  • .kilo/skills/kilo-mcp/SKILL.md
  • apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.test.ts
  • apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.tsx
  • apps/web/src/components/cloud-agent-next/hooks/useWorktreeCleanup.ts
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts (re-verified, no issue)
  • apps/web/src/routers/cli-sessions-v2-router.ts
  • apps/web/src/routers/cli-sessions-v2-worktree.test.ts
  • apps/web/src/scripts/mcp-catalog/catalog.test.ts
  • apps/web/src/scripts/mcp-catalog/catalog.ts
  • services/cloud-agent-next/src/e2e-entry.ts
  • services/cloud-agent-next/src/router/handlers/worktree-deletion.test.ts
  • services/cloud-agent-next/src/router/handlers/worktree-deletion.ts
  • services/cloud-agent-next/test/unit/render-e2e-worker-config.test.ts
  • services/kilo-mcp/catalog.json
Previous Review Summary (commit 1092de9)

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

Previous review (commit 1092de9)

Status: 7 Issues Found | Recommendation: Address before merge

Executive Summary

A type-only import used with typeof breaks the web typecheck, and the eligibility SQL joins cli_sessions_v2 without the user key, so a colliding session row can change which merged workspaces get deleted.

Overview

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

CRITICAL

File Line Issue
apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts 44 WorktreeCleanupScope / WorkerStartWorktreeCleanupInput are imported with type but used in typeof at lines 257-258, which TypeScript rejects (TS1361), failing typecheck/build.

WARNING

File Line Issue
apps/web/src/routers/cli-sessions-v2-router.ts 998 Outer join to cli_sessions_v2 matches on session_id only; the primary key is (session_id, kilo_user_id), so another user's row can feed the merged-PR aggregation and change destructive-cleanup eligibility.
services/cloud-agent-next/wrangler.jsonc 337 New WORKTREE_CLEANUP binding survives into the rendered e2e config, but src/e2e-entry.ts does not export WorktreeCleanupCoordinator, so deployed/local e2e cannot resolve the class.
services/kilo-mcp/catalog.json 5779 The data-deleting startMergedWorktreeCleanup and retryWorktreeCleanup mutations are now reachable from MCP (kilo_call) without the PR explaining why an agent may invoke them.

SUGGESTION

File Line Issue
apps/web/src/components/cloud-agent-next/hooks/useWorktreeCleanup.ts 39 In-memory reconciliation dedupe plus never-cleared terminal batches means every layout remount replays deletion reconciliation for all past cleanup items.
apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.tsx 115 retry.error is never reset, so an error from a previous batch can be shown against a new batch's retry button.
services/cloud-agent-next/src/router/handlers/worktree-deletion.ts 242 The merged-only guard runs again in the post-runtime record_cleanup call, so a late eligibility change can permanently fail an item after its sandbox/worktree is already deleted.
Files Reviewed (32 files)
  • .kilo/skills/kilo-mcp/SKILL.md - no issues
  • apps/web/src/components/cloud-agent-next/ChatSidebar.tsx - no issues
  • apps/web/src/components/cloud-agent-next/CloudSidebarLayout.tsx - no issues
  • apps/web/src/components/cloud-agent-next/CloudSidebarLayout.worktree-cleanup.test.ts - no issues
  • apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.test.ts - no issues
  • apps/web/src/components/cloud-agent-next/MergedWorktreeCleanup.tsx - 1 issue
  • apps/web/src/components/cloud-agent-next/hooks/useWorktreeCleanup.ts - 1 issue
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.test.ts - no issues
  • apps/web/src/lib/cloud-agent-next/cloud-agent-client.ts - 1 issue
  • apps/web/src/routers/cli-sessions-v2-router.ts - 1 issue
  • apps/web/src/routers/cli-sessions-v2-worktree.test.ts - no issues
  • packages/session-ingest-contracts/src/rpc-contract.ts - no issues
  • services/cloud-agent-next/src/index.ts - no issues
  • services/cloud-agent-next/src/router.test.ts - no issues
  • services/cloud-agent-next/src/router.ts - no issues
  • services/cloud-agent-next/src/router/handlers/worktree-cleanup.test.ts - no issues
  • services/cloud-agent-next/src/router/handlers/worktree-cleanup.ts - no issues
  • services/cloud-agent-next/src/router/handlers/worktree-deletion.test.ts - no issues
  • services/cloud-agent-next/src/router/handlers/worktree-deletion.ts - 1 issue
  • services/cloud-agent-next/src/types.ts - no issues
  • services/cloud-agent-next/src/worktree-cleanup/WorktreeCleanupCoordinator.test.ts - no issues
  • services/cloud-agent-next/src/worktree-cleanup/WorktreeCleanupCoordinator.ts - no issues
  • services/cloud-agent-next/src/worktree-cleanup/schemas.ts - no issues
  • services/cloud-agent-next/src/worktree-cleanup/stub.ts - no issues
  • services/cloud-agent-next/test/integration/worktree-cleanup.test.ts - no issues
  • services/cloud-agent-next/test/test-worker.ts - no issues
  • services/cloud-agent-next/worker-configuration.d.ts - no issues
  • services/cloud-agent-next/wrangler.jsonc - 1 issue
  • services/cloud-agent-next/wrangler.test.jsonc - no issues
  • services/cloud-agent-next/src/e2e-entry.ts - missing export (reported on wrangler.jsonc)
  • services/session-ingest/src/services/worktree-deletion.ts - no issues
  • services/session-ingest/test/postgres/worktree-deletion.test.ts - no issues
  • services/kilo-mcp/catalog.json - 1 issue

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 100.2K · Output: 29.9K · Cached: 2.3M

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