You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Connecting a node onto a filled single-valued pin deletes the node that was there, and undo does not bring it back #414
#91 fixed the sequence-pin (Cardinality: Many) case of "connecting onto a filled pin silently drops a node". The single-valued case is still broken.
Coder.Graph/AstGraph.cs:343-354: OccupantAt returns null for any slot that is not Cardinality.Many.
AstGraph.cs:393 (Place): displaced = OccupantAt(location) is therefore always null for a One slot, so the branch at lines 417-420 that keeps a swapped-out node loose (detached.Add(displaced)) never runs.
AstSchema.TryAttachAt (Coder.Graph/AstSchema.cs:192-212): sends a One slot to TryAttachOperand, which simply overwrites the property (e.g. case (BinaryExpression binary, "Left")).
ValidateConnection (AstGraph.cs:661-694): does not refuse a filled pin.
AstGraphEditor.RecordMove (Coder.Graph/AstGraphEditor.cs:~1621-1645): restores only a displaced node that OccupantAt reported, so undo restores nothing here either.
The doc comment on Place promises that "dropping a node onto a filled pin swaps it in, and the user can see what came out and connect it somewhere else". For single-valued pins that promise is not kept.
Reproduction
The review reproduced this with a scratch test against AstGraph:
Start from a function whose body is return a + b, and add a loose VariableReference("c").
Connect c's output pin to the BinaryExpression's Left pin. Connect succeeds and binary.Left is c.
a is no longer in graph.Nodes, and graph.Detached.Count == 0. The subtree is gone.
Undo, which is graph.PutBack(c, AstLocation.Detached). binary.Left becomes the empty placeholder literal instead of a, and a is still not in the graph.
The same happens for any filled single-valued pin: binary/unary operands, a return value, a variable's initial value, an assignment's value, a call target, and so on. One drag destroys user work in a way that undo cannot recover.
Suggested fix
Make OccupantAt report the current occupant of a One slot too. That is AstSchema.ChildrenOf(parent, slot)[0] when the slot holds a node that is not IsUnfilled. Place then moves it to detached through the existing branch.
Check that RecordMove restores the displaced node on undo in the right order for One slots: the displaced node is put back only after the moved node has left the slot, otherwise the moved node overwrites it again.
Acceptance criteria
Connecting onto a filled single-valued pin leaves the previous occupant in graph.Detached, with its subtree intact.
Undoing that connection restores the original occupant to the slot and returns the moved node to where it came from.
Tests next to AstGraphSequenceUndoTests cover at least a binary operand and a return value, for both connect and undo.
Priority: High. One ordinary drag in the graph editor deletes a subtree the user built, and undo can't get it back. Most single-valued pins are affected: operands, return values, initialisers, assignment values and call targets. Silent data loss in the main editing gesture makes this more than a correctness nit.
Area:Coder.Graph: AstGraph.OccupantAt / Place (~343-420), AstSchema.TryAttachAt / TryAttachOperand, and AstGraphEditor.RecordMove for undo. Tests go next to AstGraphSequenceUndoTests.
Activity
matt-edmondson commentedon Oct 31, 2026
Triage
Coder.Graph:AstGraph.OccupantAt/Place(~343-420),AstSchema.TryAttachAt/TryAttachOperand, andAstGraphEditor.RecordMovefor undo. Tests go next toAstGraphSequenceUndoTests.Coder.Graph) owner, the same area as the Undoing Remove/Disconnect in a statement or parameter list deletes the next sibling, and connecting onto a filled sequence pin silently drops a node #91 fix.Cardinality.Manycase. The fix suggested in the issue reuses Undoing Remove/Disconnect in a statement or parameter list deletes the next sibling, and connecting onto a filled sequence pin silently drops a node #91's existingdetached.Add(displaced)branch.AstGraph/OccupantAtor references this issue.Generated by Claude Code