Skip to content

feat(policy): add bounded lifecycle hook bus - #361

Open
PhilipJohnBasile wants to merge 3 commits into
youssofal:mainfrom
PhilipJohnBasile:feat/policy-hooks
Open

feat(policy): add bounded lifecycle hook bus#361
PhilipJohnBasile wants to merge 3 commits into
youssofal:mainfrom
PhilipJohnBasile:feat/policy-hooks

Conversation

@PhilipJohnBasile

@PhilipJohnBasile PhilipJohnBasile commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Splits the provider-neutral lifecycle hook bus out of #336 as one isolated system.

The bus supports request, stream-event, response, and error phases with explicit allow, reject, rewrite, and annotate outcomes. Hook execution uses a fixed worker count, a bounded queue, per-hook timeouts, input and annotation size limits, and configurable fail-open or fail-closed behavior. No policy module is loaded from the environment and no external policy service is contacted.

Measurement on commit a6edbf9, macOS 27.0 arm64, Python 3.13.14, from scripts/bench_policy_hooks.py --requests 5000:

Hooks p50 p95 p99 Throughput
0 3.458 us 3.750 us 5.666 us 267,004/s
1 19.208 us 30.542 us 58.042 us 46,044/s
4 62.125 us 81.208 us 148.333 us 15,207/s
16 236.083 us 389.125 us 559.667 us 3,904/s

Rewrite and reject arms each returned 5,000 correct outcomes. Under 32 concurrent callers with 2 callback workers and 2 pending slots, observed callback concurrency stayed at 2. Four calls timed out and 28 were rejected by the saturated executor. Caller p95 was 5.320 ms with a configured 5 ms hook timeout.

Validation:

  • 7 passed in 0.10s
  • ruff check passed
  • compileall passed
  • git diff --check passed

This PR does not wire the bus into the OpenAI server yet. That integration stays separate so this system can be reviewed and measured without coupling it to request capture, replay, telemetry, memory control, or dashboard work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant