Reusable overlay toolkit for stabilizing gateway WebSocket handshakes. Rule-based patches with apply/check/rollback CLI.
可复用的 Gateway 稳定性 overlay 工具。基于规则的补丁系统,支持 apply/check/rollback 工作流。
gateway-stability-patch is a public, reusable overlay toolkit that turns a live gateway runtime stability hotfix into a documented, repeatable workflow.
It focuses on one goal: reduce gateway crashes or false outage symptoms caused by local loopback handshake races, connect-challenge timeout drift, and retryable pre-connect closes.
This repository does not ship the target gateway runtime or patched vendor bundles. It ships:
- patch rules
- overlay maintenance scripts
- integrity checks
- rollback helpers
- bilingual documentation
For the supported gateway runtime build, the patch set adds or extends:
- configurable gateway handshake timeout
- configurable connect-challenge timeout
- bounded retry for retryable local-loopback pre-connect failures
- broader local fallback handling in the
devicesCLI for loopback1000/1006/no-reasonand timeout cases
Configured in src/gateway_stability_patch/patch_set.py as SUPPORTED_RUNTIME_VERSION.
The project is intentionally version-strict. If the detected runtime version does not match, the CLI refuses to patch unless you explicitly pass --allow-unsupported-version.
- It is repeatable.
- It creates backups automatically.
- It writes a manifest with file hashes.
- It gives you a stable
apply -> check -> rollbackworkflow. - It survives future maintenance better than one-off manual edits.
gateway-stability-patch/
├── docs/
├── examples/
├── src/gateway_stability_patch/
├── tests/
├── LICENSE
├── README.md
└── README.zh-CN.md
python3 -m pip install .Or run directly from the source tree:
PYTHONPATH=src python3 -m gateway_stability_patch describegateway-stability apply \
--install-root /path/to/gateway/runtime \
--overlay-root ~/.gateway-stability/overlays/gateway-stability \
--env-file ~/.gateway-stability/.envgateway-stability check \
--install-root /path/to/gateway/runtime \
--overlay-root ~/.gateway-stability/overlays/gateway-stability \
--env-file ~/.gateway-stability/.envgateway-stability rollback \
--install-root /path/to/gateway/runtime \
--overlay-root ~/.gateway-stability/overlays/gateway-stability \
--env-file ~/.gateway-stability/.envThe tool ensures these values exist in the chosen env file:
GW_STABILITY_HANDSHAKE_TIMEOUT_MS=8000
GW_STABILITY_CONNECT_CHALLENGE_TIMEOUT_MS=6000
GW_STABILITY_PRECONNECT_RETRY_ATTEMPTS=3
GW_STABILITY_PRECONNECT_RETRY_MIN_DELAY_MS=250
GW_STABILITY_PRECONNECT_RETRY_MAX_DELAY_MS=1500
GW_STABILITY_PRECONNECT_RETRY_BACKOFF=2An example file lives at examples/gateway-stability.env.example.
gateway-stability describegateway-stability applygateway-stability checkgateway-stability rollback
- Usage guide:
docs/usage.en.md - Chinese usage guide:
docs/usage.zh-CN.md - Development guide:
docs/development.en.md - Chinese development guide:
docs/development.zh-CN.md - Publishing guide:
docs/publishing.en.md - Chinese publishing guide:
docs/publishing.zh-CN.md - Contribution policy:
CONTRIBUTING.md
- Always back up the target machine before testing on a new runtime version.
- This project only supports a known runtime release by default.
- Do not publish private
.envfiles, backup directories, or host-local overlay trees. - Re-run
checkafter every runtime upgrade because upstream files may change.
MIT. See LICENSE.