Repository navigation
Description
Parent: #1785. Part 3 of 5. Depends on #1797 and #1798. Run it with /sdd-fast <this issue>.
Goal
Show each PPE decision in the session rows, so agentop shows a policy denial with its code. Today a denied request shows only 403 gateway_refused, or 200 gateway_refused for an MCP deny. The violation code is lost.
Facts (spikes, 2026-11-11)
- A denial does not reach
cortex_observe's response hooks. The row comes fromemit_deferred_record(ctx, status), which gets only the status (praxis-proxy-filter-0.8.0 src/filter.rs:175,observe.rs:268). TheX-Policy-Violationheader is not available there. - The
policyfilter publishes no decision to later filters. It drops thePipelineResult(policy/filter.rs:901-912). It sets only thellm.modelandllm.streammetadata. - PPE audit sinks see each decision. A host registers a factory with
register_policy_plugin_factory(kind, Arc<dyn Fn() -> Box<dyn ppe::PluginFactory>>)(policy/host_plugins.rs:40,61). The plugin implementsAuditHandler::handle(payload, &Extensions, &DecisionLog)and returns itself fromPlugin::as_audit_handler(praxis-policy-core-0.6.0 src/audit.rs:40-60,plugin.rs:145).- The engine calls it once for each hook invocation, after the assertions, for an allow and for a deny. This includes a route-resolution deny (
engine.rs:3280-3325). log.verdict()givesDeny(PluginViolation { code, reason, plugin_name, .. }).- A sink sees only what its
capabilities:allow:read_headersforext.http.request_headers,read_labelsforext.security.labels,read_agentforext.agent.session_id.
- The engine calls it once for each hook invocation, after the assertions, for an allow and for a deny. This includes a route-resolution deny (
- A hook plugin in
mode: auditdoes not see a Sequential deny (executor.rs:884-908). Use the audit-sink trait, not a hook. - A policy file must declare the sink:
A sink with no hooks loads. In a spike, a compiled sketch against 0.6.0 gave
plugins: - {name: cortex-recorder, kind: cortex/recorder, capabilities: [read_headers]}
LOAD OK; sink attached: true(a local spike file, not in the repo). Nobody saw a live call tohandleon a deny. Task 1 must prove it first. - The filter sets no request id in
Extensions. The join key is theX-Cortex-Request-Idhop header.cortex_observereads it (observe.rs:26,119-125).cortex_attributionremoves the hop headers only before the upstream (request_headers_to_remove,attribution.rs:79), so the header is still on the request whenpolicyruns. - The row schema already has the field:
invocations: {inbound: [...], outbound: [...]}, withplugin,action(allow,deny,skip,modify,observe) andreason(docs/session-api.md:495-498, 807-822). The gateway does not set it now:NOT_SET_IN_PRAXIS_MODEinpraxis/filters/src/record/line.rs:35lists it, andTestPraxisE2E_SameEventsAsDirectasserts that it is absent (praxis_e2e_test.go:781-785).
Requirements
-
Add a Rust audit sink with kind
cortex/recordertopraxis/filters. Register it inpraxis/server/src/main.rswithregister_policy_plugin_factory, before the server starts. -
For each
handlecall, the sink readsX-Cortex-Request-Idfromext.http.request_headers. It stores the decision for that id:- a deny:
{plugin: "policy", action: "deny", reason: <violation code>}; - an allow:
{plugin: "policy", action: "allow", reason: ""}.
For one request, a deny replaces an allow. Calls with no request id are dropped.
- a deny:
-
Keep the store bounded: at most 4096 request ids, and evict the oldest first.
cortex_observetakes the entry out when it writes the response row, including the deferred row. So a decision is never in two rows, and the store does not grow. -
cortex_observeputs the stored decision into the row asinvocations.outbound(one entry). It does this on the normal response path and on theemit_deferred_recordpath. RemoveinvocationsfromNOT_SET_IN_PRAXIS_MODE, and keep a comment saying that only the policy decision sets it. -
With no
praxis.policy, or with a policy file that does not declarecortex/recorder, the rows do not change. -
Go ingestion keeps
invocationsfrom a gateway row. Check that/v1/ingestdecodes it, and fix it if it does not. agentop shows the policy row as a deny with its code, the same as a Go plugin deny.
Plan
Task 1: prove the sink and add the store (no dependency inside this issue).
- Files: a new
praxis/filters/src/policy_recorder.rs(or a similar name),praxis/filters/src/lib.rs,praxis/server/src/main.rs,praxis/filters/Cargo.toml(addpraxis-policywith the same version aspraxis-proxy-filter'sppedependency, or reach it throughpraxis-proxy-filter's re-export if one exists). - First test, before the rest: build a
PolicyFilterwith a policy that declarescortex/recorderand denies one tool or model. Run one request, and check thathandleran with the deny code. Ifhandledoes not run on a deny, stop and report this in the PR. Do not change the design. - More tests: an allow is recorded; a deny replaces an allow; a call with no id is dropped; the 4097th id evicts the first.
Task 2: put the decision into the row (needs Task 1).
- Files:
praxis/filters/src/filters/observe.rs,praxis/filters/src/record/row.rsand/orrecord/line.rs(anInvocationtype that serializes the same way as Go'spipeline.Invocation), the parity and schema drift tests that coverinvocations. - Tests:
- a deferred deny row carries the deny invocation;
- a normal row carries the allow invocation;
- after the row is written, the store holds no entry for that id.
Task 3: Go ingestion and end-to-end test (needs Task 2).
- Files: Go
/v1/ingestdecoding (find it fromcmd/cortex/praxis.goandcore/sessionapi),cmd/cortex/praxis_e2e_test.go. - Change
TestPraxisE2E_SameEventsAsDirectso that a run with no policy still asserts noinvocations. - Add
TestPraxisE2E_PolicyDecisionInRow: the policy declarescortex/recorderand deniesmodel-bad. Expected rows:model-badhasinvocations.outbound = [{plugin: "policy", action: "deny", reason: "model_not_allowed"}];model-okhas anallowentry;- an MCP tool deny (from PPE 2/5: Set MCP metadata in cortex_observe for the policy filter #1798) has a
denyentry withtool_not_allowed.
Order: Task 1, Task 2, Task 3. One PR, stacked on #1798.
Done when
- The requirements hold and the tests above pass.
cargo fmt --check,cargo clippy -D warningsandcargo testpass inpraxis/.go vet ./...passes in the Go modules that changed.- The
praxis_e2etests pass.
Not in scope
- Labels and taints in the row. We add them when a user needs them.
- A Cortex-written policy wrapper that adds
cortex/recorderautomatically. PPE 4/5: Document PPE in praxis mode and deprecate the laptop CPEX build #1800 documents theplugins:line.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
docs: Add the plan for PPE decisions in the gateway's rows (#1799)
docs: Fix the task order and the gate of the #1799 plan
docs: Record the reserved join header in the #1799 plan