Skip to content

feat(chat): render a local chat's runs through AG-UI by default - #1728

Merged
edenreich merged 3 commits into
mainfrom
feat/issue-1713-loopback-default
Nov 6, 2026
Merged

edenreich merged 3 commits into
mainfrom
feat/issue-1713-loopback-default

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Part of #1713. Stacked on #1727.

Summary

infer chat now renders its runs through AG-UI by default, the path a daemon chat takes: the encoder writes each run and the reducer reads it back, so both chats share one mapping. chat.agui_loopback: false (INFER_CHAT_AGUI_LOOPBACK=false) falls back to the handlers reading the agent directly.

This also closes the gaps #1725 listed, and one it did not know about.

Gaps closed

  • A judge rejection printed over the screen. RunEncoder wrote it to stderr while the TUI owned the terminal, which only showed in Auto+Judge mode. RunEncoderDeps.Quiet keeps a run off stderr for such a host.
  • An unanswered prompt held the run. The encoder waited for an answer nobody needed any more, so a timeout or a spent time budget only showed once the user answered. ToolApprovalRequestedEvent and UserQuestionRequestedEvent now carry a Done channel that closes when the agent stops waiting, and render.AnswerApproval and render.AnswerQuestions let go on it.
  • A run that hit a limit failed with a sticky error. A local chat now completes it, as it does without AG-UI. A serve worker still fails it for its exit code.
  • CI never ran this path. The e2e job now covers it by default, and a second step runs the local chat tests on the direct path for as long as the fallback exists.
  • Common flows had no permanent test. See below.

Changes

  • internal/presentation/tui/loopback: a prompt's wait ends once the encoder has moved past it, so a late answer goes nowhere. A completion loses its limit flags before the encoder sees it.
  • internal/platform/render: both answer functions select on Done as well as the broker. A nil Done never fires, so other emitters behave as before.
  • internal/agent/loop: the approval, sandbox and question prompts close Done when they return.
  • config: chat.agui_loopback defaults to true, and infer init writes it to new config files.
  • tests/e2e/chat_tui_flows_test.go (new): question form, cancel, queued message, todos, provider error, auto-approve, plan reject, plan approve-each-step, sandbox prompt, judge rejection and a time budget ending a run with a prompt open.
  • startLocalChat runs its tests in parallel, which keeps the added CI time small.

Verification

  • The judge rejection and time budget tests failed only with the loopback on before the fixes, and pass now on both settings.
  • The new unit tests failed before the fixes: a synctest deadlock on the answer functions, the stream staying open, and max_duration_reached surfacing as an error.
  • go test -race ./... on all 120 packages, task precommit:run, and the full e2e suite with the loopback on and off.
  • By hand with tmux and tokenless: an interactive subagent, whose child runs infer chat and writes its result file, gives the same result on main and here. It has no permanent test.
  • Everything ran against the mock gateway. It has not been tried against a real model.

Behavior change

  • After a tool finishes, the status reads Tools completed (1/1 successful) - preparing response... instead of Starting response..., because the wire has no step start event.

Still different from a daemon chat

  • A plan skips the run in a local chat, and is an interrupt in a daemon chat.
  • A run hitting its time budget or turn limit completes quietly in a local chat, and shows an error in a daemon chat.

Not in this PR

Seen while testing, not changed here

  • A daemon chat's /tasks reports it is unavailable, the same as on main.

Downstream

  • chat.agui_loopback is listed in docs/configuration-reference.md. A docs follow-up for inference-gateway/docs is not filed.

@edenreich
edenreich requested a review from a team as a code owner November 6, 2026 22:12
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 6, 2026
@edenreich
edenreich added this pull request to stack #1726 November 6, 2026 22:16
@edenreich
edenreich force-pushed the feat/issue-1713-loopback-default branch 5 times, most recently from 6f81a70 to 498f7c3 Compare November 6, 2026 22:32
Base automatically changed from fix/issue-1713-approve-before-running to main November 6, 2026 22:32
…irect one

A rejection from the judge was written to stderr, which printed over the screen
while the TUI owned the terminal. The encoder now stays off stderr for such a
host.

A prompt the agent gave up on held the run, since the encoder waited for an
answer that nobody needed any more. A timeout or a spent time budget only showed
once the user answered. The agent's prompts now carry a Done channel that closes
when it stops waiting, and AnswerApproval and AnswerQuestions let go on it. Both
are shared, so a serve worker gets this too.

A run that hit its time budget or turn limit failed with a sticky error. A local
chat completes it, as it does without AG-UI, and a serve worker still fails it
for its exit code.
Nothing drove the question form, a cancel, a queued message, todos, a provider
error, auto-approve, a plan decided either way, a sandbox prompt, a judge
rejection or a time budget ending a run through the TUI. These tests do, and the
same suite proves either path.

startLocalChat now runs its tests in parallel, which keeps them well under a
minute apart from the time budget's.
infer chat now takes the path a daemon chat takes: the encoder writes each run
and the reducer reads it back, so both chats share one mapping. Setting
chat.agui_loopback to false falls back to the handlers reading the agent
directly.

CI's e2e job now covers the new default, and a second step keeps the fallback
honest by running the local chat tests on the direct path.
@edenreich
edenreich force-pushed the feat/issue-1713-loopback-default branch from 498f7c3 to eacc802 Compare November 6, 2026 22:32
@edenreich
edenreich merged commit 58f557e into main Nov 6, 2026
@edenreich
edenreich deleted the feat/issue-1713-loopback-default branch November 6, 2026 22:33
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.246.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 Nov 7, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 7, 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

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant