fix: preserve sell event routing owner

This commit is contained in:
Hermes Agent
2026-09-20 20:34:00 +09:00
parent 3f6a967aa1
commit c66acf6e47
20 changed files with 766 additions and 32 deletions
+30 -11
View File
@@ -386,28 +386,47 @@ class Daemon:
def _make_event_emitter(self):
def emit(event_type: str, slot, routing_strategy_id: str | None = None) -> None:
payload = slot_transition_event_payload(slot, event_type=event_type)
# routing_strategy_id is supplied when the transition clears
# slot.strategy_id (e.g. PENDING_SELL -> INACTIVE for slot_filled_sell).
# Without this hint the routing key would use "_" and the message would
# be NO_ROUTEd to the DLQ instead of reaching the strategy queue
# (M2 REL-009 feedback / slot_filled NO_ROUTE fix).
# routing_strategy_id is captured before transitions that clear owner
# fields (for SELL, the admission-owned sell_strategy_id). Missing
# SELL ownership is blocked below instead of synthesizing "_".
effective_strategy_id = (
routing_strategy_id or getattr(slot, "strategy_id", None) or "_"
routing_strategy_id or getattr(slot, "strategy_id", None)
)
# req-0011/ac-0039 defense in depth: application execution normally
# skips ownerless SELL events before this hook. Never synthesize the
# legacy "_" owner if a direct caller violates that boundary.
if (
event_type == "slot_filled_sell"
and not (
isinstance(effective_strategy_id, str)
and effective_strategy_id.strip()
)
):
_log.error(
"sell event publish blocked reason=sell_event_owner_missing "
"slot_id=%s symbol=%s event_type=%s",
getattr(slot, "slot_id", None) or getattr(slot, "id", None),
getattr(slot, "symbol", None),
event_type,
)
return
effective_strategy_id = effective_strategy_id or "_"
rk = topology.event_routing_key(
event_type, effective_strategy_id, slot.symbol or "_",
)
try:
self.event_publisher.publish_event(rk, payload)
except Exception: # noqa: BLE001 - publish failure must not roll back
# REQ-093: escalate to ERROR so operators can observe via log
# alert. Include routing key + slot identity for correlation.
except Exception as exc: # noqa: BLE001 - publish failure must not roll back
# req-0011/ac-0039: transport failures are observable without
# rendering raw exception text, traceback, broker payload, or
# connection details into logs.
_log.error(
"event publish failed (rk=%s slot_id=%s strategy=%s)",
"event publish failed reason=event_publish_failed "
"rk=%s slot_id=%s strategy=%s exc_type=%s",
rk,
getattr(slot, "slot_id", None) or getattr(slot, "id", None),
getattr(slot, "strategy_id", None),
exc_info=True,
type(exc).__name__,
)
return emit