Skip to content

fix(agent): read long Codex sessions in pages - #416

Merged
fcoury merged 2 commits into
mainfrom
fix/agent-large-session-history
Oct 23, 2026
Merged

fcoury merged 2 commits into
mainfrom
fix/agent-large-session-history

Conversation

@fcoury

@fcoury fcoury commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Opening the Agent session picker (Alt-s, :AgentSessions) failed with "Could not load sessions: Codex app-server failed: Codex app-server frame exceeds the limit", and the Codex connection went down with it. Red asked Codex for whole conversations in single responses, and real sessions are far bigger than Red's 1 MiB frame limit: five recent threads read back at 3 to 303 MiB, mostly tool output. Older threads also keep their whole first prompt as the list preview, so one 100-thread page of the session list reached 9 MiB. Any frame over the limit was treated as fatal, so one large response stopped everything.

Fixing that exposed a second failure: with the All scope loaded (about 2,300 sessions), rendering the picker used up the Agent plugin's instruction budget, and Red quarantined the plugin.

What changed

History is read in pages (src/codex/history.rs, new). Previews, continuations and resumes use thread/turns/list, newest first, instead of thread/read with includeTurns or a full thread/resume:

  • A preview reads the newest five turns as summaries.
  • A continuation reads summaries until it reaches the transcript's limits (256 exchanges or 1 MiB of message text), then injects them as before.
  • A resume sends excludeTurns: true and reads full turns, so annotations still replay from tool calls. If a full page is too large, it is retried as summaries. An app-server that ignores excludeTurns still sends turns in the resume response, and those are used as before.
  • If an app-server doesn't support thread/turns/list, previews and continuations fall back to thread/read.

An oversized frame fails only its own request. The reader skips the rest of the line without buffering it, and recovers the frame's id from its opening bytes (app-server responses start with {"id":). The request it answers then gets an error. An oversized server request is refused so Codex doesn't wait for an answer, and an oversized notification is logged and dropped. The frame limit rises from 1 MiB to 8 MiB, matching plugin RPC.

The session list stays bounded.

  • A list page that is too large is retried at half the size.
  • If a single thread can't be listed at all, the picker shows the sessions before it.
  • The list stops at the 200 most recently updated matches, and returns more when older ones were left out; the picker says to search for those. This also means Red no longer fetches every page (about 20 MiB in the All scope) before showing anything.

Annotations from partial history. A history marked historyTruncated lacks earlier annotations, so its replay only fills an empty record and never replaces annotations Red saved.

Header. The pane header's "restoring…" now clears when a restore finishes. Before, it stayed until the next turn ended.

How to Test

  1. Have some long Codex conversations, for example from the Codex CLI or the VS Code extension. Open Red, then the Agent pane, and press Alt-s. The Red scope list should load.
  2. Press Alt-s twice more to reach the All scope. The list should load and end with "Showing the 200 most recent · type to search older sessions". :plugin-status should still show the agent plugin as active.
  3. Select a long session and press Alt-p. The preview should show its latest exchange.
  4. Press Enter on a long external session. The pane should show its recent transcript, and the header should change from "restoring…" to the model name.
  5. Quit and relaunch Red in the same workspace. The continued conversation should resume, with its transcript.

Targeted tests:

  • cargo test --test codex_app_server: paged previews and continuations, an oversized preview that fails alone, the thread/read fallback, halving an oversized list page, the 200-session cap, and resume both through paging (with an oversized full page retried as summaries) and from an app-server that ignores excludeTurns.
  • cargo test --lib oversized_frames_are_skipped_and_keep_their_request_id
  • cargo test --lib truncated_history_only_replays_annotations_into_an_empty_record

The session picker failed with "Codex app-server frame exceeds the limit" and
took the whole Codex connection down. Codex answered with full histories and
whole pasted prompts as list previews, which pass Red's frame limit for long
sessions (one real thread is 303 MiB).

- Page history with thread/turns/list: previews read the newest turns,
  continuations and resumes stop at the transcript's own limits, and a full
  page that is too large is retried as message summaries. Older app-servers
  fall back to thread/read.
- Skip an oversized frame without buffering it and fail only the request it
  answers, recovering its id from the opening bytes.
- Retry an oversized session-list page at half the size, and list only the
  200 most recent sessions so the plugin stays within its instruction budget.
- A truncated history only replays annotations into an empty record.
- Clear the header's "restoring…" once the thread is back.
@fcoury

fcoury commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T04:26:51.877511Z a4d52d5 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: a4d52d53b7

ℹ️ 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 src/codex/history.rs Resolved
Summaries drop the tool calls that carry annotations, so a resume that
downgraded a page could replace saved annotations with a partial set.
@fcoury
fcoury merged commit ba90111 into main Oct 23, 2026
18 checks passed
@fcoury
fcoury deleted the fix/agent-large-session-history branch October 23, 2026 04:25
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