feat(core): add TaskSupervisor for centralized async task lifecycle#2965
Merged
feat(core): add TaskSupervisor for centralized async task lifecycle#2965
Conversation
…anagement
Introduces TaskSupervisor in zeph-core as a workspace-wide spawn surface
for application-lifetime background tasks (memory loops, skill watcher,
scheduler, indexer). Complements the existing BackgroundSupervisor which
handles per-turn agent tasks — the two tiers are not merged.
Features:
- spawn(), spawn_blocking(), spawn_restartable() as the single spawn API
- Automatic tracing span per task (task.name, task.origin, task.id, task.kind,
task.restart_count) with parent span captured from caller
- RestartPolicy: RunOnce, Restart { max, delay } with catch_unwind-safe
factory to prevent reap driver death on factory panics
- BlockingError { Panicked, SupervisorDropped } with correct JoinError mapping
- Graceful shutdown via CancellationToken with configurable timeout
- Task registry via list_tasks() returning Vec<TaskSnapshot>
- completion_tx moved to Inner to eliminate double mutex acquisition in spawn()
- 10 unit tests covering all major code paths
Also renames agent/supervisor.rs to agent/agent_supervisor.rs to avoid
ambiguity with the new type. Updates 8 import sites.
Closes #2959
Part of #2958
8aa892f to
afa6d81
Compare
5 tasks
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
Implements Phase 1 of the unified TaskSupervisor epic (#2958).
Introduces
TaskSupervisorinzeph-coreas a workspace-wide spawn surface for application-lifetime background tasks. The existingBackgroundSupervisor(per-turn agent loop) is unchanged — the two tiers serve different purposes and are not merged.spawn(),spawn_blocking(),spawn_restartable()task.name,task.origin,task.id,task.kind,task.restart_count; parent span captured from caller viatracing::Span::current()tokio::spawnboundary catches panics; reap driver protected from factory panics viacatch_unwind(AssertUnwindSafe(...))RunOnceandRestart { max, delay }with correct lock release before sleep (no mutex held across await)BlockingError:{ Panicked, SupervisorDropped }with properJoinError::is_panic()mappingCancellationToken-based with configurable timeout and task abort on expirylist_tasks()returnsVec<TaskSnapshot>for TUI panel and CI diagnosticscompletion_txmoved toInnerto eliminate double mutex acquisition inspawn()Also renames
agent/supervisor.rs→agent/agent_supervisor.rsto remove naming ambiguity. Updates 8 import sites.Test plan
cargo build -p zeph-core— cleancargo nextest run -p zeph-core --lib -E 'test(task_supervisor)'— 10 tests passcargo nextest run --workspace --lib --bins— all 7932 tests passcargo clippy --workspace -- -D warnings— cleancargo +nightly fmt --check— cleanRelated
Closes #2959 (Phase 1: Foundation)
Part of epic #2958
Next phases: