Skip to content

Implement customizable task dispatch interceptor scheme #105

@conradbzura

Description

@conradbzura

Summary

Implement a customizable interceptor system for task dispatch that allows users to hook into the task lifecycle — modifying tasks before dispatch and wrapping response streams during execution. Interceptors follow an async generator protocol with three phases: pre-dispatch, stream processing, and cleanup.

Add an InterceptorLike protocol, an @interceptor decorator for global registration, an InterceptorBridge that adapts Wool interceptors to gRPC's server interceptor interface, and integrate interceptor support into LocalWorker and WorkerProcess.

Motivation

Cross-cutting concerns such as logging, metrics, RBAC, and distributed tracing need a clean extension point in the task dispatch path. Without an interceptor mechanism, users must modify worker internals or wrap proxy calls ad hoc. A first-class interceptor protocol provides a composable, testable, and well-documented way to observe and transform tasks and their response streams.

Affected code

  • wool/src/wool/runtime/work/interceptor.py — new module
  • wool/src/wool/runtime/worker/local.py — interceptor integration
  • wool/src/wool/runtime/worker/process.py — interceptor bridge wiring
  • wool/src/wool/runtime/worker/connection.py — type annotation fix
  • wool/src/wool/runtime/loadbalancer/roundrobin.py — type annotation fix
  • wool/src/wool/runtime/work/task.py — type annotation fix, assertions
  • wool/src/wool/__init__.py — public API exports
  • wool/pyproject.tomlgrpc-interceptor dependency
  • wool/tests/runtime/work/test_interceptor.py — comprehensive test suite

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or capability

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions