Skip to content

feat: add remote phase policy wiring - #137

Merged
delete-cloud merged 4 commits into
mainfrom
feat/setup-agent-phase-policy
May 12, 2026
Merged

delete-cloud merged 4 commits into
mainfrom
feat/setup-agent-phase-policy

Conversation

@delete-cloud

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

Copy link
Copy Markdown
Owner

Summary

  • load [remote_phases] into cloud workspace config and validate production setup/agent phase policy
  • add request-level setup_commands schema plus server-side allow_request_commands gating
  • expose CLI/client --setup-command as a thin HTTP payload field and document the production boundary

Validation

  • uv run pytest tests/ui/test_http_server.py -k "invalid_request_setup_commands or remote_phases or setup_commands" -q
  • uv run pytest tests/cli/test_remote_client.py -k "setup_commands or runtime_profile" -q
  • uv run pytest tests/ui/test_http_server.py tests/cli/test_remote_client.py -k "remote_phases or setup_commands or runtime_profile" -q
  • uv run ruff format --check src/coding_agent/ui/http_server.py src/coding_agent/ui/schemas.py src/coding_agent/remote/client.py src/coding_agent/main.py tests/ui/test_http_server.py tests/cli/test_remote_client.py
  • uv run basedpyright --level error src/coding_agent/ui/http_server.py src/coding_agent/ui/schemas.py src/coding_agent/remote/client.py src/coding_agent/main.py tests/ui/test_http_server.py tests/cli/test_remote_client.py

Summary by CodeRabbit

  • Documentation

    • Added production guidance and ADR describing setup vs. agent phase policy and recommending server-configured setup commands.
  • New Features

    • Added configurable remote phases (setup and agent) with network, timeout, and secret-env allowlist controls; setup disabled by default.
    • Request payloads may include optional setup commands (subject to policy).
  • Bug Fixes / Validation

    • Production validators enforce safe remote-phase configurations and reject disallowed request-provided setup.
  • Tests

    • Added tests for config loading, validation, and setup-command request handling.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 12, 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: 554282e4-32b5-4971-a198-b7bbc6bf39c6

📥 Commits

Reviewing files that changed from the base of the PR and between bdd1041 and 0319081.

📒 Files selected for processing (3)
  • coding-agent/docs/remote-sandbox-production.md
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/tests/ui/test_http_server.py
✅ Files skipped from review due to trivial changes (1)
  • coding-agent/docs/remote-sandbox-production.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • coding-agent/tests/ui/test_http_server.py
  • coding-agent/src/coding_agent/ui/http_server.py

📝 Walkthrough

Walkthrough

Adds ADR-0023 remote phases: request schema setup_commands, server loading/merge of remote_phases, production validators for setup/agent rules, request-side enforcement rejecting client-provided setup commands until execution is implemented, plus tests and documentation updates.

Changes

Remote Phases Setup/Agent Policy Implementation

Layer / File(s) Summary
Request schema for setup commands
coding-agent/src/coding_agent/ui/schemas.py
Add setup_commands optional field to DockerWorkspaceSourceRequest with per-item (1–100 chars) and list-length (max 20) validation constraints.
Server configuration loading for remote phases
coding-agent/src/coding_agent/ui/http_server.py, coding-agent/tests/ui/test_http_server.py
Load remote_phases from agent.toml into cloud_workspace runtime config via new _load_remote_phases_config helper and verify parsed setup/agent phase tables.
Validation helpers & production validator
coding-agent/src/coding_agent/ui/http_server.py
Add _require_positive_int_field and _require_string_list_field helpers and _validate_production_remote_phases to enforce structure/types and conditional rules for remote_phases.setup and remote_phases.agent; hook into production startup validation.
Request policy enforcement for setup commands
coding-agent/src/coding_agent/ui/http_server.py, coding-agent/tests/ui/test_http_server.py
Reject client-provided workspace_source.setup_commands in POST /sessions unless remote_phases.setup.allow_request_commands=true; raise "setup phase execution is not implemented yet" when execution is unavailable; include HTTP 400/422 tests.
Tests for invalid remote_phases configs
coding-agent/tests/ui/test_http_server.py
Extend parametrized “reject unsafe remote workspace config” cases to cover disallowed setup network values, invalid timeouts, empty commands when disallowed, and disallowed agent network values.
Documentation and configuration examples
coding-agent/docs/remote-sandbox-production.md
Extend example production TOML with [remote_phases.setup] and [remote_phases.agent]; add ADR-0023 policy text describing setup/agent separation, allowlisted setup secrets, agent no-secret requirement, and CLI guidance that request-provided setup commands currently fail closed.

Sequence Diagram

sequenceDiagram
  participant Client
  participant HTTPServer
  participant ConfigLoader as _load_cloud_workspace_config
  participant Validator as _validate_production_remote_phases
  participant Provisioner as _provisioned_execution_binding_from_request

  Client->>HTTPServer: POST /sessions with workspace_source (may include setup_commands)
  HTTPServer->>ConfigLoader: load cloud_workspace_config (including remote_phases)
  ConfigLoader->>Validator: provide remote_phases for production validation
  HTTPServer->>Validator: validate workspace_source.setup_commands policy
  HTTPServer->>Provisioner: proceed or reject provisioning based on policy/validation
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through TOML, tests, and docs today,
Setup phases mapped so servers have their way.
Policies penned and CLI refuses a stray,
Secrets stay guarded, network kept at bay.
A tiny rabbit applauds this measured relay.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding infrastructure to wire and validate remote phase policies (setup/agent phases) into the cloud workspace configuration and HTTP server layer.
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/setup-agent-phase-policy

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.

🧹 Nitpick comments (2)
coding-agent/docs/remote-sandbox-production.md (1)

68-74: ⚡ Quick win

Consider clarifying the empty setup commands configuration.

The example configuration shows commands = [] (line 72) combined with allow_request_commands = false (line 74), which means no setup commands will run—neither server-configured nor client-provided.

However:

  • Lines 101-102 describe the setup phase as "configured for dependency bootstrap with explicit commands"
  • Lines 232-233 recommend "server-configured setup commands for production deployments that need repeatable bootstrap behavior"

This creates ambiguity about whether:

  1. The empty commands = [] is intentional to show a minimal no-setup baseline that users should customize, or
  2. It's a placeholder that should contain example commands

Consider adding a brief inline comment or note in the configuration example to clarify that commands = [] should be populated with project-specific setup commands when dependency installation is required.

📝 Proposed clarification
 [remote_phases.setup]
 enabled = true
 network = "bridge"
 timeout_seconds = 600
-commands = []
+commands = []  # Populate with setup commands if dependency installation is needed
 secret_env_allowlist = ["PIP_INDEX_URL", "GITHUB_TOKEN"]
 allow_request_commands = false

Also applies to: 101-107, 223-233

🤖 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/docs/remote-sandbox-production.md` around lines 68 - 74, Update
the remote_sandbox production example to clarify that the empty array in
remote_phases.setup (commands = []) is intentional as a minimal/no-setup
baseline and should be replaced with project-specific bootstrap commands when
dependencies must be installed; add a short inline note adjacent to
remote_phases.setup or next to the commands entry (and mirror the same
clarification in the other examples mentioned around remote_phases.setup and the
sections at lines ~101-107 and ~223-233) so readers know whether to populate
commands or rely on allow_request_commands toggles.
coding-agent/src/coding_agent/ui/http_server.py (1)

266-270: ⚡ Quick win

Add comment explaining the timeout_seconds validation asymmetry between setup and agent phases.

The setup phase validates timeout_seconds as required when enabled=True (lines 266-270), while the agent phase treats it as optional with an explicit None check (lines 295-301). Although this asymmetry is intentional—setup is a bootstrap operation requiring a timeout, while agent timeout is optional—the design decision is not documented in the code. Add a comment explaining why setup demands timeout_seconds while agent makes it optional, referencing ADR-0023 for context.

🤖 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/ui/http_server.py` around lines 266 - 270, Add
an inline comment near the call to _require_positive_int_field for setup_phase
explaining that setup_phase.timeout_seconds is required when enabled because the
bootstrap/setup operation must complete within a bounded time (it cannot rely on
optional timeouts), whereas the agent phase intentionally treats timeout_seconds
as optional (explicit None allowed) because runtime agents may operate with no
enforced timeout; cite ADR-0023 to document this deliberate design asymmetry
between setup and agent phases (reference setup_phase, remote_phases.setup,
timeout_seconds, and the agent phase handling).
🤖 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.

Nitpick comments:
In `@coding-agent/docs/remote-sandbox-production.md`:
- Around line 68-74: Update the remote_sandbox production example to clarify
that the empty array in remote_phases.setup (commands = []) is intentional as a
minimal/no-setup baseline and should be replaced with project-specific bootstrap
commands when dependencies must be installed; add a short inline note adjacent
to remote_phases.setup or next to the commands entry (and mirror the same
clarification in the other examples mentioned around remote_phases.setup and the
sections at lines ~101-107 and ~223-233) so readers know whether to populate
commands or rely on allow_request_commands toggles.

In `@coding-agent/src/coding_agent/ui/http_server.py`:
- Around line 266-270: Add an inline comment near the call to
_require_positive_int_field for setup_phase explaining that
setup_phase.timeout_seconds is required when enabled because the bootstrap/setup
operation must complete within a bounded time (it cannot rely on optional
timeouts), whereas the agent phase intentionally treats timeout_seconds as
optional (explicit None allowed) because runtime agents may operate with no
enforced timeout; cite ADR-0023 to document this deliberate design asymmetry
between setup and agent phases (reference setup_phase, remote_phases.setup,
timeout_seconds, and the agent phase handling).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a5a3c27c-33f4-4e06-9449-e579c94de31c

📥 Commits

Reviewing files that changed from the base of the PR and between 7c6075a and 084408a.

📒 Files selected for processing (7)
  • coding-agent/docs/remote-sandbox-production.md
  • coding-agent/src/coding_agent/__main__.py
  • coding-agent/src/coding_agent/remote/client.py
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/src/coding_agent/ui/schemas.py
  • coding-agent/tests/cli/test_remote_client.py
  • coding-agent/tests/ui/test_http_server.py

@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/ui/http_server.py (1)

788-795: ⚡ Quick win

Use remote_phases.setup.allow_request_commands in request policy checks.

Line 790 passes cloud_workspace_config, but the function ignores it and always rejects setup_commands. Add an explicit policy gate first, then keep the current “not implemented yet” rejection.

Proposed fix
 def _validate_workspace_source_phase_policy(
     workspace_source: dict[str, object],
     cloud_workspace_config: dict[str, Any],
 ) -> None:
     setup_commands = workspace_source.get("setup_commands")
     if setup_commands is None:
         return
+    remote_phases = cloud_workspace_config.get("remote_phases")
+    setup_phase = (
+        remote_phases.get("setup")
+        if isinstance(remote_phases, dict)
+        else None
+    )
+    allow_request_commands = (
+        isinstance(setup_phase, dict)
+        and setup_phase.get("allow_request_commands") is True
+    )
+    if not allow_request_commands:
+        raise ValueError(
+            "workspace_source.setup_commands requires remote_phases.setup.allow_request_commands=true"
+        )
     raise ValueError("setup phase execution is not implemented yet")
🤖 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/ui/http_server.py` around lines 788 - 795, The
function _validate_workspace_source_phase_policy currently ignores
cloud_workspace_config and always rejects workspace_source["setup_commands"];
update it to first read the request policy flag
remote_phases.setup.allow_request_commands from cloud_workspace_config (or its
nested policy structure) and only proceed to reject when that flag is False or
missing, otherwise allow the existence of setup_commands (but still keep the
existing ValueError("setup phase execution is not implemented yet") as the
fallback rejection for now); use the function name
_validate_workspace_source_phase_policy and the policy key
remote_phases.setup.allow_request_commands to locate where to add this policy
gate.
🤖 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/ui/http_server.py`:
- Around line 248-311: _validate_production_remote_phases currently allows
setup.enabled=True but with no effective commands (empty/missing "commands" and
"allow_request_commands" false), creating a no-op; update the logic inside the
setup_phase.enabled branch to require a usable command source by ensuring either
"commands" is present and non-empty or "allow_request_commands" is True, e.g.
after calling _require_string_list_field for "commands" check that
setup_phase.get("commands") is a non-empty list (and if not, raise
ValueError("remote_phases.setup must provide non-empty 'commands' or set
'allow_request_commands' to true")), and ensure the existing boolean validation
for allow_request_commands is preserved.

---

Nitpick comments:
In `@coding-agent/src/coding_agent/ui/http_server.py`:
- Around line 788-795: The function _validate_workspace_source_phase_policy
currently ignores cloud_workspace_config and always rejects
workspace_source["setup_commands"]; update it to first read the request policy
flag remote_phases.setup.allow_request_commands from cloud_workspace_config (or
its nested policy structure) and only proceed to reject when that flag is False
or missing, otherwise allow the existence of setup_commands (but still keep the
existing ValueError("setup phase execution is not implemented yet") as the
fallback rejection for now); use the function name
_validate_workspace_source_phase_policy and the policy key
remote_phases.setup.allow_request_commands to locate where to add this policy
gate.
🪄 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: 7f9daf0f-664c-4076-ab67-dc635847524e

📥 Commits

Reviewing files that changed from the base of the PR and between 084408a and d7a5e47.

📒 Files selected for processing (3)
  • coding-agent/docs/remote-sandbox-production.md
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/tests/ui/test_http_server.py
✅ Files skipped from review due to trivial changes (1)
  • coding-agent/docs/remote-sandbox-production.md

Comment thread coding-agent/src/coding_agent/ui/http_server.py
@delete-cloud
delete-cloud merged commit 7723456 into main May 12, 2026
1 check passed
@delete-cloud
delete-cloud deleted the feat/setup-agent-phase-policy branch May 12, 2026 09:08
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