Skip to content

fix(cloud-agent-next): clean up workspace on failed cold-start resume#944

Merged
eshurakov merged 3 commits intomainfrom
eshurakov/cloud-agent-next-failed-import-wrapper
Mar 9, 2026
Merged

fix(cloud-agent-next): clean up workspace on failed cold-start resume#944
eshurakov merged 3 commits intomainfrom
eshurakov/cloud-agent-next-failed-import-wrapper

Conversation

@eshurakov
Copy link
Copy Markdown
Contributor

@eshurakov eshurakov commented Mar 9, 2026

Summary

When a post-clone step (e.g. kilo import, snapshot fetch, diff apply) fails during cold-start resume, the workspace directory — including .git — was left behind. On the next retry, handleColdStartResume saw isColdStart = false (because .git existed) and skipped the full restore flow, leaving the session in a broken half-initialized state.

This wraps the post-clone steps in handleColdStartResume in a try/catch that calls cleanupWorkspace() on failure, removing the workspace and session home directories so the next retry sees a true cold start and re-runs the full restore from scratch. This applies to all failure modes, including SessionSnapshotRestoreError (404).

Two tests are added covering the workspace-cleanup behavior on import failure and on 404 snapshot response.

Verification

  • pnpm vitest run — all 641 tests pass
  • pnpm typecheck — passes
  • Additional verification details

Visual Changes

N/A

Reviewer Notes

  • The cleanupWorkspace helper (from workspace.ts) removes both the workspace directory and the session home directory using session.exec(). This is best-effort — the original error is always re-thrown.
  • The initial commit excluded 404 from cleanup; the follow-up commit (02d0959) corrected this to also clean up on 404 since a stale .git causes the same warm-start misrouting regardless of the error type.

Comment thread cloud-agent-next/src/session-service.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • cloud-agent-next/src/session-service.ts
  • cloud-agent-next/src/session-service.test.ts

Comment thread cloud-agent-next/src/session-service.ts
@eshurakov eshurakov changed the title fix(cloud-agent-next): clean up workspace on failed kilo import during cold-start resume fix(cloud-agent-next): clean up workspace on failed cold-start resume Mar 9, 2026
Move restoreWorkspace() inside the try/catch block so that clone or
branch-checkout failures also trigger workspace cleanup. Previously,
a failure in manageBranch (after .git was created) would leave the
workspace in a state where the next retry saw isColdStart = false and
skipped the full restore flow.
@eshurakov eshurakov merged commit fc10a04 into main Mar 9, 2026
18 checks passed
@eshurakov eshurakov deleted the eshurakov/cloud-agent-next-failed-import-wrapper branch March 9, 2026 16:21
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