Skip to content

fix: scope one-shot event handlers to registrations - #3741

Open
Hughhhhcoder wants to merge 2 commits into
openai:mainfrom
Hughhhhcoder:codex/openai-python-event-handler-once
Open

fix: scope one-shot event handlers to registrations#3741
Hughhhhcoder wants to merge 2 commits into
openai:mainfrom
Hughhhhcoder:codex/openai-python-event-handler-once

Conversation

@Hughhhhcoder

@Hughhhhcoder Hughhhhcoder commented Aug 27, 2026

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

EventHandlerRegistry tracks one-shot handlers by callback identity, so registering the same callback for two event names lets the first event consume the one-shot registration for the other event.

Reproduction

  1. Register the same callback persistently for persistent.
  2. Register it once for one-shot.
  3. Dispatch both events.

Expected: the one-shot registration is consumed only by one-shot, while the persistent registration remains available for persistent.

Actual: callback identity is shared across event names, so dispatching one event can suppress the other registration.

Root cause and changes

The registry stored callbacks separately from a registry-wide set of callback IDs. That set could not represent the event name or the registration mode for duplicate registrations.

  • Store the one-shot flag with each event registration.
  • Preserve registration modes when merging registries.
  • Keep removal scoped to the first matching registration, as before.
  • Preserve identity-first removal before invoking overloaded equality.
  • Add regression coverage for cross-event registration, duplicate removal, merge behavior, and callable objects with custom equality.

Additional context & links

Validation

  • uv run --no-project --with-editable . --with pytest python -m pytest -c /dev/null --rootdir=. --noconftest -o addopts='' -q tests/test_event_handler.py — 4 passed.
  • ruff check src/openai/_event_handler.py tests/test_event_handler.py — passed.
  • ruff format --check src/openai/_event_handler.py tests/test_event_handler.py — passed.
  • Current-head Codex code and security reviews found no issues.

This is an internal registry-state correction. No public API signatures or event payloads change.

@Hughhhhcoder
Hughhhhcoder requested a review from a team as a code owner August 27, 2026 06:37
@Hughhhhcoder

Copy link
Copy Markdown
Author

Focused regression tests and repository formatting checks pass on the current head (7d8fc3d). @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7d8fc3d0bd

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

ℹ️ 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 src/openai/_event_handler.py Outdated
@Hughhhhcoder

Copy link
Copy Markdown
Author

The P2 identity-removal feedback is addressed in the current head (da89e62), with a focused regression test. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: da89e625fa

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: da89e625fa

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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