Bryan Marty 3c914b8f38
fix: enqueue fallback event on delivery throw and align resolveGatewayTarget with callGateway URL resolution
Two regressions addressed (PR #34580 CR review):

1. server-restart-sentinel.ts – deliverOutboundPayloads catch block was
   silently swallowing errors and proceeding to agentCommand without any
   fallback. When delivery throws before bestEffort handling (e.g. channel
   plugin error), the user would receive neither the deterministic notice
   nor a system event if the resumed run emits no payloads. Fix: enqueue a
   system event in the catch block, mirroring prior behaviour.

2. gateway.ts resolveGatewayTarget – two mismatches with callGateway's
   actual URL resolution path:
   a. gateway.mode=remote + missing gateway.remote.url: callGateway falls
      back to local loopback, but resolveGatewayTarget returned 'remote',
      suppressing deliveryContext for what is actually a local call.
   b. Env URL overrides (OPENCLAW_GATEWAY_URL / CLAWDBOT_GATEWAY_URL) are
      picked up by callGateway but were ignored here, causing incorrect
      local/remote classification. Fix: check env overrides first, then
      require both mode=remote AND remote.url present for 'remote'.

Tests: add regression coverage for both fixes.
2026-03-21 04:16:07 +00:00
..