Skip to content

fix: own Feishu WebSocket readiness and resource lifecycle - #659

Merged
mateaix merged 2 commits into
mateaix:devfrom
RobinZhiBin:codex/fix-feishu-lifecycle
Oct 9, 2026
Merged

mateaix merged 2 commits into
mateaix:devfrom
RobinZhiBin:codex/fix-feishu-lifecycle

Conversation

@RobinZhiBin

Copy link
Copy Markdown
Contributor

Feishu's SDK start() returns after initiating the connection; it does not block for the socket lifetime. The adapter currently treats that return as a disconnect, while SDK close() leaves its executors alive. Quiet channels can also be restarted solely because no business message arrived.

This PR makes the adapter the single owner of reconnect scheduling and waits for the SDK handshake before reporting CONNECTED. Transport health uses protocol ping/pong and synchronized SDK connection-state reads, so quiet channels do not trigger reconnects. Permanent stop cancels the transport and closes SDK/HTTP executors, including startup races and exceptional SDK shutdown.

Changes

  • Disable SDK auto-reconnect; route handshake/transport failures through the adapter's existing backoff loop.
  • Add a narrow lifecycle wrapper for oapi-sdk 2.7.1, with synchronized connection-state access and permanent resource disposal.
  • Let asynchronously connected adapters defer CONNECTED until ready. Feishu opts out of message-age staleness via Duration.ZERO; ERROR recovery and other adapter thresholds stay active.
  • Retain current dev bot identity/CardKit behavior. No Web/WebChat implementation or dependency changes.

Compatibility

The pinned SDK has no public disposal/transport-status APIs. The wrapper uses a version-bound reflection bridge for executor, httpClient and conn, with field-type checks and real SDK regression coverage. SDK upgrades require rechecking these contracts. The old Feishu silent_disconnect_threshold_seconds setting no longer causes reconnects; actual protocol/transport health replaces message-age detection. Details are in docs/compatibility/feishu-websocket-lifecycle.md.

Validation

  • Baseline: 5 regressions, 2 expected failures (unreleased SDK executor and quiet-channel reconnect).
  • Final candidate: 182 tests passed, 0 failures/errors/skips, Java 21 and SDK 2.7.1.
  • Real loopback HTTP/WebSocket tests cover delayed/rejected handshakes, peer close/TCP reset, missing pongs, startup/stop races and 25 start/stop cycles with strict executor termination and empty connection-pool assertions.
  • Independent review added deterministic SDK-monitor and transport-cancel regressions (both demonstrated failure before the fix), plus cleanup when SDK close throws.
  • Existing Feishu behavior and channel health/staleness regressions pass, including ERROR recovery and Weixin's positive stale threshold.
JAVA_TOOL_OPTIONS=-Djdk.httpclient.allowRestrictedHeaders=connection \
  mvn -B -o -pl mateclaw-server -am \
  '-Dtest=Feishu*Test,ChannelHealthMonitor*Test,ChannelAdapterStalenessTest' \
  -Dsurefire.failIfNoSpecifiedTests=false test

The JVM option matches application startup for existing Feishu HTTP tests. All fixtures use synthetic credentials and loopback peers. No live Feishu messages or production changes; these tests do not establish real-user delivery or multi-day reliability.

@mateaix
mateaix merged commit 61b7f56 into mateaix:dev Oct 9, 2026
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.

2 participants