Skip to content

fix(tools): stop NotebookEdit reusing cell ids after a delete - #3371

Merged
Yeachan-Heo merged 1 commit into
ultraworkers:mainfrom
NotAFlightRisk:fix/notebook-duplicate-cell-id
Nov 4, 2026
Merged

Yeachan-Heo merged 1 commit into
ultraworkers:mainfrom
NotAFlightRisk:fix/notebook-duplicate-cell-id

Conversation

@NotAFlightRisk

Copy link
Copy Markdown
Contributor

Summary

After a cell's deleted from anywhere but the end of a notebook, NotebookEdit can give the next inserted cell an id that another cell already has. The agent's next edit by that id then goes to the older cell, so it rewrites or deletes one it never meant to touch.

New ids are the cell count plus one, which is only guaranteed free while nothing's been deleted. Insert three cells, delete cell-1, and the next insert comes back as cell-3 too. Replace cell-3 after that and it's the original third cell that changes, while the new one's left alone. Jupyter's own ids are random, so the clash is always with a cell the agent added earlier.

This counts up from the same number until it finds a free one, so ids only change where they'd have clashed.

Anti-slop triage

  • Classification: actionable-fix (only bites after a delete, mind)
  • Evidence: the existing notebook test now does one more insert after its delete. Without the fix that insert comes back as cell-3, which is already taken, and with it the test passes
  • Non-destructive review result: merge candidate

Verification

  • Targeted tests/docs checks ran, or the gap is explicitly recorded. Only the tools crate - cargo test -p tools passes apart from three git tests that fail the same way on main for me (my git config won't let them commit in a temp repo), and cargo clippy -p tools --all-targets and cargo fmt --all --check are clean
  • git diff --check passes.
  • No live secrets, tokens, private logs, or unrelated generated churn are included.

Resolution gate

  • If this PR resolves an issue, the issue number and fix evidence are linked. There isn't an issue for it
  • If this PR should not merge, the rejection/defer rationale is evidence-backed and does not rely on vibes. Doesn't apply
  • I did not merge/close remote PRs or issues from an automation lane without owner approval.

Inserted cells were named cell-{len+1}, which is still taken once any
cell but the last has been deleted, so a later edit by the returned id
went to the older cell instead.

@Yeachan-Heo Yeachan-Heo 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.

Review

Fix confirmed: The change correctly addresses the cell id collision bug by searching for the first unused id starting from cells.len() + 1 instead of naively using that value.

Logic verification:

  • Search terminates correctly via .find()
  • No off-by-one errors: starts from cells.len() + 1 which is the right baseline
  • Handles non-cell-N ids (e.g., custom ids like 'cell-a'): collision check only affects numeric ids
  • Replace and delete operations unaffected: resolve_cell_index still finds cells by id correctly

Test coverage: Regression test extended with insert-after-delete scenario verifying cell-4 is correctly assigned when cells [cell-2, cell-3] exist.

No duplication found: make_cell_id is the only function in the codebase that generates notebook cell ids.

Local verification:

cargo fmt --all --check        ✓
cargo clippy -p tools --all-targets -- -D warnings  ✓
cargo test -p tools           ✓ (120 tests)

CI check-runs: All 6 checks passing (build, cargo test, cargo fmt, cargo clippy, docs, windows smoke).

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

@Yeachan-Heo
Yeachan-Heo merged commit db58b19 into ultraworkers:main Nov 4, 2026
6 checks passed
@Yeachan-Heo

Copy link
Copy Markdown
Contributor

Merged as db58b190. Thanks @NotAFlightRisk! Before merging I confirmed the new regression check fails without the fix (cell-3 instead of cell-4 after a non-tail delete) and passes with it.

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

@Yeachan-Heo Yeachan-Heo mentioned this pull request Nov 4, 2026
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.

2 participants