Skip to content

feat(agent): add workflow revert & redo for AI agent turns#6211

Draft
sshiv012 wants to merge 1 commit into
apache:mainfrom
sshiv012:feat/agent-turn-revert
Draft

feat(agent): add workflow revert & redo for AI agent turns#6211
sshiv012 wants to merge 1 commit into
apache:mainfrom
sshiv012:feat/agent-turn-revert

Conversation

@sshiv012

@sshiv012 sshiv012 commented Jul 6, 2026

Copy link
Copy Markdown

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: #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)

What changes were proposed in this PR?

Any related issues, documentation, discussions?

How was this PR tested?

Was this PR authored or co-authored using generative AI tooling?

Per-turn "Revert" rewinds the workflow and the agent-service HEAD to before
a turn; a toolbar "Redo" undoes the revert (redo stack, cleared on new prompt).
Reuses the ReAct step version-tree + per-step snapshots; adds WsClientRevert/
RedoCommand and WsServerHeadChangeEvent, with revert/redo blocked while the
agent is busy and the connect snapshot carrying workflow content for reconnects.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for your first contribution to Texera, @sshiv012!

If you're looking for a good place to start, browse issues labeled starter-task; they're scoped to be approachable for newcomers.

You can drive common housekeeping yourself by commenting one of these commands on its own line:

  • Issues. Comment /take to assign an open issue to yourself, or /untake to release it. You can find unclaimed work with the search filter is:issue is:open no:assignee.
  • Sub-issues. To link issues into a parent/child hierarchy, comment /sub-issue #5166 #5222 on the parent to attach those children (or /unsub-issue #5166 #5222 to detach them). From a child issue, comment /parent-issue #5166 to set its parent, or /unparent-issue to clear it (the current parent is detected automatically). References may be written as #5166 or as a bare 5166; cross-repository references are not supported.
  • Pull requests (author only). Comment /request-review @user to request a review from someone, or /unrequest-review @user to withdraw that request.

Each command must match exactly: /take this will not work, only /take does. For the full contribution flow, see CONTRIBUTING.md.

@github-actions github-actions Bot added feature frontend Changes related to the frontend GUI agent-service labels Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @bobbai00, @Yicong-Huang
    You can notify them by mentioning @bobbai00, @Yicong-Huang in a comment.

@aglinxinyuan aglinxinyuan marked this pull request as draft July 6, 2026 06:22
@chenlica

chenlica commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@sshiv012 Thank you. The PR is a "Draft" currently. Please mention @bobbai00 after it's ready to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-service feature frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants