feat: Add task naming support for improved debugging#5
Merged
takeshishimada merged 2 commits intomainfrom Oct 27, 2025
Merged
Conversation
Implement task naming feature leveraging Swift 6.2's SE-0469 task naming
capability. This enhancement allows developers to assign human-readable names
to tasks created with .run effects, significantly improving observability
during debugging and profiling.
## Changes
### Core Implementation
**ActionTask.swift:**
- Add `name: String?` parameter to `Operation.run` case
- Add `name` parameter to `.run(name:operation:)` factory method (optional, default nil)
- Preserve `name` through all configuration methods (`.catch`, `.cancellable`, `.priority`)
- Update documentation with task naming examples
**TaskManager.swift:**
- Add `name: String?` parameter to `executeTask` method
- Pass `name` to Swift's `Task(name:priority:)` initializer
- Update documentation and examples
**Store.swift:**
- Add `name` parameter to `executeRunTask` helper method
- Thread `name` through to TaskManager.executeTask
- Extract `name` from ActionTask operation
### Tests
**ActionTaskTests.swift:**
- Add 6 new tests for task naming feature:
- `run_withName()` - Verify name is set
- `run_withoutName()` - Verify backward compatibility
- `run_namePreservedAfterCatch()` - Name preserved through `.catch`
- `run_namePreservedAfterCancellable()` - Name preserved through `.cancellable`
- `run_namePreservedAfterPriority()` - Name preserved through `.priority`
- `run_namePreservedThroughChaining()` - Name preserved through complete chain
**Test Pattern Updates:**
- Update all test pattern matches to account for new `name` field in `Operation.run`
- 299 tests pass (293 existing + 6 new)
## Benefits
- ✅ **Improved Debugging**: Tasks are easily identifiable in Xcode, Instruments, and swift-inspect
- ✅ **Better Observability**: Human-readable task names in debugging tools
- ✅ **Backward Compatible**: `name` parameter is optional with `nil` default
- ✅ **Minimal Impact**: No breaking changes to existing code
## Example Usage
```swift
// Named task for better debugging
return .run(name: "🔄 Fetch user profile") { state in
let profile = try await api.fetchProfile()
state.profile = profile
}
// Dynamic naming with interpolation
return .run(name: "Load user \(userId)") { state in
let user = try await api.fetchUser(userId)
state.user = user
}
// Name preserved through chaining
return .run(name: "Critical operation") { state in
try await performOperation()
}
.cancellable(id: "op", cancelInFlight: true)
.priority(.high)
.catch { error, state in
state.error = error
}
```
## Requirements
- Swift 6.2+ (for Task naming API)
- Fully backward compatible with existing code
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add swiftlint:disable:next comment for executeRunTask method which requires 6 parameters (id, name, operation, onError, cancelInFlight, priority) as part of the task naming feature implementation. This is an internal helper method where the parameter count is justified by the complexity it manages, including task identification, naming, operation execution, error handling, cancellation policy, and priority configuration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement task naming feature leveraging Swift 6.2's SE-0469 task naming capability. This enhancement allows developers to assign human-readable names to tasks created with
.runeffects, significantly improving observability during debugging and profiling.Motivation
Swift 6.2 introduced task naming (SE-0469) to help developers identify tasks in debugging and profiling tools. This PR brings that capability to Flow's
.runeffects, making it easier to:Implementation
Core Changes
ActionTask.swift
name: String?parameter toOperation.runcasenameparameter to.run(name:operation:)factory methodnameis preserved through all configuration methods (.catch,.cancellable,.priority)TaskManager.swift
nameparameter toexecuteTaskmethodnameto Swift'sTask(name:priority:)initializerStore.swift
executeRunTaskto accept and pass throughnameparameternamefrom ActionTask operationTests
Added 6 comprehensive tests covering:
.catch,.cancellable,.priorityAll 299 tests pass (293 existing + 6 new).
Example Usage
Benefits
✅ Improved Debugging: Tasks are easily identifiable in development tools
✅ Better Observability: Human-readable names in profiling and debugging
✅ Backward Compatible: Optional parameter with
nildefault✅ Zero Breaking Changes: Existing code works unchanged
✅ Type-Safe: Leverages Swift's native task naming API
Requirements
Testing
Related
This feature is inspired by similar implementations in other Swift architecture libraries and directly utilizes Swift Evolution proposal SE-0469.
Screenshots
Task names will appear in:
🤖 Generated with Claude Code