fix(common/misc_utils): allow once decorator retries after failure (#16174)

### What problem does this PR solve?
`common/misc_utils.once` set `executed=True` before invoking the wrapped
function, so an exception on the first call permanently disabled future
calls and returned the cached `None`.

This change marks `executed=True` only after a successful call, allowing
retries after transient failures while preserving once-only behavior
after success. It also adds regression tests for retry-after-exception
and thread-safe single execution.

### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Harsh Kashyap <harshkashyap@Harshs-MacBook-Pro.local>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Harsh Kashyap
2026-07-31 20:13:18 +05:30
committed by GitHub
parent 1b5ce4c27e
commit d67d14e4c6
2 changed files with 74 additions and 2 deletions

View File

@@ -224,8 +224,8 @@ def once(func):
nonlocal executed, result
with lock:
if not executed:
executed = True
result = func(*args, **kwargs)
executed = True
return result
return wrapper