Skip to content

feat(core): add TaskSupervisor for centralized async task lifecycle#2965

Merged
bug-ops merged 1 commit intomainfrom
unified-task-supervisor
Apr 13, 2026
Merged

feat(core): add TaskSupervisor for centralized async task lifecycle#2965
bug-ops merged 1 commit intomainfrom
unified-task-supervisor

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 13, 2026

Summary

Implements Phase 1 of the unified TaskSupervisor epic (#2958).

Introduces TaskSupervisor in zeph-core as a workspace-wide spawn surface for application-lifetime background tasks. The existing BackgroundSupervisor (per-turn agent loop) is unchanged — the two tiers serve different purposes and are not merged.

  • Single spawn API: spawn(), spawn_blocking(), spawn_restartable()
  • Automatic tracing: every task gets a span with task.name, task.origin, task.id, task.kind, task.restart_count; parent span captured from caller via tracing::Span::current()
  • Panic capture: tokio::spawn boundary catches panics; reap driver protected from factory panics via catch_unwind(AssertUnwindSafe(...))
  • Restart policies: RunOnce and Restart { max, delay } with correct lock release before sleep (no mutex held across await)
  • BlockingError: { Panicked, SupervisorDropped } with proper JoinError::is_panic() mapping
  • Graceful shutdown: CancellationToken-based with configurable timeout and task abort on expiry
  • Task registry: list_tasks() returns Vec<TaskSnapshot> for TUI panel and CI diagnostics
  • Performance: completion_tx moved to Inner to eliminate double mutex acquisition in spawn()

Also renames agent/supervisor.rsagent/agent_supervisor.rs to remove naming ambiguity. Updates 8 import sites.

Test plan

  • cargo build -p zeph-core — clean
  • cargo nextest run -p zeph-core --lib -E 'test(task_supervisor)' — 10 tests pass
  • cargo nextest run --workspace --lib --bins — all 7932 tests pass
  • cargo clippy --workspace -- -D warnings — clean
  • cargo +nightly fmt --check — clean

Related

Closes #2959 (Phase 1: Foundation)
Part of epic #2958

Next phases:

@github-actions github-actions Bot added rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels Apr 13, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 13, 2026 21:03
…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
@bug-ops bug-ops force-pushed the unified-task-supervisor branch from 8aa892f to afa6d81 Compare April 13, 2026 21:05
@bug-ops bug-ops merged commit 0ecebbd into main Apr 13, 2026
30 checks passed
@bug-ops bug-ops deleted the unified-task-supervisor branch April 13, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate enhancement New feature or request rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(core): TaskSupervisor — foundation: types, spawn API, panic capture, registry

1 participant