Command engine transactions are not re-entrant, and an agent turn holds one across awaits #98

Open
opened 2026-10-13 02:28:38 +00:00 by ImBenji · 0 comments
Owner

From the engineering review on 2026-10-13.

In lib/history/command_engine.dart: executeKind swallows commands while a transaction is open (line 130), beginTransaction overwrites the pending snapshot (line 182), and undoOwnLatest has no transaction guard. lib/agent/agent_controller.dart (around line 440) holds a transaction open across the awaits of a whole agent turn.

Scenarios:

  • The agent is mid-turn and the user drags a node. The drag's begin overwrites the agent's snapshot and its commit clears it, so the agent's earlier edits end up in no history entry and cannot be undone.
  • The user presses Cmd+Z mid-turn or mid-drag. The in-flight edits are wiped and the commit records a bogus agentTurn command.
  • Every user command during an agent turn is folded into the agent's single undo entry (from reading).

Evidence: test/review_probes/engine_command_engine_probe.dart (local, untracked), engine level. No UI guard blocking undo or canvas input during an agent turn was found, but not every input path was traced.

Fix sketch: make transactions a stack or refuse a nested begin, refuse or queue undo/redo while one is open, and do not hold a transaction across awaits (snapshot per tool call and merge at the end). Related: #54.

From the engineering review on 2026-10-13. In `lib/history/command_engine.dart`: `executeKind` swallows commands while a transaction is open (line 130), `beginTransaction` overwrites the pending snapshot (line 182), and `undoOwnLatest` has no transaction guard. `lib/agent/agent_controller.dart` (around line 440) holds a transaction open across the awaits of a whole agent turn. **Scenarios:** - The agent is mid-turn and the user drags a node. The drag's begin overwrites the agent's snapshot and its commit clears it, so the agent's earlier edits end up in no history entry and cannot be undone. - The user presses Cmd+Z mid-turn or mid-drag. The in-flight edits are wiped and the commit records a bogus `agentTurn` command. - Every user command during an agent turn is folded into the agent's single undo entry (from reading). **Evidence:** `test/review_probes/engine_command_engine_probe.dart` (local, untracked), engine level. No UI guard blocking undo or canvas input during an agent turn was found, but not every input path was traced. **Fix sketch:** make transactions a stack or refuse a nested begin, refuse or queue undo/redo while one is open, and do not hold a transaction across awaits (snapshot per tool call and merge at the end). Related: #54.
ImBenji added the bug label 2026-10-13 02:28:38 +00:00
ImBenji added this to the Arcs & Angles project 2026-10-13 02:28:38 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: IMBENJI.NET/Metro-Map-Maker#98