Skip to content

Conversation

@yedidyakfir
Copy link
Collaborator

Summary

Fixes bug where normal (non-signature) tasks did not properly propagate errors and results. When a task was run without a signature, the error handling logic would incorrectly attempt to update non-existent signature state, and successful results were wrapped unnecessarily.

Closes #54

Changes

  • Added is_vanilla_run() method to HatchetInvoker to detect normal task runs (no task_id)
  • Normal tasks now properly raise exceptions without signature-related handling
  • Normal tasks return results directly without HatchetResult wrapping
  • Simplified invoker API: replaced run_success/run_error/remove_task with task_success/task_failed
  • Removed unused SIGNATURES_NAME_MAPPING and update_register_signature_models() function
  • Reordered callback flow: signature.done()/signature.failed() now called after task lifecycle callbacks

Testing

  • Added tests for normal task failure (test_check_normal_task_fails__sanity)
  • Added tests for normal task retry (test_retry_normal_tasks__sanity)
  • Added tests for cancel task output (test_cancel_task_output__sanity)
  • Added tests for timeout task output (test_timeout_task_output__sanity)
  • Updated existing tests with shorter sleep times

…est to check that normal fail task raises the correct error message
…f task is normal task, if true raise error noramlly
…d fail is called after callbacks. rename to task success
Copilot AI review requested due to automatic review settings February 3, 2026 20:39
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 PR fixes a critical bug where normal (non-signature) tasks did not properly propagate errors and results. The implementation now correctly differentiates between signature-based tasks and vanilla task runs.

Changes:

  • Added is_vanilla_run() method to detect when tasks are run without signatures (no task_id)
  • Implemented proper exception handling for normal tasks that raises exceptions immediately without attempting signature-related operations
  • Changed normal tasks to return results directly without unnecessary HatchetResult wrapping
  • Simplified and clarified the invoker API by renaming methods from run_success/run_error/remove_task to task_success/task_failed
  • Removed unused code (SIGNATURES_NAME_MAPPING and update_register_signature_models)
  • Reordered the callback flow so signature.done()/signature.failed() are called after task lifecycle callbacks complete
  • Added comprehensive test coverage for normal task failures, retries, cancellations, and timeouts

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mageflow/callbacks.py Updated task callback handler to detect vanilla runs and handle them separately; reordered signature status updates to occur after task lifecycle callbacks
mageflow/invokers/base.py Simplified abstract base class by renaming methods to clearer names (task_success/task_failed)
mageflow/invokers/hatchet.py Implemented is_vanilla_run() method; renamed and refactored task lifecycle methods; removed unused remove_task method
mageflow/signature/model.py Removed unused SIGNATURES_NAME_MAPPING global variable
mageflow/startup.py Removed unused update_register_signature_models function and its call from init_mageflow
tests/unit/conftest.py Removed call to deleted update_register_signature_models function; minor formatting improvement
tests/integration/hatchet/worker.py Changed fail_task to raise MageflowTestError for clearer test assertions; added normal_retry_once task for testing normal task retry behavior
tests/integration/hatchet/models.py Added MageflowTestError exception class for testing
tests/integration/hatchet/assertions.py Removed assert_task_done helper function that was specific to wrapped task results
tests/integration/hatchet/signature/test_edge_case.py Added four new test cases for normal task failure, retry, cancel, and timeout scenarios
tests/integration/hatchet/signature/test__signature.py Reduced sleep times in tests for faster execution; updated assertions to check task status directly for normal tasks

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

@yedidyakfir yedidyakfir merged commit 4e00092 into develop Feb 3, 2026
20 checks passed
@yedidyakfir yedidyakfir deleted the feature/54-fix-task-failure-handling-when-task-is-not-a-signature branch February 3, 2026 23:05
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.

1 participant