Skip to content

PPE 3/5: Record PPE policy decisions in the gateway's rows #1799

Closed

Description

@huang195

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 from emit_deferred_record(ctx, status), which gets only the status (praxis-proxy-filter-0.8.0 src/filter.rs:175, observe.rs:268). The X-Policy-Violation header is not available there.
  • The policy filter publishes no decision to later filters. It drops the PipelineResult (policy/filter.rs:901-912). It sets only the llm.model and llm.stream metadata.
  • 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 implements AuditHandler::handle(payload, &Extensions, &DecisionLog) and returns itself from Plugin::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() gives Deny(PluginViolation { code, reason, plugin_name, .. }).
    • A sink sees only what its capabilities: allow: read_headers for ext.http.request_headers, read_labels for ext.security.labels, read_agent for ext.agent.session_id.
  • A hook plugin in mode: audit does not see a Sequential deny (executor.rs:884-908). Use the audit-sink trait, not a hook.
  • A policy file must declare the sink:
    plugins:
      - {name: cortex-recorder, kind: cortex/recorder, capabilities: [read_headers]}
    A sink with no hooks loads. In a spike, a compiled sketch against 0.6.0 gave LOAD OK; sink attached: true (a local spike file, not in the repo). Nobody saw a live call to handle on a deny. Task 1 must prove it first.
  • The filter sets no request id in Extensions. The join key is the X-Cortex-Request-Id hop header. cortex_observe reads it (observe.rs:26,119-125). cortex_attribution removes the hop headers only before the upstream (request_headers_to_remove, attribution.rs:79), so the header is still on the request when policy runs.
  • The row schema already has the field: invocations: {inbound: [...], outbound: [...]}, with plugin, action (allow, deny, skip, modify, observe) and reason (docs/session-api.md:495-498, 807-822). The gateway does not set it now: NOT_SET_IN_PRAXIS_MODE in praxis/filters/src/record/line.rs:35 lists it, and TestPraxisE2E_SameEventsAsDirect asserts that it is absent (praxis_e2e_test.go:781-785).

Requirements

  1. Add a Rust audit sink with kind cortex/recorder to praxis/filters. Register it in praxis/server/src/main.rs with register_policy_plugin_factory, before the server starts.

  2. For each handle call, the sink reads X-Cortex-Request-Id from ext.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.

  3. Keep the store bounded: at most 4096 request ids, and evict the oldest first. cortex_observe takes 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.

  4. cortex_observe puts the stored decision into the row as invocations.outbound (one entry). It does this on the normal response path and on the emit_deferred_record path. Remove invocations from NOT_SET_IN_PRAXIS_MODE, and keep a comment saying that only the policy decision sets it.

  5. With no praxis.policy, or with a policy file that does not declare cortex/recorder, the rows do not change.

  6. Go ingestion keeps invocations from a gateway row. Check that /v1/ingest decodes 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 (add praxis-policy with the same version as praxis-proxy-filter's ppe dependency, or reach it through praxis-proxy-filter's re-export if one exists).
  • First test, before the rest: build a PolicyFilter with a policy that declares cortex/recorder and denies one tool or model. Run one request, and check that handle ran with the deny code. If handle does 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.rs and/or record/line.rs (an Invocation type that serializes the same way as Go's pipeline.Invocation), the parity and schema drift tests that cover invocations.
  • 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/ingest decoding (find it from cmd/cortex/praxis.go and core/sessionapi), cmd/cortex/praxis_e2e_test.go.
  • Change TestPraxisE2E_SameEventsAsDirect so that a run with no policy still asserts no invocations.
  • Add TestPraxisE2E_PolicyDecisionInRow: the policy declares cortex/recorder and denies model-bad. Expected rows:

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 warnings and cargo test pass in praxis/.
  • go vet ./... passes in the Go modules that changed.
  • The praxis_e2e tests pass.

Not in scope

Metadata

Metadata

Assignees

Labels

laptoprust

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions