Skip to content

[AAASM-4782] 🐛 (openai_agents): Fail closed on governance error and never downgrade a decided deny - #273

Merged
Chisanan232 merged 2 commits into
masterfrom
v0.0.1/AAASM-4782/openai_agents_failclosed
Jul 17, 2026
Merged

[AAASM-4782] 🐛 (openai_agents): Fail closed on governance error and never downgrade a decided deny#273
Chisanan232 merged 2 commits into
masterfrom
v0.0.1/AAASM-4782/openai_agents_failclosed

Conversation

@Chisanan232

@Chisanan232 Chisanan232 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Description

openai_agents governed_invoke wrapped the check-and-deny in a broad try/except that caught any AssemblyError and then ran the tool unconditionally, with no enforce gate. Two defects:

  1. Fail-open under enforce — a governance error (e.g. GatewayError) raised by check_tool_start was swallowed, so the tool ran ungoverned even under enforce. Every other adapter (and the shared _shared/tool_governance flow) fails closed here.
  2. Deny silently downgraded — the deny branch called _record_async_tool_result before returning blocked_result, inside the same try. If that audit call raised an AssemblyError, the exception was caught and execution fell through to run the tool — turning a computed DENY into an ALLOW.

This PR makes openai_agents match the other 10 adapters:

  • In the except handler, when the error is a governance error and the posture is enforce (via the adapter's existing _interceptor_enforces signal), it now returns a blocked/deny string instead of falling through to the original invoke. Under observe/disabled the current fall-through (fail-open by design) is unchanged.
  • The deny-branch audit is routed through a guarded _record_denied_tool_result helper that swallows any audit failure, so a fault-prone audit call can never re-enter the run path and downgrade a decided deny.

Happy path and observe/disabled behavior are identical to before.

Type of Change

  • 🔧 Bug fix

Breaking Changes

  • No

Related Issues

Fixes AAASM-4782

Testing

  • Unit tests added/updated

Added regression tests under test/unit/adapters/openai_agents/:

  • S1/S2 — under enforce, a GatewayError from check_tool_start → tool BLOCKED (deny string).
  • S6 — check returns deny but record_result raises AssemblyError → tool still BLOCKED (deny not downgraded).
  • Negative control — under observe (no enforce), a governance error still fails open (tool runs), unchanged.

How to verify:

uv sync
.venv/bin/python -m pytest test/unit/adapters/openai_agents -q

Result: 45 passed. ruff check, ruff format --check, and mypy agent_assembly on the changed files are all clean.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • All tests passing

…e a deny

Under enforce, a governance error (e.g. GatewayError) from check_tool_start
was swallowed and the tool ran ungoverned; the deny branch's audit ran inside
the same handler, so a fault there fell through and downgraded a decided deny
to an allow. Mirror the other adapters: deny under enforce on a governance
fault (fall-open kept for observe/disabled), and guard the deny audit so its
failure cannot re-enter the run path.

Refs AAASM-4782
…ny integrity

Assert under enforce a GatewayError from check_tool_start blocks the tool
(S1/S2) and a deny whose audit raises AssemblyError is not downgraded (S6),
plus the observe negative control that a governance fault still fails open.

Refs AAASM-4782
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Chisanan232

Copy link
Copy Markdown
Contributor Author

Claude Code — automated review

CI: green. Scope: matches the ticket. Side effects: none — green full-suite CI (incl. build/lint/impacted tests) validates no existing-function breakage. Front-End: no FE/dashboard code touched → no Playwright validation applies. Verdict: ✅ ready to approve & merge.
Fix: openai_agents governance-error now fails closed under enforce + deny cannot be downgraded by an audit fault. 45 tests pass, negative control confirmed.

@Chisanan232
Chisanan232 merged commit 580cedc into master Jul 17, 2026
26 checks passed
@Chisanan232
Chisanan232 deleted the v0.0.1/AAASM-4782/openai_agents_failclosed branch July 17, 2026 12: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