PR Architecture Summary: Edit and Regenerate Message History (Issue #511)
*Disclaimer: This Pull Request and summary were structurally generated and organized by an AI Assistant.
High-Level Objective
This PR implements the "Edit and Regenerate" feature for message history, allowing users to modify an existing message mid-thread and seamlessly rewind the conversational context to branch off from that point.
Explicit Architectural Choices
-
State Isolation (
useMessageEdit.ts) Instead of ballooninguseMainAppLayoutSurfacesoruseThreadswith transient UI state for hovering, editing, and prompt validations, we created a dedicated hookuseMessageEdit.ts. This encapsulates text mutation, image retention, UI transition states (idle, editing, confirming, regenerating), and validation guards natively. -
Frontend Reducer Action (
truncateThreadItems) Truncation of orphaned thread items (any downstream context succeeding the edited turn ID) was explicitly wired intouseThreadsReducer.ts. The UI optimistically and cleanly prunes these items leveragingafterItemIdimmediately following a successful network rollback, prior to sending the new generation request. It utilizes the existing thread hierarchy invariants safely. -
Backend / Daemon Parity Following backend routing rules, the new
rollback_threadcommand traverses all necessary stacks cleanly:- Added
rollback_thread_coreinsrc-tauri/src/shared/codex_core.rs. - Wired the tauri endpoint using the frontend IPC standard
src/services/tauri.ts. - Covered JSON-RPC proxy endpoints for the headless Daemon in
src-tauri/src/bin/codex_monitor_daemon/rpc/codex.rs. - Handles the
remote_backendremote switch logic properly withinsrc-tauri/src/codex/mod.rs.
- Added
-
UI/UX Aesthetics & Design System Reuse Rather than introducing a global top-level modal for editing logic, the message edit menu and confirmation warning inject conditionally via
MessageRows.tsx. All CSS builds purely upon existing tokenized primitives (--surface-accent,--cm-surface-panel-strong, etc.) avoiding drift and duplicated components as outlined in theAGENTS.mdguidelines.
Areas of Consideration / Potential Concerns
- Concurrent Execution / Double Submit Guards:
The
useMessageEditdisables interactable elements via anisRegeneratingstate guard. In addition, the controller (useThreadMessaging.ts) double-checksthreadStatusById[threadId]?.isProcessingto prevent an incoming rollback while a background thought is actively polling. - Rollback Failures:
Currently, if
rollbackThreadService(...)throws an error on the Rust backend, the subsequenttruncateThreadItemsaction is bypassed, and the UI will push a standard generic Error Message into the chat stream viapushThreadErrorMessage. This prevents local desync where the UI wipes out items but the database retains them, guaranteeing server authority. - Image handling over edits:
Images present in previous prompts are automatically extracted, buffered in
EditState, and re-attached dynamically into the new regenerated payload without requiring the user to manually re-upload them. - Legacy "any" Cleanups:
Addressed implicit/explicit typing where applicable. For example,
rollback_threadandarchive_threadIPC services return strictly typedinvoke<void>instead ofinvoke<any>.
Activity
17@codex review
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 330794611a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
@codex review
@codex review
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b481d27d8f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c4451246b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fe9c049e2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
What's left before this is considered ready for acceptance?
This pull request is a draft
Merging is unavailable until it is marked ready for review.
@codex review