Skip to content

feat: integrate contextual guardrails into execution and approvals - #1510

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

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

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the hook-based guardrail reviewer with contextual action and inbound-result review integrated into the execution and approval pipeline.

This implements the proposal in #1455 (ADR 0342). It is not only a prompt change: it adds restricted evidence investigation, private task context across workers, exact action grants, and one-time release of already-produced tool results. It also changes shared dispatch, approval, and restart behavior, with corresponding engine, wire, TUI, and SDK changes.

Stacked PR: targets plan/contextual-guardrails-20260914, not main. The amended proposal baseline is 4d130baf25f4d1d9f2051a21a2765c4fa7fa4a77. Stacked implementation before proposal merge was explicitly authorized; merge sequencing remains human-owned.

What changes

Contextual review

  • Replace the legacy reviewer outright; remove sanitize and automatic replacement execution. There is no parallel legacy mode.
  • Resolve the checker provider/model independently at Build, using the existing guardrail slot.
  • Use separate source-aware action and inbound rubrics. Investigation can read only bounded, explicitly authorized, version-bound evidence through opaque handles.
  • Carry private root-task facts across main, Subagent, Parallel, and Team execution without copying worker conversations into the parent's model prompt.
  • Distinguish prohibited actions/content, completed-but-unresolved assessments, and operational checker failures.

Execution and approval correctness

  • Review effective arguments after trusted mutation. Recheck deterministic authorization when arguments change and revalidate bindings after human waits; do not rerun mutation after approval.
  • Assess eligible read-only siblings concurrently, but drain decisions and asks in original order before execution.
  • Keep contextual repeat grants session-scoped and dependency-bound, separate from permission learning and durable replay.
  • Review covered results before final recording/delivery. Enforcing review can hold the exact already-produced result for Release once or denial, without rerunning the tool or its side effects.
  • Validate approval origin, purpose, review identity, verdict eligibility, and pending state before consuming an approval. Reject unknown/stale/mismatched controls without treating them as valid denial or release.

Operator and client surfaces

  • Add owner-authorized coverage/detail RPCs and bounded, transient human-readable rationale.
  • Update Mecatui and the TypeScript SDK for scoped approvals, result release, typed refusals, and retry correlation.
  • Update generated contracts, engine API snapshots/changelog, user documentation, and the cloud-native resource inventory.
  • Add a paired evaluation corpus, measurement runner/report schema, and offline capacity/stress evidence.

Compatibility and operational consequences

  • Guardrails remain opt-in, with the existing disable control and explicit advisory mode. Existing enabled deployments receive the replacement behavior and expanded default coverage.
  • Guardrails off does not mean the entire change is bypassed: shared dispatch and ordinary approval/provenance handling also change.
  • Intentional engine API changes include Run.Approve returning an error, atomic ResolveApproval, and explicit serialized approval origins replacing the previous representation. See engine/CHANGELOG.md.
  • Result release requires an explicit review/purpose acknowledgement. Older clients that cannot provide it are refused rather than permitted to release content unknowingly.
  • Held results, review details, task trajectory, and repeat grants are not restart-complete state. Lost held results produce a synthetic withholding error; completed tools are not rerun to recover them. Unknown legacy approval origins fail closed.
  • The change affects 189 files at the current head. Generated contracts and tests account for substantial churn, but handwritten production Go/TypeScript still grows by approximately 3,935 net lines. This is a substantial architectural change, not merely generated-file inflation.

Verification and evidence

At ff1245c8a40d47959e2b8cc991047ac68d7d8079, published CI completed with 30 passed, four expected skips, zero failed or pending:

  • CI: race partitions, both SDK Node versions, docs/site, API compatibility, lint, vulnerability, standalone-module and macOS portability checks.
  • Perf.
  • k8s e2e.

Recorded local verification includes full lint/race tests, docs/site, build, offline demo and benchmarks; later corrections passed affected suites. The final SDK fixture correction passed all 216 SDK tests. The macOS portability job received a 10-to-15-minute timeout adjustment for FreeBSD cross-compilation, without removing checks.

The scoped acceptance trace maps 32 ACs: 31 to executable tests and one to an inspection artifact. Prior implementation reviews reported no blocking or important findings at their checkpoint. These are verification records, not proof of complete semantic conformance, minimal design, low regression risk, or checker efficacy. The subsequent budget discrepancy below remains open.

Open issues and remaining validation

End-to-end review budget discrepancy

The plan requires a 90-second total budget including setup and evidence gathering. Source inspection found that action dependency snapshots and evidence preparation run before the timeout begins in contextualToolReviewer.Review:

  • engine/agent/actionreview.go:177 and :201 — preparation under the parent context.
  • internal/app/contextual_reviewer.go:336 — reviewer timeout begins.
  • internal/app/contextual_reviewer_protocol_test.go:184 — the budget test calls the reviewer directly and does not cover preceding preparation.

The reviewer invocation has a shared deadline and up to three attempts, but that does not establish the advertised end-to-end bound. This discrepancy needs resolution before claiming full budget-contract compliance. It was identified by source inspection; no new runtime reproduction has been run.

Checker quality is not yet established

No paid/live checker-quality comparison was authorized or run. The current corpus is a seed of ten short cases in five benign/adversarial pairs. Offline tests demonstrate protocol and safety mechanics, not reduced false positives or reliable attack detection.

Actual checker false-warning, false-block and missed-attack rates, latency, and cost remain release-validation work requiring an agreed route, spend authorization, and acceptance thresholds. This PR does not claim production efficacy or that the added intelligence has yet demonstrated its operational value.

Whole-tree acceptance tooling

The recorded whole-tree task ac-trace-strict fails because actrace v0.0.3 rejects status: proposed in the unrelated docs/acceptance/callmcpwithquery-broker-support.md. The feature-scoped trace passes; unrelated plan metadata was not changed to hide the failure.

Review focus

Review the necessity and correctness of the machinery, not only feature coverage: shared approvals with guardrails disabled; effective-action ordering and post-wait authority; bounded evidence access; cancellation/restart and exactly-once result delivery; worker ownership/privacy; and older-client behavior. Green CI does not eliminate these architectural and operational risks.

@JAORMX
JAORMX marked this pull request as ready for review September 15, 2026 11:46
@JAORMX JAORMX changed the title feat: implement contextual guardrails (stacked WIP) feat: integrate contextual guardrails into execution and approvals Sep 15, 2026
@JAORMX JAORMX added the e2e-live Run the live e2e suite on this PR label Sep 16, 2026
@JAORMX
JAORMX added this pull request to stack #1617 September 16, 2026 07:51
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch 2 times, most recently from 97bc9cd to a27173b Compare September 21, 2026 13:04
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from a27173b to f1bc5a2 Compare September 22, 2026 05:12
Comment thread engine/agent/actionreview.go Resolved
Comment thread engine/agent/dispatch.go Resolved

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

I've been hitting Inspection returned an assessment that did not satisfy the review contract locally. Left a few comments on why it happens and how we could make the checker more robust to it.

Comment thread internal/app/contextual_reviewer.go Resolved
Comment thread internal/app/contextual_reviewer.go Resolved
Comment thread internal/app/contextual_reviewer.go Resolved
Comment thread internal/app/contextual_reviewer.go Resolved
Comment thread internal/app/contextual_reviewer.go Resolved
Comment thread internal/app/contextual_reviewer.go Resolved
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from df51996 to ec6d1f5 Compare September 24, 2026 12:10
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from ec6d1f5 to 6b5810c Compare September 24, 2026 12:32
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from 6b5810c to b4b3706 Compare September 24, 2026 14:13
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from b4b3706 to 3643198 Compare September 24, 2026 15:08
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from 3643198 to 8b7fc79 Compare September 24, 2026 18:57
Comment thread internal/app/contextual_reviewer.go Resolved
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from 8b7fc79 to 61eccd6 Compare September 25, 2026 06:50
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from 61eccd6 to 143c063 Compare September 25, 2026 07:20
@JAORMX
JAORMX force-pushed the impl/contextual-guardrails-20260914 branch from 143c063 to 73be1c1 Compare September 25, 2026 08:21
Base automatically changed from plan/contextual-guardrails-20260914 to main September 25, 2026 08:39
@JAORMX
JAORMX merged commit 409ea74 into main Sep 25, 2026
38 of 40 checks passed
@JAORMX
JAORMX deleted the impl/contextual-guardrails-20260914 branch September 25, 2026 09:07
aponcedeleonch added a commit that referenced this pull request Sep 25, 2026
Main's contextual guardrails integration (#1510) removed
buildGuardrailsHooks in favour of an engine ToolReviewer, which broke the
build of this branch's configured-guardrail correlation test after rebase.
Drive the same dispatch through the real buildGuardrailsActionReviewer and
attachGuardrailReviewer wiring, and expect the reviewer's
guardrail-review- child session as the active ID while root stays intact.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Sep 25, 2026

This branch was successfully deployed

1 active deployment
Preview — c1b2ab29 Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-live Run the live e2e suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants