Skip to content

feat(sdk): add task retry/cancel methods and expose available actions#1187

Merged
polmichel merged 2 commits into
infrahub-developfrom
pmi-20260716-sdk-retry-cancel-tasks
Jul 16, 2026
Merged

feat(sdk): add task retry/cancel methods and expose available actions#1187
polmichel merged 2 commits into
infrahub-developfrom
pmi-20260716-sdk-retry-cancel-tasks

Conversation

@polmichel

@polmichel polmichel commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Why

The Infrahub backend added InfrahubTaskRetry and InfrahubTaskCancel mutations (opsmill/infrahub#9754) for recovering webhook deliveries, but the SDK's task manager was read-only.

Tracked in IFC-2836

Goal: give client.task first-class retry/cancel methods, and let callers see which actions a task actually supports.

What changed

Behavioral changes:

  • client.task.retry(id) — replays a settled task as a new independent task, returning the new task id. Wraps InfrahubTaskRetry.
  • client.task.cancel(id) — cancels an in-flight task, returning the ok flag. Wraps InfrahubTaskCancel.
  • Task now carries available_actions (mirroring the backend TaskAction type) with can_retry / can_cancel convenience properties.
  • Task queries accept include_actions=True (threaded through all / filter / get), alongside the existing include_logs / include_related_nodes.
  • Both are implemented identically on InfrahubClient and InfrahubClientSync.

How to test

uv run pytest tests/unit/sdk/test_task.py
uv run invoke format lint-code

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4172f36
Status: ✅  Deploy successful!
Preview URL: https://7c3199c0.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pmi-20260716-sdk-retry-cance.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/task/models.py 95.00% 0 Missing and 1 partial ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop    #1187      +/-   ##
====================================================
+ Coverage             83.03%   83.10%   +0.07%     
====================================================
  Files                   139      139              
  Lines                 12365    12403      +38     
  Branches               1846     1849       +3     
====================================================
+ Hits                  10267    10308      +41     
+ Misses                 1531     1528       -3     
  Partials                567      567              
Flag Coverage Δ
integration-tests 40.36% <4.65%> (-0.14%) ⬇️
python-3.10 56.99% <48.83%> (+0.04%) ⬆️
python-3.11 56.99% <48.83%> (+0.04%) ⬆️
python-3.12 56.97% <48.83%> (+0.02%) ⬆️
python-3.13 56.99% <48.83%> (+0.04%) ⬆️
python-3.14 56.97% <48.83%> (+0.04%) ⬆️
python-filler-3.12 22.38% <48.83%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/task/__init__.py 100.00% <100.00%> (ø)
infrahub_sdk/task/manager.py 91.39% <100.00%> (+4.57%) ⬆️
infrahub_sdk/task/models.py 97.40% <95.00%> (-0.88%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add retry() and cancel() convenience methods to InfrahubTaskManager and
InfrahubTaskManagerSync, wrapping the InfrahubTaskRetry/InfrahubTaskCancel
mutations so consumers no longer fall back to raw execute_graphql calls.

Surface the backend's available_actions on the Task model along with
can_retry/can_cancel helpers and an include_actions query flag, so callers
can introspect eligibility rather than acting blind. The server remains
authoritative and still rejects ineligible actions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@polmichel
polmichel force-pushed the pmi-20260716-sdk-retry-cancel-tasks branch from 3b9ca2c to 4436703 Compare July 16, 2026 13:08
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Jul 16, 2026
@polmichel
polmichel force-pushed the pmi-20260716-sdk-retry-cancel-tasks branch from 3f9adf7 to 4436703 Compare July 16, 2026 13:11
@github-actions github-actions Bot removed the type/documentation Improvements or additions to documentation label Jul 16, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrahub_sdk/task/manager.py
Comment thread tests/unit/sdk/test_task.py
The limit fast path in filter() built its query without forwarding
include_logs / include_related_nodes / include_actions, so those fields
(including available_actions) were silently dropped for all(limit=...)
and filter(limit=...). Forward all three in both async and sync paths.

Also harden the retry/cancel tests to assert the outgoing GraphQL
mutation name and input id, so wiring regressions surface.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@polmichel
polmichel marked this pull request as ready for review July 16, 2026 15:01
@polmichel
polmichel requested a review from a team as a code owner July 16, 2026 15:01
@polmichel
polmichel merged commit 3b385f4 into infrahub-develop Jul 16, 2026
21 checks passed
@polmichel
polmichel deleted the pmi-20260716-sdk-retry-cancel-tasks branch July 16, 2026 19:08
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.

2 participants