Skip to content

Bound context scans and bind audit-event content - #42

Merged
yui-stingray merged 3 commits into
masterfrom
codex/harden-context-and-event-binding
Aug 13, 2026
Merged

Bound context scans and bind audit-event content#42
yui-stingray merged 3 commits into
masterfrom
codex/harden-context-and-event-binding

Conversation

@yui-stingray

@yui-stingray yui-stingray commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • run repository-controlled context-regex matching in an isolated bounded process, with sanitized fail-closed timeout and runtime-failure results
  • bind reviewed repo-local agent-policy audit events by canonical JSON content, an explicit profile, and a public-safe portable digest
  • require packaged consumers of bound audit-event entries to receive the event and profile separately and verify the binding; document additive v1 compatibility and the replacement threat boundary
  • cover POSIX and Windows path boundaries plus lossless JSON-number canonicalization without embedding the event body

Verification

  • full pytest suite
  • focused context, evidence-pack, consumer, and Windows-boundary suites
  • AGB: 60 self-authored local regression cases; TP 55, FP 3, FN 0
  • self-dogfood gates and packaged consumer
  • changelog, actionlint, package build, Twine 7 metadata check, and wheel contract

Boundary check

  • No network access added
  • Scanner roots stay explicit and invalid policy input fails closed
  • CLI exit-code contract remains compatible

Scope

This does not add runtime MCP or OAuth validation, semantic agent-policy audit-event schema validation, generic secret scanning, or producer authentication.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds bounded context-policy loading and regex scanning. It also replaces path-only audit-event references with profile-bound canonical JSON digests, secure artifact handling, producer integration, consumer verification, schemas, documentation, and expanded platform and contract tests.

Changes

Audit-event content binding

Layer / File(s) Summary
Audit-event binding contract
src/agent_guard/evidence_pack.py, src/agent_guard/schemas/*
Audit-event files use validated profiles, canonical JSON, repository-safe reads, SHA-256 Base32 bindings, and strict manifest schemas.
Producer CLI integration and validation
src/agent_guard/cli/*, tests/cli/*, scripts/check_wheel_contract.py, tests/test_windows_file_boundaries.py, .github/workflows/ci.yml
Report and evidence-pack commands accept profiles and emit validated audit-event artifacts. Tests cover path handling, malformed JSON, limits, races, symlinks, and nested basenames.
Consumer-side event verification
src/agent_guard/consumer/*, tests/test_evidence_consumer.py, tests/test_evidence_contract_examples.py
Consumers validate supplied event files against manifest paths, profiles, and content bindings for reports and bundles.
Audit-event contract documentation
README.md, docs/compatibility.md, docs/evidence-contracts.md, docs/quickstart-existing-repo.md, CHANGELOG.md
Documentation describes profile-bound digests, separate event verification, fail-closed handling, and exclusion of event bodies from public evidence.

Bounded context-policy scanning

Layer / File(s) Summary
Bounded policy loading and scanning
src/agent_guard/context_guard.py, tests/test_context_guard.py, docs/compatibility.md, CHANGELOG.md
Policy loading and regex scanning enforce byte, nesting, count, length, and execution-time limits with standardized sanitized errors.

Test environment isolation

Layer / File(s) Summary
Isolated tag-step environment
tests/test_workflow_hardening.py
Tag-step subprocesses now use a temporary HOME directory.

Estimated code review effort: 4 (Complex) | ~60 minutes

Mergeability Score: 🟡 Moderate · up to 96269

Invalid context-policy values can currently fall back to default scanning instead of failing closed, while published evidence contracts and documentation can disagree with packaged validation for audit-event bundles. This can produce inconsistent repository scanning and event-binding behavior, so the PR needs fixes or explicit owner acceptance before merge.

Possibly related PRs

Poem

A rabbit checks each digest bright,
With nested paths kept safe and right.
Regex bounds guard every hop,
Events stay out of public cop.
Profiles match, then tests all cheer—
“A tidy evidence trail is here!”

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes both primary changes: bounded context scans and audit-event content binding.
Description check ✅ Passed The description covers the summary, validation results, boundary checks, scope, and documentation updates, with only minor template wording differences.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/harden-context-and-event-binding

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96269a0e9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agent_guard/evidence_pack.py Outdated

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 359-361: Align both documentation sites with the conditional
behavior of _validate_evidence_bundle: update README.md lines 359-361 and
docs/quickstart-existing-repo.md lines 280-284 to state that the standalone
manifest is required only if present, rather than unconditionally required. No
consumer code change is needed.

In `@src/agent_guard/consumer/_bindings.py`:
- Around line 36-66: Add a concise docstring to
validate_agent_policy_audit_event_files documenting that each paths[i] is
positionally paired with the i-th manifest artifact whose role is
agent-policy-audit-event, preserving the required ordering contract at the API
boundary.

In `@src/agent_guard/context_guard.py`:
- Around line 349-354: Update the YAML loading flow around load_bounded_yaml in
the context-policy scan so only a None result is replaced with an empty mapping.
Validate all other loaded values, including falsy non-mappings such as lists,
false, zero, and empty strings, with the existing isinstance(loaded, dict) check
so they raise BoundedYamlInvalidError and preserve ERROR_CONTEXT_POLICY_INVALID
behavior.

In `@src/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.json`:
- Around line 77-103: Require content_binding for artifacts whose role is
agent-policy-audit-event by adding the same role-based allOf conditional to the
artifact item schemas at
src/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.json lines
77-103 and src/agent_guard/schemas/agent-guard.report_evidence.v1.schema.json
lines 309-336; leave report artifacts unaffected.

In `@tests/test_evidence_consumer.py`:
- Around line 103-106: Update the anchored match patterns in the pytest.raises
calls near the existing ValueError assertions, including both occurrences, to
use raw string literals while preserving the exact ^...$ patterns and error
text.

In `@tests/test_evidence_contract_examples.py`:
- Around line 478-479: Add an assertion in the missing-event/missing-metadata
test case that missing_event_result.stdout is empty, matching the negative-path
assertions for wrong-profile and replaced-content cases while preserving the
existing returncode and stderr checks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a68faf1f-8cb9-45eb-ba2a-378139738ff1

📥 Commits

Reviewing files that changed from the base of the PR and between 0b4f985 and 96269a0.

📒 Files selected for processing (28)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • docs/compatibility.md
  • docs/evidence-contracts.md
  • docs/evidence-samples/agent-guard-report.json
  • docs/quickstart-existing-repo.md
  • scripts/check_wheel_contract.py
  • src/agent_guard/cli/evidence_pack.py
  • src/agent_guard/cli/report.py
  • src/agent_guard/consumer/__init__.py
  • src/agent_guard/consumer/_bindings.py
  • src/agent_guard/consumer/_bundle.py
  • src/agent_guard/consumer/_cli.py
  • src/agent_guard/consumer/_sections.py
  • src/agent_guard/context_guard.py
  • src/agent_guard/evidence_pack.py
  • src/agent_guard/schemas/agent-guard.evidence_pack_manifest.v1.schema.json
  • src/agent_guard/schemas/agent-guard.report_evidence.v1.schema.json
  • tests/cli/test_evidence_pack.py
  • tests/cli/test_report_output.py
  • tests/test_context_guard.py
  • tests/test_contract_stability.py
  • tests/test_docs_contract.py
  • tests/test_evidence_consumer.py
  • tests/test_evidence_contract_examples.py
  • tests/test_windows_file_boundaries.py
  • tests/test_workflow_hardening.py

Comment thread README.md Outdated
Comment thread src/agent_guard/consumer/_bindings.py
Comment thread src/agent_guard/context_guard.py
Comment thread tests/test_evidence_consumer.py
Comment thread tests/test_evidence_contract_examples.py
@yui-stingray
yui-stingray merged commit 9920904 into master Aug 13, 2026
13 checks passed
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.

1 participant