Skip to content

fix: avoid duplicate async authentication calls - #1755

Merged
vitalik merged 1 commit into
vitalik:masterfrom
tunglambk:agent/fix-async-auth-double-call
Sep 14, 2026
Merged

vitalik merged 1 commit into
vitalik:masterfrom
tunglambk:agent/fix-async-auth-double-call

Conversation

@tunglambk

Copy link
Copy Markdown
Contributor

Summary

  • await the coroutine returned by the first invocation of an async-marked authentication callback
  • add regression coverage for async bearer authentication on a synchronous endpoint
  • verify the callback runs once and emits no warnings

Root cause

The synchronous authentication path called an async-marked callback once to inspect its return value. When that value was a coroutine, it discarded the coroutine and invoked the callback a second time through async_to_sync. This duplicated synchronous work in __call__ and emitted both an un-awaited coroutine warning and an async_to_sync warning.

The fix bridges the coroutine returned by the first invocation instead of invoking the callback again.

Fixes #1751.

Validation

  • .venv/bin/pytest -q tests/test_auth_async.py — 8 passed
  • .venv/bin/pytest -q tests/test_auth.py — 34 passed
  • .venv/bin/ruff format --check ninja/operation.py tests/test_auth_async.py
  • .venv/bin/ruff check ninja/operation.py tests/test_auth_async.py
  • .venv/bin/mypy ninja/operation.py

@tunglambk
tunglambk marked this pull request as ready for review August 14, 2026 10:04
@vitalik
vitalik merged commit 7d2a27a into vitalik:master Sep 14, 2026
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.

[BUG] An async authenticator is called twice on a synchronous operation

2 participants