Skip to content

fix(wecom): redeliver sends lost in the 846609 reconnect gap - #124

Open
TaoMasterCoder wants to merge 2 commits into
NousResearch:mainfrom
TaoMasterCoder:fix/wecom-redelivery-846609
Open

TaoMasterCoder wants to merge 2 commits into
NousResearch:mainfrom
TaoMasterCoder:fix/wecom-redelivery-846609

Conversation

@TaoMasterCoder

Copy link
Copy Markdown
Contributor

What

Port of hermes-agent core PR NousResearch/hermes-agent#114751, closed without merging when the WeCom platform tree was deleted from core. The fix never landed anywhere — this plugin still silently loses sends that race the websocket reconnect gap.

Scenario / bug

_listen_loop reconnects with backoff [2, 5, ...]s. A send rejected during the closed → reconnect → subscribed gap fails with errcode 846609 (aibot websocket not subscribed) and the old code returned a plain failed SendResult — the payload, often the agent's final response, was lost forever (and stranded as abandoned in the delivery ledger because the raw WeCom error is not on its runtime-redelivery allowlist).

Fix (ported hunk-for-hunk onto current wecom/)

  • Provably-undelivered only: 846609 (server rejection before enqueue) and _require_ws refusals (raised before any frame was written) are transient — the same payload is retried after the reconnect (bounded: 2 retries, 15s send-path wait).
  • Ambiguous failures never retried: timeouts and post-write ack drops (_fail_all "connection interrupted") may already have delivered — they keep the original fail-closed / passive→proactive-exactly-once shape, so no duplicate payload ever reaches the wire.
  • Fail closed to the ledger: exhausted reconnect waits return send_path_degraded + retryable — core's runtime-redelivery token (gateway/delivery_ledger.py _RUNTIME_RETRYABLE_ERRORS) — so the final response is replayed with a visible marker instead of lost.
  • Reconnect kicks the replay: WeCom self-heals in-process so the gateway's adapter-swap replay never fires for it; _listen_loop now calls _redeliver_failed_obligations_for_platform directly after a successful reconnect (best-effort, ledger failures never break the reconnect path).

Tests

wecom/tests/test_wecom_redelivery.py (ported from the core PR): 9 tests covering deliver-exactly-once retry, send_path_degraded fail-closed, reconnect kick, non-transient errcodes, single timeout fallback, and the reviewer's duplicate-send cases on the real _request path — 9/9 red without the fix, green with it; whole suite 102 passed. (test_wecom_image_link_fallback.py fails identically on untouched main locally — unrelated core-version drift.)

Related

Supersedes the lost coverage of the three closed core PRs; this is #3 of 3 (stream-tail = #122, inbound video/voice = #123).

TaoMasterCoder added 2 commits November 29, 2026 09:13
Port of hermes-agent core PR #114751 (closed when the WeCom platform moved out
of core). Without it a send rejected with errcode 846609 (subscription lost)
during the websocket reconnect gap returned a plain failed SendResult and the
message - often a final response - was lost forever.

Contract: only provably-undelivered failures (846609 server rejection before
enqueue, _require_ws refusal before any frame was written) are transient and
retried after the reconnect (bounded, backoff 2s, wait 15s, max 2 retries);
ambiguous failures (timeouts, post-write ack drops) keep the original
fail-closed / passive->proactive shape and are never retried. Exhausted waits
fail closed as send_path_degraded so the core delivery ledger replays them,
and a successful _listen_loop reconnect kicks that replay itself since WeCom
self-heals in-process (the adapter-swap replay never fires for it).

Tests: wecom/tests/test_wecom_redelivery.py (9 new; 9/9 red without the fix,
green with it; whole suite 102 passed).
… reconnect kick

CI (current core main) has no Platform.WECOM member any more; plugin platforms
resolve through Platform(PLATFORM_NAME) via the enum's dynamic _missing_ hook,
the same call-time pattern the adapter constructor and yuanbao already use.
Platform.WECOM raised AttributeError in _trigger_failed_obligation_redelivery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant