Skip to content

docs: plan contextual investigative guardrails - #1455

Merged
JAORMX merged 1 commit into
mainfrom
plan/contextual-guardrails-20260914
Sep 25, 2026
Merged

JAORMX merged 1 commit into
mainfrom
plan/contextual-guardrails-20260914

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Stage: Plan / Interface

Proposed contract, not an implementation PR. This is Architectural / Split work under docs/development-process.md. The user completed the product decision walkthrough. All product decisions are resolved; implementation measurements are deliverables, not prerequisites for plan approval. The merged-plan gate has not been waived.

Approved direction

  • Replace the existing reviewer outright. Remove sanitize; no legacy mode, parallel configuration system, deprecation period, or compatibility implementation.
  • Keep Run once / Don't ask again for this action in this session / Cancel. Include the narrow approval-origin/replay correctness fix so a guardrail waiver cannot become a permission grant.
  • Recheck deterministic permission on the exact hook-mutated action, without redundant asks or rerunning the mutation.
  • Reuse models.slots.guardrail; propose the smallest shared-slot extension for an independent, Build-stable provider/model route rather than session-provider inheritance.
  • Review main and worker actions and results, including local files/search. Hold rejected results and allow the human to release that exact existing result once, without rerunning the tool or repeating effects.
  • Include understandable status, coverage, human concern/source explanations, and exact approval scope; keep raw checker/evidence prose out of durable audit and working-model instructions.
  • Treat false warnings/blocks on ordinary GitHub issues, admitted CLAUDE.md/AGENTS.md instructions, and quoted security examples as core quality failures. Distinguish actual authority-crossing attempts from mere instruction-like wording.
  • Use a researched 90-second review deadline with up to three recoverable attempts sharing it; ordinary cases should finish with one assessment. Remove unsupported four-read/six-turn limits. Retain current-task worker trajectory awareness, not cross-session history.

Implementation measurements and release validation

The plan has 30 acceptance criteria and no unresolved human product decisions. The previous circular gate—requiring measurements from code before implementation could begin—has been removed.

  1. Build the corpus, baseline/comparison runner, and instrumentation alongside the reviewer. Actual model execution remains separately route/spend-authorized and informs release readiness, not permission to write the code. Do not claim efficacy from mocks or unrun evaluations.
  2. Select finite private evidence/trajectory limits during implementation, backed by native source/context bounds, stress measurements, and before-allocation exhaustion tests. Do not invent public deployment knobs with unspecified defaults or silently discard required evidence.

Wider cloud-native work (replica coordination, restart-complete reviewer state, cross-process held-result recovery) stays deferred; only the narrow approval-provenance repair is included.

Verification and review

  • Reconciled plan and proposed ADR independently reviewed for design and security; corrections include serial human release decisions after parallel reads, origin-preserving replay projection, safe repeat eligibility, additive operator policy prompts, and capacity-exhaustion requirements.
  • Acceptance-plan checker: passed (30 criteria; all human decisions resolved; proposed status).
  • Acceptance checker fixtures: passed.
  • task docs: passed via dev toolbox and SDK-pinned pnpm 11.25.0; strict links passed.
  • git diff --check: passed.
  • No production code changed, no live model evaluation, no efficacy claim.

Worktree: .scratch/worktrees/plan-contextual-guardrails-20260914
Branch: plan/contextual-guardrails-20260914

@JAORMX
JAORMX marked this pull request as ready for review September 14, 2026 10:46

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Design review of the plan (docs-only PR, no code). Overall thorough and well-grounded, but flagging two load-bearing ambiguities that should be resolved in the plan text before this Split gate merges, plus two AC-quality issues and one hidden risk in the HMAC digest design. See inline comments.

@JAORMX

JAORMX commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all five review threads in the plan and replied inline. The implementation worktree also now has regression-tested corrections for concurrent pre-action review, completed-unresolved classification, and purpose-separated grant MACs; inbound release integration is still in progress, so these are not a claim that the implementation PR is complete.

One mechanical follow-up: main assigned ADR 0334 to the ToolHive provider decision while this plan was open. Renumbered this plan's ADR to 0342 in 4d130ba and updated the named acceptance proofs accordingly; the design and review resolutions are unchanged. The plan now has 32 ACs, with report inspection distinct from executable proofs. Plan documentation checks and the renamed focused implementation tests pass.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed after the 3 commits pushed since my last pass (5131f356e, beaa5fcdf, 4d130baf2). All 5 findings from the initial review are genuinely fixed, not just reworded:

  1. Dispatch-batch/action-gate concurrency — the new "Pre-action read-batch assessment and execution" section spells out the shape: assessments run concurrently into private records, no speculative execution, dispatcher drains decisions/asks in original order with at most one live ask, then dispatches approved reads concurrently. Explicitly no serial-LLM regression for WebSearch/WebFetch/Subagent/Parallel. New AC1.5 pins it.
  2. unresolved assessment disposition — the new "Completed-review disposition matrix" adds explicit rows for unresolved under both action and inbound jobs, per enforcing/advisory mode.
  3. AC bundling code-testable + report-only claims — AC6.4 narrowed to the code-testable capacity/exhaustion claim; the report/rationale requirement split into a new inspection-only AC6.5 with no verify: test attached.
  4. AC spanning 5 heterogeneous artifact categories — moved to Definition of Done item 3 with an explicit "no single code test is treated as proof of prose/generated-artifact freshness/UI semantics" disclaimer; AC7.4 narrowed to the protobuf/mapper/stream-projection fields only.
  5. HMAC key reuse / domain separation — grant digest preimage now has a mandatory purpose-tag prefix (mecatl/guardrail-grant/v1 + NUL byte) regardless of key choice, plus a new TestADR_0342_..._GrantDomainSeparation test.

Resolving all 5 threads. Approving.

@JAORMX
JAORMX added this pull request to stack #1617 September 16, 2026 07:51
JAORMX added a commit that referenced this pull request Sep 21, 2026
Integrate Plan PR #1455 head 4d130ba into the stacked implementation checkpoint.

Co-Authored-By: mecatl <[email protected]>
@JAORMX
JAORMX force-pushed the plan/contextual-guardrails-20260914 branch 2 times, most recently from bfaa5b7 to 4831b2a Compare September 21, 2026 13:04

@aponcedeleonch aponcedeleonch 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.

Two observations from reading through, neither blocking.


Retain the existing `guardrails.rules[].prompt` field, but deliberately change it from full rubric replacement to additive operator policy. The reviewer prompt always starts with a fixed harness-owned rubric containing the authority/provenance model, source-aware false-positive requirements, distinct action/inbound protocol, evidence-handle rules, structured-output contract, and operational-failure behavior. A non-empty rule `prompt` is fenced and appended beneath that rubric as operator policy for task-specific risk classification within the caller's existing permissions; it cannot replace, weaken, or conceal the fixed security/protocol contract. No legacy full-override mode is retained.

Guardrails remain off unless the existing `--guardrails-model` or `models.slots.guardrail` enable path selects a model, and the existing kill switch still wins. Route precedence is: kill switch; an explicit `guardrail` slot; the current `cheap` tier fallback used by that slot; then the legacy gate model. Thus either existing slot path continues to supersede `--guardrails-model`/`guardrails.model`. The checker provider/model pair is resolved once at Build and captured by every main, per-session, and worker checker factory; changing a session's provider/model never changes that pair.

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.

Side observation, not a blocker on this plan. Happy to move it to its own issue. I hit it while reading through and it seemed worth raising where the context already is.

The two-knob setup is hard to discover. --posture auto for the rule layer, guardrails.model in user-global settings.yaml for the checker. I went looking for an auto mode, found only default and accept-edits in the TUI, and didn't find posture at all until someone pointed me at --help. The combination that delivers the intended behaviour is the one an operator is least likely to stumble into, and --posture yolo looks like the obvious pick while actually demoting the checker to advisory.

Three directions, roughly in order of how much I believe in them.

One, collapse both into a single --posture with strict/auto/yolo. This was my first instinct and I don't think it survives contact with the code. A posture token can't name a checker model, it inverts the configure-to-enable convention from ADR 0046 and 0042, and a flag that silently starts spending per call is its own objection.

Two, go the other way and drop --posture entirely, YAML only. Default strict, and configuring guardrails is what moves you to auto. That fits the configure-to-enable convention instead of fighting it, and it's mostly a deletion rather than new machinery: posture: already exists as an operator-tier settings.yaml key, the CLI flag just out-ranks it. Two caveats worth weighing. It welds "I want a checker" to "I want allow-all", so anyone who wants both gates at strict loses that. And removing a flag breaks existing invocations, including mecak8s, which defaults to --posture auto today.

Three, leave the surface alone and just make the current state legible:

  • --posture auto with no checker configured prints a startup line saying nothing is supervising the session.
  • /posture reports guardrail state next to the tier.

I see #1510 adds /guardrails for coverage and checker health, which is good. It only registers once guardrails are wired though, so it helps people who already set it up rather than people trying to find it.


Action and inbound review are separate jobs and separate prompts. Action review runs after one trusted inner mutation and deterministic permission/plan/system-scope re-evaluation of changed effective args. An unchanged call does not receive a redundant permission ask. Deny, configured Ask, plan mode, and Shell system-scope decisions always bind. Approval executes the byte-identical reviewed call without rerunning mutation.

Authority comes from harness provenance: current genuine user task, genuinely admitted project instructions, actual positive plan/approval callbacks, caller capabilities, exact environment, and current delegation-root trajectory. Text remains untrusted. No filename, repository, or domain is intrinsically trusted. The reviewer must find affirmative attempted authority crossing or redirection; imperative language, ordinary GitHub issue instructions, admitted `AGENTS.md`/`CLAUDE.md` project instructions, assistant-directed prose, or quoted security examples alone are not findings. Missing evidence does not itself increase intrinsic risk. The action-risk rubric is not reused wholesale for inbound content.

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.

This is the line I got stuck on. What counts as the current genuine user task isn't defined anywhere in the plan, and the field it feeds is a list, so it could reasonably be the last prompt, the last few, or something the harness composes.

#1510 answers it as exactly one message. actionreview.go:150 emits a single genuine_user_task fact from r.currentPrompt.Text, set in recordPrompt from the prompt just recorded. Synthetic continuations never touch it, which is right.

So it's K=1, and I think that's a real design decision rather than an implementation detail. Worth stating here. If I say "deploy to staging" and then "check the logs first", only the second reaches the reviewer, and whatever authorization the first carried is invisible to it.

Suggestion: make K configurable and clamp it to [1, 3]. One keeps today's behaviour as the default, three is enough to catch an authorization a turn or two back without turning the fact list into a transcript. The clamp is the point, so it can't grow into a window that reintroduces the mixed-provenance problem this design avoids.

Two related things I noticed while checking:

  • establishPrincipal returns early if already set, so the facts freeze at the first review of a root run. A later prompt in the same run doesn't update them. Is that intended, given a run can span several prompts?
  • The plan lists "actual positive plan/approval callbacks" as principal facts, but feat: integrate contextual guardrails into execution and approvals #1510 only emits genuine_user_task, admitted_*_instruction, target_dependency_version, and repeat_dependency_incomplete. An approved plan doesn't reach the reviewer as authority.

Separately, the provenance gating on instruction fragments reads right to me. PositiveVerdict only for project and rules, so soul and memory go in as context but not authority.

@JAORMX
JAORMX force-pushed the plan/contextual-guardrails-20260914 branch 3 times, most recently from a9a07f7 to 0b917bd Compare September 24, 2026 12:10
@JAORMX
JAORMX force-pushed the plan/contextual-guardrails-20260914 branch from 0b917bd to b15cb4b Compare September 24, 2026 12:32
@JAORMX
JAORMX force-pushed the plan/contextual-guardrails-20260914 branch 3 times, most recently from fce19d8 to 0b10d21 Compare September 25, 2026 06:50
@JAORMX
JAORMX force-pushed the plan/contextual-guardrails-20260914 branch from 0b10d21 to 3e5207f Compare September 25, 2026 08:20
@JAORMX
JAORMX merged commit a24ecc1 into main Sep 25, 2026
31 checks passed
@JAORMX
JAORMX deleted the plan/contextual-guardrails-20260914 branch September 25, 2026 08:39
aponcedeleonch added a commit that referenced this pull request Sep 25, 2026
Collapse the operator posture ladder and the per-session permission mode into
one ordered vocabulary, plan < default < accept-edits < trusted < auto < yolo,
bound at two scopes: an operator ceiling set at boot and a session tier clamped
to it. Add two boot refusals so a deployment whose ceiling promises supervision
or project trust it does not actually have fails to start with an error naming
the fix.

ADR 0351 supersedes the "no new PermissionMode" clause of ADR 0022 only. Its
decisions 2, 3 and 4 (subordinate to the governance invariants, no hardcoded
circuit breaker, loud root/sandbox-gated opt-in) carry over verbatim as binding
constraints: no tier bypasses governance.Evaluate, so deny-dominance and the
configured-Ask floor hold at every tier including yolo.

Plan / Interface stage only. No implementation.

Relates to #1455 (comment)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Sep 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants