Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #825.
Problem
The Feishu frontend already retries with exponential backoff when
cli.start()returns or raises. However, synchronous work that stalls the SDK event loop can leave the process alive while it stops processing incoming events, preventing both the outer retry loop and a process supervisor's exit-based restart policy from helping. This change adds an application-owned event-loop watchdog so a supervised deployment can recover from that failure mode.One concrete trigger is endpoint discovery during startup or reconnection: the SDK versions inspected perform a synchronous HTTP request on the WebSocket event-loop thread without an explicit request timeout. See larksuite/oapi-sdk-python#169 for the dependency-level report. The frontend guard does not require an SDK upgrade or override its endpoint-discovery implementation.
Reproduction and expected behavior
The committed regression tests simulate both startup and runtime stalls in disposable subprocesses with shortened deadlines. Normal idle time and asynchronous retry waits continue advancing the loop and must not trigger recovery.
Changes
frontends/fsapp.py, wrapping the existingcli.start()call.cli.start()returns or raises, includingKeyboardInterrupt, so retries do not accumulate watchers.frontends/tests/test_fsapp_watchdog.py.Validation
python -m pytest -q frontends/tests/test_fsapp_watchdog.py: 6 passed on Python 3.11.lark-oapiclients passed for the versions listed below: receive an event, stall endpoint discovery after disconnection, exit via the watchdog, restart in a fresh process, and receive another event. These checks used Python 3.11, dummy credentials, a shortened 0.5-second watchdog deadline, and a simulated process supervisor. They validate watchdog recovery, not every frontend feature or every SDK/dependency combination.SDK compatibility and dependency declaration
This watchdog does not require
lark-oapi>=1.6.8. Its integration point islark_oapi.ws.client.loop:Client.start()must run the same module-level event loop on which the heartbeat is scheduled.websockets==15.0.1.websockets==13.1, respecting this SDK release'swebsockets>=11,<14constraint. This yanked release was checked for compatibility, not recommended for installation.Client.start()uses it; no runtime check was performed for this version.lark_oapi.ws.client; these versions cannot support the existing Feishu WebSocket frontend.The new top-level loop import makes the last case fail earlier, at frontend import time, including
--checkand--check-agent. Previously, the existinglark.ws.Clientstartup path was already unsupported on those releases. This earlier failure is a compatibility limitation of this patch, not evidence that all versions allowed by the current dependency declaration work.Suggested project follow-up: tighten
lark-oapi>=1.0in theall-frontendsextra. The earliest stable SDK release found to provide the required WebSocket module is 1.2.1, solark-oapi>=1.2.1is a candidate minimum, subject to validating the complete frontend against it. It should not be raised to 1.6.8 solely for this watchdog. Before choosing the final lower bound, test configuration checks, client initialization, and message handling on the candidate oldest supported version, then keep that version and a current SDK in the compatibility checks. A clear unsupported-SDK error would also improve startup diagnostics.This PR leaves dependency declarations unchanged; the lower-bound adjustment above is a recommendation, not an implemented or fully validated frontend support guarantee. The runtime checks are representative versions, not an exhaustive sweep of every release between them.
Scope and tradeoffs
os._exit(1)terminates the whole frontend process without normal Python cleanup and can interrupt in-flight tasks. RaisingSystemExitinside the watchdog thread would only stop that thread and would not recover the service.