Skip to content

test(adapters): lock in OpenAI Agents hook enforcement - #57

Merged
prashar32 merged 1 commit into
mainfrom
test/openai-agents-enforcement
Jun 4, 2026
Merged

test(adapters): lock in OpenAI Agents hook enforcement#57
prashar32 merged 1 commit into
mainfrom
test/openai-agents-enforcement

Conversation

@prashar32

Copy link
Copy Markdown
Owner

Context

The LangChain fix (#55) found that an SDK can silently swallow a budget halt raised inside a callback. The OpenAI Agents adapter raises halts from its async RunHooks (on_agent_startrun.step(), on_tool_start → approval gate) — the same raise-in-a-hook pattern — so it deserved the same scrutiny.

Finding: no bug here

The OpenAI Agents SDK awaits hooks via await asyncio.gather(hooks.on_agent_start(...), ...) without return_exceptions=True, so an exception raised in a hook propagates out of Runner.run. I verified this directly (a hook raising a sentinel propagates out of a real Runner.run). No adapter change needed — unlike LangChain, nothing is swallowed.

What this PR adds

The adapter was correct but untested (the same gap LangChain had before #55). Three tests in test_sdk.py:

  • test_openai_agents_hooks_enforce_loop_budget — one agent turn == one governed step; the loop budget halts at the cap (BudgetExceeded). CI-safe (the adapter falls back to an object base when agents isn’t installed).
  • test_openai_agents_hooks_gate_denied_tool — a denied tool raises ApprovalDenied.
  • test_openai_agents_integration_halts_run@skipUnless(openai-agents installed): runs a real Runner.run with a fake model (no API key) and asserts the budget halt propagates out and stops the agent. This is the regression guard for the SDK’s propagation behavior.

Verification

  • With openai-agents 0.17.4 (py3.12): all 15 SDK tests pass, including the integration test.
  • Bare (py3.12, the CI matrix): 13 pass, 2 integration tests skip, no warnings.

The OpenAI Agents adapter raises budget halts (BudgetExceeded) and approval
denials (ApprovalDenied) from its async RunHooks — the same raise-in-a-hook
pattern that silently no-opped in the LangChain adapter until it set raise_error.

Checked whether the OpenAI Agents SDK has the same flaw: it does not. Runner.run
awaits hooks via asyncio.gather without return_exceptions, so a halt raised in
on_agent_start propagates out and stops the run — verified directly. No adapter
change needed.

But the adapter was untested. Added a unit test (one agent turn == one governed
step; the loop budget halts at the cap), a tool-gating test (a denied tool raises
ApprovalDenied), and a skip-unless-openai-agents integration test that runs a real
agent with a fake model and asserts the halt propagates out of Runner.run —
guarding the SDK's propagation behavior against a future regression.
@prashar32
prashar32 merged commit ad8ba0a into main Jun 4, 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