fix: route workspace tree to host when sandbox_mode is native/local#490
fix: route workspace tree to host when sandbox_mode is native/local#490sami-marreed wants to merge 1 commit into
Conversation
Avoid OpenSandbox SDK calls (and 503s) for /api/workspace/tree when opensandbox_sandbox is true but sandbox_mode is native or local.
📝 WalkthroughWalkthroughWorkspace tree backing decisions now account for ChangesWorkspace backing selection
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cuga/backend/server/workspace_sandbox.py (1)
29-32: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winDuplicated mode-resolution logic uses a fallback default that contradicts the project's documented default.
The
mode = str(getattr(settings.advanced_features, "sandbox_mode", "opensandbox") or "opensandbox")snippet is duplicated verbatim in both functions. More importantly, project docs state "That preset turns on skills for the run and uses [advanced_features] sandbox_mode in settings.toml (default native)." The getattr/orfallback here defaults to"opensandbox"instead of"native". In the normal case the real Settings object always carries a value so this fallback rarely fires, but ifsandbox_modeis ever missing/None/empty (partial settings, older schema, a different mock), this silently falls back to OpenSandbox routing — the exact class of bug (#484) this PR fixes.Extracting a single helper also removes the duplication risk of the two copies drifting out of sync.
♻️ Suggested consolidation
+def _resolve_sandbox_mode() -> str: + return str(getattr(settings.advanced_features, "sandbox_mode", "native") or "native") + + def workspace_tree_is_sandbox_backed() -> bool: ... if not bool(getattr(settings.advanced_features, "opensandbox_sandbox", False)): return False - mode = str(getattr(settings.advanced_features, "sandbox_mode", "opensandbox") or "opensandbox") + mode = _resolve_sandbox_mode() return mode not in ("native", "local") def workspace_tree_is_native_backed() -> bool: ... - mode = str(getattr(settings.advanced_features, "sandbox_mode", "opensandbox") or "opensandbox") + mode = _resolve_sandbox_mode() if mode in ("native", "local"): return TruePlease confirm what the real Settings schema's default for
advanced_features.sandbox_modeis, to make sure the fallback here matches it.Also applies to: 42-47
🤖 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 `@src/cuga/backend/server/workspace_sandbox.py` around lines 29 - 32, Consolidate the duplicated sandbox-mode resolution used by both functions into one shared helper, and make its missing, None, or empty-value fallback match the Settings schema’s documented default of "native". Update both callers to use this helper while preserving the existing OpenSandbox-enabled check and native/local routing behavior.
🤖 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 `@src/cuga/backend/server/workspace_sandbox.py`:
- Around line 29-32: Consolidate the duplicated sandbox-mode resolution used by
both functions into one shared helper, and make its missing, None, or
empty-value fallback match the Settings schema’s documented default of "native".
Update both callers to use this helper while preserving the existing
OpenSandbox-enabled check and native/local routing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 264b00c2-dad8-4f15-ad1a-fd8428601265
📒 Files selected for processing (2)
src/cuga/backend/server/workspace_sandbox.pytests/unit/test_workspace_sandbox.py
PR Review: #490 — fix: route workspace tree to host when sandbox_mode is native/localSummaryVerdict: merge with fixes. The core fix is correct and minimal: gating Strengths:
What to resolve before merge: Minor:
Issues[MIN-1] What's wrong: The new guard at lines 42–44 ( What it can cause: When |
Bug fix
Fixes #484
Summary
/api/workspace/treewas taking the OpenSandbox path wheneveropensandbox_sandbox=true, even with defaultsandbox_mode=native(and shell tools off). That caused noisy import errors and 503s when the optional OpenSandbox SDK was not installed.Workspace routing now follows
sandbox_mode:native/localuse the host thread workspace; OpenSandbox is only required when mode is actually opensandbox-backed.Testing
uv run pytest tests/unit/test_workspace_sandbox.py— 31 passeduv run pytest tests/unit/test_workspace_upload.py— 16 passedSummary by CodeRabbit