Skip to content

Conversation

philippotto
Copy link
Member

@philippotto philippotto commented May 26, 2025

This PR fixes an issue with with WK loading duplicate tree when enabling agglomerate skeletons. This bug is a regression from #8596 .

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • Load a agglomerate skeleton
  • Verify that only one tree was loaded
  • Do any operation (spllit, rename) on the agglomerate skeleton without issue
  • also see added tests

Issues:


(Please delete unneeded items, merge only when none are left open)

@philippotto philippotto self-assigned this May 26, 2025
Copy link
Contributor

coderabbitai bot commented May 26, 2025

📝 Walkthrough

Walkthrough

This update fixes a crash during tree import when annotations are non-empty, modifies a test fixture to export a variable, adds tests for tree ID relabeling, and refactors a helper function to use immutable patterns for tree collections.

Changes

Files/Paths Change Summary
CHANGELOG.unreleased.md Added an entry describing the fix for crashes during tree import with non-empty annotations.
frontend/javascripts/test/fixtures/hybridtracing_object.ts Changed initalTreeOne from a local constant to a named export.
frontend/javascripts/test/reducers/skeletontracing_reducer.spec.ts Added tests for tree addition and ID relabeling; no changes to function signatures or core logic.
frontend/javascripts/viewer/model/reducers/skeletontracing_reducer_helpers.ts Refactored addTreesAndGroups to use a new MutableTreeMap for immutability, avoiding in-place mutations; no signature changes.

Possibly related PRs

Suggested labels

backend

Suggested reviewers

  • hotzenklotz

Poem

A bug in the forest, a crash in the trees,
When annotations were full, it brought code to its knees.
Now rabbits rejoice, for imports are sound,
With new tests and exports, stability’s found.
The woods are restored, the mappings are neat—
Hop, hop, hooray, for a bug-free retreat! 🐇🌲

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hotzenklotz hotzenklotz changed the title Fix adding tree with id greater than 1M Fix regression with DiffableMaps and duplicate agglomerate skeletons May 26, 2025
@philippotto philippotto marked this pull request as ready for review May 26, 2025 13:39
@philippotto philippotto requested a review from hotzenklotz May 26, 2025 13:39
// The original tree id 4 should have survived.
expect(ids).toEqual([4]);
expect(state.annotation.skeleton?.trees.size()).toBe(1);
expect(state.annotation.skeleton?.trees.getNullable(4)).toBeDefined();
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to also test that the newly added tree has tree id 5(?) now?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, doesn't hurt. luckily, the id will be 4 and not 5 😅

Copy link
Member

@hotzenklotz hotzenklotz left a comment

Choose a reason for hiding this comment

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

LGTM

@philippotto philippotto enabled auto-merge (squash) May 26, 2025 13:46
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
frontend/javascripts/test/reducers/skeletontracing_reducer.spec.ts (1)

1813-1817: Test implementation is correct.

The test properly verifies that tree IDs are preserved when adding to an empty skeleton. The assertion confirms the tree retains its original ID of 4.

Note: The past review comment about testing tree id 5 doesn't apply here as this test intentionally uses ID 4 to verify no relabeling occurs.

🧹 Nitpick comments (1)
frontend/javascripts/test/reducers/skeletontracing_reducer.spec.ts (1)

1801-1803: Consider clarifying the comment about ID relabeling.

The current comment could be misinterpreted. Consider rephrasing for clarity.

-      // Id-relabeling is only done if the skeleton is not empty.
-      // Therefore, delete the two existing trees so that the new tree will
-      // be added without id-relabeling.
+      // When the skeleton is empty, ID relabeling is not performed.
+      // Therefore, delete the two existing trees so that the new tree will
+      // retain its original ID.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb09162 and 4255fd1.

📒 Files selected for processing (2)
  • frontend/javascripts/test/fixtures/hybridtracing_object.ts (2 hunks)
  • frontend/javascripts/test/reducers/skeletontracing_reducer.spec.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: backend-tests
  • GitHub Check: frontend-tests
  • GitHub Check: build-smoketest-push
🔇 Additional comments (3)
frontend/javascripts/test/fixtures/hybridtracing_object.ts (1)

33-33: LGTM!

The export addition follows the existing pattern in the file and is necessary for the new test cases.

frontend/javascripts/test/reducers/skeletontracing_reducer.spec.ts (2)

12-13: Import changes look good.

The imports are properly organized and necessary for the new test cases.

Also applies to: 18-24


1820-1839: Test correctly validates ID relabeling behavior.

The test properly verifies that large tree IDs are relabeled to the next available ID when adding to a non-empty skeleton. Good coverage of both positive (new ID exists) and negative (old ID doesn't exist) assertions.

@philippotto philippotto merged commit 6ed9baf into master May 26, 2025
5 checks passed
@philippotto philippotto deleted the fix-id-relabelling-when-adding-trees branch May 26, 2025 13:52
philippotto added a commit that referenced this pull request Jun 2, 2025
…8656)

* create new tree map when re-assigning tree ids instead of adding to old map

* add tests for addTreesAndGroupsAction

* update changelog

* fix typo

* also assert ids
This was referenced Jun 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jun 17, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants