Repository navigation
fix: import workspace snapshot before setup - #139
Conversation
📝 WalkthroughWalkthroughSnapshot archive initialization moves from HTTP server asynchronous pre-population to Docker workspace provider extraction during provisioning. The provider now validates and extracts base64 snapshots into the workspace root before running the setup phase. Corresponding HTTP server snapshot code is removed, and test configuration is consolidated via a helper function. ChangesWorkspace Snapshot Initialization Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@coding-agent/src/coding_agent/environment/docker_workspace_provider.py`:
- Around line 402-411: The extraction of snapshot_archive_base64 via
extract_workspace_archive_base64 can fail before any container is started, and
currently the outer exception path may skip removing workspace_root if docker
cleanup also errors; update the logic around extract_workspace_archive_base64 in
DockerWorkspaceProvider (refer to workspace_root and
extract_workspace_archive_base64) so that any exception raised during extraction
immediately deletes/cleans up workspace_root (or uses a finally block that
guarantees workspace_root removal if containers were never created) before
re-raising the error, rather than relying on later docker cleanup; ensure the
cleanup is robust (ignore errors during deletion) so no workspace directories
are leaked on extraction failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1d7a976a-5757-40b9-88b0-b9fc97653fd2
📒 Files selected for processing (4)
coding-agent/src/coding_agent/environment/docker_workspace_provider.pycoding-agent/src/coding_agent/ui/http_server.pycoding-agent/tests/coding_agent/environment/test_docker_workspace_provider.pycoding-agent/tests/ui/test_http_server_workspace_transfer.py
💤 Files with no reviewable changes (1)
- coding-agent/src/coding_agent/ui/http_server.py
| snapshot_archive_base64 = source.get("snapshot_archive_base64") | ||
| if snapshot_archive_base64 is not None: | ||
| if not isinstance(snapshot_archive_base64, str): | ||
| raise ValueError( | ||
| "workspace_source.snapshot_archive_base64 must be a string" | ||
| ) | ||
| extract_workspace_archive_base64( | ||
| workspace_root, | ||
| snapshot_archive_base64, | ||
| ) |
There was a problem hiding this comment.
Avoid leaking workspace directories when snapshot extraction fails before any container starts.
If extract_workspace_archive_base64(...) fails here, the except block still attempts docker cleanup; if that cleanup errors, workspace_root is not deleted (Line 429), leaking directories and potentially consuming quota over repeated failures.
Suggested fix
try:
+ docker_cleanup_needed = False
snapshot_archive_base64 = source.get("snapshot_archive_base64")
if snapshot_archive_base64 is not None:
if not isinstance(snapshot_archive_base64, str):
raise ValueError(
"workspace_source.snapshot_archive_base64 must be a string"
)
extract_workspace_archive_base64(
workspace_root,
snapshot_archive_base64,
)
+ docker_cleanup_needed = True
_run_docker_setup_phase_if_configured(provider_config, config, binding)
_start_docker_workspace_container(provider_config, binding)
except Exception as exc:
logger.exception(
"Docker workspace creation failed for workspace_id=%s",
workspace_id,
)
cleanup_failed = False
- try:
- _remove_docker_workspace_container(provider_config, workspace_id)
- except Exception as cleanup_exc:
- cleanup_failed = True
- note = (
- "failed to clean up docker workspace container after start failure: "
- + str(cleanup_exc)
- )
- exc.add_note(note)
+ if docker_cleanup_needed:
+ try:
+ _remove_docker_workspace_container(provider_config, workspace_id)
+ except Exception as cleanup_exc:
+ cleanup_failed = True
+ note = (
+ "failed to clean up docker workspace container after start failure: "
+ + str(cleanup_exc)
+ )
+ exc.add_note(note)
if not cleanup_failed and workspace_root.exists():
shutil.rmtree(workspace_root)
raise🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@coding-agent/src/coding_agent/environment/docker_workspace_provider.py`
around lines 402 - 411, The extraction of snapshot_archive_base64 via
extract_workspace_archive_base64 can fail before any container is started, and
currently the outer exception path may skip removing workspace_root if docker
cleanup also errors; update the logic around extract_workspace_archive_base64 in
DockerWorkspaceProvider (refer to workspace_root and
extract_workspace_archive_base64) so that any exception raised during extraction
immediately deletes/cleans up workspace_root (or uses a finally block that
guarantees workspace_root removal if containers were never created) before
re-raising the error, rather than relying on later docker cleanup; ensure the
cleanup is robust (ignore errors during deletion) so no workspace directories
are leaked on extraction failure.
Summary
Validation
Summary by CodeRabbit
New Features
Refactor
Tests