Repository navigation
fix(tui): keep conversation pinned to tail when approval box opens - #1289
Merged
Merged
Conversation
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
Contributor
|
🎉 This PR is included in version 0.207.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1286.
Root cause
ConversationView.SetHeightcalledViewport.SetHeightbeforerebuild(). When the approval box opens the viewport shrinks, which raises bubbles' max Y offset, so theAtBottom()check insideupdateViewportContentFullwas already false →GotoBottom()skipped → follow mode lost for the rest of the turn.Fix
Read
AtBottom()before resizing and re-pin withGotoBottom()after the rebuild (skipped in message-history mode).Tests
TestConversationView_AutoFollow: a shrink while at the bottom keeps following, and a shrink while scrolled up holds the offset.TestChatTUIApprovalBoxFollowsTailfills 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 onmainand passes with the fix.Also bumps tokenless v0.8.0 → v0.9.0 (separate commit). Integration, container and e2e suites pass on it.