Simplify CPEX hooks with operation modules and typed request state - #134
Merged
Conversation
Signed-off-by: lucarlig <luca.carlig@ibm.com>
dawid-nowak
approved these changes
Sep 7, 2026
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.
Tool, prompt, and resource hooks repeated CMF conversion plumbing and passed erased request state through two runtime layers. This refactor groups each operation with its conversions and gives in-flight requests typed state that owns the selected runtime.
CmfResponsetrait for post-hook projection and application. Preserve each operation's existing conversion and rejection rules.Anystate and registry wrappers with typed states. Tool events and the final response share one mutex; prompt and resource state is owned directly. Migrate gateway callers to invoke post-hooks through their captured state.Requests retain their original hook policy across successful or failed reloads. Resource URI authorization, text/blob conversion, metadata preservation, prompt validation, and denial behavior are unchanged. The routing wiki documents the new module boundaries.
Validation: 242 all-feature workspace tests passed, with 13 existing skips; all-feature Clippy and build, formatting, dependency/license audit, cargo shear, wiki build/test, and repository commit hooks passed. Added coverage for all pre/post hook combinations across the three operations, prompt context after a failed reload, concurrent tool events after reload, and releasing a retired runtime when the last request state is dropped.
Dataplane-only end-to-end verification passed against release images of base
d768052and PR headc2b4d4d: 27 functional cases and 24 concurrent requests per image, with identical JSON-RPC responses. The test used real Redis and a local stateless MCP2026-07-28backend directly, without dev-tools or a control plane. It checked tool/prompt argument redaction, tool/resource response redaction, pre-hook denial before backend access, post-hook denial, disabled plugins, metadata and binary preservation, backend errors, unpublished-route rejection, and concurrent request isolation. All temporary test containers and networks were removed. Full-stack, sustained load, and conformance testing are outside this focused verification.Follows up on Dawid's refactoring suggestion. Based on
main; no new dependencies.