fix(run_agent): acquire lock in IterationBudget.used property

The `used` property was reading `self._used` without holding the lock,
while `consume()`, `refund()`, and `remaining` all properly acquire
`self._lock` before accessing `_used`. This means a concurrent call to
`used` during `consume()` or `refund()` could observe a partially-
updated value, leading to incorrect iteration budget metrics reported
to the gateway, or in extreme cases a ValueError from CPython's list
implementation when the internal array resizes during iteration.

Fix: acquire the lock in `used` just like `remaining` does.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ricardo-M-L 2026-04-27 00:28:59 +08:00 committed by Teknium
parent 64ad7dec0d
commit fbc477df71
2 changed files with 111 additions and 1 deletions

View file

@ -304,7 +304,8 @@ class IterationBudget:
@property
def used(self) -> int:
return self._used
with self._lock:
return self._used
@property
def remaining(self) -> int: