fix: guard unmanaged resolution on authoritative balances

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-12 13:29:45 +00:00
committed by GitHub
co-authored by genichin
parent f2b825e720
commit 5a13c0494b
5 changed files with 105 additions and 5 deletions
+21 -1
View File
@@ -364,6 +364,18 @@ def _notify_unmanaged_position_transition(
)
def _broker_balances_are_authoritative_for_unmanaged_resolution(broker: BrokerPort) -> bool:
marker = getattr(broker, "exposes_full_balance_snapshot", None)
if callable(marker):
try:
return bool(marker())
except Exception: # noqa: BLE001 - fail closed on broker self-report failure
return False
if isinstance(marker, bool):
return marker
return True
def reconcile_core_holdings(
*,
slot_repo,
@@ -535,7 +547,10 @@ def reconcile_core_holdings(
symbol=sym,
quantity=bq,
)
if unmanaged_position_store is not None:
if (
unmanaged_position_store is not None
and _broker_balances_are_authoritative_for_unmanaged_resolution(broker)
):
try:
for state in unmanaged_position_store.resolve_absent(
instance_key=instance_key,
@@ -555,6 +570,11 @@ def reconcile_core_holdings(
)
except Exception: # noqa: BLE001
_log.exception("reconcile_core_holdings: unmanaged_position resolve failed")
elif unmanaged_position_store is not None:
_log.debug(
"reconcile_core_holdings: unmanaged_position resolve skipped "
"(non-authoritative broker balance view)"
)
# req-0007 / ac-0024: retry pending_resolved for B-case identities no longer mismatched.
if alarm_emitter is not None and notification_store is not None:
try: