Skip to content

fix(tui): keep conversation pinned to tail when approval box opens - #1289

Merged
edenreich merged 2 commits into
mainfrom
fix/approval-box-follow-tail
Sep 23, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/approval-box-follow-tail

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Fixes #1286.

Root cause

ConversationView.SetHeight called Viewport.SetHeight before rebuild(). When the approval box opens the viewport shrinks, which raises bubbles' max Y offset, so the AtBottom() check inside updateViewportContentFull was already false → GotoBottom() skipped → follow mode lost for the rest of the turn.

Fix

Read AtBottom() before resizing and re-pin with GotoBottom() after the rebuild (skipped in message-history mode).

Tests

  • Unit: two rows in TestConversationView_AutoFollow: a shrink while at the bottom keeps following, and a shrink while scrolled up holds the offset.
  • E2E (tmux + tokenless mock): TestChatTUIApprovalBoxFollowsTail fills the viewport, runs the issue's Write/Read/Write repro, and asserts that the first Write result is visible while the second approval box is open and that the final reply is visible without PageDown. It fails on main and passes with the fix.

Also bumps tokenless v0.8.0 → v0.9.0 (separate commit). Integration, container and e2e suites pass on it.

SetHeight shrank the viewport before rebuild() checked AtBottom(), so the
larger max offset made it false and follow mode was lost for the turn.
Read follow state before resizing and re-pin afterwards.

Fixes #1286
@edenreich
edenreich requested a review from a team as a code owner September 23, 2026 22:45
@edenreich
edenreich merged commit 0efdb66 into main Sep 23, 2026
1 check passed
@edenreich
edenreich deleted the fix/approval-box-follow-tail branch September 23, 2026 22:54
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.207.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 Sep 23, 2026
edenreich added a commit that referenced this pull request Nov 6, 2026
)

Part of #1713. Stacked on #1725.

## Summary

The agent now asks for every approval in a tool batch before it runs any
of the calls. Before, an approved call started at once, while the user
was still deciding on the next one, and its progress and result were
reported behind the open prompt.

That made the views disagree. The chat TUI reading the agent directly
showed the first tool's result while the second approval was open. Any
client of the AG-UI stream did not: an approval suspends the run,
`RunEncoder` waits for the answer, and whatever the running tool
reported in the meantime arrived only after it. It is the gap that kept
#1725 a draft.

## Changes

- `internal/agent/loop/states/approving_tools.go`: a call the user or
the judge approved, or one the policy does not gate, is recorded as
cleared instead of spawned. `finishApprovals` runs the cleared calls
once the round is decided. They still overlap, bounded by the same
semaphore, and their results are still flushed in tool-call order as
they complete.
- A cancelled session runs none of the cleared calls. The conversation
validator already answers calls left without a result.
- An approval that fails ends the turn before anything ran. Before,
calls approved earlier in the round were already executing.
- A round that ends early drops the approval entries of the calls it
will not run. Only running a call clears its entry, so the chat kept
showing a call as approved although it never ran.
- The status says `Tool approved: <tool>` instead of claiming the tool
is executing while the next prompt is open.

## Behavior change

This applies to every user and reverses behavior added on purpose: #609
made approved tools run concurrently while later prompts were open, and
#1289 asserted the first result is visible while the second approval is
open.

- With a gated call in a batch, no call of that batch runs until the
last prompt is answered. That includes ungated calls such as `Read` or
`TodoWrite` batched with a gated one, and a background job.
- The cost: a long first tool does not start until the user has answered
every prompt.
- Rejecting a later call leaves an earlier approval standing, so that
call still runs.
- A single gated call, auto-accept mode, and fully ungated batches
behave as before.

## What this does not change

Tools can still open a prompt during execution: sandbox access,
`RequestApproval` escalations and `AskUserQuestion`. A read-only sibling
can overlap such a prompt, so on the AG-UI stream its reports still wait
for the answer. This PR only covers the prompts of the approval round.

## Verification

- New `TestApprovingToolsState_RunsNothingWhileAPromptIsOpen` on the
fake clock, for an approved call and an ungated one. It fails on the old
behavior.
- New `TestApprovingToolsState_ForgetsApprovedCallsItWillNotRun`, for a
failed approval and a cancelled session. It fails without the fix.
- New `TestChatTUIBackgroundJobWaitsForItsBatch` fails on `main` with
`the job started while the second approval was open`, and passes here on
both paths.
- New `TestChatTUIRejectingACallStillRunsTheApprovedOne` passes on
`main` and here.
- `TestChatTUIApprovalBoxFollowsTail` now asserts the first Write has
not run while the second approval is open, and shows once both are
answered.
- The stale approval entry and the false status were reproduced by hand
in tmux with `INFER_AGENT_MAX_DURATION_MINUTES=1`, and are gone with the
fix.
- `go test -race ./...`, `task precommit:run`, and the full e2e suite
with `-race` on both paths.

## Seen while testing, not changed here

- After a run ended by its time budget, the next approval box stays
open.
- The `n` and `s` plan keys in `config/keybindings.go` do nothing on
`main` either. The screen offers arrows and Enter.

## Downstream

- Clients of the AG-UI stream need no change. They already saw nothing
between an interrupt and its answer.
- Docs follow-up: inference-gateway/docs#1110
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.

[BUG] Chat view stops following the tail when the tool-approval box opens

1 participant