Skip to content

Conversation

@ronpal
Copy link
Contributor

@ronpal ronpal commented Sep 24, 2025

Description

Added new task type to Workflows based on spec

https://pr-2871.specs.preview.cogniteapp.com/20230101-internal.json.html#tag/Workflow-versions/operation/CreateOrUpdateWorkflowVersion

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

@ronpal ronpal requested review from a team as code owners September 24, 2025 10:47
@gemini-code-assist
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 93.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.98%. Comparing base (489c703) to head (16d9738).
⚠️ Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
cognite/client/data_classes/workflows.py 93.75% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2342      +/-   ##
==========================================
+ Coverage   90.96%   90.98%   +0.01%     
==========================================
  Files         192      192              
  Lines       26138    26217      +79     
==========================================
+ Hits        23777    23853      +76     
- Misses       2361     2364       +3     
Files with missing lines Coverage Δ
cognite/client/data_classes/workflows.py 96.12% <93.75%> (+0.17%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

This seems to not be completed. Lots of the spec is missing.

@doctrino
Copy link
Contributor

Description

Added new task type to Workflows based on spec

https://pr-2871.specs.preview.cogniteapp.com/20230101-internal.json.html#tag/Workflow-versions/operation/CreateOrUpdateWorkflowVersion

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

Seems the taskType is not updated in the API docs:
image

Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

Good job. There are a few minor fixes that are necessary.

@doctrino doctrino self-requested a review September 26, 2025 07:07
ronpal and others added 9 commits September 26, 2025 09:07
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
doctrino
doctrino previously approved these changes Sep 26, 2025
Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

Good stuff :)

@doctrino doctrino added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Sep 26, 2025
@doctrino
Copy link
Contributor

One thing to consider, should we have raise an alpha warning everytime a TagDetectionParameter is initialized? I assume this feature is in alpha?

@ronpal
Copy link
Contributor Author

ronpal commented Sep 26, 2025

One thing to consider, should we have raise an alpha warning everytime a TagDetectionParameter is initialized? I assume this feature is in alpha?

It is in private beta, does the same apply?

@arnels arnels self-assigned this Sep 29, 2025
@arnels arnels added the risk-review-ongoing Risk review is in progress label Sep 29, 2025
Copy link
Contributor

@arnels arnels left a comment

Choose a reason for hiding this comment

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

This looks good. Could you please add unit tests for the new classes? Since they contain custom logic for serialization/deserialization in methods like _load and dump, it's important to ensure that logic is covered.

@arnels arnels added waiting-for-team Waiting for the submitter or reviewer of the PR to take an action and removed waiting-for-risk-review Waiting for a member of the risk review team to take an action labels Sep 29, 2025
@haakonvt
Copy link
Contributor

This looks good. Could you please add unit tests for the new classes? Since they contain custom logic for serialization/deserialization in methods like _load and dump, it's important to ensure that logic is covered.

Just to narrow this a bit, any object inheriting from e.g. CogniteObject or -Resource are automatically picked up and tested in a variety of ways.

Other class hierarchies must be tested, e.g. subclasses of WorkflowTaskOutput which just inherits from ABC.

@VerstraeteBert
Copy link
Contributor

VerstraeteBert commented Oct 1, 2025

Sorry for the late review, was on vacation.

Making some last changes to the API spec before the testing is commencing (out-of-sync updates and some small breaking changes). Will write a summary here when ready.

Waiting for this PR to be merged on the Jazz side:
https://github.com/cognitedata/jazz-api/pull/1913

@queCognite
Copy link
Contributor

The pr above has been merged. @ronpal @VerstraeteBert

@VerstraeteBert
Copy link
Contributor

@ronpal
Summary of changes:

  • More possible statuses for a Tag Detection Job:
                  [
                   "Queued",
                   "Distributing",
                   "Distributed",
                   "Loading Entities",
                   "Loaded Entities",
                   "Running",
                   "Detected",
                   "Annotated",
                   "Collecting",
                   "Completed",
                   "Failed",
                   "Timeout",
                 ]
  • An errorMessage (str | null) is added to both the Job and SubJobs.
  • A minimum of 1 file is expected for the fileInstanceIds
  • entityFilters takes [1; 10] filters.

@ronpal
Copy link
Contributor Author

ronpal commented Oct 9, 2025

@ronpal Summary of changes:

  • More possible statuses for a Tag Detection Job:
                  [
                   "Queued",
                   "Distributing",
                   "Distributed",
                   "Loading Entities",
                   "Loaded Entities",
                   "Running",
                   "Detected",
                   "Annotated",
                   "Collecting",
                   "Completed",
                   "Failed",
                   "Timeout",
                 ]
  • An errorMessage (str | null) is added to both the Job and SubJobs.
  • A minimum of 1 file is expected for the fileInstanceIds
  • entityFilters takes [1; 10] filters.

@VerstraeteBert can you please review again? These are the commits that address these changes 👆

94c1801
8f15c0a
cbc7008

@ronpal ronpal force-pushed the tag-detection-workflow-task branch from cbc7008 to 3f79906 Compare October 9, 2025 08:18
@ronpal ronpal enabled auto-merge October 9, 2025 09:50
@ronpal ronpal added waiting-for-risk-review Waiting for a member of the risk review team to take an action and removed waiting-for-team Waiting for the submitter or reviewer of the PR to take an action labels Oct 9, 2025
@thorkildcognite
Copy link
Contributor

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for the new tagDetection task type in Workflows. The changes include new data classes for the task parameters and output, as well as integrating it into the existing workflow structure. The implementation is mostly solid, but I've identified a critical issue with loading optional parameters that could lead to runtime errors, and some inconsistencies with the project's naming conventions and API consistency. Addressing these points will improve the robustness and maintainability of the new feature.

Comment on lines +610 to +612
min_tokens=tag_detection["minTokens"],
partial_match=tag_detection["partialMatch"],
write_annotations=tag_detection["writeAnnotations"],
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The _load method should handle optional fields gracefully. Accessing minTokens, partialMatch, and writeAnnotations with [] will raise a KeyError if they are not present in the API response. Since these are optional in __init__, you should use the .get() method to avoid potential runtime errors.

Suggested change
min_tokens=tag_detection["minTokens"],
partial_match=tag_detection["partialMatch"],
write_annotations=tag_detection["writeAnnotations"],
min_tokens=tag_detection.get("minTokens"),
partial_match=tag_detection.get("partialMatch"),
write_annotations=tag_detection.get("writeAnnotations", False),

Comment on lines +923 to +926
def __init__(self, instanceId: NodeId, page_range: PageRange, error_message: str | None) -> None:
self.instanceId = instanceId
self.page_range = page_range
self.error_message = error_message
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The parameter instanceId and attribute self.instanceId should be instance_id to adhere to the snake_case naming convention specified in the style guide.1 You will also need to update the dump method to use self.instance_id.

Suggested change
def __init__(self, instanceId: NodeId, page_range: PageRange, error_message: str | None) -> None:
self.instanceId = instanceId
self.page_range = page_range
self.error_message = error_message
def __init__(self, instance_id: NodeId, page_range: PageRange, error_message: str | None) -> None:
self.instance_id = instance_id
self.page_range = page_range
self.error_message = error_message

Style Guide References

Footnotes

  1. The style guide requires snake_case for variable and function names.

Comment on lines +954 to +964
def __init__(
self,
jobId: int,
status: TagDetectionStatus,
filePageRanges: list[TagDetectionJobFilePageRange],
errorMessage: str | None,
) -> None:
self.jobId = jobId
self.status = status
self.filePageRanges = filePageRanges
self.errorMessage = errorMessage
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The parameters jobId, filePageRanges, and errorMessage and their corresponding attributes should be job_id, file_page_ranges, and error_message to follow the snake_case naming convention from the style guide.1 You will also need to update the _load and dump methods to use these new attribute names.

Suggested change
def __init__(
self,
jobId: int,
status: TagDetectionStatus,
filePageRanges: list[TagDetectionJobFilePageRange],
errorMessage: str | None,
) -> None:
self.jobId = jobId
self.status = status
self.filePageRanges = filePageRanges
self.errorMessage = errorMessage
def __init__(
self,
job_id: int,
status: TagDetectionStatus,
file_page_ranges: list[TagDetectionJobFilePageRange],
error_message: str | None,
) -> None:
self.job_id = job_id
self.status = status
self.file_page_ranges = file_page_ranges
self.error_message = error_message

Style Guide References

Footnotes

  1. The style guide requires snake_case for variable and function names.

output = data["output"]
return cls([TagDetectionJob.load(tagDetectionJob) for tagDetectionJob in output["jobs"]])

def dump(self, camel_case: bool = False) -> dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The default value for camel_case in the dump method is False, which is inconsistent with most other WorkflowTaskOutput subclasses that default to True. For consistency across the SDK, it's better to use True as the default.

Suggested change
def dump(self, camel_case: bool = False) -> dict[str, Any]:
def dump(self, camel_case: bool = True) -> dict[str, Any]:

@thorkildcognite thorkildcognite added waiting-for-team Waiting for the submitter or reviewer of the PR to take an action and removed waiting-for-risk-review Waiting for a member of the risk review team to take an action labels Jan 5, 2026
@thorkildcognite
Copy link
Contributor

@ronpal Going through old PRs that have been "stuck", this seems like it needs a team-review, and potentially some follow-ups of the Gemini feedback (I haven't looked at whether it is sensible things it raises). Could you please help us figure out if this PR is still relevant to risk-review? And get a team-review so it is ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants