Skip to content

Conversation

@kariy
Copy link
Member

@kariy kariy commented Sep 30, 2025

Summary

Implements unique task IDs for all tasks spawned via TaskManager to improve debugging and visibility during development.

Changes

  • TaskId Type: Added a new TaskId type that uniquely identifies each spawned task

    • Implements Display, Debug, Clone, Copy, PartialEq, Eq, and Hash
    • IDs are generated sequentially using an atomic counter for thread-safety
  • Shutdown Initiator Tracking: Tasks that trigger graceful shutdown are now tracked

    • Added shutdown_initiator field to store the ID of the task that initiated shutdown
    • Public method TaskManager::shutdown_initiator() returns the initiator task ID
  • Enhanced Logging: All task completion and panic messages now include task IDs

    • Tasks with graceful shutdown log at info level with ID and name
    • Regular task completion logs at debug level with ID and name
    • Format: id = <task_id>, task = <optional_name>
  • TaskBuilder Integration: Each TaskBuilder gets a unique ID when created

    • Added TaskBuilder::id() method to retrieve the task's ID before spawning
    • ID is automatically assigned when calling build_task()

Benefits

  • Better Debugging: Identify exactly which task caused graceful shutdown
  • Improved Tracing: All log messages include task IDs for easier task execution tracking
  • Backward Compatible: Existing code continues to work without changes
  • Thread-Safe: Uses atomic operations for ID generation

Usage Example

let manager = TaskManager::current();
let spawner = manager.task_spawner();

let task = spawner.build_task()
    .name("Block production")
    .graceful_shutdown()
    .spawn(some_future);

// Later, after shutdown:
if let Some(task_id) = manager.shutdown_initiator() {
    println!("Shutdown was initiated by task: {}", task_id);
}

Testing

  • Updated existing tests to verify shutdown initiator tracking
  • All tests pass successfully
  • Code is properly formatted according to project standards

Closes DOJ-1071

🤖 Generated with Claude Code

Implement unique task IDs for all tasks spawned via TaskManager to improve
debugging and visibility during development.

Key changes:
- Add TaskId type with unique sequential ID generation using atomic counter
- Track which task initiated graceful shutdown via shutdown_initiator field
- Include task IDs in all logging statements (completion, panic, etc.)
- Add TaskManager::shutdown_initiator() to query shutdown initiator
- Add TaskBuilder::id() to retrieve task ID before spawning
- Update tests to verify shutdown initiator tracking

This helps identify which task caused the manager to shut down, making
debugging easier during development.

Closes DOJ-1071

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@codecov
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 77.33333% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.58%. Comparing base (9bde0ae) to head (f76ca1d).
⚠️ Report is 122 commits behind head on main.

Files with missing lines Patch % Lines
crates/tasks/src/manager.rs 69.04% 13 Missing ⚠️
crates/tasks/src/spawner.rs 87.87% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #294      +/-   ##
==========================================
+ Coverage   73.32%   75.58%   +2.26%     
==========================================
  Files         209      230      +21     
  Lines       23132    27276    +4144     
==========================================
+ Hits        16961    20617    +3656     
- Misses       6171     6659     +488     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

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