Skip to content

feat(tui): restore composer history in app-server tui#14945

Merged
etraut-openai merged 1 commit intoopenai:mainfrom
fcoury:fcoury/fix/composer-history
Mar 18, 2026
Merged

feat(tui): restore composer history in app-server tui#14945
etraut-openai merged 1 commit intoopenai:mainfrom
fcoury:fcoury/fix/composer-history

Conversation

@fcoury
Copy link
Contributor

@fcoury fcoury commented Mar 17, 2026

Problem

The app-server TUI (tui_app_server) lacked composer history support. Pressing Up/Down to recall previous prompts hit a stub that logged a warning and displayed "Not available in app-server TUI yet." New submissions were silently dropped from the shared history file, so nothing persisted for future sessions.

Mental model

Codex maintains a single, append-only history file ($CODEX_HOME/history.jsonl) shared across all TUI processes on the same machine. The legacy (in-process) TUI already reads/writes this file through codex_core::message_history. The app-server TUI delegates most operations to a separate process over RPC, but history is intentionally not an RPC concern — it's a client-local file.

This PR makes the app-server TUI access the same history file directly, bypassing the app-server process entirely. The composer's Up/Down navigation and submit-time persistence now follow the same code paths as the legacy TUI, with the only difference being where the call is dispatched (locally in App, rather than inside CodexThread).

The branch is rebuilt directly on top of upstream/main, so it keeps the
existing app-server restore architecture intact. AppServerStartedThread
still restores transcript history from the server Thread snapshot via
thread_snapshot_events; this PR only adds composer-history support.

Non-goals

  • Adding history support to the app-server protocol. History remains client-local.
  • Changing the on-disk format or location of history.jsonl.
  • Surfacing history I/O errors to the user (failures are logged and silently swallowed, matching the legacy TUI).

Tradeoffs

Decision Why Risk
Widen message_history from pub(crate) to pub Avoids duplicating file I/O logic; the module already has a clean, minimal API surface. Other workspace crates can now call these functions — the contract is no longer crate-private. However, this is consistent with recent precedent: 590cfa617 exposed mention_syntax for TUI consumption, 752402c4f exposed plugin APIs (PluginsManager), and 14fcb6645/edacbf7b6 widened internal core APIs for other crates. These were all narrow, intentional exposures of specific APIs — not broad "make internals public" moves. 1af2a37ad even went the other direction, reducing broad re-exports to tighten boundaries. This change follows the same pattern: a small, deliberate API surface (3 functions) rather than a wholesale visibility change.
Intercept AddToHistory / GetHistoryEntryRequest in App before RPC fallback Keeps history ops out of the "unsupported op" error path without changing app-server protocol. This now routes through a single submit_thread_op entry point, which is safer than the original duplicated dispatch. The remaining risk is organizational: future thread-op submission paths need to keep using that shared entry point.
session_configured_from_thread_response is now async Needs await on history_metadata() to populate real history_log_id / history_entry_count. Adds an async file-stat + full-file newline scan to the session bootstrap path. The scan is bounded by history.max_bytes and matches the legacy TUI's cost profile, but startup latency still scales with file size.

Architecture

User presses Up                     User submits a prompt
       │                                    │
       ▼                                    ▼
ChatComposerHistory                 ChatWidget::do_submit_turn
  navigate_up()                       encode_history_mentions()
       │                                    │
       ▼                                    ▼
  AppEvent::CodexOp                  Op::AddToHistory { text }
  (GetHistoryEntryRequest)                  │
       │                                    ▼
       ▼                            App::try_handle_local_history_op
  App::try_handle_local_history_op    message_history::append_entry()
    spawn_blocking {                        │
      message_history::lookup()             ▼
    }                                $CODEX_HOME/history.jsonl
       │
       ▼
  AppEvent::ThreadEvent
  (GetHistoryEntryResponse)
       │
       ▼
  ChatComposerHistory::on_entry_response()

Observability

  • tracing::warn on append_entry failure (includes thread ID).
  • tracing::warn on spawn_blocking lookup join error.
  • tracing::warn from message_history internals on file-open, lock, or parse failures.

Tests

  • chat_composer_history::tests::navigation_with_async_fetch — verifies that Up emits Op::GetHistoryEntryRequest (was: checked for stub error cell).
  • app::tests::history_lookup_response_is_routed_to_requesting_thread — verifies multi-thread composer recall routes the lookup result back to the originating thread.
  • app_server_session::tests::resume_response_relies_on_snapshot_replay_not_initial_messages — verifies app-server session restore still uses the upstream thread-snapshot path.
  • app_server_session::tests::session_configured_populates_history_metadata — verifies bootstrap sets nonzero history_log_id / history_entry_count from the shared local history file.

Copilot AI review requested due to automatic review settings March 17, 2026 15:42
@fcoury
Copy link
Contributor Author

fcoury commented Mar 17, 2026

@codex review

Copy link
Contributor

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

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: a36ffd6dd2

ℹ️ 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".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Restores cross-session composer history support in the app-server TUI by handling history reads/writes locally against $CODEX_HOME/history.jsonl (matching the legacy TUI), including mention encoding/decoding for durable recall.

Changes:

  • Persist submitted composer text to the shared history file (with mention placeholder encoding) via Op::AddToHistory.
  • Replace the previous “stub” Up/Down behavior with async history lookup requests (Op::GetHistoryEntryRequest) and local handling in App.
  • Expose codex_core::message_history publicly and use history_metadata() during session bootstrap to populate history_log_id / history_entry_count.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
codex-rs/tui_app_server/src/chatwidget.rs Encodes mentions and submits AddToHistory on user submit.
codex-rs/tui_app_server/src/bottom_pane/chat_composer_history.rs Emits real history lookup ops instead of inserting a stub error cell; updates tests accordingly.
codex-rs/tui_app_server/src/app_server_session.rs Makes session bootstrap mapping async to fetch local history_metadata() for history navigation.
codex-rs/tui_app_server/src/app.rs Intercepts AddToHistory / GetHistoryEntryRequest and handles them locally (append + spawn_blocking lookup).
codex-rs/core/src/message_history.rs Widens visibility of history helpers to pub and updates docs.
codex-rs/core/src/lib.rs Exports message_history module publicly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

fcoury added a commit to fcoury/codex that referenced this pull request Mar 17, 2026
Move app-server TUI `Op::AddToHistory` persistence onto a
background task so local history writes no longer block the app
event loop while waiting on file locks.

This matches the existing `codex-core` behavior more closely and
avoids UI stalls under multi-session use, which was called out in
PR feedback on `try_handle_local_history_op`.
@fcoury
Copy link
Contributor Author

fcoury commented Mar 17, 2026

@codex review

Copy link
Contributor

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

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: e0abe5ae12

ℹ️ 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".

@fcoury
Copy link
Contributor Author

fcoury commented Mar 17, 2026

@codex review

Copy link
Contributor

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

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: 5677ee8242

ℹ️ 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".

@fcoury
Copy link
Contributor Author

fcoury commented Mar 17, 2026

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ 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".

fcoury added a commit to fcoury/codex that referenced this pull request Mar 17, 2026
Move app-server TUI `Op::AddToHistory` persistence onto a
background task so local history writes no longer block the app
event loop while waiting on file locks.

This matches the existing `codex-core` behavior more closely and
avoids UI stalls under multi-session use, which was called out in
PR feedback on `try_handle_local_history_op`.
@fcoury fcoury force-pushed the fcoury/fix/composer-history branch 3 times, most recently from ab20e38 to 9e99840 Compare March 18, 2026 00:05
@fcoury
Copy link
Contributor Author

fcoury commented Mar 18, 2026

@codex review

Copy link
Contributor

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

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: 9e99840090

ℹ️ 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".

@fcoury
Copy link
Contributor Author

fcoury commented Mar 18, 2026

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ 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".

Restore cross-session composer history in `tui_app_server` without
changing the app-server protocol. The app-server TUI now fetches and
persists composer history locally through `codex_core::message_history`,
populates real history metadata during session bootstrap, and routes
lookup responses back to the requesting thread.

This rebuilds the feature directly on top of `upstream/main` while
keeping the upstream app-server restore path intact. The branch no
longer rewrites startup replay around `initial_messages`, so the PR is
focused on the composer-history behavior only.
@fcoury fcoury force-pushed the fcoury/fix/composer-history branch from 7607f68 to 4d02185 Compare March 18, 2026 16:10
@fcoury
Copy link
Contributor Author

fcoury commented Mar 18, 2026

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Breezy!

ℹ️ 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".

@etraut-openai etraut-openai merged commit 334164a into openai:main Mar 18, 2026
29 of 33 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants