feat: implement message editing and thread rollback functionality with UI support#1
Draft
zip700 wants to merge 6 commits into
Draft
feat: implement message editing and thread rollback functionality with UI support#1zip700 wants to merge 6 commits into
zip700 wants to merge 6 commits into
Conversation
added 5 commits
April 3, 2026 15:01
4c44512 to
5fe9c04
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Architecture Summary: Edit and Regenerate Message History (Issue Dimillian#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 ballooning
useMainAppLayoutSurfacesoruseThreadswith 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 into
useThreadsReducer.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:rollback_thread_coreinsrc-tauri/src/shared/codex_core.rs.src/services/tauri.ts.src-tauri/src/bin/codex_monitor_daemon/rpc/codex.rs.remote_backendremote switch logic properly withinsrc-tauri/src/codex/mod.rs.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
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.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.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.Addressed implicit/explicit typing where applicable. For example,
rollback_threadandarchive_threadIPC services return strictly typedinvoke<void>instead ofinvoke<any>.