feat(policy): add bounded lifecycle hook bus - #361
Open
PhilipJohnBasile wants to merge 3 commits into
Open
Conversation
youssofal
force-pushed
the
main
branch
2 times, most recently
from
September 1, 2026 08:07
2382dfd to
8bc4d88
Compare
PhilipJohnBasile
force-pushed
the
feat/policy-hooks
branch
from
September 1, 2026 13:02
286d7c8 to
ce64b47
Compare
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.
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, fromscripts/bench_policy_hooks.py --requests 5000: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.10sruff checkpassedcompileallpassedgit diff --checkpassedThis 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.