Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(tasks): add task identification system#294

Open
kariy wants to merge 1 commit into
main from
karii/doj-1071-feattask-task-identification
Open

feat(tasks): add task identification system #294
kariy wants to merge 1 commit into
main from
karii/doj-1071-feattask-task-identification

Conversation

@kariy

@kariy kariy commented Sep 30, 2025

Copy link
Copy Markdown
Member

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 <noreply@anthropic.com>

codecov Bot commented Sep 30, 2025

Copy link
Copy Markdown

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.

@kariy kariy force-pushed the main branch 2 times, most recently from e3bd68b to e897bbb Compare December 30, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /