fix: validate browser process before reporting launch success#1379
Draft
eureka928 wants to merge 3 commits intoeigent-ai:mainfrom
Draft
fix: validate browser process before reporting launch success#1379eureka928 wants to merge 3 commits intoeigent-ai:mainfrom
eureka928 wants to merge 3 commits intoeigent-ai:mainfrom
Conversation
Contributor
Author
|
@Wendong-Fan would you review this PR? |
15cc909 to
2d460a1
Compare
Contributor
Author
|
@fengju0213 would you review this please? |
Collaborator
|
@eureka928 can you provide video for the problem and the video after your solution? |
Replace blind asyncio.sleep(3) with CDP port readiness check in /browser/login. Catch FileNotFoundError when npx is missing, distinguish process crash from CDP timeout, and add GET /browser/status endpoint that the frontend already polls.
The fetchPost response is truthy even when success is false, so if (response) always passed. Check response?.success instead and show toast.error with the backend error message on failure.
Use run_in_executor for blocking readline so the event loop stays responsive during the CDP readiness check. Treat the timeout case (process alive, CDP slow) as success since the browser window is already open for the user. Only report failure when the process actually crashes.
b835323 to
faf8de8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1377 —
POST /browser/loginreturned"success": trueeven when the Electron process exited immediately (e.g., sandbox misconfiguration,npxnot found). The frontend (Cookies.tsx) also polledGET /browser/statuswhich didn't exist, causing silent 404s.Changes
Backend (
tool_controller.py)_login_browser_processmodule-level variable to track the subprocess_wait_for_cdp_ready()helper that polls both process liveness and CDP port availabilityopen_browser_login()to validate process state instead of blindasyncio.sleep(3)FileNotFoundErrorwhennpxis missing on PATHrun_in_executorfor blockingreadline()to avoid stalling the event loopGET /browser/statusendpoint the frontend already expectsFrontend (
Cookies.tsx)response?.successinstead of justresponse(object is truthy even whensuccess: false)toast.errorwith the backend error message on failureBefore / After Proof
BEFORE (old behavior on
main)The old code blindly awaited
asyncio.sleep(3)then returned success unconditionally:GET /browser/statusdid not exist → frontend polls got silent 404 errors.AFTER (this PR)
Tested locally with
uv run uvicorn main:api --port 5001:Backend logs showing the process crash is detected and reported:
Test plan
cd backend && uv run pytest— 402 passed, 11 skippedskillsStore.tsonly)POST /browser/loginreturnssuccess: falsewhen Electron is unavailableGET /browser/statusreturns{"is_open": false}when no browser is runningsuccess: trueonly after CDP port opens or process is confirmed alive