Skip to content

feat(agent): drive chats through infer daemon threads and retire the browser bridge - #374

Merged
edenreich merged 1 commit into
mainfrom
feat/issue-367
Oct 1, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/issue-367

Conversation

@edenreich

@edenreich edenreich commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #367 and #369. Part of inference-gateway/cli#1396. Builds on #373. Needs cli v0.220.0 and the opentask release carrying inference-gateway/opentask#213.

#367 — chats run as daemon threads

  • daemon.rs: the binding comes from ~/.infer/daemon.yaml (binding.{port,token}), falling back to browser_use.yaml, and is seeded with a token when neither has one. ensure_running reuses a listening daemon and otherwise starts infer daemon with the app's env plus INFER_DAEMON_BINDING_*. The app starts it at launch, and a saved auth change or browser-use toggle restarts the one the app owns.
  • thread.rs: one WebSocket per chat. browser_hello with client: "desktop" and protocol_version: 2, a mismatch on the ack is reported as "update infer". resume_conversation carries the thread options (model, mode, system prompt, custom instructions, sandbox directories, max turns), the app spawns no infer headless.
  • A prompt is a run_agent_input with attached images as content parts. Stop sends interrupt and the run ends with outcome cancelled. Busy state follows RUN_STARTED to the terminal event, which the thread turns into the Done / Cancelled events the UI already keys on.
  • Approvals and questions come from RUN_FINISHED outcome interrupt, mapped by the parser onto the existing ApprovalRequest / UserQuestionRequest events (the question form's questions come from the AskUserQuestion call's args). The answer is one resume covering every open interrupt. A RUN_STARTED clears the open interrupts. The worker always runs with the approval broker and the thread's mode carries auto mode, so fix(agent): ask before a path outside the sandbox in auto mode #366's sandbox prompt in auto mode still reaches the user.
  • Token usage is read from usage and the state key usage (the last request's input is the delta between patches), background tasks from backgroundTasks. computer_use_control is gone, the monitor's pause stops the run and resume continues with a new one.
  • A RUN_ERROR without a runId is shown and ends no run.
  • Opening a chat uses open_thread, which returns the MESSAGES_SNAPSHOT, instead of infer conversations show.

#369 — browser bridge retired

  • browser_bridge.rs is deleted: no listener on 52789, no relay on 52790, no INFER_BROWSER_USE_EXTENSION_PORT, no chat_event, user echo, JSONL snapshot or request_id approvals.
  • The extension's state comes from the browser_extension_status frame every thread connection receives, surfaced through the existing browser-bridge event, so the status-bar globe and the Settings dot keep working.

Known gaps

  • The "always allow" approval scope has no counterpart in the interrupt contract, so it approves this call only.
  • Thread options apply when the worker launches, so a project context changed after the first prompt of a chat reaches the worker only after it idles out (10 minutes) or the daemon restarts.
  • A conversation rolled over to a new id by the worker is not followed.

Verification

  • cargo test: 171 passed. thread.rs tests drive a fake daemon over a real socket: hello and options, the version refusal, a streamed run with an interrupt, a cancelled run, a routing error, and a resume that waits for every open interrupt.
  • bun test: 175 passed, with the history loader tests rewritten onto the snapshot shape.
  • bun run build, cargo fmt --check, cargo clippy -D warnings, and cargo check of the e2e crate are clean.
  • task e2e against infer built from cli main: 28 of 29 pass. The one failure, bash-mode, is a CLI gap (the serve worker sent !cmd to the model) fixed in fix(headless): run direct tasks in the serve worker without a model turn cli#1443, against which bash-mode and queued-prompt pass. The driver stops the mock daemon by its pid file between runs.

…browser bridge

The app spawned infer headless per prompt, read busy state off the
process, stopped a run with SIGKILL, loaded history with infer
conversations show, and ran a second copy of the extension panel
protocol in browser_bridge.rs that held port 52789 and relayed browser
commands to each child on port 52790. Since cli v0.220.0 only infer
daemon binds the port and the released app breaks against it.

Every chat is now a daemon thread. The app makes sure a daemon listens
on the binding, reusing one that already runs and otherwise starting
infer daemon with its env and the binding switched on, and opens one
WebSocket per chat with a desktop hello on protocol version 2. The
per-run env the app set becomes the thread options of
resume_conversation, a prompt is a run_agent_input with images as
content parts, stop is an interrupt, and busy state follows the run's
terminal event. Approvals and questions arrive as the interrupt outcome
and are answered with one resume covering every open interrupt. Token
usage, background tasks and the recording state are read from the
standard usage and state keys. Opening a chat renders the thread's
MESSAGES_SNAPSHOT. Pausing computer use stops the run and resuming
continues the thread with a new run.

The browser bridge is gone with its chat_event wrapping, user echo,
JSONL snapshot and request_id approvals. The extension's state comes
from the browser_extension_status frame the daemon sends, and browser
tools from a chat reach the extension through the daemon.

Closes #367
Closes #369
@edenreich
edenreich merged commit 7776277 into main Oct 1, 2026
1 check passed
@edenreich
edenreich deleted the feat/issue-367 branch October 1, 2026 14:52
edenreich added a commit to inference-gateway/cli that referenced this pull request Oct 1, 2026
…urn (#1443)

## Summary

Part of #1396. Found by the desktop e2e suite against
inference-gateway/desktop#374.

A one-shot `infer headless "!cmd"` runs the command through the tool
service with no model, and so does the TUI, but the serve worker fed the
same text to the agent as an ordinary prompt. A daemon client (the
desktop app's bash mode) therefore got a model turn instead of the
command's output.

`runServeTurn` now takes a lone `!cmd` or `!!Tool(...)` input off the
queue and renders it as its own run: the tool call and its result, or
the parse error the task failed on. A turn carrying several messages
still goes to the agent untouched.

## Verification

- `TestQueuedDirectCall` covers the lone command, a malformed tool call,
and a multi-message turn.
- `task precommit:run` passes.
- The desktop e2e `bash-mode` and `queued-prompt` scenarios pass against
this build through the daemon.
@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.51.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-maintainer inference-gateway-maintainer Bot added the released Shipped in a release label Oct 1, 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.

[FEATURE] Drive agents through infer daemon instead of spawning infer headless per prompt

1 participant