-
Notifications
You must be signed in to change notification settings - Fork 7
Fix: extension disconnected issue #53
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
Conversation
Greptile OverviewGreptile SummaryThis PR implements a comprehensive fix for extension disconnection issues by refactoring the BrowserOS controller architecture. The changes simplify WebSocket reconnection logic, implement a multi-client bridge with failover capabilities, and introduce better environment configuration management. Key architectural changes include:
The refactoring addresses reliability issues by implementing response queuing, automatic client promotion on disconnect, and better separation of concerns between controller logic and lifecycle management. Important Files Changed
Confidence score: 3/5
Sequence DiagramsequenceDiagram
participant Extension as "BrowserOS Extension"
participant WebSocketClient as "WebSocket Client"
participant Server as "Controller Bridge Server"
participant BrowserOSController as "BrowserOS Controller"
participant ActionRegistry as "Action Registry"
Note over Extension,ActionRegistry: Extension Startup & Connection
Extension->>BrowserOSController: "Initialize controller"
BrowserOSController->>WebSocketClient: "Create WebSocket client (port)"
BrowserOSController->>ActionRegistry: "Register all actions"
BrowserOSController->>WebSocketClient: "connect()"
WebSocketClient->>Server: "WebSocket connection request"
Server->>Server: "Register client & set as primary"
Server-->>WebSocketClient: "Connection established"
WebSocketClient-->>BrowserOSController: "Connection status: CONNECTED"
Note over Extension,ActionRegistry: Heartbeat Mechanism
loop Every 20s
WebSocketClient->>Server: "ping message"
Server-->>WebSocketClient: "pong response"
end
Note over Extension,ActionRegistry: Request Processing Flow
Server->>WebSocketClient: "Action request message"
WebSocketClient->>BrowserOSController: "handleIncomingMessage()"
BrowserOSController->>BrowserOSController: "processRequest() - validate & track"
BrowserOSController->>ActionRegistry: "dispatch(action, payload)"
ActionRegistry->>ActionRegistry: "Execute specific action"
ActionRegistry-->>BrowserOSController: "Action response"
BrowserOSController->>WebSocketClient: "send(response)"
WebSocketClient->>Server: "Response message"
Note over Extension,ActionRegistry: Connection Failure & Recovery
Server->>Server: "Connection lost"
Server->>Server: "Clear pending requests"
WebSocketClient->>WebSocketClient: "Detect connection failure"
WebSocketClient->>WebSocketClient: "Start reconnection timer"
WebSocketClient->>Server: "Reconnection attempt"
Server->>Server: "Re-register client as primary"
Server-->>WebSocketClient: "Reconnection successful"
WebSocketClient->>BrowserOSController: "Flush queued responses"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
packages/controller-ext/src/config/environment.tslogic: Complete removal of environment configuration system eliminates type safety and validation. Ensure replacement configuration approach provides equivalent safety and that all dependent code is updated. What configuration system is replacing this comprehensive environment management, and have all imports of these types and functions been updated throughout the codebase?
9 files reviewed, 3 comments
| this.wsClient.onMessage((message: ProtocolResponse) => { | ||
| this.handleIncomingMessage(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Type mismatch - receiving ProtocolResponse but processing as request message. Should this be ProtocolRequest since you're checking for rawMessage.action on line 195?
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/controller-ext/src/background/BrowserOSController.ts
Line: 183:184
Comment:
**logic:** Type mismatch - receiving ProtocolResponse but processing as request message. Should this be ProtocolRequest since you're checking for rawMessage.action on line 195?
How can I resolve this? If you propose a fix, please make it concise.Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Why refactor the controller bootstrap?
We were spinning up overlapping controllers every time Chrome poked the service worker. Refactoring into a real singleton (BrowserOSController) and managing it from background/index.ts means one KeepAlive, one socket, and deterministic restarts. It's boring by design, which is exactly what we wanted.
How do we prevent future "extension not connected" loops?
We taught ControllerBridge to track all extension sockets and only send work through a selected primary. When the primary dies, we promote the next client and keep going. Pending requests are rejected loudly so agents know to retry, and standbys disconnecting no longer nuke the bridge.
Why strip the backoff logic?
Exponential backoff sounded fancy, but in practice it just delayed recovery when the controller was killed intentionally. A flat 30s retry is predictable, debuggable, and avoids random jitter that made logs harder to read.
Why collapse env/config sprawl?
We realized keeping both config/constants.ts and config/environment.ts was garbage duplication, so we deleted the unused env loader entirely and made WEBSOCKET_CONFIG the single source of truth. That let us set a fixed reconnectIntervalMs (30s) and drop the exponential backoff math—far fewer moving parts, same resiliency.