Skip to content

refactor(agui): host the extension socket behind a Request seam and fail pending requests fast - #1406

Merged
edenreich merged 4 commits into
mainfrom
fix/issue-1395
Sep 29, 2026
Merged

edenreich merged 4 commits into
mainfrom
fix/issue-1395

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1395

Summary

The opentask browser-extension bridge was a protocol living inside a browser adapter. This moves the extension socket, the Origin check, the browser_hello token handshake, one-active-connection replacement, pings, the /artifacts/ route and the panel units into internal/protocols/agui, and leaves internal/browser as a thin ExtensionDriver adapter. The container injects bridge.Request into browserinfra.NewExtensionDriver, so browser never imports protocols/agui. Every frame on the wire keeps its shape, so the extension works unchanged.

The move also picks up two small hardening changes on the same seam. Request fails fast when the connection goes away, and the bridge takes only the extension config it uses.
no docs ticket: internal-only refactor (no public-facing behavior or protocol change)

Changes

  • internal/protocols/agui gains the bridge and its panel units: extension_bridge.go (listener, handshake, connection replacement, routing, Request), extension_chat.go (chat mirror and approvals), extension_panel.go (conversations, history, skills, model picker, modes), extension_tools.go (tool_request execution). Render stays the one AG-UI encoder and the chat mirror keeps reusing it.
  • bridge.Request(ctx, id, frame) writes a pre-built frame and resolves on the browser_result carrying that id, returning raw JSON. A failed listen is retried first, so a process that lost the port takes it over once the other infer exits, and the caller owns the deadline via ctx.
  • Request now returns errBrowserExtensionDisconnected as soon as the extension disconnects, is replaced by a new connection or the bridge closes, and returns the write error when the frame cannot be sent. Before, both cases waited out the full deadline. Pending requests are failed inside the same lock that swaps the connection, so a request registered on the new connection is never failed by mistake.
  • agui.Deps takes Extension config.ExtensionConfig (port and token) instead of the whole BrowserUseConfig, so the protocol package no longer reads browser-specific config.
  • browser/infrastructure/extension_driver.go: an ExtensionDriver that builds browser_command frames (uuid id, timeout_ms from browser_use.browser.timeout_seconds), owns the per-action timeout with a friendly timeout error, and maps results and extension errors to BrowserToolResult. Its Close is a no-op because the container closes the bridge.
  • internal/container: builds agui.NewExtensionBridge, injects c.extensionBridge.Request into browserinfra.NewExtensionDriver, and closes the bridge on shutdown.
  • .golangci.yml: the depguard rule websocket-only-in-browser-and-web becomes websocket-only-in-agui-and-web, allowing internal/protocols/agui and denying internal/browser again.
  • The extension_bridge_test.go scenarios are ported to internal/protocols/agui, not dropped. The ExtensionDriver is tested through a fake ExtensionRequest in extension_driver_test.go, and a new bridge test drives the real ExtensionDriver over bridge.Request so the duplicated wire literals cannot drift unnoticed. Another new test covers a disconnect failing a pending Request at once.
  • internal/protocols/agui/README.md, internal/browser/README.md and AGENTS.md describe the new layout.

Verification

  • go test -race passes for internal/protocols/agui, internal/browser and internal/container, and the full suite runs in CI
  • task precommit:run passes (mod:tidy, mocks, fmt, lint:imports, golangci-lint, markdownlint)
  • e2e: on the first push the sandboxed runner reported a pre-existing TestChatTUIApprovalBoxFollowsTail failure that is identical on clean main (e6357da), and CI e2e passed

Move the opentask bridge (listener, origin check, browser_hello token handshake, one-active-connection replacement, pings, /artifacts/ route and the panel units) from browser/infrastructure into protocols/agui, and add bridge.Request(ctx, id, frame) as the command/result RPC. The browser capability keeps a thin ExtensionDriver that builds browser_command frames, owns the per-action timeout and maps results, wired by the container through the injected ExtensionRequest so browser never imports protocols/agui. The depguard rule becomes websocket-only-in-agui-and-web and every frame on the wire keeps its shape, so the extension works unchanged.
… config

Request now returns at once when the extension disconnects, is replaced or the write fails, instead of waiting out the deadline. The bridge takes only the extension port and token, and a test drives the real ExtensionDriver over the bridge.
@edenreich edenreich changed the title refactor(agui): host the extension socket behind a Request seam refactor(agui): host the extension socket behind a Request seam and fail pending requests fast Sep 29, 2026
Wrap the browser_result decode error with the action, default the screenshot mime type with cmp.Or and fix two stale doc comments. The driver tests share one config helper, and the bridge tests share one retry-until-connected helper. The disconnect test now runs under a 2s deadline, so a regression fails instead of hanging. A depguard rule keeps internal/browser from importing protocols/agui.
@edenreich
edenreich merged commit ff438f0 into main Sep 29, 2026
12 checks passed
@edenreich
edenreich deleted the fix/issue-1395 branch September 29, 2026 01:06
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.219.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor move the browser extension socket into internal/protocols/agui behind an injected browser request

1 participant