auth_budget
Give-up policy for EHR requests the server keeps rejecting as unauthenticated.
A single place decides how many authentication failures in a row may happen
before a run is abandoned, so the worker algorithms, the DAG query steps and
FHIRClient's per-patient callers cannot disagree about it.
This is a give-up policy, not a retry policy: FHIRClient already
force-refreshes its token and retries once per request, so a failure that
reaches the budget has already survived a fresh token. A run of them means
the credentials themselves are wrong, and continuing produces one warning per
patient — tens of thousands for a large cohort — followed by an empty result
set that reads as "this cohort has no EHR data" rather than "the EHR rejected
us".
Counting a failure and acting on the count are separate, so a failure can be counted where the run cannot be stopped, such as inside one request, and acted on where it can, such as before the next patient is looked up.
Classes
AuthFailureBudget
class AuthFailureBudget(limit: int = 3):Tracks consecutive EHR authentication failures.
Arguments
limit: How many consecutive failures are tolerated before the budget is exhausted.
Variables
consecutive_failures : int- Failures recorded since the last success.
Methods
check
def check(self, cause: BaseException | None = None) ‑> None:Abort the run if the budget is spent.
Arguments
cause: The authentication error that led here, if any, chained onto the raisedEHRConnectionErrorso the original response survives.
Raises
EHRConnectionError: If the failures counted since the last success have reached the limit.
count_failure
def count_failure(self) ‑> None:Count an authentication failure, without acting on it.
record_failure
def record_failure(self, cause: BaseException | None = None) ‑> None:Record an authentication failure, aborting once the budget is spent.
Arguments
cause: The authentication error, chained onto the raisedEHRConnectionErrorso the original response survives.
Raises
EHRConnectionError: If this failure exhausts the budget.
record_success
def record_success(self) ‑> None:Reset the count.
FHIRClient calls this only for a successful response, to a request
other than its CapabilityStatement request: a request that fails other
than as unauthenticated (a 400, 404 or 5xx) neither counts nor resets.
The per-patient callers also call it for a patient whose lookup failed
for a reason other than authentication.