-
Notifications
You must be signed in to change notification settings - Fork 21
fix: resolve window ownership race condition with async polling #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: resolve window ownership race condition with async polling #278
Conversation
- Add waitForWindowOwnership() method that polls for up to 500ms - Update sendRequest() to wait for window registration before routing - Remove hacky 1-second delay from scheduledJobRuns.ts - Improves multi-window and multi-profile routing reliability Fixes browseros-ai#277
|
Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement. To sign the CLA, please add a comment to this PR with the following text: You only need to sign once. After signing, this check will pass automatically. Troubleshooting
|
|
I have read the CLA Document and I hereby sign the CLA |
Greptile OverviewGreptile SummaryThis PR resolves a critical race condition in multi-window/multi-profile routing by implementing async polling in Key Changes:
Impact:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent as Agent Extension
participant Bridge as ControllerBridge
participant Ext as Controller Extension
Note over Agent,Ext: Race Condition Scenario
Agent->>Agent: chrome.windows.create()
Agent->>Bridge: HTTP Request with windowId
Note over Ext: Window creation event triggered
Ext->>Bridge: WebSocket: window_created message
Note over Bridge: BEFORE FIX: Request arrives before window_created<br/>Result: Falls back to primaryClientId (wrong routing)
Note over Agent,Ext: With Fix Applied
Agent->>Agent: chrome.windows.create()
Agent->>Bridge: HTTP Request with windowId
Bridge->>Bridge: Check windowOwnership.get(windowId)
Bridge->>Bridge: Not registered yet, call waitForWindowOwnership()
loop Poll every 50ms (max 500ms)
Bridge->>Bridge: Check windowOwnership.get(windowId)
Note over Ext: Window creation event triggered
Ext-->>Bridge: WebSocket: window_created message
Bridge->>Bridge: handleWindowCreated() registers window
Bridge->>Bridge: ownerClientId found!
end
Bridge->>Ext: Route request to correct client
Ext->>Bridge: Response
Bridge->>Agent: Response
|
I have read the CLA Document and I hereby sign the CLA |
Fixes #277
Resolves a critical race condition where HTTP requests arrive before window_created WebSocket message is processed.
Changes
Benefits