playbook: publish undo on its own gesture (#1088) - #1117
Merged
Conversation
C-x u mutated the buffer and returned, so the undone document never left the client — and because the next keystroke's anchored edit was then derived from a base the daemon had never seen, everything typed afterwards failed to apply as well (#1088). The in-editor C-/ alias never had the bug: it goes through handle_playbook_key, which publishes for every key. Extracts the snapshot/publish pair spec 0171 asks every non-keystroke mutation to use, and rewrites the paste and template-button call sites in terms of it, so there is one obvious way to satisfy the invariant instead of three copies of the same three steps. The only behavior change is undo. playbook_undo_reaches_the_daemon follows the undo with no further input: the recovery path from #1089 would reconcile it on the next keystroke, which is a different guarantee. playbook_recovers_from_a_diverged_buffer used C-x u to open the divergence it repairs, so it no longer reaches that path. Retitled and rewritten to describe what it now covers rather than leave a doc comment this commit makes false.
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.
Fixes #1088, the last member of the family #1116 addressed.
C-x umutated the buffer and returned. The undone document never left the client, and because the next keystroke's anchored edit was then derived from a base the daemon had never seen, everything typed afterwards failed to apply as well — the same shape paste and template buttons had. The in-editorC-/alias never had the bug: it goes throughhandle_playbook_key, which publishes for every key.The fix, and a small refactor
Rather than hand-roll the snapshot-and-flush dance a fourth time, this extracts the pair that spec 0171 asks every non-keystroke mutation to use:
Paste and the template button are rewritten in terms of it, so there is one obvious way to satisfy the invariant instead of three copies that each had to remember the same three steps. Net effect on those two call sites is a reduction; the only behavior change is undo.
Tests
playbook_undo_reaches_the_daemonis new. It deliberately follows the undo with no further input — the recovery path added for #1089 would reconcile this on the next keystroke, which is a different guarantee, and undo has to stand on its own. Verified it fails without the fix:All four in the file pass with it:
One test got weaker, and now says so
playbook_recovers_from_a_diverged_bufferusedC-x uto open the divergence that #1089's recovery path repairs. With undo fixed there is no divergence left to create, so it no longer reaches that path — it now guards the weaker property that an undo and the keystroke after it both land. Its doc comment said "#1088 … today mutates without publishing", which this PR makes false, so it has been retitled and rewritten to describe what it actually covers now.That leaves #1089's recovery with no deterministic e2e trigger: it fires on a genuine race between an agent's write and a keystroke. It is still exercised indirectly — it is the same merge
C-x C-sperforms — but if we want it pinned directly, that wants a client-level unit test with a stubbed IPC client rather than an e2e. Flagging rather than silently dropping the coverage.Binaries
Only
crates/clichanges →construct:/Users/moon/agentd/.claude/worktrees/fix-playbook-undo-sync/target/debug/construct