Skip to content

fix: preserve revert consistency - #46974

Open
CasualDeveloper wants to merge 1 commit into
anomalyco:v2from
CasualDeveloper:fix/37751-revert-consistency
Open

fix: preserve revert consistency#46974
CasualDeveloper wants to merge 1 commit into
anomalyco:v2from
CasualDeveloper:fix/37751-revert-consistency

Conversation

@CasualDeveloper

@CasualDeveloper CasualDeveloper commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #37751
Supersedes #42461

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A V2 session could accept a new prompt while an undo was still being saved. Undo a message, edit it, and send it again. The server could record the new message before it finished recording the undo, so the two landed in the wrong order. #37752 tried to fix this by running the operations one at a time. GitHub closed that PR as stale; maintainers did not reject it. This branch finishes that approach.

For each session, one undo or message change now finishes before the next one starts. When a prompt replaces a staged undo, the server commits the undo and admits the prompt in one transaction. Queued work that sits before the undo boundary is kept instead of dropped. The undo boundary is chosen by position in the message list, not by message ID, so a later message with a smaller ID can no longer move the boundary backwards. That last part is the #42461 fix. It is folded in here because a bot opened that PR on a three-week-old base and its branch cannot be updated.

Running operations one at a time would deadlock a plugin that sends a message during its own setup: that message would queue behind the prompt that is waiting for the plugin to load. So plugin setup and prompt hooks get a narrow bypass that admits their own messages directly. The bypass is scoped to the running setup or hook and expires when it returns. Current v2 already waits for plugin activation before preparing a prompt; this PR extends the same wait to undo staging, undo clearing, and shell start.

On the client side, the TUI and the web composer show the prompt in the chat right away, then run agent setup, model setup, and prompt admission in order. A failed send is retried under the same message ID, so a lost response cannot create a duplicate prompt.

API surface: session.prompt gains an optional context field. It is a synthetic message that the server admits in the same transaction as the prompt. A new ContextDeliveryError rejects context when the prompt uses queued delivery. OpenAPI and the generated clients are regenerated.

How did you verify your code works?

  • bun typecheck in core, plugin, client, tui, app, schema, protocol, and server
  • bun run test in packages/core: 4075 pass. The 6 session-shell timeouts also fail on clean v2.
  • bun test in packages/tui: 1197 pass. The one session-home failure is pre-existing on v2.
  • bun test in packages/client: 150 pass
  • bun run test:unit in packages/app: 704 pass
  • bun test in packages/server: 50 pass
  • bun run check:generated in packages/protocol and packages/client: no drift

New tests cover successful and failed replacement prompts, retries under the same message ID, concurrent submissions, revert staging ordered against prompt admission, Effect and Promise plugin hooks that admit input during prompt preparation, and undo boundaries that fall outside the loaded message page.

Screenshots / recordings

Not a visual change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Process: human-directed and reviewed, with agentic assistance from Anthropic/Claude.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

The search found PR #42461 "fix: make revert boundaries chronological" which is the related PR mentioned in the current PR's description as being superseded. This is expected since PR #46974 explicitly states it "Supersedes #42461" and folds in that fix.

No other duplicate or competing PRs were found that are addressing the same revert consistency and session prompt ordering issue.

No duplicate PRs found

Serialize per-session revert and admission changes, commit staged
reverts atomically with their replacement admission, preserve queued
work across reverts, and compare undo boundaries chronologically
instead of by message ID. Plugin activation completes before session
changes are blocked so plugin setup can still admit its own input.

Includes the anomalyco#42461 boundary fix; supersedes that PR.
Closes anomalyco#37751. Continues the approach from anomalyco#37752.
@CasualDeveloper
CasualDeveloper force-pushed the fix/37751-revert-consistency branch from 4821120 to 7c3cb99 Compare September 3, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant