Skip to content

fix(guardrails): slot enables, startup reports resolved posture (#159) - #163

Merged
JAORMX merged 3 commits into
mainfrom
fix/guardrails-enable-ux-159
Jun 23, 2026
Merged

JAORMX merged 3 commits into
mainfrom
fix/guardrails-enable-ux-159

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #159 — the guardrails enable UX overhaul.

Aligns the guardrails enable model with the router's "configure = enable" posture (ADR 0042): a bound guardrail model slot now enables guardrails (it no longer only routes an already-enabled checker). The build-time guardrails ACTIVE line — which reported the gate value, not the resolved checker model a slot may supersede — is replaced by one always-present guardrails: ON|OFF … posture line carrying the resolved model + provenance.

Problems fixed

Changes

  • internal/app/guardrails.go — guardrailsConfigured ORs in a bound slot; new pure resolveGuardrailsCheckerModel (single source of truth for resolved model + provenance, shared by the live checker and the posture line); buildGuardrailsChecker rewired onto it.
  • internal/app/build.go — normalizeGuardrailsModel is validate-only (ACTIVE emit removed); new logGuardrailsPosture (one build-once INFO per Build, all states) + guardrailsPostureLine pure helper.
  • cmd/mecated/main.go, cmd/mecatequi/flags.go, cmd/mecademo/main.go — help text + --guardrails=on error name both enable paths.
  • docs/adr/0046-guardrails-slot-enable.md — new ADR (supersedes the enable-model clause of 0021).
  • docs/usage.md, docs/architecture/providers.md, docs/design/PRODUCTION-READINESS.md — stale-proofed.
  • Tests: gate truth table, resolver provenance, posture branches (incl. the bound-but-unresolvable-slot OFF regression), direct table tests for the pure helpers.

Review

Ran the dev-pipeline panel (spec + standards + secure-code + software-architect + QA). One cross-confirmed ship-blocker (posture↔checker divergence on a bound-but-unresolvable slot) was fixed in iteration 2 by branching the ON line on the resolver's configured return. Test gaps closed. task lint && task test && task docs green; go run ./cmd/mecademo prints exactly one guardrails: OFF line.

Backward compatibility

Byte-identical OFF-by-default: hook wiring unchanged (buildGuardrailsHooks returns inner unchanged). The only delta for a configure-nothing operator is one explicit guardrails: OFF line. The kill-switch (--guardrails=off) still wins absolutely. Operator-tier-only RULES enforcement untouched.

Live e2e

This is a composition-layer UX change (config gate + a startup log line); the offline suite + task lint/task test/task docs are the faithful gates. Requesting the e2e-live label for a live OpenRouter run per the operator's ask, to confirm no live-provider regression.

JAORMX and others added 3 commits June 23, 2026 17:29
The guardrails enable model was split across two unrelated surfaces —
the ON/OFF gate (cfg.GuardrailsModel != "") and the model-picker
`guardrail` slot (which superseded the gate VALUE but could not open
the gate). A bound slot with no `--guardrails-model` left the checker
silently OFF (the "armed but unloaded" footgun for a security control),
and the build-time `guardrails ACTIVE` line logged the gate value,
not the resolved checker model a slot had superseded.

This aligns guardrails with the router's "configure = enable" model
(ADR 0042) and adds one always-present startup posture line:

- guardrailsConfigured now ORs in a bound `guardrail` slot (explicit
  or via the `cheap`-tier fallthrough). The kill-switch still wins.
- A single pure resolver `resolveGuardrailsCheckerModel` is the source
  of truth for the resolved model + provenance (srcGate/srcSlot/
  srcSlotSupersedingGate), shared by buildGuardrailsChecker and the
  new posture line so they can never disagree.
- `normalizeGuardrailsModel` is now validate-only; the old ACTIVE emit
  is replaced by `logGuardrailsPosture` — exactly one INFO per Build
  carrying the RESOLVED model + provenance + mode + rules + maxChecks,
  and an explicit OFF line (no more inferring OFF from silence).
- `--help` / the `--guardrails=on` error name BOTH enable paths.

Byte-identical OFF-by-default: hook wiring unchanged (buildGuardrailsHooks
returns `inner` unchanged); the only delta for a configure-nothing
operator is one explicit `guardrails: OFF` line.

Co-Authored-By: mecatl <[email protected]>
Review iteration 2 (panel + QA):

- logGuardrailsPosture now branches on resolveGuardrailsCheckerModel's
  `configured` return (the same truth buildGuardrailsChecker uses), not on
  guardrailsConfigured. A bound-but-UNRESOLVABLE slot (selectorForSlot
  non-empty but resolveSlotModel fail-softs to "") previously reported
  `guardrails: ON, checker= (via ), ...` while buildGuardrailsChecker
  returned nil (OFF) — the exact posture↔checker divergence the refactor
  claimed to eliminate. The posture line and the live checker now share
  one truth; the false-ON for a security control is gone.
- highestSeverityGuardrailMode normalizes an empty/unknown mode to "block"
  (the adapter's CompileRule safe default) instead of returning the raw
  unrecognised token.
- Tests: bound-but-unresolvable-slot OFF regression case; direct table
  tests for highestSeverityGuardrailMode (9 cases) and guardrailsPostureLine
  (7 cases, incl. the usedDefaults=true + maxChecks>0 branch).
- mecatequi --guardrails-model help no longer names the unregistered
  --model-slot flag (says "via a bound `guardrail` model slot").
- usage.md notes a trusted project's allowlisted guardrail slot binding
  enables the checker (operator-tier-only RULES gate untouched).

Co-Authored-By: mecatl <[email protected]>
Adds a live e2e spec proving issue #159's slot-only enable against the
real OpenRouter backend: a mecated spawned with `--model-slot
guardrail=cheap` + `--model-alias cheap=<checker>` (NO --guardrails-model)
must (A) emit the build-once `guardrails: ON` startup line naming the
RESOLVED slot model with `via slot \`guardrail\`` provenance (must-fix #1
+ #2), and (B) run the checker on a WebSearch tool call (observed by the
default advisory set) through a real PreToolUse/PostToolUse verdict
round-trip on the slot model and complete cleanly. The offline twin pins
the gate + posture branches; this adds what only a live provider can
show. Env MECATL_E2E_GUARDRAIL_MODEL (default openai/gpt-4.1-mini);
FlakeAttempts(2), local-target only.

Co-Authored-By: mecatl <[email protected]>
@JAORMX JAORMX added e2e-live Run the live e2e suite on this PR config Operator settings.yaml / YAML config surface, flags, and config UX (init, reference, enable models) labels Jun 23, 2026
@JAORMX
JAORMX merged commit fa8b6c0 into main Jun 23, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Operator settings.yaml / YAML config surface, flags, and config UX (init, reference, enable models) e2e-live Run the live e2e suite on this PR

Projects

None yet

1 participant