Skip to content

fix(tui): scroll /models without manual page rows - #2130

Merged
zjywill merged 2 commits into
mainfrom
fix/model-picker-scroll-2129
Nov 24, 2026
Merged

zjywill merged 2 commits into
mainfrom
fix/model-picker-scroll-2129

Conversation

@zjywill

@zjywill zjywill commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2129.

  • App Server checks managed-account eligibility before model candidates count toward the page. A stored catalog with no account descriptor yields one unreadable-provider diagnostic instead of displacing Magpie models.
  • The conversation and fixed subagent pickers show a single scrollable list. Forward navigation near the end loads and appends the next bounded batch, preserving the selection. Empty batches advance automatically, without Next/Previous rows.
  • OAuth build, login, and release configuration are unchanged.

Design rule checklist

  • Scope/lifecycle and infrastructure: no new plugin parts or services; the existing provider query owns eligibility, and the CLI picker owns the loaded results only while open. Assembly, Timeline, Dispatcher, and session/branch facades are unchanged.
  • Commands/results, handover, before, atomic fact batches and model context: n/a, this changes a read and its UI projection, not event or state-write contracts.
  • Core mechanisms, plugin ownership and configuration: the provider query uses the account owner's existing status contract; no plugin-private state, new mechanism, or loader configuration.
  • Cross-language faces: no new service or face. The CLI uses the existing public provider.models.query RPC with unchanged request and response fields.

Documentation

Verification

  • cargo test --locked -p dimcode --test cli_tui_flow tui_models_picker — 7 passed.
  • cargo test --locked -p dim-app-server --test app_server_flow model_page — 3 passed, including the Magpie-only regression without the Dim account plugin.
  • Scoped rustfmt, git diff --check, and the ADR freeze check passed.
  • On the local build with a disposable home and real App Server, verified the rendered picker in tmux: stale account rows did not block the first selectable models, scrolling reached the 35th row and returned to the first, and a search with no matches showed the empty state.

Exclude stale managed catalog rows before pagination when the account cannot use them. Keep the unreadable-provider diagnostic if its descriptor is missing.

Append model batches as the user scrolls, keeping selection and skipping batches with no selectable model. Keep cursor navigation out of the picker.

Amp-Thread-ID: https://ampcode.com/threads/T-01a20b77-de7e-761c-ac5a-7cb00ce255e9

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Refresh all loaded rows for the provider after clearing model preferences. The list now keeps multiple batches active, but the clear action chooses only the selected row's batch, and the worker rereads just that batch. Since expectedVersion is the provider record version, a successful clear changes it for every model under that provider. page() keeps the other cached batches when the cursor is unchanged, so opening two pages from one provider, clearing saved preferences on page 2 and immediately clearing a model on page 1 sends the old version and needlessly conflicts. Before, changing pages reread them; now those stale rows remain actionable in one list.

Please refresh or invalidate the other loaded batches for the affected provider before allowing another versioned action. A regression with one provider spanning two batches can assert that clearing a model in either batch leaves the other batch's next action using the new version. I did not find a blocker in the managed-account eligibility change. Source review only; exact CI was still running.

Provider versions are shared by every model from the same provider. Reread the loaded prefix as one update before reporting the clear result, and do not queue another clear while the picker is waiting for fresh rows.

Amp-Thread-ID: https://ampcode.com/threads/T-01a20b77-de7e-761c-ac5a-7cb00ce255e9

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head 0ece570.

The App Server half is a decision the query owner should be making, and now it is. A Managed record whose account is present and matches scans its models; one whose stored account no longer matches is skipped without displacing anything; one with no account descriptor stops the scan and yields the unreadable-provider diagnostic. That is the three-way distinction the bug needed — a stored catalog missing its descriptor was counting toward the page and pushing Magpie models out, which made an unreadable provider look like a provider with models. Doing it in the provider query rather than filtering in the picker keeps the rule where the records are read, and accounts.get(&id) consulted before the cost of scanning is the right order.

The CLI half removes the page rows and lets the picker append bounded batches as the operator scrolls toward the end, preserving the selection and advancing automatically through empty ones. That is the right model for a list that is longer than the visible window: the interface owns the loaded results only while it is open, and the wire stays bounded. Removing the Next/Previous strings across every locale follows from the rows being gone rather than being left as dead text.

Blocking: none.

Checks are green at this head. I read the provider/query.rs eligibility branch and the shape of the picker's batch loop in session_host.rs and model.rs; I did not read the 70 lines added to provider_flow.rs, the CLI flow tests, the i18n removals in full, or the design deltas, and ran nothing.

Non-blocking: none.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope

Fixes #2129. A stored managed catalog that this build cannot use must not fill the first provider.models.query page, and the conversation and fixed subagent pickers must scroll through bounded batches without manual Next/Previous rows.

Verdict

APPROVE at 0ece570. No P1 or P2 defect found.

The prior CHANGES_REQUESTED is addressed. A clear now rereads the loaded prefix in one update before the notice, and tui_models_picker_rereads_loaded_batches_after_clearing_preferences checks that a clear on one batch leaves the next clear on the other batch using the new provider version.

CI is green: verify (linux), macos-native, windows-cli and ci-ok pass; the path-filtered jobs are skipped (acp-registry, dependencies, scripts, static-checks, web). Local targeted runs with an isolated home and target directory:

  • cargo test -p dim-app-server --test app_server_flow model_page_keeps_magpie_visible_without_the_dim_account_plugin: 1 passed.
  • cargo test -p dimcode --test cli_tui_flow tui_models_picker: 8 passed.
  • cargo test -p dim-cli --lib models_panel: 23 passed.

Note: the PR body's Verification section predates the second commit; it lists 7 picker tests and the head has 8.

Findings

P3: a rejected reply can leave the fixed picker on an old query with requesting set

Problem: page() returns early when the reply's query differs from the active view's query and does not clear requesting (crates/dim-cli/src/ui/models_panel.rs:164-168). open_child fills the Fixed list from listed.query, the last accepted reply, not from the root filter (crates/dim-cli/src/ui/models_panel.rs:291-295), and query() is view dependent (crates/dim-cli/src/ui/models_panel.rs:145-150).

Failure scenario: type a search in the conversation list, then Tab to the policy section, open it, choose Fixed before the reply arrives. The Fixed list shows the previous query's models, the reply is rejected, and requesting stays true. Down, PageDown and End no longer load batches (models_panel.rs:743-753) and Ctrl+X is ignored (models_panel.rs:821-823). Typing or Escape starts another request and recovers. The same happens when the ChatGPT connect flow opens /models with a prefilled search and the user opens Fixed while that first reply is outstanding.

Evidence: crates/dim-cli/src/ui/models_panel.rs:164-168, 291-295, 743-753 and 821-823.

Fix: paste self.root.query() into the Fixed list in open_child, so the pending reply matches; or clear requesting when a reply is rejected because its query no longer binds.

P3: a search in the fixed picker discards the conversation list's loaded batches

Problem: search() clears the shared pages and the reply replaces the shared listed (crates/dim-cli/src/ui/models_panel.rs:675-680, 182-202). The new Fixed Escape branch then reloads only one page of the root query (models_panel.rs:766-774), and the save path does not reload at all.

Failure scenario: load more than one batch in /models and move to a later row, open Policy, choose Fixed, type a search, then Escape back to the sections. The conversation list is rebuilt from the fixed query results or from one root page, so the old row is not present and the selection clamps to the last loaded row, contrary to the restore promise at models_panel.rs:38-41. Choosing a fixed model after a search leaves the root filter over the fixed query's rows because set_policy calls back_to_root without a reload (models_panel.rs:272-274, 301-310).

Evidence: crates/dim-cli/src/ui/models_panel.rs:675-680, 182-202, 766-774 and 272-274.

Fix: keep the root's pages and listed while a child search is active, or capture the root's loaded batch count on entry and reload it on return. A query-change reload in back_to_root would also cover the save path.

P3: the TUI routing inventory is stale

Problem: docs/architecture/tui-e2e.md:369 still lists tui_models_picker_reads_pages_on_demand_and_reopens_without_a_cache, which this PR renames to tui_models_picker_scrolls_across_batches_and_reopens_without_a_cache, and it does not list the new tui_models_picker_rereads_loaded_batches_after_clearing_preferences.

Failure scenario: a maintainer following the routing doc looks for a CI case that no longer exists and does not see the new case in the inventory or its count.

Evidence: docs/architecture/tui-e2e.md:369 and the PR's test rename and addition at crates/dimcode/tests/cli_tui_flow.rs:7755 and 7813.

Fix: update the name and add the new case (and the case count) in this PR.

P3: the new scroll test would not catch a selection jump

Problem: after the third batch arrives, the test waits for the row and then presses Down before asserting Selected: Test / third (crates/dimcode/tests/cli_tui_flow.rs:7793-7799). If the append moved the selection to the last row, the extra Down would still satisfy the assertion.

Failure scenario: an append that clamps the selection to the new last row passes this test, so the stated selection preservation has no regression guard.

Evidence: crates/dimcode/tests/cli_tui_flow.rs:7794-7797. The fixed picker has no batch test, and the new providers() merge (crates/dim-cli/src/ui/models_panel.rs:1109-1147) has no test with a provider split across pages.

Fix: assert Selected: Test / second right after Test / third appears, before the second Down; add one fixed-picker batch case or state that the shared path is covered, and one merged-provider case.

Cross-PR

Open PR #2096 rewrites docs/design/appserver/provider-management.md and keeps the same "Model display queries" paragraph that this PR updates; its current head still has the old sentence about an empty managed provider. Expect a rebase conflict and keep the new eligibility sentence when resolving.

Unverified

  • The P3 scenarios come from source review, not from a terminal reproduction.
  • Auto-advance relies on the server cursor advancing on every empty batch. The real App Server does, because each cursor is the last candidate; no server that repeats an empty cursor was exercised.
  • The fixed picker's batch path was not run end to end; only the shared code and the conversation picker tests were exercised.
  • OAuth build, login and release code is untouched by the diff, as claimed.

after: Option<ModelId>,
result: Result<Vec<ModelList>, String>,
) -> Effect {
if query != self.query()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: a rejected reply can leave requesting set. open_child fills the Fixed list from the last accepted reply's query (models_panel.rs:291-295), so a Models search reply that is still in flight when Fixed opens has a different query and this guard returns without clearing requesting. Failure scenario: type a search, open the policy section, choose Fixed before the reply arrives; the Fixed list shows the previous query, and Down, PageDown and End (models_panel.rs:743-753) and Ctrl+X (models_panel.rs:821-823) stop working until typing or Escape issues another request. Fix: paste self.root.query() in open_child, or clear requesting on a query-mismatch rejection.

}

fn search(&mut self) -> Effect {
self.pages.clear();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: this clears the conversation list's batches when the search is typed in the fixed picker. pages and listed are shared by View::Models and View::Fixed, and the new Fixed Escape branch reloads only one page of the root query (models_panel.rs:766-774). Failure scenario: load two batches in /models, move to a later row, open Fixed, type a search, Escape back; the conversation list keeps one batch and the selection clamps, contrary to models_panel.rs:38-41. Choosing a fixed model has the same mismatch because set_policy calls back_to_root without a reload. Fix: keep the root's pages and listed while a child search is active, or restore the root's loaded batch count on return; a reload in back_to_root also covers the save path.

terminal.until("Test / second");
terminal.until_anywhere("Empty: no models");
terminal.raw(b"\x1b[B");
terminal.until("Test / third");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: this would not catch a selection jump on append. The third batch is triggered by the Down at line 7794; the test waits for the row and then presses Down again before asserting Selected: Test / third. If appending moved the selection to the last row, the second Down keeps it there and the assertion still passes. Assert Selected: Test / second immediately after Test / third appears and before the second Down.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loaded-batch version issue is resolved. Clearing preferences rereads the loaded prefix and replaces it as one update before accepting another clear. The regression alternates between two batches of the same provider and checks the expected version on each write. I also verified that managed-account eligibility is checked before pagination and that scrolling and selection operate across loaded batches.

I verified the exact integrated checkout and passing Linux workspace tests, including the batch refresh and scroll regressions. The selected Windows and macOS jobs and the required gate also passed. No material blocker remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tui): make /models scroll continuously past empty batches

4 participants