sshiv012 opened a new pull request, #6211:
URL: https://github.com/apache/texera/pull/6211

   ### What changes were proposed in this PR?
   
   The Texera AI agent edits the user's **live workflow canvas**, its tools 
add, modify, and delete operators, and the changes auto-persist. Until now 
there was no agent-aware way to back out a turn that went wrong; the user had 
to manually undo a multi-operator change. This PR adds two controls:
   
   - **Per-turn "Revert"**  rewinds the workflow (and the agent-service's 
`HEAD`) to the state
     *before* an agent turn.
   - **"Redo"** undoes the most recent revert; a redo stack supports multiple 
consecutive
     reverts→redos, and is cleared when a new prompt starts a new branch.
   
   **Use case / why:** the agent mutates real state, so a bad suggestion (a 
wrong delete, an unwanted restructure) is expensive to recover from. A cheap, 
reliable "step back" lowers the cost of letting the agent experiment. A 
frontend-only visual undo is insufficient, the agent-service keeps its own 
`HEAD`, so the next message would silently clobber a cosmetic revert. This does 
a **true rewind** that keeps the agent's context consistent.
   
   **How it works:** the agent-service already models a conversation as a 
version tree of ReAct steps (`id`/`parentId` + 
`beforeWorkflowContent`/`afterWorkflowContent` snapshots + a `HEAD` pointer).
   The only missing primitive was moving `HEAD` backward.
   - *Revert(T):* `HEAD ← parent(T)`, restore `T.beforeWorkflowContent`, push 
old HEAD onto an in-memory redo stack (reverted steps stay in the tree, nothing 
is deleted).
   - *Redo:* pop the stack, move `HEAD` forward, restore that step's 
`afterWorkflowContent`.
   - A new prompt / clear-history clears the redo stack.
   - Both commands are rejected while the agent is `GENERATING`, to avoid 
racing the loop's own HEAD/workflow mutations.
   
   **Protocol additions:** `WsClientRevertCommand { messageId }`, 
`WsClientRedoCommand` (client→server); `WsServerHeadChangeEvent { headId, 
workflowContent, canRedo }` and a `canRedo` field on `WsServerSnapshotEvent` 
(server→client, so a reconnecting client renders the correct Redo state).
   
   No new persistence, no schema changes, no new services; revert/redo state is 
the in-memory step tree the agent already maintains.
   
   *Scoped as follow-ups:* per-individual-step revert, forward/branch 
navigation UI beyond single-level redo, and persisting revert history across 
agent-service restarts (currently session-scoped).
   
   ### Any related issues, documentation, discussions?
   
   Design discussion / RFC: apache/texera#6039 
   
   ### How was this PR tested?
   
   New automated tests were added and all existing suites pass:
   
   - **agent-service (bun):** unit tests for `revertToTurnStart` / `redo` / 
`canRedo`, clear-on-new-prompt, and the WS command handlers including 
reject-while-generating, unknown-turn, and nothing-to-redo negative cases.
   - **frontend (vitest):** the `WsServerHeadChangeEvent` handler (HEAD update 
+ `canRedo` + canvas reload), the `revertTurn` / `redo` senders, and the button 
enable/disable logic.
   
   Full local run of the CI pipeline for both services (rebased on latest 
`main`) passes: `format` / `typecheck` / `bun test` (agent-service), and 
`format:ci` / `build:ci` / `test:ci` / browser-mode tests (frontend).
   
   Manual: agent adds operators → **Revert** rolls them back → **Redo** 
restores them → sending a new message branches and clears Redo.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 4.8)
   <!--
   Thanks for sending a pull request (PR)! Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: 
        [Contributing to 
Texera](https://github.com/apache/texera/blob/main/CONTRIBUTING.md)
     2. Ensure you have added or run the appropriate tests for your PR
     3. If the PR is work in progress, mark it a draft on GitHub.
     4. Please write your PR title to summarize what this PR proposes, we 
       are following Conventional Commits style for PR titles as well.
     5. Be sure to keep the PR description updated to reflect all changes.
   -->
   
   ### What changes were proposed in this PR?
   <!--
   Please clarify what changes you are proposing. The purpose of this section 
   is to outline the changes. Here are some tips for you:
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
     3. If it is a refactoring, clarify what has been changed.
     3. It would be helpful to include a before-and-after comparison using 
        screenshots or GIFs.
     4. Please consider writing useful notes for better and faster reviews.
   -->
   
   
   ### Any related issues, documentation, discussions?
   <!--
   Please use this section to link other resources if not mentioned already.
     1. If this PR fixes an issue, please include `Fixes #1234`, `Resolves 
#1234`
        or `Closes #1234`. If it is only related, simply mention the issue 
number.
     2. If there is design documentation, please add the link.
     3. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### How was this PR tested?
   <!--
   If tests were added, say they were added here. Or simply mention that if the 
PR 
   is tested with existing test cases.  Make sure to include/update test cases 
that
   check the changes thoroughly including negative and positive cases if 
possible.
   If it was tested in a way different from regular unit tests, please clarify 
how
   you tested step by step, ideally copy and paste-able, so that other 
reviewers can
   test and check, and descendants can verify in the future. If tests were not 
added, 
   please describe why they were not added and/or why it was difficult to add. 
   -->
   
   
   ### Was this PR authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
   please include the phrase: 'Generated-by: ' followed by the name of the tool 
   and its version. If no, write 'No'. 
   Please refer to the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to