Skip to content

feat: provision git workspace sources - #145

Merged
delete-cloud merged 2 commits into
mainfrom
feat/git-workspace-provisioning
May 13, 2026
Merged

delete-cloud merged 2 commits into
mainfrom
feat/git-workspace-provisioning

Conversation

@delete-cloud

@delete-cloud delete-cloud commented May 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • let the Docker workspace provider provision workspace_source.kind = git
  • clone the requested Git remote/ref into the allocated workspace and checkout base_sha before setup and agent containers start
  • keep .git in the remote workspace so later ADR-0024 diff/patch/publish work has Git metadata
  • add provider and HTTP tests for Git source provisioning while preserving snapshot behavior

Validation

  • uv run pytest tests/coding_agent/environment/test_docker_workspace_provider.py -k "clones_git_source_before_setup_phase" -q
  • uv run pytest tests/ui/test_http_server.py -k "provisions_git_workspace_source" -q
  • uv run pytest tests/coding_agent/environment/test_docker_workspace_provider.py -q
  • uv run pytest tests/ui/test_http_server.py -k "workspace_source or git_workspace or docker_cloud_workspace or RemoteResultPublicationContract" -q
  • uv run pytest tests/coding_agent/environment/test_docker_workspace_provider.py tests/coding_agent/environment/test_docker_workspace_provider_transfer.py tests/ui/test_http_server.py tests/ui/test_http_server_workspace_transfer.py tests/cli/test_remote_client.py -k "git_workspace or workspace_source or docker_workspace or workspace_transfer or remote_run or RemoteResultPublicationContract" -q
  • uv run basedpyright --level error src/coding_agent/environment/docker_workspace_provider.py src/coding_agent/ui/http_server.py src/coding_agent/ui/schemas.py tests/coding_agent/environment/test_docker_workspace_provider.py tests/ui/test_http_server.py
  • uv run ruff format --check src/coding_agent/environment/docker_workspace_provider.py src/coding_agent/ui/http_server.py src/coding_agent/ui/schemas.py tests/coding_agent/environment/test_docker_workspace_provider.py tests/ui/test_http_server.py
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Workspace provisioning supports Git-based sources: repositories are cloned and checked out to the requested commit when creating workspaces.
  • Bug Fixes

    • Removed prior rejection of Git workspace requests.
    • Improved error reporting when Git operations fail by surface-friendly notes and no leftover workspace on failure.
    • Validation now rejects invalid commit SHAs before attempting clone/checkout.
  • Tests

    • Added end-to-end tests covering Git clone/checkout flow, SHA validation, and failure reporting.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d595a817-d67c-4b85-8b2a-2c745fd577c5

📥 Commits

Reviewing files that changed from the base of the PR and between 88c2ab8 and 9301ab7.

📒 Files selected for processing (2)
  • coding-agent/src/coding_agent/environment/docker_workspace_provider.py
  • coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py

📝 Walkthrough

Walkthrough

This PR enables Docker workspace provisioning to support Git-backed workspace sources alongside the existing snapshot-based flow. Docker workspace provider now clones a remote Git repository into the workspace root before Docker setup phases, and the HTTP API removes the "not implemented" rejection for Git sources. Git operations are guarded by configurable timeouts and binary paths.

Changes

Git Workspace Source Support

Layer / File(s) Summary
Git operation infrastructure and helper
coding-agent/src/coding_agent/environment/docker_workspace_provider.py
Adds _GIT_OPERATION_TIMEOUT_SECONDS constant and _clone_git_workspace_source helper that validates remote URL, base ref, and base SHA, then executes git clone --no-checkout followed by git checkout --detach with timeout enforcement.
Docker workspace provider git_binary configuration
coding-agent/src/coding_agent/environment/docker_workspace_provider.py
_DockerWorkspaceProviderConfig model includes git_binary field; configuration reading extracts it from effective runtime config (default "git"), validates with assertion, and wires into the provider config instance.
Docker workspace provisioning branch by kind
coding-agent/src/coding_agent/environment/docker_workspace_provider.py
provision_cloud_workspace_binding accepts kind in {"docker", "git"}; routes to _clone_git_workspace_source for git sources or snapshot archive extraction for docker sources.
HTTP server git workspace source handling
coding-agent/src/coding_agent/ui/http_server.py
Removes 501 Not Implemented rejection for workspace_source.kind == "git" from _provisioned_execution_binding_from_request; adds workspace source phase policy validation and delegates to cloud binding provisioning.
Docker provider git cloning test
coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py
New tests mock subprocess to validate git clone and checkout operations, assert setup observes cloned repository, reject invalid base_sha before subprocesses, and verify clone failure attaches redacted stdout/stderr notes.
HTTP server git session test
coding-agent/tests/ui/test_http_server.py
Renamed/updated test method validates session creation with git workspace source; captures incoming workspace_source data, asserts HTTP 200 response, and verifies session execution_binding and origin.workspace_source_kind.

Sequence Diagram

sequenceDiagram
  participant Client
  participant HTTPServer as HTTP Server
  participant DockerProvider as Docker Provider
  participant Git as git subprocess
  participant DockerSetup as Docker Setup Phase

  Client->>HTTPServer: POST /sessions with git workspace source
  HTTPServer->>HTTPServer: validate workspace source phase policy
  HTTPServer->>DockerProvider: provision cloud workspace binding
  DockerProvider->>Git: git clone --no-checkout --branch <base_ref> <remote_url> (timeout)
  Git->>DockerProvider: repository initialized (files, .git)
  DockerProvider->>Git: git -C <workspace_root> checkout --detach <base_sha> (timeout)
  Git->>DockerProvider: workspace updated to base SHA
  DockerProvider->>DockerSetup: run setup phase with cloned workspace
  DockerSetup->>DockerSetup: observe cloned repository
  HTTPServer->>Client: return 200 with execution binding and origin
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped into repos with a soft little click,
Cloned branches with care and detached each quick,
Timeouts kept tidy, notes redacted with art,
Workspaces bloom ready — a developer's start! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: provision git workspace sources' directly summarizes the main change: enabling git workspace source provisioning in the Docker workspace provider.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/git-workspace-provisioning

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
coding-agent/src/coding_agent/environment/docker_workspace_provider.py (1)

1102-1127: ⚡ Quick win

Prevent interactive hangs and surface git failure output.

Two reliability gaps in the clone/checkout invocations:

  • env=None inherits the parent process environment and stdin is inherited as well, so a private/auth-required remote will trigger a credential prompt that blocks until _GIT_OPERATION_TIMEOUT_SECONDS fires. Set GIT_TERMINAL_PROMPT=0 (and stdin=subprocess.DEVNULL) to fail fast.
  • With check=True, a failed clone/checkout raises CalledProcessError but the captured stdout/stderr are not attached as notes. The setup phase already uses _add_setup_failure_output_notes for this; mirroring that here would make diagnosing remote/auth/branch errors much easier.
♻️ Sketch of the change
+    git_env = {**os.environ, "GIT_TERMINAL_PROMPT": "0"}
     clone_command = [...]
-    _ = subprocess.run(
-        clone_command,
-        shell=False,
-        capture_output=True,
-        text=True,
-        timeout=_GIT_OPERATION_TIMEOUT_SECONDS,
-        env=None,
-        check=True,
-    )
+    try:
+        _ = subprocess.run(
+            clone_command,
+            shell=False,
+            capture_output=True,
+            text=True,
+            timeout=_GIT_OPERATION_TIMEOUT_SECONDS,
+            env=git_env,
+            stdin=subprocess.DEVNULL,
+            check=True,
+        )
+    except subprocess.CalledProcessError as exc:
+        if exc.stdout:
+            exc.add_note(f"git clone stdout:\n{exc.stdout}")
+        if exc.stderr:
+            exc.add_note(f"git clone stderr:\n{exc.stderr}")
+        raise

The same treatment can be applied to the checkout invocation.

🤖 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 1102 - 1127, The clone and checkout subprocess.run calls (for
variables clone_command and checkout_command) must be hardened to avoid
interactive hangs and surface git output: set stdin=subprocess.DEVNULL and pass
an env dict that includes GIT_TERMINAL_PROMPT="0" (instead of env=None) so git
fails fast for auth prompts, and wrap each call in a try/except for
subprocess.CalledProcessError to capture the failed process output and call the
existing _add_setup_failure_output_notes helper with the exception and relevant
context (same pattern used elsewhere in this module), retaining
timeout=_GIT_OPERATION_TIMEOUT_SECONDS and check=True.
🤖 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 1093-1127: The clone_command currently passes remote_url as a
positional arg which allows argument injection; update the clone_command
(symbol: clone_command) to insert a "--" separator before remote_url so git
stops parsing further args as options; additionally, validate base_sha (used in
checkout_command) against a hex SHA regex (e.g., ^[0-9a-fA-F]{4,64}$) before
calling the checkout_command (symbol: checkout_command) and reject or raise a
clear error if it fails validation to avoid passing unsafe values; reference
provider_config.git_binary and the GitWorkspaceSourceRequest inputs when
locating the variables to change.

---

Nitpick comments:
In `@coding-agent/src/coding_agent/environment/docker_workspace_provider.py`:
- Around line 1102-1127: The clone and checkout subprocess.run calls (for
variables clone_command and checkout_command) must be hardened to avoid
interactive hangs and surface git output: set stdin=subprocess.DEVNULL and pass
an env dict that includes GIT_TERMINAL_PROMPT="0" (instead of env=None) so git
fails fast for auth prompts, and wrap each call in a try/except for
subprocess.CalledProcessError to capture the failed process output and call the
existing _add_setup_failure_output_notes helper with the exception and relevant
context (same pattern used elsewhere in this module), retaining
timeout=_GIT_OPERATION_TIMEOUT_SECONDS and check=True.
🪄 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: 3f396f3d-9a32-4d8e-96af-3187901ada92

📥 Commits

Reviewing files that changed from the base of the PR and between 04673f6 and 88c2ab8.

📒 Files selected for processing (4)
  • coding-agent/src/coding_agent/environment/docker_workspace_provider.py
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py
  • coding-agent/tests/ui/test_http_server.py
💤 Files with no reviewable changes (1)
  • coding-agent/src/coding_agent/ui/http_server.py

Comment thread coding-agent/src/coding_agent/environment/docker_workspace_provider.py Outdated
@delete-cloud
delete-cloud merged commit 9dde89f into main May 13, 2026
1 check passed
@delete-cloud
delete-cloud deleted the feat/git-workspace-provisioning branch May 13, 2026 06:41
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