Skip to content

Fix removing a history step after a node's inputs shrink - #5029

Open
dev-aditya-hub wants to merge 1 commit into
GraphiteEditor:masterfrom
dev-aditya-hub:repair-missing-input-slot
Open

dev-aditya-hub wants to merge 1 commit into
GraphiteEditor:masterfrom
dev-aditya-hub:repair-missing-input-slot

Conversation

@dev-aditya-hub

@dev-aditya-hub dev-aditya-hub commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Removing a step in the History panel does nothing when a node's input list has shrunk since that step was made. The button has no effect, the document is left as it was, and the only sign of it is change_line logging Changing the history line with Remove failed: InputIndexOutOfBounds(1).

Cause

repair_ops emits a ChangeNodeInput for an input index the node no longer has. In set, the write to the local registry is guarded by node.inputs.get_mut(index), but the op is pushed outside that guard, so a slot that is gone still produces an op. drop_interaction applies repair ops with ApplyMode::Strict and ? (session.rs:507), so slot_for_write rejects the index and the whole operation unwinds.

What reaches set with an index past the end is a stale chain head. owner_is_live checks that the node exists but not that the index does, so a head taken from the before or intended registry survives onto a line where that node has fewer inputs.

Fix

set now leaves the slot alone when it is no longer there, so nothing is emitted for it. I put the guard there rather than in owner_is_live because it covers every path into set, but happy to move it into the head filter instead if you'd prefer the stale head never got that far.

Testing

The branching simulation now also rewrites a node's whole input list, which is the only thing an index-addressed write cannot express. It swaps the first two inputs, adds one, or drops one, the last matching what remove_input leaves behind.

Without the change the default 200 seeds fail at seed 4, with InputIndexOutOfBounds(1) out of drop_interaction. With it, 20000 seeds pass. The stack simulation passes 20000 seeds either way, and cargo test -p document-graph-storage is 168 green. cargo fmt --all -- --check and cargo clippy -p document-graph-storage --all-targets are clean.

What I did not verify

The reproduction is at the storage layer. I traced the trigger to remove_import_slot and move_import_slot calling remove_input, which emits SetInputs with a shorter list, so removing or reordering a subgraph's imports shrinks the inputs of the nodes wrapping it. I did not drive that through the editor and then remove a step, so treat the user-facing path as read from the code rather than observed.

Reproducing it

Revert the guard in set and run cargo test -p document-graph-storage branch_simulation:

thread '...' panicked at document/graph-storage/src/tests/simulation.rs:281:64:
remove the step: InputIndexOutOfBounds(1)

The failing run is seed 4. Node ...815 is grown to three inputs, shrunk to one a few steps later, and a step that wrote its second input is removed after that.

Nothing visual changes, so there is no before and after to show.

The repair emitted a write to an input index the node no longer had, and
strict application of repair ops rejected it, so the whole step removal
failed and the History panel did nothing.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@dev-aditya-hub

dev-aditya-hub commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-11-26 145746

Same test, before and after. Without the fix, the default 200 seeds stop at seed 4 with InputIndexOutOfBounds(1) raised by drop_interaction. With it, 20000 seeds pass.

This branch has not been deployed

No deployments
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