Skip to content

fix: support synchronous guardrails inside running event loops - #149

Merged
jbeckwith-oai merged 2 commits into
mainfrom
fix/sync-guardrails-running-loop
Oct 26, 2026
Merged

jbeckwith-oai merged 2 commits into
mainfrom
fix/sync-guardrails-running-loop

Conversation

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

This pull request fixes synchronous Guardrails calls made while an event loop is already running, including notebooks and synchronous helpers invoked by async handlers. Both synchronous clients execute configured guardrails in a scoped worker with copied request context, while retaining the existing idle-loop behavior and tripwire/suppression semantics.

Synchronous Moderation fallback now constructs, uses and closes a native synchronous client inside its worker. Async-client and no-context fallback behavior stays the same. Custom checks that require caller-loop resources should use the asynchronous clients.

Addresses the scenario reported in #131. Includes real SDK contracts for OpenAI/Azure, Chat/Responses, streaming, repeated calls and tripwires, plus a repeated fallback check with a real loopback HTTP connection pool.

Validation: formatting, Ruff, mypy, pyright and the full test suite pass. Two consecutive independent adversarial review rounds were clean.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T21:09:03.311282Z ed4414f Manual request
🔒 Security Review ✅ Completed 2026-10-26T21:04:03.004290Z ed4414f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread tests/unit/test_client_sync.py Fixed

Copy link
Copy Markdown
Contributor Author

@codex review

Please review the current head ed4414f. The follow-up replaces a bare Future await in the context regression test with a scheduled asyncio.Event; runtime code is unchanged. Current-head CI and security review pass, and the code-quality feedback is fixed and resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ed4414f142

ℹ️ 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".

@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit d9c89bb Oct 26, 2026
8 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the fix/sync-guardrails-running-loop branch October 26, 2026 21:13
@openai-sdks openai-sdks Bot mentioned this pull request Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge validation: merge-queue integration checks passed, and CI on main is also green: https://github.com/openai/openai-guardrails-python/actions/runs/40402499049 .

The docs deployment fails during Setup uv because its cache glob expects an uncommitted uv.lock (No file matched to [**/uv.lock]): https://github.com/openai/openai-guardrails-python/actions/runs/40402499143 . This is the same pre-existing failure seen before this work (https://github.com/openai/openai-guardrails-python/actions/runs/37715113582) and after the preceding release (https://github.com/openai/openai-guardrails-python/actions/runs/40400735123). The docs workflow cache configuration needs a separate follow-up to match tracked dependency files.

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.

2 participants