fix(approval): simplify gateway_keys expression and document race window

Drop the redundant 'if gw_data else []' guard — gw_data is already
guaranteed to be a dict by the 'or {}' fallback above.

Add a one-line comment explaining the peek-without-pop race window:
a concurrent resolver may pop a different gateway entry, but
approve_session is idempotent over the session key set so the
outcome is the same regardless.
This commit is contained in:
keyos
2026-05-19 20:56:17 +00:00
parent 729ed415ff
commit ada59d73e6
+6 -1
View File
@@ -8784,7 +8784,12 @@ def _resolve_approval_legacy(sid: str, approval_id: str, choice: str) -> bool:
# _gateway_queues stores _ApprovalEntry objects; their
# .data dict carries command, pattern_key, pattern_keys.
gw_data = getattr(gw_entry, 'data', None) or {}
gateway_keys = gw_data.get("pattern_keys") or [gw_data.get("pattern_key", "")] if gw_data else []
gateway_keys = gw_data.get("pattern_keys") or [gw_data.get("pattern_key", "")]
# Peek is not strict — a concurrent resolver may pop a
# different gateway entry before we reach
# resolve_gateway_approval below, but approve_session is
# idempotent over the session key set so the outcome is
# the same regardless of which entry wins the race.
found_target = True
# Notify SSE subscribers of the new head (or empty state) so the UI
# surfaces any trailing approvals that were queued behind this one