fix(browser): add diagnostic logging for container readiness failures#820
fix(browser): add diagnostic logging for container readiness failures#820
Conversation
When a browser container fails to become ready (e.g. #786), the logs now show: the container_host being probed, the full docker run command, container status (running/exited/OOM-killed), Chrome's own logs from inside the container, and a targeted warning when Moltis itself is running inside Docker suggesting the user set browser.container_host to "host.docker.internal". The root cause in #786 is a Docker-in-Docker networking issue: Moltis probes 127.0.0.1 (its own loopback) instead of the Docker host where the sibling browser container's port is mapped. These logs make the misconfiguration immediately obvious. Entire-Checkpoint: 4999fc827276
Greptile SummaryThis PR adds structured diagnostic logging for browser container readiness failures — surfacing container status, Chrome logs, the full All three concerns raised in the previous review round ( Confidence Score: 5/5Safe to merge — diagnostic-only additions with no changes to the happy-path launch logic. All three P1/P2 concerns from the previous review round are resolved: --rm removed so crash state is preserved, output.status.success() checked in fetch_container_logs, and the Apple Container --tail guard is in place. No new logic bugs introduced. The browserless env vars logged in the docker run command are all non-sensitive (TIMEOUT, MAX_CONCURRENT_SESSIONS, PREBOOT_CHROME). No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/browser/src/container.rs | Adds fetch_container_logs, inspect_container_status, and is_running_in_container helpers; removes --rm from docker run args; adds explicit rm in stop_container_by_id for all backends; emits container_host in log fields and a DinD warning on failure. All previous review concerns addressed. |
| crates/browser/src/pool.rs | Adds an info! log before spawn_blocking capturing session_id, image, container_host, profile_dir, and session_timeout_ms. Straightforward observability improvement with no logic changes. |
Sequence Diagram
sequenceDiagram
participant Pool as BrowserPool
participant C as container.rs
participant RT as Container Runtime
participant Chrome as Chrome/Browserless
Pool->>C: BrowserContainer::start_with_backend()
C->>RT: docker run -d (no --rm)
RT-->>C: container_id
C->>C: log "browser container run command" (full args)
C->>Chrome: wait_for_ready() — poll /json/version up to 60s
alt Chrome ready
Chrome-->>C: HTTP 200
C-->>Pool: Ok(BrowserContainer)
else Timeout / failure
C->>RT: fetch_container_logs() — docker logs --tail 50
RT-->>C: stdout + stderr
C->>RT: inspect_container_status() — docker inspect --format
RT-->>C: Status (running/exited/OOMKilled)
C->>C: warn container_status, container_host, error
C->>C: warn container logs
C->>C: is_running_in_container()? warn DinD hint
C->>RT: stop_container_by_id() → docker stop + docker rm
C-->>Pool: Err(error)
end
Reviews (2): Last reviewed commit: "fix(browser): address PR review — preser..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- Remove --rm from docker run so crashed containers keep their logs and status available for diagnostic collection (P1) - Add explicit docker rm in stop_container_by_id for all backends, not just Apple Container - Guard fetch_container_logs against Apple Container (unsupported --tail flag) and check output.status.success() to avoid surfacing Docker CLI errors as container logs (P2) - Remove redundant in-process 50-line truncation since --tail 50 already limits the output (P2) Entire-Checkpoint: 28138c8eeff4
|
@greptile review |
Summary
docker runcommand, and thecontainer_hostbeing probedbrowser.container_hosttohost.docker.internal— the exact fix for the Docker-in-Docker networking issue in [Bug]: Browser container fails to become ready within 60s #786container_hostto existing startup and failure log lines for visibilityCloses #786
Validation
Completed
cargo check -p moltis-browsercargo test -p moltis-browser— 86 tests passcargo clippy -p moltis-browser -- -D warningscargo +nightly-2025-11-30 fmt --all -- --checkRemaining
./scripts/local-validate.shManual QA
container_host="127.0.0.1"in the startup logbrowser.container_host = "host.docker.internal"in moltis.toml and verify browser works🤖 Generated with Claude Code