Skip to content

[codex] stabilize Hermes Feishu gateway lifecycle - #24337

Closed
foras910521-lab wants to merge 6 commits into
NousResearch:mainfrom
foras910521-lab:codex/hermes-stability-cleanup
Closed

[codex] stabilize Hermes Feishu gateway lifecycle#24337
foras910521-lab wants to merge 6 commits into
NousResearch:mainfrom
foras910521-lab:codex/hermes-stability-cleanup

Conversation

@foras910521-lab

Copy link
Copy Markdown
Contributor

What does this PR do?

Stabilizes Hermes gateway behavior around Feishu websocket startup/reconnect, Hindsight local_external health checks, API server memory-provider cleanup, and macOS launchd restart handoff.

The fixes keep retryable Feishu startup failures inside the gateway lifecycle instead of letting service managers spin in restart loops. They also make Hindsight local_external availability reflect the actual local HTTP endpoint, and close memory providers after API server runs.

Root Cause

  • Feishu websocket startup could be marked connected too early or fail during transient OpenAPI/WSS timeouts.
  • When Feishu was the only configured messaging platform, retryable startup failures could make the gateway exit, causing launchd/service-manager churn instead of background reconnect.
  • macOS launchd generated gateway run --replace, mixing service-manager restart semantics with Hermes replace handoff.
  • Hindsight local_external availability was config-only and could report healthy while 127.0.0.1:9177 was unreachable.
  • API server run paths did not consistently close the agent memory provider after completion.

Changes Made

  • gateway/platforms/feishu.py: wait for websocket readiness, improve disconnect/CLOSE handling, reduce sensitive SDK URL logging, and drop stale replayed messages after reconnect.
  • gateway/run.py: keep the gateway alive for retryable startup platform failures and let the reconnect watcher recover.
  • plugins/memory/hindsight/__init__.py: require reachable /health or /version for local_external availability.
  • gateway/platforms/api_server.py: shut down memory provider in finally after run handling.
  • hermes_cli/gateway.py: stop adding --replace to macOS launchd plist generation.
  • Tests updated/added for the changed gateway, Feishu, Hindsight, API server, and service behavior.

How to Test

  1. venv/bin/python -m ruff check .
  2. scripts/run_tests.sh tests/gateway/test_runner_startup_failures.py tests/gateway/test_platform_reconnect.py tests/gateway/test_feishu.py tests/hermes_cli/test_gateway_service.py tests/hermes_cli/test_update_gateway_restart.py tests/plugins/memory/test_hindsight_provider.py tests/gateway/test_api_server.py tests/gateway/test_api_server_runs.py
  3. On macOS launchd, restart ai.hermes.gateway and confirm ProgramArguments are python -m hermes_cli.main gateway run without --replace.
  4. With transient Feishu OpenAPI/WSS timeouts, confirm gateway remains running, starts the reconnect watcher, and Feishu later returns to connected.
  5. Confirm Hindsight local API health returns {"status":"healthy","database":"connected"}.

Validation Performed

  • Ruff passed.
  • Targeted official wrapper tests passed: 670 passed.
  • Rebased cleanly on origin/main at dd0923bb8.
  • macOS runtime check: gateway PID refreshed, launchd has no --replace, Hindsight healthy, Feishu connected.

Platform Tested

  • macOS launchd on local Hermes gateway.

Notes

This PR intentionally does not modify system networking, Wi-Fi, DNS, proxy services, or third-party proxy app configuration. The stability work stays inside Hermes gateway and provider lifecycle boundaries.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins platform/feishu Feishu / Lark adapter P2 Medium — degraded but workaround exists labels May 12, 2026
@foras910521-lab

Copy link
Copy Markdown
Contributor Author

Draft upstream de-dup note after rechecking main on 2026-05-12:

Proposed next step: keep this PR as an umbrella draft, then split or narrow it into focused PRs rather than asking for review in its current shape.

@foras910521-lab

Copy link
Copy Markdown
Contributor Author

Follow-up split: the low-overlap Hindsight local_external reachability and API server memory-provider cleanup changes have been separated into draft PR #24353. This keeps #24337 as an umbrella/Feishu-gateway draft rather than asking reviewers to evaluate unrelated lifecycle fixes together.

@foras910521-lab

Copy link
Copy Markdown
Contributor Author

Additional Feishu lifecycle note from local re-diagnosis: this umbrella draft should not be promoted as-is. The local runtime still shows Lark SDK event-loop lifecycle errors (Future attached to a different loop and _select was never awaited). The risky part appears to be the draft Feishu shutdown path that proactively calls the SDK internal _disconnect() from Hermes shutdown via the SDK thread loop; that can overlap with the SDK receive-loop disconnect/reconnect lifecycle. I will treat the Feishu portion as needing a smaller redo from main: no cross-loop SDK internal _disconnect(), no broad lifecycle coupling, and ready/cleanup behavior tested in isolation.

@foras910521-lab

Copy link
Copy Markdown
Contributor Author

Follow-up split: the narrower Feishu websocket readiness work has been separated into draft PR #24358. That PR starts from main, waits for the SDK websocket _connect() readiness signal before marking Feishu connected, drops stale pre-connect message replays, and intentionally does not include the broader shutdown experiment that called SDK _disconnect() across the SDK loop boundary.

@foras910521-lab

Copy link
Copy Markdown
Contributor Author

Follow-up split: retryable gateway startup degradation has been separated into draft PR #24364. It aligns with #17984 by keeping the process alive in degraded state for all-retryable startup failures, while preserving current main semantics for non-retryable startup conflicts (startup_failed plus clean exit). This keeps #24337 as an umbrella draft rather than mixing gateway runner state policy with Feishu adapter lifecycle changes.

@foras910521-lab foras910521-lab closed this by deleting the head repository Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants