Skip to content

refactor(agent-core-v2): make undo domain-owned#2055

Draft
7Sageer wants to merge 7 commits into
mainfrom
refactor-undo
Draft

refactor(agent-core-v2): make undo domain-owned#2055
7Sageer wants to merge 7 commits into
mainfrom
refactor-undo

Conversation

@7Sageer

@7Sageer 7Sageer commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

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

  • Adds an Agent-scoped conversation undo service that serializes undo requests, validates the requested count, and acquires loop quiescence only when no turn or request is active or queued.
  • Returns a structured busy error for active loop work or an already-running compaction without cancelling either operation.
  • Keeps context.undo as the only persisted undo fact. Context memory owns the history cut and token-measurement rebase.
  • Defines Todo, Plan, and task-notification delivery as checkpointed conversation-time models while leaving world-time state such as turn counters and task registries untouched.
  • Reconciles state and projections after the context cut, including task-notification eligibility, Todo state, Plan status, session metadata, telemetry, and the context.undone event.
  • Rebuilds the post-undo transcript from the stable journal projection and realigns restored context with the last surviving turn, preventing restored task notifications from producing an empty phantom turn.
  • Uses loop quiescence as the only admission guard; no separate prompt or compaction launch-pausing API is introduced.
  • Removes the generic wire time-travel design and keeps REST :undo, RPC undoHistory, the debug surface, and TUI error handling aligned.

User-visible: /undo now 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

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 87d08d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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
@7Sageer 7Sageer changed the title refactor(agent-core-v2): rebuild undo as wire-level journal rewind refactor(agent-core-v2): make undo domain-owned Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant