Skip to content

Opt dare - #120

Merged
bouillipx merged 6 commits into
mainfrom
opt_dare
Feb 28, 2026
Merged

Opt dare#120
bouillipx merged 6 commits into
mainfrom
opt_dare

Conversation

@bouillipx

Copy link
Copy Markdown
Collaborator

Summary

  • What does this PR change?
  • Why is this change needed?

Scope (One PR One Thing)

  • Primary objective:
  • Out of scope:
  • I confirm this PR handles a single objective only: [ ] Yes

Changed Files (required)

List all touched files and why each file changed.

File Reason
path/to/file reason

If this PR is a large diff (>300 changed lines), explain why split PRs are not possible and provide a split follow-up plan.

Acceptance Criteria

  • Criteria 1
  • Criteria 2

Test Evidence (required)

  • Local commands run:
    • ...
  • CI links or job names:
    • ...
  • Evidence/output summary:
    • ...

If this PR changes high-risk runtime paths (auth/concurrency/execution control), include risk-matrix evidence.

Risk and Rollback

  • Risk level: Low / Medium / High
  • Main risk points:
  • Rollback plan:

Dependency and Lockfile Changes

  • Lockfile changed in this PR: [ ] Yes [ ] No
  • If yes, manifest updated in same PR (requirements.txt/pyproject.toml/package.json): [ ] Yes [ ] No [ ] N/A

Agent Rules Checklist (required)

Reference: docs/agent_rules.md

  • Only task-related files changed; no opportunistic refactor
  • Public interfaces/data structures unchanged unless explicitly required
  • Tests added/updated and evidence attached
  • Any skip/only/exclude usage is explained and reviewed
  • Merge will be done by approved reviewer (no self-merge auto-ship)

Implement the p0-enforce-security-boundary change end-to-end across runtime wiring, policy mapping, auditability, and release gates.

Key changes:

- Add default security boundary implementations (no-op + policy) and structured security error codes.

- Add DareAgentBuilder security boundary injection via with_security_boundary() and config-driven resolution (default policy, optional noop).

- Enforce security preflight in DareAgent tool loop: verify_trust -> check_policy before any gateway invoke.

- Map policy decisions deterministically: ALLOW continues, APPROVE_REQUIRED enters approval memory flow, DENY blocks with stable status/code/message payload.

- Extend GovernedToolGateway with force_approval, approval_reason, and approval_observer so policy-triggered approval reuses existing approval memory control plane.

- Emit structured security audit events (security.trust_verified, security.policy_checked, security.policy_denied, security.policy_approval) with capability/tool correlation fields.

- Tighten RegistryPlanValidator to fail when trusted risk metadata is missing/invalid rather than silently defaulting.

- Add security config surface to Config (from_dict/to_dict) and builder tests for config/override behavior.

- Expand tests: unit coverage for allow/deny/approve_required paths, boundary defaults, gateway observer integration, trusted metadata validation; add integration flow proving high-risk tools are gated before invocation.

- Add the new security gate test group to scripts/ci/run_risk_matrix.sh as a release gate.

Additional fix included:

- Harden event_trace_bridge OpenTelemetry compatibility by supporting both property- and method-style is_valid APIs to avoid runtime crashes during event append.

Validation executed locally:

- .venv/bin/python -m pytest -q tests/unit/test_security_boundary.py tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_builder_security_boundary.py tests/unit/test_governed_tool_gateway.py tests/unit/test_registry_plan_validator.py tests/unit/test_config_model.py tests/integration/test_security_policy_gate_flow.py

- .venv/bin/python -m pytest -q tests/unit/test_five_layer_agent.py
…, and step-driven execution

Add OpenSpec change artifacts to drive the remaining P0 workstreams in a structured, reviewable workflow.

Scope:

- Add full change artifacts (.openspec.yaml, proposal, design, specs, tasks) for p0-conformance-gate.

- Add full change artifacts for p0-default-eventlog.

- Add missing OpenSpec metadata/design/spec docs for p0-enforce-security-boundary so implementation and tasks are fully traceable.

- Add full change artifacts for p0-step-driven-execution.

Rationale:

- Capture explicit requirements and contracts before implementation to reduce ambiguity and regression risk.

- Keep P0 tracks independently auditable with per-change design, requirement deltas, and executable task checklists.

- Enable deterministic follow-up implementation via openspec apply/verify/archive workflow.

Notes:

- This commit is documentation/spec only; no runtime source code behavior changes are introduced.
Resolve the GitHub conflict on opt_dare by merging origin/main into the branch in an isolated worktree.

Key changes:
- keep the opt_dare security-boundary builder and runtime preflight work intact
- keep main's tool disable propagation, approval/session_id CLI flow, and runtime cleanup changes
- resolve the event_trace_bridge conflict by preserving the OpenTelemetry is_valid compatibility handling from main
- drop trailing blank-line noise from the newly added mailbox docs brought in from main

Verification:
- .venv/bin/python -m pytest tests/unit/test_builder_security_boundary.py tests/unit/test_config_model.py tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_governed_tool_gateway.py tests/unit/test_security_boundary.py tests/unit/test_builder_manager_resolution.py tests/unit/test_client_cli.py tests/unit/test_examples_cli.py tests/unit/test_examples_cli_mcp.py tests/unit/test_tool_approval_action_handler.py tests/unit/test_tool_approval_manager.py -q
- git diff --cached --check
@bouillipx

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 40fbdc3587

ℹ️ 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 dare_framework/agent/dare_agent.py Outdated
Comment thread dare_framework/agent/builder.py
Address the P1 review finding on PR #120.

The tool preflight path was passing envelope risk defaults into verify_trust. Because ToolLoopRequest creates a default Envelope with read_only risk, strict PolicySecurityBoundary mode could incorrectly derive a trusted risk level even when the capability descriptor had no trusted risk metadata.

Changes:
- stop forwarding envelope risk fields into the trust-derivation context in DareAgent._evaluate_tool_security
- add a regression test proving strict trust mode rejects a capability that lacks trusted risk metadata even when the request uses the default envelope

Why this shape:
- policy evaluation still receives the trusted risk derived from the boundary result
- strict mode now behaves consistently with RegistryPlanValidator and PolicySecurityBoundary.require_trusted_metadata expectations

Verification:
- .venv/bin/python -m pytest tests/unit/test_dare_agent_security_policy_gate.py::test_strict_policy_boundary_rejects_missing_trusted_risk_metadata_even_with_default_envelope -q
- .venv/bin/python -m pytest tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_security_boundary.py tests/unit/test_builder_security_boundary.py tests/unit/test_config_model.py tests/unit/test_governed_tool_gateway.py tests/unit/test_registry_plan_validator.py -q
- git diff --check
@bouillipx

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 9f8c2439fc

ℹ️ 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 dare_framework/agent/builder.py
Resolve the new merge conflicts caused by origin/main advancing after the prior PR sync.

Keep the step-driven execution and execute_safe wiring from main while preserving the security-boundary policy gate behavior from opt_dare.

Key conflict resolutions:
- keep DareAgentBuilder execution_mode and step_executor wiring while retaining config-driven security boundary resolution
- preserve strict tool security preflight and structured policy errors in DareAgent
- stop trusting default tool-loop envelope risk metadata, but continue trusting validated step risk metadata in step-driven execution
- expose DefaultSecurityBoundary, PolicySecurityBoundary, NoOpSecurityBoundary, and security errors from the security facade for compatibility
- add a regression test covering strict trusted-metadata enforcement in step-driven mode

@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: c7a68090ad

ℹ️ 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 dare_framework/security/__init__.py
Comment thread dare_framework/agent/builder.py Outdated
Merge origin/main into the PR branch while preserving the policy-gated tool loop behavior added on opt_dare.

Key changes:
- keep the new DareAgent orchestration split and output envelope normalization from main
- move the reviewed tool-loop security preflight flow into the new internal tool executor so trust verification, policy decisions, approval escalation, and step-driven trusted risk metadata keep working after the refactor
- treat config.security.boundary=null as unset so templated/null config values do not silently select the noop security boundary
- add regression coverage for null boundary config, orchestration delegation, step-driven trusted risk propagation, and output envelope behavior

Verification:
- .venv/bin/python -m pytest tests/unit/test_builder_security_boundary.py tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_dare_agent_step_driven_mode.py tests/unit/test_dare_agent_orchestration_split.py tests/unit/test_agent_output_envelope.py tests/unit/test_output_normalizer.py -q
- python3 -m py_compile dare_framework/agent/dare_agent.py dare_framework/agent/_internal/tool_executor.py dare_framework/agent/builder.py tests/unit/test_builder_security_boundary.py tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_dare_agent_step_driven_mode.py tests/unit/test_dare_agent_orchestration_split.py

Notes:
- git diff --cached --check still reports pre-existing trailing whitespace in openspec/changes/unify-agent-output-envelope/{design,proposal}.md from origin/main; no code files fail the check.
@bouillipx

Copy link
Copy Markdown
Collaborator Author

Follow-up on the latest review round after merging origin/main into opt_dare at 7db0adc:

  • Fixed the config.security.boundary = null case in DareAgentBuilder._resolve_security_boundary(). None/empty values now fall back to the default policy boundary instead of being coerced into the noop boundary path, and there is a regression test in tests/unit/test_builder_security_boundary.py covering the null-config case.
  • Kept the new orchestration split from main, but moved the reviewed tool-loop security preflight behavior into dare_framework/agent/_internal/tool_executor.py so the earlier trust/policy/approval fixes still apply after the refactor.
  • I did not change dare_framework/security/__init__.py to make DefaultSecurityBoundary policy-backed in this PR. The current design/docs still treat DefaultSecurityBoundary as the permissive baseline facade for direct/default construction, while the builder default is the policy boundary. Changing the facade alias here would change that public default contract rather than just aligning the builder path.

Local verification run on this head:

  • .venv/bin/python -m pytest tests/unit/test_builder_security_boundary.py tests/unit/test_dare_agent_security_policy_gate.py tests/unit/test_dare_agent_step_driven_mode.py tests/unit/test_dare_agent_orchestration_split.py tests/unit/test_agent_output_envelope.py tests/unit/test_output_normalizer.py -q
  • Result: 55 passed, 1 warning

Note: git diff --cached --check still reports trailing whitespace in openspec/changes/unify-agent-output-envelope/{design,proposal}.md from the merged main changes, but no code files fail that check.

@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: 7db0adcaf0

ℹ️ 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 on lines +94 to +96
before_tool_dispatch = await agent._emit_hook(
HookPhase.BEFORE_TOOL,
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Run security preflight before emitting BEFORE_TOOL hook

BEFORE_TOOL is now emitted before _evaluate_tool_security, so the hook payload can report requires_approval=False and a stale risk level for calls that policy later upgrades to APPROVE_REQUIRED (for example high-risk tools with requires_approval false in descriptor metadata). This regresses hook consumers that rely on these fields for correctness, including the tracing hook (dare_framework/observability/_internal/tracing_hook.py) which records dare.tool.requires_approval from BEFORE_TOOL; those traces/metrics become inaccurate for policy-gated calls.

Useful? React with 👍 / 👎.

@bouillipx
bouillipx merged commit f2fc7ff into main Feb 28, 2026
7 checks passed
@bouillipx
bouillipx deleted the opt_dare branch February 28, 2026 06:55
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