Skip to content

fix(agent): make the session picker fast and readable - #420

Merged
fcoury merged 5 commits into
mainfrom
fix/session-picker-review
Oct 23, 2026
Merged

fcoury merged 5 commits into
mainfrom
fix/session-picker-review

Conversation

@fcoury

@fcoury fcoury commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The Agent session picker (Alt-s, :AgentSessions) worked after #416, but trying it against a real Codex history (about 2,300 threads) showed it was slow and hard to read. The default Red scope took about 10 s to load, because Codex doesn't tag Red's threads, so Red paged through every thread, rescanning rollouts, and opened files to find its own. A search took 20 to 30 s before anything appeared. The Red scope also listed Red sessions from every directory, and Enter resumed one into the current workspace even though the thread kept its old working directory. Red threads have no name, so their rows showed the raw first prompt with Red's editor context glued on ("Reply with just OK.Active editor context from file:///…"), and conversations resumed after an interruption all read "Previous conversation (the last turn was interrupted): …". The peek and the restored transcript showed the same text. After resuming from the picker, the header said "Codex" instead of the model. Switching scope left the cursor at an arbitrary row, and Ctrl-U didn't clear the search field. The pane header also squeezed Sessions, New and Clear into cryptic [S] [N] [C] buttons, and the picker's scope was only a word in the title, with its Alt-s hint cut off at the end of the hint row.

What changed

Faster listing. thread/list now asks Codex to answer from its state DB (useStateDbOnly) rather than rescanning every rollout: listing all 2,267 threads went from 7.7 s to 0.2 s. The Red and This workspace scopes pass the workspace to Codex as a cwd filter. A thread is recognized as Red's from its recorded originator when Codex has one, and otherwise from the rollout's first line as before. Codex has compressed older rollouts to .jsonl.zst while still listing the .jsonl path, so that fallback now also reads the compressed file, using the pure-Rust ruzstd decoder.

Search in two steps. A query first matches thread names and first prompts in Red itself (every word, ignoring case), which takes well under a second. The picker then asks for a text search with thread/search, shows "Searching conversation text…" meanwhile, and merges the content matches in, adding snippets to rows it already shows. AgentListSessions gains an optional search_contents argument for this (host API 0.21.0 is still unreleased).

Scopes and resuming. The Red scope now lists Red sessions from this workspace. A session gains a resumable flag, set only for a Red thread from this workspace, and the picker resumes only those. Any other session, including a Red one from another directory, continues in a new thread here and is labelled "Continue here" or "Continue in Red".

Readable rows. Labels, peeks and restored transcripts drop the editor context Red sends after a prompt, and show only the follow-up a recap was sent with (typed_prompt in src/agent_conversation.rs, shared by all three). The recap and context text are built from the same constants.

Model header. Codex reports the model of a resumed thread right after restoring it, in the same batch, before Red tells the plugin which thread is active, so the plugin dropped the event. The pane now takes the thread id from the restore event itself.

Selection. Changing scope or query starts the list again at its first row: replacing a picker's blocks with an empty list now resets the host's selection, and the plugin does that before showing new results. Selecting the first row scrolls its group heading back into view. The peek uses the row the host shows as selected, which it didn't always do before.

Scope tabs. The picker shows its scopes as tabs under the search field: Red, This workspace, All Codex. The selected one is highlighted, a click selects one, and Tab / Shift-Tab (or Alt-s) move to the next or previous. On narrow panes the tabs use short labels, and then show only the selected scope. EnterTextPanelContext options gain tabs, tab and tab_shortcut for this, and the host emits context_tab with the tab's id. The hint row no longer carries the scope, and leaves out whole hints rather than cutting one off.

Pane actions. Sessions, New and Clear moved out of the header to a row of key hints under the composer (Alt-s sessions · Alt-n new · Alt-c clear), which can be clicked. Any composer panel lists the actions it declares with show_in_header: false there. The header keeps only the close button, drawn without brackets.

Pane on the left. The Agent pane now opens on the left. When the file tree is open too, the tree keeps the outer edge, whichever opened first: docked side panels without a composer are placed before conversation panes on the same side. Ctrl-w L still moves the pane right, per workspace.

Search field. Ctrl-U in Insert mode deletes back to the start of the line, in the session search and the composer alike.

How to Test

  1. Use a machine with a long Codex history. Open Red in a project where you have used the Agent pane, open the pane, and press Alt-s. The Red list should appear within about a second, with labels that are just the prompts you typed.
  2. Press Alt-s twice to go through This workspace and All Codex. Each should load in well under a second and start with the first row selected. In All Codex, a Red session from another directory should say "Continue here".
  3. Type a word from a session's title. Matching titles should appear right away, the status should say "Searching conversation text…", and content matches with snippets should be added once it finishes. Press Ctrl-U: the field should clear and the full list return.
  4. Move down a few rows and press Alt-p. The peek should show the highlighted session, without any "Active editor context" block.
  5. Check the tabs: the selected scope is highlighted, Tab, Shift-Tab, Alt-s and clicking a tab all switch it, and narrowing the pane switches to "Red Here All". Press Esc: the header shows only the model and ×, and the row under the composer reads Alt-s sessions · Alt-n new · Alt-c clear; clicking "Alt-n new" starts a new conversation.
  6. Close and reopen the pane: it opens on the left. Open the file tree (:NeoTree) before or after it: the tree is always at the left edge, with the pane between it and the editor.
  7. Press Enter on a Red session from this workspace. The pane should restore it, and the header should show its model, not "Codex". A session that was continued after an interruption should show only the follow-up you typed.

Targeted tests:

  • cargo test --test codex_app_server direct_app_server_lists_searches_and_continues_sessions_for_red: the state-DB listing, the workspace filter, originators, title and text search, and the cap.
  • cargo test --lib codex::sessions: labels, peeks, title matching, and compressed rollouts.
  • cargo test --lib bundled_agent_session_browser_cycles_scope_and_continues_in_the_same_pane
  • cargo test --lib bundled_agent_plugin_restores_the_bound_codex_thread_and_keeps_input_open: the model header after a picker restore.
  • cargo test --lib temporary_picker_starts_over_at_its_first_row_and_heading
  • cargo test --lib restored_prompts_leave_out_the_recap_and_context_red_sent
  • cargo test --lib picker_tabs_show_the_scope_and_switch_it_by_click_or_shortcut
  • cargo test --lib composer_lists_the_pane_actions_left_out_of_the_header
  • cargo test --lib file_tree_stays_outside_a_conversation_pane_on_the_same_side
  • cargo test --lib control_u_deletes_to_the_start_of_the_line_in_insert_mode

List sessions from Codex's state DB, scope Red sessions to the workspace, match titles before the slower text search, resume only Red threads from this workspace, strip Red's context and recap from labels, peeks and restored prompts, keep the model header after a picker restore, reset the selection on a new scope or query, and let Ctrl-U clear the search field.
@fcoury

fcoury commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T13:44:12.888398Z 68496f9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68496f9766

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/agent.hk Outdated
red::state_patch(AgentState { model_info: event.model_info, accepted_model: Json {}, turn_model_info: Json {} });
// The thread's model follows in its own event, which can arrive before the
// pane state names the restored thread.
red::state_patch(AgentState { session_id: event.thread_id });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Check the displayed thread before replacing its session ID

When switching sessions while the pane already contains a conversation, this assignment makes shows_thread(event.thread_id) compare the restored ID against itself. Since switching also clears resume_age, the existing nonempty transcript makes that predicate true, so load_conversation(event) is skipped. The pane consequently keeps displaying the previous session's messages even though subsequent prompts go to the selected session. Determine whether the restored thread is already displayed before updating session_id, or update it after the transcript-loading decision.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in c9dc257. session_restored now decides whether the thread is already shown before it sets session_id. session_id is still set before the model event arrives, so the header fix stays. The restore test now switches from a shown conversation to a picked thread and checks that the picked transcript is rendered. It fails without the fix.

Comment thread src/codex/sessions.rs Outdated
Comment on lines +317 to +319
if request.sessions.len() >= MAX_LISTED_SESSIONS {
let more = request.more || next_cursor.is_some() || wants_contents(&request);
return finish(request.sessions, more, request_id, events).await;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Search conversation contents even when title matches reach the cap

When a query matches at least 200 session titles, this early return also runs for requests with search_contents: true, before they can transition to ListPhase::Contents. The picker's second request therefore repeats the title results without ever issuing thread/search; a newer session matching only in its conversation text cannot appear, despite the documented promise to return the 200 most recently updated matches. Apply the display cap without skipping the contents phase, then retain the newest matches from the merged results.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, fixed in c9dc257. Each phase now stops at the cap on its own: titles stop at 200 matches, and the text search still runs and stops at 200 hits. finish then keeps the 200 newest of the merged results and sets more. The integration test's capped query now gets a text-only match newer than every title match, and that match comes first.

…omposer

The pane header squeezed Sessions, New and Clear into [S] [N] [C] buttons,
and the picker's scope was only a word in the title, with its Alt-s hint cut
off at the end of the hint row.

Picker contexts can now declare tabs, which the host shows in a row under the
search field and switches by click or shortcut, emitting context_tab. Pane
actions left out of the header are listed as key hints under the composer.
The picker hint row now leaves out whole hints that don't fit.
The file tree keeps the outer edge when both are docked on the same side,
whichever opened first.
…he cap

Naming the restored thread before checking whether the pane shows it made
every switch look like the thread already on screen, so the old transcript
stayed. A query matching 200 titles also skipped the text search, hiding
newer sessions that match only in their conversation.
@fcoury
fcoury merged commit aa02c9f into main Oct 23, 2026
18 of 22 checks passed
@fcoury
fcoury deleted the fix/session-picker-review branch October 23, 2026 15:47
fcoury added a commit that referenced this pull request Oct 23, 2026
#420 stopped drawing brackets around header actions, so the RPC panel test
could no longer find "[Run]" to click.
fcoury added a commit that referenced this pull request Oct 23, 2026
* chore(release): write the v0.10.0 release campaign

Replace the v0.9.1 stories with this release's, update the README's release
section, which still described the v0.8.2 notify-only updater, and list the
host API 0.21.0 symbols added by #420.

* docs(agent): describe the session picker's scope tabs

* test(rpc): find the Run panel action without header brackets

#420 stopped drawing brackets around header actions, so the RPC panel test
could no longer find "[Run]" to click.
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.

1 participant