Skip to content

feat(py): require a live Operation on check and cancel - #6131

Open
huangjeff5 wants to merge 5 commits into
feat/py-bg-ops-2-boxfrom
feat/py-bg-ops-3-coerce
Open

feat(py): require a live Operation on check and cancel#6131
huangjeff5 wants to merge 5 commits into
feat/py-bg-ops-2-boxfrom
feat/py-bg-ops-3-coerce

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • check_operation / cancel_operation take a live Operation. A persist dump is Operation.model_validate(dumped) first. Extra keys (latencyMs) are ignored so that validate does not 500.
  • Published check/cancel input schema stays one Operation (extra='ignore'). Not Operation | dict.
  • A raw dump, a boxed ModelResponse, or a str is INVALID_ARGUMENT (not AttributeError). Messages: got a dump; pass Operation.model_validate(...), got ModelResponse; pass response.operation, got str, expected Operation.
  • The same gate runs on BackgroundAction.check / BackgroundAction.cancel, so a dump cannot AttributeError on .action before UNIMPLEMENTED.
  • Missing cancel fn is UNIMPLEMENTED on both the veneer and a real BackgroundAction.cancel. Unknown action is INVALID_ARGUMENT.

@google-cla

google-cla Bot commented Aug 20, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the background operation polling and cancellation mechanisms to accept both live Operation objects and raw dictionary mappings (persisted poll handles), ignoring extra keys like latencyMs to prevent failures during reload. It also introduces more robust error handling using GenkitError and adds comprehensive unit tests. The review feedback suggests two performance optimizations: avoiding redundant serialization/re-validation when the input is already an Operation instance, and precomputing the set of valid operation fields to avoid linear scans in is_operation_field.

Comment thread py/packages/genkit/src/genkit/_core/_background.py Outdated
Comment thread py/packages/genkit/src/genkit/_core/_background.py Outdated
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch 2 times, most recently from a9d6a64 to e685b5f Compare August 20, 2026 19:37
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch from e685b5f to c726ab6 Compare August 20, 2026 20:52
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch 2 times, most recently from 12a19b4 to 45e341a Compare August 21, 2026 00:52
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch from 0e0d436 to 5af4013 Compare August 21, 2026 18:13
@huangjeff5 huangjeff5 changed the title feat(py): accept Operation or dump in check and cancel operation feat(py): require a live Operation on check and cancel Aug 21, 2026
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch from 0d02936 to 705c1d4 Compare August 21, 2026 21:16
@huangjeff5
huangjeff5 force-pushed the feat/py-bg-ops-3-coerce branch from 705c1d4 to 89b7f9a Compare August 21, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant