Skip to content

Use ObjectId in TracingStore where applicable #8674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 23, 2025
Merged

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Jun 5, 2025

Using our ObjectId class + validation in the tracingstore for annotationId and userId fields, to match the data model on the wk side.

For some reason putting the sbt setting that enables using ObjectId in routes files in commonSettings would not work, I had to repeat it for all three projects 🤷

Steps to test:

  • Trace some, should still work
  • Annotation user state should still work
  • Re-test availableBySwitching workflow for annotations (not sure why there was String there previously instead of ObjectId despite this living on the wk side)

  • Removed dev-only changes like prints and application.conf edits
  • Considered common edge cases
  • Needs datastore update after deployment

@fm3 fm3 self-assigned this Jun 5, 2025
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

📝 Walkthrough

Walkthrough

This change refactors the codebase to replace all uses of plain String types for annotation, user, and owner identifiers with a strongly typed ObjectId. This affects method signatures, case classes, controller routes, test helpers, and internal logic across backend, frontend, and build configuration files. No control flow or business logic is altered.

Changes

Files/Areas Change Summary
app/controllers/AuthenticationController.scala, app/controllers/WKRemoteTracingStoreController.scala, app/security/AccessibleBySwitchingService.scala Changed annotationId and related parameters from String or Option[String] to ObjectId or Option[ObjectId] in controller and service method signatures and logic.
app/models/annotation/AnnotationLayerPrecedence.scala, AnnotationMerger.scala, AnnotationService.scala, WKRemoteTracingStoreClient.scala Updated user and annotation ID handling from String to ObjectId in models and client logic, including case classes and method parameters.
webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/TSRemoteDatastoreClient.scala, TSRemoteWebknossosClient.scala Refactored cache keys, parameters, and case classes to use ObjectId for annotation IDs instead of String.
webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/annotation/*.scala (AnnotationReversion.scala, AnnotationTransactionService.scala, AnnotationUpdateActions.scala, AnnotationWithTracings.scala, TSAnnotationService.scala, UpdateActions.scala) Systematic replacement of String with ObjectId for annotation and user IDs in annotation services, update actions, and related traits/classes.
webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/*.scala (EditableMappingController.scala, SkeletonTracingController.scala, TSAnnotationController.scala, VolumeTracingController.scala, VolumeTracingZarrStreamingController.scala) Controller method signatures updated to accept ObjectId for annotation and user IDs instead of String.
webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/*.scala (AnnotationUserStateUtils.scala, RemoteFallbackLayer.scala, TemporaryTracingService.scala, EditableMappingLayer.scala, EditableMappingMergeService.scala, EditableMappingUpdateActions.scala, EditableMappingUpdater.scala, SkeletonTracingService.scala, SkeletonUpdateActions.scala, TSFullMeshService.scala, VolumeSegmentStatisticsService.scala, VolumeTracingDefaults.scala, VolumeTracingLayer.scala, VolumeTracingService.scala, VolumeUpdateActions.scala) All tracing, editing, and update action classes and methods now use ObjectId for relevant IDs, replacing prior String usage.
webknossos-datastore/app/com/scalableminds/webknossos/datastore/helpers/SkeletonElementDefaults.scala, AnnotationSource.scala, services/AccessTokenService.scala Changed user and annotation ID parameters to ObjectId in helper and model classes.
build.sbt Localized ObjectId import to specific projects instead of global scope; minor formatting changes (commas).
conf/webknossos.latest.routes, webknossos-tracingstore/conf/com.scalableminds.webknossos.tracingstore.routes Changed route parameter types from String to ObjectId for annotation and user IDs, reflecting backend signature changes.
frontend/javascripts/test/backend-snapshot-tests/annotations.e2e.ts, e2e-setup.ts, helpers/saveHelpers.ts Test helpers and constants updated to use ObjectId-like IDs and propagate new function signatures with additional parameters.
test/backend/AnnotationUserStateTestSuite.scala Test suite now uses ObjectId for user IDs instead of strings, updating test data and method calls accordingly.

Possibly related PRs

  • scalableminds/webknossos#8542: Implements per-user state handling for annotations, modifying core classes and methods related to annotation user states and update actions.
  • scalableminds/webknossos#8285: Refactors route/controller method signatures to use ObjectId for annotation IDs, including the same method in AuthenticationController.scala.
  • scalableminds/webknossos#8405: Updates annotation and tracing ID handling to use explicit, strongly typed identifiers in services and controllers.

Possibly related issues

  • Use ObjectId case class in tracingstore #8650: This PR addresses the issue's goal of replacing string IDs with the ObjectId case class in the tracingstore for type safety and consistency by changing method signatures and internal handling accordingly.

Suggested reviewers

  • philippotto

Poem

In the warren of code, where IDs once ran free,
Now ObjectId hops with strict certainty.
Strings have been gathered, tucked out of sight,
For type-safe carrots—oh, what a delight!
The controllers all cheer, the tracings all beam,
As rabbits refactor their strongly-typed dream.
🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d190849 and 8d066c3.

📒 Files selected for processing (1)
  • webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/VolumeTracingZarrStreamingController.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/VolumeTracingZarrStreamingController.scala
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: frontend-tests
  • GitHub Check: build-smoketest-push
  • GitHub Check: backend-tests

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.

@fm3
Copy link
Member Author

fm3 commented Jun 17, 2025

@philippotto with this change the e2e tests fail because dummy-user-id is not a valid bson object id, and this is now validated by the tracingstore routes. Do you think there would be downsides to changing it to a (fixed) real object id?

@philippotto
Copy link
Member

@philippotto with this change the e2e tests fail because dummy-user-id is not a valid bson object id, and this is now validated by the tracingstore routes. Do you think there would be downsides to changing it to a (fixed) real object id?

hmm, I find it quite pleasant to use readable ids in tests. I also made use of that in #8664. however, maybe we can still get away with it in the non-e2e tests. also, I understand that this is hijacking the ids and not a strong argument against having proper objectids.

@fm3 fm3 marked this pull request as ready for review June 19, 2025 13:20
@fm3 fm3 changed the title use objectid in tracingstore where applicable Use ObjectId in TracingStore where applicable Jun 19, 2025
@fm3 fm3 requested a review from frcroth June 19, 2025 13:29
@fm3 fm3 merged commit 6721996 into master Jun 23, 2025
5 checks passed
@fm3 fm3 deleted the objectid-tracingstore branch June 23, 2025 08:00
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.

3 participants