refactor(agent-core-v2): make undo domain-owned - #2055
Merged
Conversation
🦋 Changeset detectedLatest commit: 4800dbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Replace the compensating context.undo op with a wire-layer rewind primitive: a log.cut control record with a persisted target, applied uniformly by the wire during fold. Turn boundaries become first-class (TurnIndexModel indexing turn.prompt record positions), models declare a temporal classification (rewindable), and a single IAgentRewindService owns the undo pipeline (quiesce -> precheck -> cut -> reconcile) with all entry points converged. - wire: log.cut record, rewindable model flag, re-fold rebuild; OpApplyContext.recordIndex for position-aware reducers - rewind service: aborts the active turn, cancels in-flight compaction, preserves the pending queue, rebases measured tokens, reconciles lastPrompt, tracks conversation_undo - todo list, plan mode, task-notification delivery and the turn index now rewind together with the undone turns - transcript reducer applies cut ranges so snapshot/messages surfaces stay consistent with the model context - REST/RPC/debug undo entry points converge on the rewind service; TUI parses the v2 undo-unavailable error shape - legacy context.undo records keep replaying for old journals
…luding todo list rollback and improved event handling
Undo now rejects with session.busy while compaction runs instead of cancelling it, so the awaitable cancel() added for the earlier rewind semantics has no callers left. Remove it from the interface and implementation; the RPC cancel path keeps using the task abort controller directly.
7Sageer
marked this pull request as ready for review
July 24, 2026 06:18
# Conflicts: # packages/agent-core-v2/src/agent/plan/planOps.ts # packages/agent-core-v2/src/agent/plan/planService.ts # packages/agent-core-v2/src/agent/task/taskService.ts # packages/agent-core-v2/test/harness/agent.ts # packages/kap-server/src/services/transcript/coreBinding.ts # packages/kap-server/src/services/transcript/coreEventMap.ts # packages/kap-server/src/services/transcript/transcriptService.ts # packages/transcript/src/history/groupTurns.ts
commit: |
…te checkpoint depth - Rename IAgentConversationUndoReconciliationRegistry to IAgentConversationUndoParticipantRegistry (conversationUndoParticipants). - Return the limiting model from checkpointDepth and include it in the SESSION_UNDO_UNAVAILABLE details; report checkpoint_lost instead of compaction_boundary when no compaction explains the missing depth. - Add a registry invariant test: every model reacting to context.* ops must be registered via defineCheckpointedModel or explicitly exempt.
# Conflicts: # packages/agent-core-v2/src/agent/task/taskService.ts # packages/agent-core-v2/src/agent/toolSelect/toolSelectService.ts
Signed-off-by: 7Sageer <sag77r@hotmail.com>
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.
Related Issue
No linked issue — the problem is explained below.
Problem
Undo in agent-core-v2 only compensated conversation context, so other conversation-time state could drift from the surviving history. Todo changes, plan mode, and task-notification delivery from an undone turn remained applied. Undo also lacked one domain-owned entry point for validation, idle admission, reconciliation, telemetry, and error handling.
A generic wire-level journal cut was considered, but it made infrastructure own business-time semantics and required every model to declare whether it should travel through conversation time.
What changed
context.undoas the only persisted undo fact. Context memory owns the history cut and token-measurement rebase.context.undoneevent.:undo, RPCundoHistory, and the debug surface aligned.User-visible:
/undonow restores conversation history, todo lists, plan mode, and background-task notification state consistently. When a turn is active or queued, or compaction is already running, it returns a busy error and leaves that work untouched.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.