Skip to content

feat: hook system and plugin support design spec - #63

Merged
shaneutt merged 4 commits into
praxis-proxy:mainfrom
araujof:feat/hook_system
May 18, 2026
Merged

shaneutt merged 4 commits into
praxis-proxy:mainfrom
araujof:feat/hook_system

Conversation

@araujof

@araujof araujof commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Description

A proposal for a second extension surface in Praxis, complementing the existing HttpFilter / TcpFilter surface with typed, lifecycle-anchored hooks backed by the CPEX runtime embedded in-process.

Specification

Closes: praxis-proxy/ai#180

What it adds

Hooks sit at well-defined points across the server lifecycle: startup, TLS handshake, TCP accept and session, and the HTTP request and response path. Each has a typed payload and a declared interaction class (observe, mutate, or policy), so plugin authors know what they can touch and the dispatcher knows how to compose results.
Plugins run as native shared libraries or WASM modules; Python is excluded because the latency budget does not accommodate it. A plugin call is an in-process function call, not an IPC hop, and a deployment with no plugins configured pays nothing beyond a single atomic check per call site.

The central structural property is tighten-only composition. Policy hooks can strengthen any of Praxis' built-in security boundaries but never weaken them, and this is enforced by the dispatcher rather than left to plugin discipline.

What it defers

Protocol-semantic concerns, such as MCP resource and prompt invocations, A2A tasks, LLM inputs and outputs, are named and reserved but intentionally unregistered. Hot reload, Python, and sidecar hosts for synchronous paths are also out of scope for v1.

@shaneutt There is a design tradeoff discussed for protocol-semantic hooks.

Operational surface

Configuration is YAML-driven, with per-hook timeouts, error policies, and priorities. Plugins that span multiple hooks, for example deciding at request-time and auditing at session-end, get a typed request-scoped state channel rather than having to smuggle state through headers. Body-handling hooks have cumulative budgets at the chunk, request, and plugin level, and a circuit breaker auto-disables plugins that repeatedly misbehave. Metrics and tracing cover invocations, rejections, short-circuits, and the time the plugin chain contributes to each request.

Rollout

The work is staged so each phase is independently shippable.

cc: @terylt @imolloy

@shaneutt shaneutt self-assigned this Apr 20, 2026
@shaneutt shaneutt added this to the v0.5.0 milestone Apr 20, 2026
@araujof

araujof commented Apr 29, 2026

Copy link
Copy Markdown
Member Author

@shaneutt Thanks for 0f0f656. It addresses the listener-wide collapse by removing the precedence rung that let one filter promote the whole listener to all-or-nothing buffered mode, and per-request set_request_body_mode / set_response_body_mode on the context means the cost is opt-in per request instead of baked into capabilities at startup.

Net: the spec's §4.1 Cost 1 is resolved at the architectural level. I'll update the plugins doc to reference per-request set_*_body_mode as the mechanism plugins use, drop the Buffer references, and reword the streaming-collapse argument to reflect "per-request opt-in" rather than "per-listener promotion."

One small thing: the BodyMode::StreamBuffer { .. } | BodyMode::Stream | _ => {} arms in request_body_filter.rs / response_body_filter.rs plus #[non_exhaustive] on the enum mean future variants silently fall through as Stream. Explicit arms would catch that at compile time.

@araujof
araujof force-pushed the feat/hook_system branch from b08e0be to 3043843 Compare May 4, 2026 16:21
@shaneutt

shaneutt commented May 8, 2026

Copy link
Copy Markdown
Member

@araujof 👋 just checking in: is it your intention that this be marked ready for review?

@araujof

araujof commented May 8, 2026

Copy link
Copy Markdown
Member Author

@shaneutt please allow me to push an update to the spec based on 1) the recent changes made to Praxis, and 2) the implementation of CPEX Rust we just completed this week. I will mark the PR ready for your review, so we can start on the initial implementation next week. Btw, here are the references to the CPEX Rust (in dev):

@araujof
araujof force-pushed the feat/hook_system branch from 3043843 to d573674 Compare May 12, 2026 22:06
araujof and others added 2 commits May 12, 2026 18:07
Signed-off-by: Ian Molloy <[email protected]>
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Co-authored-by: Ian Molloy <[email protected]>
Co-authored-by: Teryl Taylor <[email protected]>
Co-authored-by: Frederico Araujo <[email protected]>
…ateway filter

Restructure the plugin spec from a lifecycle-only design into a complete
v1 specification covering protocol-semantic hooks. Major additions:
MCP gateway filter (§4.4), route-driven body mode (§4.3), identity hooks
(I1/I2), CMF-based tool hook payloads, capability-gated Extensions with
WriteToken enforcement, and a phased rollout plan. Replaces the deferred
layering model with a concrete gateway-filter-now / protocol-native-later
decision. Updates CPEX integration from hypothetical versioned crates to
pinned git dependency on cpex-core.

Signed-off-by: Frederico Araujo <[email protected]>
@araujof
araujof force-pushed the feat/hook_system branch from d573674 to 377be60 Compare May 12, 2026 22:07
@araujof
araujof marked this pull request as ready for review May 12, 2026 22:08
@araujof
araujof requested a review from a team May 12, 2026 22:08
@praxis-bot

Copy link
Copy Markdown

PR too large

This PR adds 1065 lines (limit: 250).

Large PRs are difficult to review and more likely to introduce subtle bugs. Please break this contribution into smaller, focused PRs that each address a single concern.

See our coding conventions for guidance.

If this PR legitimately requires a large change, a maintainer can add the conventions/bypass label to skip this check.

@praxis-bot praxis-bot closed this May 12, 2026
@araujof

araujof commented May 12, 2026 •

Copy link
Copy Markdown
Member Author

@shaneutt I rewrote the hook system spec to align with latest Praxis (including our discussions and fix for the buffer collapse issue) and the implemented CPEX Rust API. The prior version deferred all protocol-semantic hooks to a future protocol-native service; this revision brings MCP tool hooks into v1 scope via a concrete delivery mechanism.

Key changes:

  • MCP gateway filter (§4.4). New builtin filter at filter/src/builtins/http/mcp/ dispatches praxis.mcp.tool_pre_invoke and tool_post_invoke against CPEX MessagePayload. Supports denial, argument redaction, response redaction, and JSON-RPC batch handling.
  • Route-driven body mode (§4.3). Routes declare body_mode: in YAML; buffering is bounded and explicit rather than filter-sniffed. Non-MCP traffic pays zero cost.
  • Identity hooks (I1, I2). praxis.identity.resolve and praxis.identity.delegate use CPEX's framework hooks for slot collision rejection, immutable sealing, scope-narrowing enforcement, and credential isolation.
  • Capability-gated Extensions with WriteToken. Header mutation, security identity, agent context, delegation chains, and raw credentials flow through typed extensions with per-capability write authority.
  • CPEX integration updated. Moved from hypothetical versioned cpex-core/cpex-hosts/cpex-sdk crates to a single cpex-core git pin against the dev branch. Dynamic loading (cdylib + libloading) specified but ships as a parallel phase.
  • Gateway-now / protocol-native-later decision. Hook names are the stable contract; plugin code doesn't change when we promote to McpProxy.

The hook catalog is now 12 hooks across startup, TLS, HTTP, identity, and MCP families, with TCP and additional protocol-semantic hooks reserved for promotion when a consumer warrants it.

@araujof araujof added documentation Improvements or additions to documentation enhancement New capabilities or major expansions to existing ones conventions/bypass labels May 12, 2026
@araujof araujof reopened this May 12, 2026
@araujof araujof removed the documentation Improvements or additions to documentation label May 12, 2026
@araujof
araujof requested a review from shaneutt May 12, 2026 23:07
@araujof

araujof commented May 13, 2026

Copy link
Copy Markdown
Member Author

@usize tagging you here too for feedback. Thanks!

@shaneutt

Copy link
Copy Markdown
Member

I'm providing my feedback in the discussion that was opened: #188

Given the addition of process, directory and template for proposals in main since this first opened, and that we have a discussion for the proposal now: I might suggest we consider closing this PR, working through the discussion, and then creating a new PR when needed. However, I don't feel strongly about it: if you prefer not to 👍

@araujof

araujof commented May 13, 2026

Copy link
Copy Markdown
Member Author

@shaneutt great! let's take the discussion over there (I tried to follow the new process by creating it 👼 ).

If you don't mind, let's keep this PR open as the living proposal. As we shape the discussion in the other thread, I will make updates here (just to avoid opening other PRs, if that's okay).

@shaneutt

Copy link
Copy Markdown
Member

@shaneutt great! let's take the discussion over there (I tried to follow the new process by creating it 👼 ).

If you don't mind, let's keep this PR open as the living proposal. As we shape the discussion in the other thread, I will make updates here (just to avoid opening other PRs, if that's okay).

Sounds good. If we can retro-bump this PR to use the proposal template, find an issue it ties well with (#164 is probably right), and move it into the docs/proposals dir, I would be inclined to merge it as proposed, continue the discussion, and iterate on it as we discuss.

@praxis-bot praxis-bot closed this May 18, 2026
@shaneutt shaneutt added skip/pr-hygiene skip/proposals Proposal validation bypass labels May 18, 2026
@shaneutt shaneutt reopened this May 18, 2026

@shaneutt shaneutt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge this and convert it to a holding state while we continue to discuss

@shaneutt
shaneutt merged commit 977ce7b into praxis-proxy:main May 18, 2026
19 checks passed
leseb added a commit to leseb/praxis that referenced this pull request Jun 3, 2026
Remove remaining em-dashes per project conventions.
Clarify that auto-registered duplicates panic because
there is no caller to propagate the Result to, while
manual registry.register() continues to return Result.
Add boundary note distinguishing filter registration
from plugin/hook discovery (praxis-proxy#63).

Signed-off-by: Sébastien Han <[email protected]>
shaneutt pushed a commit that referenced this pull request Jun 8, 2026
* fix(ci): fix bash syntax error and regex bug in conventions workflow (#456)

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): add build-time filter registry proposal

Propose a build.rs + cargo metadata discovery mechanism
that lets external filter crates self-register into the
FilterRegistry at build time. Operators add a Cargo.toml
dependency and write YAML config with zero Rust code
changes to Praxis.

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): remove How? section per proposal guidelines

Submit What? and Why? first. How? will be added in a
follow-up after the proposal direction is accepted.
Also add missing discussion field to frontmatter.

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): address PR review feedback

Remove remaining em-dashes per project conventions.
Clarify that auto-registered duplicates panic because
there is no caller to propagate the Result to, while
manual registry.register() continues to return Result.
Add boundary note distinguishing filter registration
from plugin/hook discovery (#63).

Signed-off-by: Sébastien Han <[email protected]>
mkoushni pushed a commit to mkoushni/praxis that referenced this pull request Jun 10, 2026
* fix(ci): fix bash syntax error and regex bug in conventions workflow (praxis-proxy#456)

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): add build-time filter registry proposal

Propose a build.rs + cargo metadata discovery mechanism
that lets external filter crates self-register into the
FilterRegistry at build time. Operators add a Cargo.toml
dependency and write YAML config with zero Rust code
changes to Praxis.

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): remove How? section per proposal guidelines

Submit What? and Why? first. How? will be added in a
follow-up after the proposal direction is accepted.
Also add missing discussion field to frontmatter.

Signed-off-by: Sébastien Han <[email protected]>

* docs(filter): address PR review feedback

Remove remaining em-dashes per project conventions.
Clarify that auto-registered duplicates panic because
there is no caller to propagate the Result to, while
manual registry.register() continues to return Result.
Add boundary note distinguishing filter registration
from plugin/hook discovery (praxis-proxy#63).

Signed-off-by: Sébastien Han <[email protected]>
@araujof
araujof deleted the feat/hook_system branch June 15, 2026 17:20
@shaneutt shaneutt modified the milestones: v0.5.0, v0.4.1 Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New capabilities or major expansions to existing ones skip/proposals Proposal validation bypass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: Context Forge

3 participants