Skip to content

Add fail-closed OpenAI Agents adapter - #36

Merged
Deathcharge merged 2 commits into
mainfrom
codex/openai-agents-adapter
Aug 2, 2026
Merged

Add fail-closed OpenAI Agents adapter#36
Deathcharge merged 2 commits into
mainfrom
codex/openai-agents-adapter

Conversation

@Deathcharge

Copy link
Copy Markdown
Owner

What changed

  • add an optional, dependency-isolated OpenAI Agents SDK adapter for strict top-level FunctionTool objects
  • route Samsarix review outcomes into native SDK interruptions and re-enforce with fresh application facts immediately before execution
  • persist the first exact-call fingerprint before interruption so missing, changed, unrelated, sticky-only, and rejected approvals fail closed
  • preserve existing SDK guardrails and approval logic, add a bounded in-memory store plus an application-owned durable store protocol
  • add an exact openai-agents==0.18.3 hashed integration lane, a no-network example, and public architecture/security/adoption documentation

Why

The core library had strong framework-neutral tool gating but no public, reproducible integration with a popular agent runtime. This closes that credibility and adoption gap without adding runtime dependencies to the base package or overstating unsupported hosted/built-in execution paths.

Validation

  • python -m pytest -q — 517 passed, 95.75% branch-aware coverage
  • python -m ruff format --check .
  • python -m ruff check .
  • python -m mypy
  • real SDK contract against the hash-locked openai-agents==0.18.3 graph
  • no-network OpenAI Agents example
  • wheel and source build plus twine check
  • isolated base-wheel import with no agents distribution installed and no unconditional dependencies
  • rebuilt wheel installed into the locked SDK environment; approval, mutation, coercion, and example paths passed

Boundaries

This adapter covers strict top-level Python FunctionTool objects only. Hosted and built-in tools, MCP-hosted tools, handoffs, namespaces, and Agent.as_tool() remain outside this interception path and are documented as such.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Deathcharge, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5bea02b4-d2a1-48e9-a568-6c7c6b656476

📥 Commits

Reviewing files that changed from the base of the PR and between 5f1cad3 and e2253b2.

📒 Files selected for processing (10)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • docs/API.md
  • docs/ARCHITECTURE.md
  • docs/OPENAI_AGENTS.md
  • integration_tests/test_openai_agents_sdk.py
  • pyproject.toml
  • src/samsarix_ethics/openai_agents.py
  • tests/test_openai_agents.py

Summary by CodeRabbit

  • New Features

    • Added an optional OpenAI Agents SDK integration for protecting supported tools with existing guardrails and approval workflows.
    • Added fail-closed behavior, exact-call approval binding, argument validation, and bounded approval tracking.
    • Added a network-free integration example.
  • Documentation

    • Added installation, configuration, security, architecture, API, and supported-boundary guidance.
  • Tests

    • Added comprehensive SDK integration and contract coverage, including approval, mutation, validation, and failure scenarios.

Walkthrough

Changes

OpenAI Agents SDK integration

Layer / File(s) Summary
Adapter enforcement and public API
src/samsarix_ethics/openai_agents.py, src/samsarix_ethics/__init__.py
Adds strict FunctionTool protection, fail-closed guardrails, approval fingerprint storage, integration errors, and public exports.
Adapter validation coverage
tests/test_openai_agents.py, tests/test_public_api.py
Tests dependency loading, tool validation, approval routing, fingerprint binding, context refresh, bounded storage, and failure handling.
SDK contract and runnable example
integration_tests/test_openai_agents_sdk.py, examples/openai_agents_guardrail_demo.py, pyproject.toml, requirements-openai-agents.txt, .github/workflows/ci.yml
Adds the pinned SDK contract, optional dependency configuration, CI verification, and a no-network integration example.
Integration documentation and release records
README.md, docs/*.md, SECURITY.md, CHANGELOG.md, ROADMAP.md
Documents installation, approval behavior, supported boundaries, security requirements, adoption evidence, and productization status.

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

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant OpenAIAgentsToolPolicy
  participant FunctionTool
  participant BoundToolGate
  participant ApprovalStore
  Application->>OpenAIAgentsToolPolicy: protect FunctionTool
  OpenAIAgentsToolPolicy->>FunctionTool: install input guardrail
  FunctionTool->>OpenAIAgentsToolPolicy: provide raw tool arguments
  OpenAIAgentsToolPolicy->>BoundToolGate: evaluate policy and approval
  OpenAIAgentsToolPolicy->>ApprovalStore: store or retrieve call fingerprint
  OpenAIAgentsToolPolicy->>FunctionTool: allow or block execution
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: a fail-closed OpenAI Agents adapter.
Description check ✅ Passed The description explains the change, security and compatibility boundaries, dependencies, verification, and documentation updates.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/openai-agents-adapter

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.

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

Actionable comments posted: 5

🤖 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 @.github/workflows/ci.yml:
- Around line 463-472: The contract dependency installation must reference an
existing requirement artifact consistently. In .github/workflows/ci.yml lines
463-472, update the cache dependency path and install command to use the chosen
requirement filename; in requirements-openai-agents.txt lines 1-2, either
replace it with a fully hashed lock file named requirements-openai-agents.lock,
or rename it consistently and remove --require-hashes from the workflow,
ensuring all direct and transitive requirements are covered.
- Around line 473-474: Update the “Test exact OpenAI Agents SDK contract” step
in the CI workflow to also execute examples/openai_agents_guardrail_demo.py
after installing the SDK, while preserving the existing integration test command
so this SDK-specific job validates both the adapter contract and the example.

In `@docs/OPENAI_AGENTS.md`:
- Around line 15-17: Limit the documented openai-agents support range to the
tested version by updating the SDK dependency declaration and corresponding
documentation from the broad >=0.18.3,<0.19 range to exactly 0.18.3. Keep the
existing contract-test setup aligned with that pinned version.

In `@integration_tests/test_openai_agents_sdk.py`:
- Around line 100-112: Add a concise comment immediately before the
on_invoke_tool assertion explaining that direct adapter calls bypass
input-guardrail enforcement, while the SDK runner enforces the blocked
raise_exception result; preserve the existing assertion and behavior.

In `@src/samsarix_ethics/openai_agents.py`:
- Around line 29-79: Add a lifecycle method such as forget or complete to
OpenAIAgentsApprovalStore and implement it in _InMemoryApprovalStore to remove
the (tool_name, tool_call_id) entry safely under the existing lock. Invoke this
method after the guardrail resolves a reviewed call, and ensure the
MAX_PENDING_OPENAI_APPROVALS failure is recorded or surfaced rather than
swallowed by _needs_approval.
🪄 Autofix (Beta)

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b87cde6d-9da5-41d9-9bd5-9a121d432442

📥 Commits

Reviewing files that changed from the base of the PR and between c8e8824 and 5f1cad3.

⛔ Files ignored due to path filters (1)
  • requirements-openai-agents.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • ROADMAP.md
  • SECURITY.md
  • docs/ADOPTION.md
  • docs/API.md
  • docs/ARCHITECTURE.md
  • docs/OPENAI_AGENTS.md
  • docs/PRODUCTIZATION.md
  • examples/openai_agents_guardrail_demo.py
  • integration_tests/test_openai_agents_sdk.py
  • pyproject.toml
  • requirements-openai-agents.txt
  • src/samsarix_ethics/__init__.py
  • src/samsarix_ethics/openai_agents.py
  • tests/test_openai_agents.py
  • tests/test_public_api.py

Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml
Comment thread docs/OPENAI_AGENTS.md Outdated
Comment thread integration_tests/test_openai_agents_sdk.py
Comment thread src/samsarix_ethics/openai_agents.py
@Deathcharge
Deathcharge merged commit 28b7f2c into main Aug 2, 2026
7 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