Skip to content

feat(rooms): approve or reject a member's tool call from the room - #1963

Merged
edenreich merged 8 commits into
mainfrom
feat/issue-1958
Nov 24, 2026
Merged

edenreich merged 8 commits into
mainfrom
feat/issue-1958

Conversation

@edenreich

@edenreich edenreich commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1958. Part of #1943.

Room members run in Auto+Judge by default, so the only call that still needs a person is one the judge rejected and the member escalated. Until now it waited in the member's own chat, and you had to leave the room and resume room-<room>-<agent> to decide it. Now the room shows the call, and the chat opens it in the approval box every tool call uses, so you decide it without leaving the room, like answering in a Slack channel.

Testing it turned up three more bugs, fixed here too. A room in mode: standard still ran its members without asking, because the room's mode never took effect after the daemon started. The chat's mode indicator showed the chat's own mode instead of the room's. And a member's call expired after five minutes, while the room claimed it was decided in the member's own chat.

Rooms (daemon)

  • The call is posted to the room. A member whose run suspends on a tool call posts it as kind: approval. The post carries the call in a new approval field (id, tool, arguments) and the note it came with as its text: the judge's reason and the member's justification. A run always suspends on one interrupt, so a waiting member holds at most one call.
  • decide_room_approval (room, member, tool_call_id, decision: approve or reject) decides it. The member resumes its run with a run_agent_input resume entry, resolved or cancelled, the way the daemon chat answers an interrupt. The room logs You approved tester's Bash call. as kind: decision, and the client that decided gets room_approval_decided.
  • The first decision wins. A later one, or one for a call that no longer waits, answers RUN_ERROR with tester's call was already decided. Anything but approve or reject is refused, so a room cannot switch a member to auto-accept.
  • A call decided elsewhere closes in the room. A run that starts while the room still holds the call was resumed from the member's own chat, and a run that ends drops its call. Each logs a kind: decision post without approval.decision, such as tester's Bash call was decided in its own chat.
  • A run suspended on anything else, such as a question, still waits in the member's own chat with the room's note, as before.
  • roomsdomain.OpenApprovals reads which approval posts are still open from the log, for the host's tests and every client.

TUI

  • The room view shows an approval post under its member: wants to run Bash {"command":"go test ./..."} and the note. The header keeps ◐ waiting for approval.
  • The newest open call opens in the chat's approval box, the one every tool call of the chat uses, with its diff preview, ←/→ and Enter. It names who asks, such as writer in #public asks to run this., above the note. It offers Approve and Reject but no Auto-Approve, and the answer goes to the room through Rooms.Decide, Esc's rejection included. The room draws no buttons of its own.
  • A call decided elsewhere, or leaving the room, takes the call off the box, and the next open call takes its place. The chat's own approval keeps the box until it is answered.
  • A refusal, such as a call already decided, shows as an error status and offers the call again. tui.Rooms gains Decide.

A room's mode takes effect, and the chat shows it

  • The daemon read rooms.yaml once, at its start. An edit, such as a room's mode, never reached a running daemon, so a room switched to standard kept running its members in auto-with-judge or auto. The rooms host now reads its settings through a function the daemon backs with a fresh config load (roomsSettings in cmd/daemon), so an edit reaches the next post. A config that does not load keeps the last good settings.
  • A member's worker kept the mode it was spawned with. Every member turn now resolves its room from the current settings and sends set_mode with the room's mode before its run input, the frame the daemon chat sends for its own worker, so a worker that started under the old mode switches too.
  • The mode indicator now shows the room's mode inside a room, such as #public ▸ STANDARD, instead of the chat's own. The room's mode reaches the TUI on its snapshot and on every room_activity, which now carries the mode the member's turn runs in.
  • A mode the daemon did not report is left out. A daemon of an older build reports none, so the indicator shows the room alone, #public, rather than claiming ▸ STANDARD for members that may run in any mode.
  • Shift+tab is held back in a room. The room's mode in rooms.yaml takes precedence, so shift+tab there only says #public's mode is set in rooms.yaml (rooms.public.mode). No room shows the chat's own mode again, and shift+tab switches it as usual.

A member's call waits until someone decides it

  • A call expired after five minutes. The agent gave up on every approval after a fixed five minutes, so a member's call nobody had decided yet failed with approval request timed out, and the room said it was decided in the member's own chat.
  • tools.safety.approval_timeout now bounds the wait, 5m by default, and 0 waits until it is decided. Every session worker the daemon launches gets 0. Its run suspends on the approval as an interrupt until a client resumes it, and the registry already stops a suspended thread nobody follows. The local chat and a one-shot headless run keep five minutes.

The issue's open questions

  • Auto-Approve in a room: not offered. A room takes approve or reject only.
  • One list of every open approval: no. The approval box shows the newest open call, and the next one follows once it is decided.

Known limit

A decision from the room that crosses one from the member's own chat in flight loses to it at the registry, which takes the first resume, while the room already logged the room's decision. The window is the time a resume takes to reach the daemon. It is named in member.decide's doc comment.

Verification

  • go test ./..., golangci-lint and the import check, plus the pre-commit gate on every commit.
  • End to end in tmux against the tokenless mock (INFER_GATEWAY_MOCK, an isolated HOME and binding port), with a writer member in #public. The room started in mode: auto, and rooms.yaml was switched to mode: standard while the daemon ran before @writer delete dummy.txt:
    • Before this fix (565149b5): the writer ran rm dummy.txt without asking and the file was gone, the room showed no mode, and shift+tab switched the chat's own mode to ▶ PLAN.
    • With it: the indicator read #public ▸ AUTO on entry and #public ▸ STANDARD once the edit applied, and shift+tab was refused. The call waited as wants to run Bash {"command":"rm dummy.txt"}, the file still in place, and approving it logged You approved writer's Bash call. and the resumed run deleted the file. The writer's worker had been spawned with --mode auto, so the switch happened on the running worker.
    • No room brought back the chat's own mode, and shift+tab switched it again.
    • Against the binary of a daemon started before this branch, the chat at 9a0a5b1b showed #public ▸ STANDARD while that daemon ran the writer in auto and it wrote dummy.txt without asking. With 9ed9242e the indicator shows #public.
  • End to end in tmux with a copy of a real ~/.infer config: rooms.yaml with mode: standard, pickup: offer and every agent, ollama_cloud/glm-5.3-flash through the local gateway, and Write a dummy.txt file in the current dir offered to the writer rather than pinged:
    • the call opened in the approval box with writer in #public asks to run this. and the new file's diff, ←/→ moved between Approve and Reject only, and Enter on Approve logged You approved writer's Write call. and wrote the file
    • Esc on a second call logged You rejected writer's Write call. and wrote nothing
    • before 60eeb189, a call left undecided for five minutes failed with approval request timed out and the room said it was decided in the member's own chat. With it, a call left for 6m42s still waited, and approving it wrote the file. The writer's worker ran with INFER_TOOLS_SAFETY_APPROVAL_TIMEOUT=0.
  • An escalation end to end against the tokenless mock in mode: auto-with-judge: the mock judge rejected Delete {"path":"dummy.txt"}, the writer escalated it with RequestApproval, the room posted it with the judge's reason and the writer's justification, and approving it deleted the file.
  • Mode tests: TestEveryTurnRunsInTheRoomsModeAsItIsNow (the set_mode frame before every run input, following an edit), TestRoomsSettingsFollowRoomsYaml (an edit read on the next use, the last good settings kept), and TestARoomShowsItsOwnModeAndHoldsBackShiftTab (a snapshot without a mode shows the room alone).
  • Host tests with the real JSONL log and a counterfeiter registry:
    • the approval post with the judge's reason and justification
    • approve resuming with resolved and reject with cancelled
    • the decision post and room_approval_decided
    • a second decision refused
    • a call decided in the member's own chat and one whose run ended, each closing the post and refusing a late decision
    • a decision other than approve or reject refused
    • a question still waiting in the member's own chat
  • OpenApprovals and Decision.Valid in the domain. Rooms.Decide against a fake daemon, its confirmation and its refusal.
  • TUI tests:
    • the approval post with its call and note and no choices of its own, and the newest open call moving on once one is decided
    • TestAMembersCallIsDecidedInTheApprovalWindow: the call in the approval box with who asks and no Auto-Approve, Approve and Reject reaching Rooms.Decide, a refusal shown as an error and the call offered again, a call decided elsewhere or a room left taking it off the box, and the chat's own approval keeping it
    • TestAnApprovalIsAnsweredWhereItCameFrom: the box's answer and Esc's rejection go to the room for a room's call and to the agent for the chat's own
  • Approval wait tests: TestAnApprovalWaitsAsLongAsApprovalTimeoutSays (on a fake clock: five minutes by default, a set timeout, and 0 never giving up) and TestWorkerArgsAndEnv (every session worker gets INFER_TOOLS_SAFETY_APPROVAL_TIMEOUT=0).

Cross-repo impact

…ecision

A member whose run suspends on a tool call, such as one the judge rejected and
the member escalated, now posts the call to its room as kind approval, with the
judge's reason and the member's justification. A client decides it with the new
decide_room_approval frame, approve or reject. The member resumes its run with
that decision, the room logs who decided as kind decision, and the client gets
room_approval_decided. The first decision wins and a later one is refused.

A call resumed from the member's own chat, or one whose run ended first, is
closed in the room the same way. A run suspended on anything else, such as a
question, still waits in the member's own chat with a note.
The room view shows a member's call waiting for you with its note and
[ Approve ] [ Reject ] while it is open. A click on either decides it, and
alt+y or alt+n decide the newest open call. The keys are chat_room_approve and
chat_room_reject in keybindings.yaml, since ctrl+y is the composer's redo. A
refusal, such as a call already decided, shows as an error.

The layout records the row the conversation area starts on, so a click maps
onto the room's buttons the way it maps onto the status indicators.
…at shows

A room's mode never took effect after the daemon started. The daemon read
rooms.yaml once at its start, and a member's worker kept the mode it was
spawned with, so a room switched to mode: standard still ran its members in
auto-with-judge or auto, and a delete ran without asking.

The rooms host now reads its settings through a function the daemon backs with
a fresh config load, so an edit reaches the next post, the last good settings
standing in for a file that does not load. Every member turn resolves its room
from those settings and sends set_mode with the room's mode before its run
input, so a worker that started under the old mode switches too.

Inside a room the chat's mode indicator showed the chat's own mode, which says
nothing about the members. It now names the room's mode, such as
#public > STANDARD, from the room's snapshot and the mode each member turn
reports on room_activity, and shift+tab is held back there, pointing at
rooms.yaml. No room shows the chat's own mode again.

Verified in tmux against the tokenless mock: with the room switched from auto
to standard while the daemon ran, the unfixed build deleted the file without
approval, and this build held the call in the room until alt+y approved it.
…report

Inside a room the indicator fell back to STANDARD whenever the daemon reported
no mode for the room, which a daemon of an older build never does. So a room
that daemon ran in auto-with-judge showed #public > STANDARD while its members
wrote files without asking. It now shows the room alone, #public, until the
daemon reports the mode.

Verified in tmux against the tokenless mock with the binary of a daemon started
before this branch: the chat at the branch head showed #public > STANDARD while
the writer wrote the file unasked, and this build shows #public.
A room's call expired after five minutes. The agent gave up on every approval
after ApprovalTimeout, so a member's call nobody had decided yet failed with
"approval request timed out", and the room said it was decided in the member's
own chat.

A daemon worker suspends its run on an approval as an interrupt until a client
resumes it, and the registry already stops a suspended thread nobody follows.
So the worker sets no deadline of its own. tools.safety.approval_timeout now
bounds the wait, five minutes by default and 0 waiting until it is decided, and
every session worker the daemon launches gets 0. The local chat and a one-shot
headless run keep five minutes.

Verified in tmux with the user's rooms.yaml and a real model: a Write call left
undecided for 6m42s still waited in the room, and approving it wrote the file.
The room drew its own [ Approve ] [ Reject ] under a member's call, with a
click hit test and alt+y / alt+n keys, beside the approval box every tool call
of the chat already uses. Now the newest open call of the room on screen opens
in that box, naming the member and the room, with its diff preview, and the
answer goes to the room. A room's call offers no Auto-Approve, since a room
never switches its member's mode. Esc rejects it in the room too, through the
same answer the box gives. A call decided elsewhere or a room the chat leaves
takes the call off the box, and the chat's own approval keeps the box until it
is answered.

The room's buttons, the chat_room_approve and chat_room_reject bindings and the
layout's ConversationTop, kept only for clicks on those buttons, are gone.

Verified in tmux with the user's rooms.yaml and a real model: Enter on Approve
wrote the file, Esc rejected the call and wrote nothing, and Auto-Approve never
showed.
edenreich added a commit that referenced this pull request Nov 24, 2026
…infer sessions (#1968)

## Summary

The daemon is the process that hosts sessions, not the place to act on
them. Yet `infer daemon` carried `workspaces`, `run`, `stop` and
`teleport`, so `infer daemon stop` stopped one session, and nothing
stopped the daemon itself. Cleaning up a daemon meant reading
`~/.infer/run/daemon.pid` and killing it by hand, which is how a daemon
from a stale build kept running members in the wrong mode during testing
of #1963.

Now `infer daemon` starts and stops the process, the session commands
live under `infer sessions`, and a stop ends everything the daemon runs
gracefully.

```bash
infer daemon                                     # start it
infer daemon stop                                # stop it, and everything it runs, gracefully
infer sessions workspaces                        # moved from infer daemon, unchanged
infer sessions run|stop|teleport <session-id>    # moved from infer daemon, unchanged
```

### `infer daemon stop`

- **It stops the daemon this user runs**, the one holding the lock on
`~/.infer/run/daemon.pid`. It sends SIGTERM, waits for the daemon's own
shutdown, and kills it if it still runs after a minute.
- **A pid file no daemon holds is left alone.** A daemon that crashed
leaves its file behind, and that pid may name another process by now, so
the pid counts only while the daemon holds the file's lock.
- **Stopping no daemon is not an error.** It prints `no infer daemon is
running` and exits 0.
- **It needs no binding**, so it also stops a daemon from another build
that would refuse a client's hello.
- `infer daemon` takes no arguments, so a leftover `infer daemon run
<id>` fails instead of starting a daemon.

### `infer sessions`

`workspaces`, `run`, `stop` and `teleport` move from `cmd/daemon` to
`cmd/sessions` unchanged, apart from naming their argument
`<session-id>`. The command tree now mirrors the bounded contexts: the
daemon hosts the sessions context, it does not own its verbs.

### Everything the daemon runs shuts down gracefully

- **Session workers** already did: the daemon sends each an `interrupt`,
closes its stdin, and the worker ends its turn and cleans up.
- **Scheduled, heartbeat and A2A runs and subagents did not.**
`agentheadless.Run` started them with `exec.CommandContext`, whose
cancel is a SIGKILL, so a run never got to stop its MCP servers, browser
and background shells. `process.TerminateOnCancel` now sends SIGTERM and
gives the run 25 seconds before a kill. `infer headless` already shuts
down on SIGTERM.
- **The scheduler left running jobs behind.** Each job ran on
`context.Background()`, so a stop waited 30 seconds and then let the job
run on for up to 30 minutes after the daemon exited. The scheduler now
cancels its jobs on stop and waits for them.
- **Windows** has no SIGTERM, so there `infer daemon stop` kills the
daemon. Its session workers still clean up as their stdin closes, but
one-shot runs outlive it. This is marked as a `shortcut:` on
`daemon.Stop`, to be replaced by a stop frame over the binding once
windows needs one.

`infer daemon workspaces`, `run`, `stop <id>` and `teleport` are gone.
Use `infer sessions workspaces`, `run`, `stop` and `teleport`. There are
no deprecated aliases, since keeping them under `infer daemon` would
keep the daemon tied to the session verbs. The docs, the examples'
Taskfiles and READMEs, and the chat's error hint use the new commands.

## Verification

- **End to end in tmux against the tokenless mock**
(`INFER_GATEWAY_MOCK`, an isolated `HOME` and binding port), with three
children of the daemon running: a chat session worker, a room member
holding a `Write` call for approval, and a heartbeat run whose mock turn
stalls forever.
- `infer daemon stop` printed `stopped the infer daemon (pid 98322)` and
returned in 0.13s, with no infer process left.
- The daemon log shows every child running its own shutdown (`stopping
background shell service`, `stopping job supervisor`, `shutting down
agent containers`), the heartbeat run included, the member's pending
approval moving to `Cancelled`, then `heartbeat service stopped` and
`daemon stopped.`
  - A second `infer daemon stop` printed `no infer daemon is running`.
- `TestStopStopsOnlyTheDaemonHoldingThePidFile`: no pid file, a pid file
no daemon holds (its process is not signalled), and the daemon holding
it (stopped, its pid returned).
- `TestStopKillsAProcessThatIgnoresTheRequestOnceGracePasses`: a process
that traps SIGTERM is killed once the grace passes, not before.
- `TestACancelledRunShutsDownOnItsOwnBeforeAnyKill`: a cancelled run
gets to run its SIGTERM handler. It fails without the change (`lines =
["ready"]`, killed before the handler ran).
- `TestCommandTopology` lists `sessions`. `go test -race` for `cmd/...`,
`internal/daemon`, `internal/platform/process`,
`internal/agent/headless` and `internal/scheduler/...`, plus the
pre-commit gate.
- **Not run:** the Kubernetes teleport examples whose Taskfiles now call
`infer sessions`, which need a cluster. The edit there is the command
name only.

## Cross-repo impact

- inference-gateway/docs#1307 updates the CLI page, `cli.md`: `infer
daemon stop`, the session commands under `infer sessions`, and the
workspace listing as `infer workspaces list`, which #1970 moves there
from `infer sessions workspaces`.
- inference-gateway/infrastructure: its README mentions `infer daemon
teleport`.
- A code search finds no use of these commands in the desktop app or the
opentask extension, which talk to the daemon over the binding.
@edenreich
edenreich merged commit 11e1918 into main Nov 24, 2026
14 checks passed
@edenreich
edenreich deleted the feat/issue-1958 branch November 24, 2026 17:08
edenreich added a commit that referenced this pull request Nov 24, 2026
…build (#1972)

## Summary

Closes #1966.

A daemon runs until `idle_exit` passes with no threads and no clients,
and every dev build declares the version `dev`, so a chat built from
newer code joined an older daemon without a word, and whatever the new
code added on the daemon's side was silently missing. That is how the
room approvals of #1963 never appeared during testing: the daemon and
its members ran a branch without them.

- **The daemon declares a build identity.** Its hello ack carries
`build`, the SHA-256 of its executable, which tells two dev builds of
one version apart and two releases too.
- **A chat that joins a daemon of another build says so once** and keeps
working:

  ```text
✗ infer daemon runs another build than this chat, so what this build
changed there is missing - stop it (pid 86806) and run again
  ```

Both `infer chat --daemon` and a plain chat's rooms warn, on the first
connection and again only if a reconnect lands on yet another build. A
daemon that declares no build predates this change and counts as another
build.
- **Released builds compare the same way**, so a chat after an upgrade
notices a daemon still running the previous version.
- `docs/daemon.md` describes the notice under the chat TUI section.

## Verification

- **In tmux against the tokenless mock**, with an isolated `HOME` and
binding port:
- a daemon built from `main` and a chat built from this branch: the
notice above appeared with the daemon's real pid, and a turn ran to
`Done.`
  - the same binary as daemon and chat: no notice
- `TestBuildNoticeTellsAnotherBuildApart`: the same build, another build
and a daemon declaring none, with and without a pid file.
- `TestSessionlessThreadSaysOnceThatTheDaemonRunsAnotherBuild`: a plain
chat's rooms dial warns once across two requests, and a same-build
daemon never warns.
- `TestThreadHandsTheBuildNoticeOverOnce`: the `--daemon` chat path
hands the notice over once.
- `go test -race` for `internal/daemon` and
`internal/presentation/tui/daemonthread`, golangci-lint, the import
check and `task precommit:run`.
- **Not run:** Windows.

## Cross-repo impact

- inference-gateway/docs#1309 adds the notice to the CLI page, `cli.md`,
next to `infer daemon stop`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

[FEATURE] Rooms: approve a member's escalated tool call from the room

1 participant