fix(browser): enforce limits and add cleanup#11
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds configurable CPU and RAM resource limits for browser container startup and introduces a stop command for container cleanup. Resource limits are loaded from environment variables, accept CLI overrides, and are applied as Docker flags during container startup. A new stop operation removes containers and reports removal status. ChangesBrowser container resource limits and lifecycle
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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)
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 `@src/browser.rs`:
- Around line 140-148: The stop_browser_container function checks
inspect_container_state(&spec.container_name) then calls docker(["rm", "-f",
&spec.container_name], ...) which can race if another process removes the
container; make stop idempotent by treating "container not found" as success:
wrap the docker rm call in error-handling that converts a not-found /
already-removed error into Ok(true) instead of propagating an Err, keeping other
errors failing normally. Update the logic inside stop_browser_container
(referencing inspect_container_state, docker, BrowserSpec::container_name and
the Result<BrowserStopRuntime> return) so if docker rm returns an error
indicating the container no longer exists the function returns as if removed.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1fb84152-87b0-4c0a-9872-83411bb2629a
📒 Files selected for processing (5)
changelog.d/20260525_000000_browser_limits_cleanup.mdsrc/browser.rssrc/lib.rssrc/main.rstests/cli_status.rs
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/browser.rs (1)
144-151:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon’t suppress
docker rmfailures via ambiguous inspect fallback.On Line 147,
inspect_container_state()returnsOk(None)for any failed inspect, not only “container missing”. Ifdocker rmfails (e.g., daemon/permission issue) and inspect also fails, this branch reports success instead of surfacing the error.Suggested fix
- match docker(["rm", "-f", &spec.container_name], "docker rm browser") { - Ok(_) => {} - Err(error) => { - if inspect_container_state(&spec.container_name)?.is_some() { - return Err(error); - } - } - } - true + match docker(["rm", "-f", &spec.container_name], "docker rm browser") { + Ok(_) => true, + Err(error) => { + let message = error.to_string(); + if message.contains("No such container") + || message.contains("No such object") + { + false + } else { + return Err(error); + } + } + }🤖 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/browser.rs` around lines 144 - 151, The current error-handling around docker(["rm", ...]) suppresses real failures by treating any non-Ok inspect as non-existent; change the logic in the docker rm error branch to only swallow the original error when inspect_container_state(&spec.container_name) returns Ok(Some(_)) (meaning the container still exists) or, better, to explicitly handle the "container not found" case by matching Err variants from inspect and propagating the docker rm error for other failures; update the match using the inspect_container_state function and the spec.container_name identifier so that any inspect errors (Ok(None) or Err(_)) do not convert a docker rm failure into success and instead return Err(error).
🤖 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.
Duplicate comments:
In `@src/browser.rs`:
- Around line 144-151: The current error-handling around docker(["rm", ...])
suppresses real failures by treating any non-Ok inspect as non-existent; change
the logic in the docker rm error branch to only swallow the original error when
inspect_container_state(&spec.container_name) returns Ok(Some(_)) (meaning the
container still exists) or, better, to explicitly handle the "container not
found" case by matching Err variants from inspect and propagating the docker rm
error for other failures; update the match using the inspect_container_state
function and the spec.container_name identifier so that any inspect errors
(Ok(None) or Err(_)) do not convert a docker rm failure into success and instead
return Err(error).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e2030b8a-4fad-41b4-a2fb-448a199a954a
📒 Files selected for processing (1)
src/browser.rs
Summary
Validation