Skip to content
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

simplify delegated operation doc #5291

Merged
merged 7 commits into from
Dec 23, 2024
Merged

simplify delegated operation doc #5291

merged 7 commits into from
Dec 23, 2024

Conversation

ritch
Copy link
Contributor

@ritch ritch commented Dec 18, 2024

  • removes redundant params from operations docs
  • removes panel_state from operations docs, since it is unused

Summary by CodeRabbit

  • New Features

    • Introduced a new method to enhance the serialization of request parameters by excluding specific keys.
  • Improvements

    • Updated the constructor to enforce stricter type requirements for the context parameter.
    • Streamlined serialization and deserialization processes for the context attribute.
    • Enhanced error handling and data integrity within repository methods related to operation queuing and state updates.
    • Improved validation for progress parameters in the update progress method.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request modifies the DelegatedOperationDocument and ExecutionContext classes to enhance type safety and serialization. The constructor of DelegatedOperationDocument now requires an ExecutionContext instead of a generic dictionary. Additionally, a new private method _get_serialized_request_params() is introduced in ExecutionContext to streamline the serialization of request parameters by excluding the panel_state. The DelegatedOperationRepo methods have also been updated to improve context handling and validation, ensuring consistent usage of the ExecutionContext type across the codebase.

Changes

File Change Summary
fiftyone/factory/repos/delegated_operation_doc.py - Updated constructor to use ExecutionContext instead of dict
- Modified from_pymongo method to directly instantiate ExecutionContext
- Updated to_pymongo method to use new serialization approach
fiftyone/operators/executor.py - Added _get_serialized_request_params() method to ExecutionContext
- Method creates a copy of request_params and removes panel_state
fiftyone/factory/repos/delegated_operation.py - Enhanced queue_operation, update_run_state, and update_progress methods for better context handling and validation
- Streamlined get_queued_operations, get_scheduled_operations, and get_running_operations methods

Possibly related PRs

  • add scheduled state for delegated_ops collection #4810: This PR modifies the delegated_operation_doc.py file, which is directly related to the changes made in the main PR that also affects this file.
  • Scheduler/default scheduled #4871: This PR introduces changes to the MongoDelegatedOperationRepo class in delegated_operation.py, which is relevant as it deals with the context and state management that aligns with the changes in the main PR.
  • add support for atomic state transitions #4893: This PR enhances the update_run_state method in delegated_operation.py, which is related to the changes in the main PR that also involve state management and the DelegatedOperationDocument.
  • delegated operator fixes #4908: This PR modifies the update_run_state method in delegated_operation.py, which is relevant to the changes in the main PR that also involve updates to the DelegatedOperationDocument and its state handling.
  • Don't require pipeline updates when setting output schema #5181: This PR addresses issues in the MongoDelegatedOperationRepo related to the update_run_state method, which is relevant to the changes in the main PR that also involve state management and initialization logic in the same repository.
  • [Docs] Treat delegated execution separately #5184: This PR discusses changes in documentation related to delegated execution, which connects to the overall context of the changes made in the main PR regarding the DelegatedOperationDocument and its handling.

Suggested reviewers

  • brimoor

🐇 In the code where changes abound,
A new ExecutionContext is found.
With parameters neat and tidy,
Our operations now feel so mighty!
Type safety's the goal, so clear and bright,
In the world of code, we hop with delight! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 635f4a8 and e2e08d8.

📒 Files selected for processing (1)
  • fiftyone/factory/repos/delegated_operation_doc.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fiftyone/factory/repos/delegated_operation_doc.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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.

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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2734ab and 8dfadc2.

📒 Files selected for processing (2)
  • fiftyone/factory/repos/delegated_operation_doc.py (2 hunks)
  • fiftyone/operators/executor.py (1 hunks)
🔇 Additional comments (3)
fiftyone/factory/repos/delegated_operation_doc.py (3)

27-27: LGTM! Type safety improvement

The parameter type change from dict to ExecutionContext enhances type safety and makes the API more explicit.


33-34: LGTM! Runtime type check added

The assertion ensures type safety at runtime and simplifies the code by removing the previous conditional conversion logic.


111-113: LGTM! Improved serialization encapsulation

The serialization logic is now properly encapsulated in the ExecutionContext class through the _get_serialized_request_params() method.

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

🧹 Nitpick comments (2)
fiftyone/factory/repos/delegated_operation.py (2)

Line range hint 203-216: Add documentation for context type conversion

The context processing logic handles conversion from dict to ExecutionContext, but this behavior isn't documented. Consider adding docstring comments to explain this type conversion.

Add documentation like this:

 if isinstance(op.context, dict):
+    # Convert dictionary context to ExecutionContext for type safety
+    # This ensures backward compatibility with older operations
     context = ExecutionContext(
         request_params=op.context.get("request_params", {})
     )

Line range hint 192-204: Enhance debug logging for dataset resolution

While the error handling is appropriate, the debug logging could be more informative for troubleshooting purposes.

Consider enhancing the logging like this:

-                logger.debug("Could not resolve dataset_id for operation. ")
+                logger.debug(
+                    "Could not resolve dataset_id for operation. "
+                    "Operator: %s, Context: %s",
+                    op.operator,
+                    context
+                )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 774bd6f and 4c5af6c.

📒 Files selected for processing (1)
  • fiftyone/factory/repos/delegated_operation.py (1 hunks)
🔇 Additional comments (1)
fiftyone/factory/repos/delegated_operation.py (1)

217-217: LGTM: Explicit context assignment ensures type safety

The explicit assignment of the processed context to op.context ensures type safety by guaranteeing that the context is always an ExecutionContext instance before serialization.

Let's verify that all existing operations in the database have valid contexts:

✅ Verification successful

LGTM: Context handling is consistent and type-safe

The explicit assignment of context to op.context is correct and consistent with the codebase's patterns. The verification shows that:

  • ExecutionContext is properly defined in fiftyone/operators/executor.py
  • The context assignment in delegated_operation.py follows the same pattern used in tests and other operational code
  • Type checking is enforced through isinstance(op.context, ExecutionContext) checks
  • The context is properly serialized and deserialized throughout the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any operations with invalid context types in the database
# Expected: All operations should have a valid ExecutionContext

# Search for context-related imports or usage
rg -A 2 "ExecutionContext" --type python

# Search for any direct dictionary assignments to context
ast-grep --pattern 'context = {$$$}'

Length of output: 110


Script:

#!/bin/bash
# Let's try a different approach to verify the context handling

# Search for ExecutionContext class definition and usage
rg -l "class ExecutionContext"

# Search for context-related patterns in Python files
rg "ExecutionContext" --type-add 'python:*.py' --type python

# Look for context assignments in operation-related files
rg "op\.context" --type-add 'python:*.py' --type python

# Find all Python files that might handle operation contexts
fd -e py | xargs rg "context.*=.*" --type-add 'python:*.py' --type python

Length of output: 19311

@@ -214,6 +214,7 @@ def queue_operation(self, **kwargs: Any) -> DelegatedOperationDocument:
context.request_params["dataset_id"] = str(op.dataset_id)
context.request_params["dataset_name"] = context.dataset.name

op.context = context
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes an existing issue that I think might explain some of the weirdness/handling of op.context as dict!

Without this change this is a no-op.

@@ -889,6 +889,11 @@ def store(self, store_name):
dataset_id = self.dataset._doc.id
return ExecutionStore.create(store_name, dataset_id)

def _get_serialized_request_params(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really liking this as the interface...but didn't feel that changing .serialize() was the right move. However there is no need for panel_state in a serialized ctx. Instead it should really be outside of request_params to begin with. I've started that change elsewhere, but its a much more complex change and regresses some functionality in the dashboard plugin.

@ritch ritch requested a review from kaixi-wang December 19, 2024 13:46
Copy link
Contributor

@kaixi-wang kaixi-wang left a comment

Choose a reason for hiding this comment

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

Lgtm

@ritch ritch merged commit c3c0225 into develop Dec 23, 2024
14 checks passed
@ritch ritch deleted the ctx-trim-serial branch December 23, 2024 19:57
@coderabbitai coderabbitai bot mentioned this pull request Jan 29, 2025
7 tasks
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.

3 participants