Skip to content

Conversation

@yedidyakfir
Copy link
Collaborator

No description provided.

yedidyakfir and others added 6 commits January 2, 2026 13:18
- Add detailed logging in swarm workflows to track task lifecycle
- Log swarm state (running/finished/failed/queued counts) at each step
- Add null checks in HatchetInvoker.run_success/run_error to prevent crashes
- Log missing tasks in fill_running_tasks when BatchItemTaskSignature not found
- Add logger parameter to fill_running_tasks for Hatchet context logging
- Log why swarm is not done when tasks are still pending
- Better error messages with task IDs for debugging

These changes help diagnose issues where tasks disappear from swarms
without being marked as finished or failed.
Copilot AI review requested due to automatic review settings January 13, 2026 15:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request focuses on code quality improvements including import reordering, removal of unused imports, enhanced logging for swarm workflows, and improved error handling for missing tasks in Redis. The changes also include GitHub workflow adjustments.

Changes:

  • Reorganized imports across test files to follow PEP 8 style (standard library → third-party → local imports)
  • Added comprehensive logging and error handling for swarm task lifecycle operations
  • Implemented null-safety checks for tasks that may have been removed from Redis before callbacks are triggered
  • Modified GitHub workflow configurations for CI and release processes

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit/test_sign.py Reordered imports to follow PEP 8 conventions
tests/unit/test_client.py Reordered imports to follow PEP 8 conventions
tests/unit/swarm/test_config.py Reordered imports to follow PEP 8 conventions
tests/unit/swarm/test_call_item.py Reordered imports to follow PEP 8 conventions
tests/unit/swarm/conftest.py Removed unused imports (mageflow, ChainTaskSignature)
tests/unit/complex/test_chain_and_swarm.py Reordered imports to follow PEP 8 conventions
tests/unit/chain/test_status_changes.py Reordered imports to follow PEP 8 conventions
tests/unit/chain/test_chain.py Reordered imports to follow PEP 8 conventions
tests/integration/test_redis_ttl.py Reordered imports and cleaned up whitespace
tests/integration/hatchet/test_task_models.py Removed unused pytest_asyncio import
tests/integration/hatchet/test_complex_scerios.py Removed blank line
tests/integration/hatchet/swarm/test_stop_resume.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/swarm/test_edge_cases.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/swarm/test__swarm.py Reordered imports and removed unused import (is_wf_done)
tests/integration/hatchet/signature/test_stop_resume.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/signature/test_edge_case.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/signature/test__signature.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/models.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/conftest.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/chain/test_edge_cases.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/chain/test__chain.py Reordered imports to follow PEP 8 conventions
tests/integration/hatchet/assertions.py Removed blank line
mageflow/swarm/workflows.py Added extensive logging and null-safety checks for swarm task lifecycle operations
mageflow/swarm/model.py Added logger parameter and enhanced error handling for missing tasks in fill_running_tasks
mageflow/invokers/hatchet.py Added null-safety checks with logging for tasks missing from Redis during callbacks
.github/workflows/release.yml Changed job trigger condition from needs dependency to conditional check
.github/workflows/ci.yml Renamed workflow from "Python tests" to "CI" and removed workflow_dispatch trigger

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 266 to +270
if len(tasks) != len(publish_coroutine):
raise MissingSwarmItemError(f"swarm item was deleted before swarm is done")
return len(tasks)
raise MissingSwarmItemError(
f"swarm item was deleted before swarm is done. "
f"Missing: {missing_task_ids}"
)
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The error check is comparing the wrong variables. The condition checks if len(tasks) differs from len(publish_coroutine), but publish_coroutine is built from valid_tasks, not tasks. This check will always pass even when tasks are missing. The condition should compare len(valid_tasks) with len(publish_coroutine) (which should always be equal), or better yet, compare len(tasks) with len(valid_tasks) to detect missing tasks.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +45
import logging
logging.warning(
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The logging module is imported inside the function body rather than at the module level. This is inefficient as the import statement will be executed every time the function is called when a task is not found. Move the import statement to the top of the file with other imports.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +66
import logging
logging.warning(
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The logging module is imported inside the function body rather than at the module level. This is inefficient as the import statement will be executed every time the function is called when a task is not found. Move the import statement to the top of the file with other imports.

Copilot uses AI. Check for mistakes.
jobs:
create-github-release:
needs: check-tests
if: github.ref_type == 'tag' && github.event.base_ref == 'refs/heads/main'
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The condition github.event.base_ref == 'refs/heads/main' will not work as expected for tag push events. When a tag is pushed, github.event.base_ref is typically empty or undefined. This condition should likely check that the tag was created from the main branch using a different approach, such as checking out the repository and verifying the tag points to a commit on main, or removing this condition entirely if tags should only be created from main by policy.

Suggested change
if: github.ref_type == 'tag' && github.event.base_ref == 'refs/heads/main'
if: github.ref_type == 'tag'

Copilot uses AI. Check for mistakes.
from threading import Thread
from typing import Generator, Callable, AsyncGenerator

import mageflow
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

Module 'mageflow' is imported with both 'import' and 'import from'.

Suggested change
import mageflow

Copilot uses AI. Check for mistakes.
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