-
Notifications
You must be signed in to change notification settings - Fork 2
Description
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 modulewool/src/wool/runtime/worker/local.py— interceptor integrationwool/src/wool/runtime/worker/process.py— interceptor bridge wiringwool/src/wool/runtime/worker/connection.py— type annotation fixwool/src/wool/runtime/loadbalancer/roundrobin.py— type annotation fixwool/src/wool/runtime/work/task.py— type annotation fix, assertionswool/src/wool/__init__.py— public API exportswool/pyproject.toml—grpc-interceptordependencywool/tests/runtime/work/test_interceptor.py— comprehensive test suite