Repository navigation
fix: route browser-use through the infer daemon and make agui a general-purpose protocol - #1413
Conversation
|
@infer can you finalise this PR? it's not ready for a review - please finish the existing todos. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessThe PR is finalized. Here is the state of PR #1413: SummaryThe salvage run's feature work (routing browser-use through the infer daemon's extension connection, resolving #1400) was already complete on the branch; this run finished the remaining todos: Fixed this session (commit
Acceptance criteria of #1400 - all verified against the code and tests:
Checks: full unit suite ( PR bookkeeping: replaced the auto-salvage body with a real description, retitled to "fix: route browser-use through the infer daemon's extension connection", and marked ready for review. Since this is a user-facing protocol/behavior change, I filed the docs follow-up: inference-gateway/docs#864. No release actions taken (semantic-release handles versioning from the Conventional Commits on merge). Model: Tokens: 2,866,325 in · 17,035 out · 2,883,360 total (39 requests) Tool calls: 53 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…restore the status indicator - DaemonClient serializes dialing and writes, so parallel Browser calls share one socket instead of racing to dial and leaking the loser's socket. - The TUI's browser indicator follows each daemon answer, since chat no longer hosts the bridge that notified it. - An unreachable port always starts the daemon. Its pid lock makes a redundant start exit, so a daemon that stopped is started again instead of timing out every call. - Relay always answers with a browser_result, so the sessions context no longer encodes the browser wire format. - Docs cover the auto-started daemon and note that the /artifacts/ route is not served under the daemon yet.
- The sessions domain declares EnsureDaemon next to LaunchWorker, and sessions/infrastructure implements it with the port probe, the start and the wait for the port. - The container injects it into the agui DaemonClient, which now only speaks the binding's socket protocol. - The daemon starts with plain os/exec and no raw syscall attributes, so the build-tagged spawn files are gone. It shares the caller's terminal, so closing that terminal stops it and the next Browser call starts another.
…tead of SIGTERM Process.Signal(SIGTERM) is not supported on Windows, so a stopped worker waited out the grace period and was killed without its cleanup. The worker is now stopped the way its stdin contract already allows on every platform. An interrupt frame ends the running turn and stdin EOF makes it run its own cleanup and exit. The grace period's kill still covers a worker that does not.
…ut raw syscalls The Unix-only process group (Setpgid plus a raw kill of the group) is replaced with a gopsutil process-tree kill. It lists each process's children before killing it and then kills their trees the same way, so a script's children die on timeout or cancel on Linux, macOS and Windows alike. gopsutil was already linked in through robotgo and is now a direct dependency.
ProcessAlive drops its build-tagged pair (a raw signal-0 kill on Unix and os.FindProcess elsewhere) for gopsutil's PidExists. On Windows it now lists pids instead of trusting OpenProcess, which can succeed for a pid that does not exist. A pid that is not positive is never alive, where the Unix probe used to signal the caller's process group for pid 0.
… between integer types' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
The AG-UI package knew its users. It named the extension, desktop and browser clients, owned the browser command relay and the daemon client, imported the sessions ports, and published the computer context's events. A depguard rule kept the browser context from importing it, which enforced the inversion. agui is now general purpose. Binding is a WebSocket server that owns the listener, the Origin check, the token handshake and the connections, and hands every frame to a Handler. Dial is its client end. The handshake frame names and the accepted origins come in as configuration, and a connection carries its client kind as an opaque string. The run encoder takes Publish functions and renders any event it does not map as the CUSTOM event its owner returns. The contexts import agui: - browser owns the wire contract, the ExtensionRelay that keeps the one extension connection and serializes commands, and the ExtensionClient that dials the binding from infer chat and a standalone headless - computer owns computer_use_paused, computer_use_resumed and screen_recording in computer.PublishedEvent - internal/daemon holds the on-demand daemon boot, which left sessions - sessions drops the EnsureDaemon and Threads ports, which had no consumer left, and imports no protocol - cmd/daemon puts the browser relay and the thread registry behind the binding's one handler The wire is unchanged: frame names, handshake, error wording and CUSTOM event payloads are the same. The /artifacts/ route is removed from the binding. The daemon never served it and the protocol doc already says it answers 404. depguard replaces browser-does-not-import-agui with agui-names-no-context, which denies agui every internal import except the shared kernel, the conversation and scheduler domains and platform.
agui still mapped agent chat events to AG-UI events and answered the panel frames of a serve worker, so it imported the agent, conversation and scheduler domains and the storage, ipc, models and render packages. agui now offers Run, a writer for the events of one run. It frames text and reasoning messages, writes tool calls, snapshots and CUSTOM events from plain values, and guarantees exactly one terminal RUN_FINISHED or RUN_ERROR. The AG-UI SDK stays confined to agui, which exposes the message types a caller builds a MESSAGES_SNAPSHOT from. presentation/headless owns what it alone consumes: - RunEncoder maps agent chat events onto a Run - Panel answers the panel frames of a serve worker - the container builds the headless Panel The AG-UI output is unchanged. agui's only internal import is the logger, and the agui-names-no-context depguard rule now allows nothing else and denies the config package too.
The depguard rule for agui denied internal packages but let any external dependency in, so nothing kept the protocol package from growing new ones. agui-imports-are-closed replaces agui-names-no-context and runs in strict mode. It allows the standard library and the five packages agui imports today, and rejects every other import in the package and its tests. The agui README records the same list and what each import is used for.
The binding, relay and client tests each carried their own implementation of the agui Handler, and the panel test its own shell history store. counterfeiter now generates FakeHandler in tests/mocks/agui and FakeShellHistoryStorage in tests/mocks/storage, and the tests stub those. The binding test moved to the external agui_test package, since the fake imports agui, and reads two unexported constants through export_test.go. The closed import list of agui allows the fake and the package under test for its tests, and the agui README records both.
The protocol doc still described the /artifacts/ route as loopback-only with path traversal blocked by http.Dir, which read as a description of a route that exists. The binding has no such route. The section now states that the route answers 404 and why, and what that means for a panel user. A comment in render pointed at the agui package for the AG-UI RUN_ERROR writer, which lives in the headless presentation.
|
🎉 This PR is included in version 0.219.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1400
Summary
Browser-use on the extension backend now reaches the browser only through the infer daemon's extension connection. Only the daemon binds the binding port.
infer chatand a standaloneinfer headlessdial the binding as browser clients (client: "browser"in the hello) and startinfer daemonon the first browser call when nothing is listening.This PR also reverses a dependency that pointed the wrong way.
internal/protocols/aguiused to know its users: it named the extension, desktop and browser clients, owned the browser relay and the daemon client, imported the sessions ports, mapped the agent's chat events, answered the panel frames and published the computer context's events. It is now a general-purpose protocol package that names no client, no context and no host. Its only internal import is the logger. Everything else imports it.Architecture
Changes
agui, general purpose
Bindingowns the listener, theOrigincheck, the token handshake, the connections and their pings, and hands every frame to aHandler(Attach,Handle,Detach).Dialis the client end over the sameHandler.BindingConfigandDialConfig. AConncarries the client kind its hello declared as an opaque string.Runwrites the events of one run from plain values: text and reasoning framing, tool calls, snapshots and CUSTOM events. It guarantees exactly one terminalRUN_FINISHEDorRUN_ERROR, andCustomEvent.Resumesdiscards the failure an interruption left.Message,Role,ToolCallandFunctionCallfor aMESSAGES_SNAPSHOT./artifacts/route is removed from the binding. The daemon never served it, and the protocol doc already says it answers 404 until [FEATURE] Serve generated artifacts per project from the infer daemon's AG-UI binding #1414 serves it per project.browser, on top of agui
extension_wire.goowns the wire vocabulary: frame names, client kinds,BindingHandshakeandAllowExtensionOrigin.ExtensionRelayis the host end. It keeps the one extension connection, replaces it when the extension reconnects, and drives everybrowser_commandthrough it one at a time. It always answers with abrowser_resultthat carries a failure in itserror.ExtensionClientis the client end and theExtensionRequestofinfer chatand a standalone headless. Dialing and writes are serialized, so parallel Browser calls share one socket. ItsEnsureHosthook runs before each dial.headless, on top of agui
RunEncodermaps agent chat events onto aRun. It takesPublishfunctions and renders any event it does not map as the CUSTOM event its owner returns.Panelanswers the panel frames of a--serveworker. The container builds it.computer, on top of agui
computer.PublishedEventownscomputer_use_paused,computer_use_resumedandscreen_recording.daemon and sessions
internal/daemonholdsEnsureRunning, the on-demand daemon boot. It startsinfer daemonin the background with plainos/execand waits for the port.sessionsdrops theEnsureDaemonandThreadsports, which had no consumer left. It keepsClient,Worker,LaunchWorkerandBrowserRelay.sessions.Registry.RouteBrowserroutes session workers'browser_commandstdout lines through the relay and writes thebrowser_resultback to the worker's stdin byid, so workers bind no port.cmd/daemonwires the relay and the registry behind the binding's one handler. A binding port held by another process fails the daemon's boot.Enforcement
browser-does-not-import-aguiwithagui-imports-are-closed, a strict allow-list. agui may import the standard library, the AG-UI SDK'seventsandtypes,google/uuid,gorilla/websocketandplatform/logger. Its tests may also import the package under test and the generatedHandlerfake. Every other import is rejected. The agui README records the list.Cross-platform process handling
interruptframe and stdin EOF instead of SIGTERM, which Windows does not support.utils.ProcessAlivechecks liveness through gopsutil'sPidExistson every platform.Removed
ServiceContainer.StartExtensionBridge, the bridge's port takeover and the daemon's listen retry.Behaviour notes
extension_version. It logs the client kind and the protocol version.inferprocess that started it. It shares that process's terminal, so closing the terminal stops it too, and the next Browser call starts another.Docs
/artifacts/, and it gives the artifacts dir as~/.infer/artifacts/. Both are wrong. Tracked in [DOCS] OpenTask page says the daemon serves /artifacts/, but the route answers 404 docs#866.Not in this PR
browser_helloandbrowser_hello_ack. That is a protocol version bump across opentask and the desktop app.Tests
Test doubles are counterfeiter output:
FakeHandlerintests/mocks/aguiandFakeShellHistoryStorageintests/mocks/storage, both registered inmocks:generate.agui run: message framing, tool calls, snapshots, one event per write, and the one terminal event for success, failure, cancellation and resume.
agui binding: handshake, bad hello, empty token, the Origin policy, frames reaching the handler, detach on close, overflow of a stalled client, and
Dialagainst a binding.browser relay: round trip, extension replacement, disconnect failing pending commands, client commands answered on the posting connection only, serialization, and the no-extension wording.
browser client: routing by id, concurrent first calls sharing one socket, the boot-failure wording, and a driver call through client, binding and relay.
headless: the encoder and panel tests moved with the code and assert the same AG-UI output.
computer: the three CUSTOM events on the AG-UI stream and the resume clearing a cancellation.
daemon.EnsureRunning: a listening daemon is left alone, and a failed start names its cause.Registry: two workers' commands routed by id, each answered on its own stdin.
Manual: a real
infer daemonwith a scripted extension peer. The client got the no-extension error before the extension connected and the navigate result after.