Repository navigation
feat(daemon): host the AG-UI WebSocket binding and supervise session workers - #1411
Conversation
…workers infer daemon now owns the extension and desktop socket. It boots with only the binding enabled (browser_use with backend: extension) and relays frames between clients and one headless --serve worker per thread. - New sessions context: the thread registry (project dir plus conversation id), first-answer-wins approvals, a RUN_ERROR for a worker that dies mid-run, idle reaping, and the process worker adapter. - The extension bridge becomes the binding. browser_hello carries client and protocol_version, the ack reports protocol_version, one extension connection is kept next to any number of desktop ones, and frames reach Threads bare. - The panel units move into the serve worker, so list_*, select_model, set_mode and tool_request answer from the project's own config and storage. new_session and resume_conversation answer with MESSAGES_SNAPSHOT, and tool_request approvals use the tool_call_id contract. - infer chat drops the in-process panel mirror and its event bridge subscription, and keeps the socket for browser commands only.
|
@infer Can you review this PR? is it ready for merge? use /ponytail:ponytail /ponytail:ponytail-review /go-concurrency /go /clean-architecture /clean-code /domain-driven-design Focus on separation of concern. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll checks pass and no prior inline comments exist. I have everything needed for the review. Let me finalize the todos and write up the assessment. Review complete. Here is my full assessment of PR #1411. Verdict: yes, ready to merge. CI is fully green on the current commit (all 12 checks, including e2e, lint, vet, and race-relevant unit suites). The architecture does what the description promises and nothing more. Two non-blocking findings below, one of which I would file as a follow-up. Separation of concerns (the focus)The layering is right, and the diff's net motion is deletions where the contexts overlapped:
Findings
Over-engineering pass (ponytail-review)
Tests, docs, CI
Bottom line: merge-ready as-is. The only thing I would actually file a follow-up for is the slow-client fan-out (finding 1), and finding 2 is optional polish. Model: Tokens: 1,671,123 in · 28,321 out · 1,699,444 total (18 requests) Tool calls: 41 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
Deliver used to write each frame to the socket itself, so one stalled desktop connection parked the relaying goroutine in a 10s write deadline and backpressure eventually stalled the worker on its stdout pipe mid-run. Each connection now owns a bounded outbound queue drained by a dedicated writer goroutine. An overflowing queue closes the client so it can reconnect for a fresh snapshot.
Deliver on a closed connection kept filling a queue nobody drains and then warned that it overflowed, even when the close came from a failed write or a disconnect. It now drops the frame. The overflow test also stops reading the socket after the detach. Frames already in the kernel buffers arrived intact and failed it, and a read timeout passed it whether or not the server closed. The detach alone proves the close.
The mark no longer shares the mutex that serializes panel writes, so the turn loop never waits behind a stalled stdout write to read it. SnapshotReplied is renamed TakeSnapshotReply since reading it clears it.
|
🎉 This PR is included in version 0.219.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1399
Summary
infer daemonnow hosts the AG-UI WebSocket binding and runs each thread (a project dir plus a conversation id) in its owninfer headless --serveworker. The binding is a relay. Worker stdout lines reach the thread's clients as bare frames, and client frames go to the worker's stdin.internal/sessionscontext.Registryowns the thread registry. A client follows one thread, and first-answer-wins applies to approvals (CUSTOMapproval_resolvedgoes to the other clients). A worker that dies mid-turn ends its open run withRUN_ERROR, and workers nobody follows are reaped after 10 idle minutes.infrastructure.LaunchWorkerruns the worker in the project dir with the thread options as flags andINFER_env overrides, and stops it with SIGTERM so its gateway, MCP servers and containers shut down.browser_hellocarriesclient(extensionordesktop) andprotocol_version, and the ack reportsprotocol_version: 1(a versionless hello is logged and accepted). There is one extension connection with replacement plus any number of desktop connections. In the daemon every frame exceptbrowser_resultgoes tosessions.infer chatinto aPanelthe serve worker answers with, solist_*,select_model,set_modeandtool_requestuse the project's own config, storage, skills and sandbox.new_sessionandresume_conversationanswer withMESSAGES_SNAPSHOT.tool_requestapprovals use the sametool_call_idcontract as agent approvals, anduser_messageattachments are honored by the worker.infer chatretires the in-process panel mirror (extension_chat.go, its event bridge subscription,FromExtension). It keeps the socket for browser commands only.browser_use.enabledwithbackend: extension, onbrowser_use.extension.portwith its token). Whileinfer chatholds the port the daemon retries every 5s.Known interim gaps
browser_commandlines are relayed to the thread's clients and time out./artifacts/is only served byinfer chat's binding, because the artifacts dir is per project.infer headlessper message ([FEATURE] Run Telegram sessions through daemon workers #1401). The sessions README describes how it plugs in as a second driving adapter.Tests
internal/sessions: two clients on one thread, approval first-answer-wins, crash mid-run, panel replies going to the requester only, launching in the project dir, bad frames, a launch failure, idle reaping and shutdown. A worker args/env table test covers the launcher.internal/protocols/agui: handshakeprotocol_version, desktops next to the extension, relaying toThreads, detaching on close. The panel tests were ported toNewPanel.internal/presentation/headless: panel frames stay off the turn's approval channel, anduser_messageattachments become image parts.tests/e2e/daemon_test.goruns the realinfer daemonagainst the mock gateway. It covers two clients on one thread, approval first-answer-wins, resume after a daemon restart, a worker crash (kill -9from Bash) ending the run withRUN_ERRORand relaunching, and project-scoped panel requests.task precommit:run,go test -race ./...andtask test:e2epass locally.