feat: verification hardening — per-key traces, stream guardrails, tunable thresholds (C6/C8/C3) - #15
Merged
Conversation
…able thresholds (C6/C8/C3) Closes the remaining verification/quality gaps from the v0.1.x audit. What changed - Per-key trace isolation (C8): new self-scoped `GET /v1/traces` (+ `/v1/traces/:id`) gated by the client's own Sentinel key, forcing `apiKeyHash = hash(callerKey)` server-side so a key sees only its own traces (admin `GET /traces` still sees all). Adds a `TraceQuery.apiKeyHash` filter to both stores (+ a SQLite index). Resolves the SR-002 deferral. - Opt-in inline guardrails on streaming (C6): `GUARDRAILS_STREAM_BUFFER=true` buffers a streamed response and runs guardrails before any byte is sent, blocking (422) on a violation. Off by default — live streaming keeps first-byte latency. - Configurable routing thresholds (C3): `routing.thresholds` tunes the `auto` complexity boundaries (defaults unchanged when omitted) — "config over code". - Real judge evidence: `docs/EVIDENCE.md` captures a real async-judge run against a local Ollama (`qwen2.5:0.5b`) — good answer → 5, off-topic answer → 2. Tests - store `apiKeyHash` filter (both backends); end-to-end `/v1/traces` isolation (a key sees only its own, another key's id 404s, no key 401s); buffered streaming guardrails (422 block + clean pass-through); classifier honours custom thresholds. Security: SECURITY_REVIEW_LOG SR-009 (forced server-side scope; streaming-bypass closed). How to verify - `pnpm verify` → green (239 tests, coverage ≥90%) - `pnpm build` → green Defaults are unchanged: no `GUARDRAILS_STREAM_BUFFER`, no `routing.thresholds`, and the self-scoped endpoint is additive — existing behavior is untouched.
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.
Closes the remaining verification/quality gaps from the v0.1.x audit.
What changed
GET /v1/traces(+/v1/traces/:id) gated bythe client's own Sentinel key, forcing
apiKeyHash = hash(callerKey)server-side so a keysees only its own traces (admin
GET /tracesstill sees all). Adds aTraceQuery.apiKeyHashfilter to both stores (+ a SQLite index). Resolves the SR-002 deferral.
GUARDRAILS_STREAM_BUFFER=truebuffers astreamed response and runs guardrails before any byte is sent, blocking (422) on a violation.
Off by default — live streaming keeps first-byte latency.
routing.thresholdstunes theautocomplexityboundaries (defaults unchanged when omitted) — "config over code".
docs/EVIDENCE.mdcaptures a real async-judge run against a localOllama (
qwen2.5:0.5b) — good answer → 5, off-topic answer → 2.Tests
apiKeyHashfilter (both backends); end-to-end/v1/tracesisolation (a key sees onlyits own, another key's id 404s, no key 401s); buffered streaming guardrails (422 block +
clean pass-through); classifier honours custom thresholds.
Security: SECURITY_REVIEW_LOG SR-009 (forced server-side scope; streaming-bypass closed).
How to verify
pnpm verify→ green (239 tests, coverage ≥90%)pnpm build→ greenDefaults are unchanged: no
GUARDRAILS_STREAM_BUFFER, norouting.thresholds, and theself-scoped endpoint is additive — existing behavior is untouched.