Repository navigation
fix(hosts): raise managed service startup readiness timeout to 45s - #9087
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
评审精确 head e1ad4029c90bf8459e4de852b8503b46123f2c94。受影响主体为通过 loopx update activate --service all 对接本地托管服务(com.loopx.status / com.loopx.chat)实施原子版本切换与在线升级的运维操作者及自动升级流程。此前 _verify_services 在 bootout 并重新 bootstrap com.loopx.status 与 com.loopx.chat 后仅等待 15 秒 HTTP 就绪;而在生产运行目录上 chat_server 完成恢复任务与管家执行器对账并进入 server.serve_forever() 实测需约 16–22 秒,导致升级必然在 15 秒时误判超时回滚;修改后将默认就绪超时常量 _SERVICE_READINESS_TIMEOUT_SECONDS 提升至 45.0 秒并支持参数注入,同时保持超时后仍快速失败并安全回滚的既有保障。可观测结果为:_verify_services 对晚于旧 15 秒阈值(如 22 秒)才就绪的 com.loopx.chat 与 com.loopx.status 正常放行通过,update activate 不再误触发回滚;若服务在 45 秒上限内仍无法响应或身份不匹配,仍明确抛出 service_runtime_alignment_failed 并完整执行原配置回滚。本 PR 不跳过启动前检查、不放宽 runtime_identity 匹配条件、不修改 Chat 初始化顺序,也不涉及任何 UI 或提示词变更。
改动思路 / Approach
架构定位与边界:复用既有 managed_service_runtime._verify_services 与故障回滚契约,仅将硬编码 15 秒就绪上限提升至可参数覆盖的 45.0 秒常量,未放松版本校验或回滚路径。仅修复 _verify_services 的服务就绪等待上限并补充时间边界单测,不改动 Chat 启动初始化顺序、plist 模板或 UI。
- 提升默认 HTTP 就绪等待预算:在
loopx/hosts/managed_service_runtime.py定义_SERVICE_READINESS_TIMEOUT_SECONDS = 45.0,并将_verify_services(..., timeout_seconds: float = _SERVICE_READINESS_TIMEOUT_SECONDS)的硬编码15替换为可注入预算,快速启动的实例依然会在首轮轮询立即返回。 - 固定时钟边界单测:在
tests/test_managed_service_runtime.py注入可控虚拟单调时钟,同时验证t=22s(超过旧 15s 上限)成功放行以及t=45s持续未就绪仍严格抛出service_runtime_alignment_failed。
具体改动 / Changes
loopx/hosts/managed_service_runtime.py(+7/-2): 提取_SERVICE_READINESS_TIMEOUT_SECONDS = 45.0常量并将_verify_services扩展为接受默认 45 秒的timeout_seconds参数。tests/test_managed_service_runtime.py(+70): 新增test_verify_services_allows_production_startup_past_legacy_15s_cutoff_and_enforces_45s_deadline验证 22 秒启动通过与 45 秒失败回滚边界。
对主干的风险 / Risks
极低风险(仅 2 个文件、+7 净生产代码行,保留全部 launchd 校验与回滚门禁):
ruff check零告警;test_managed_service_runtime.py与test_doctor_installation_scope.py共72 passed, 1 skipped(含真实 macOS launchd 对齐/回滚套件);control-plane-maintainability-ratchet-smoke.py、semantic-vocabulary-drift-smoke.py及canary premerge2/2全数通过。
我的整体评价 / Verdict
该微小修复直接消除了多绑定生产环境下 update activate 因 chat_server 16–22 秒冷启动略超旧 15 秒上限而触发的误回滚阻塞,同时完整保留了 runtime_identity 严格核验与 45 秒失配回滚语义,长期可维护性与用户体验均获改善(UI visual review 不适用)。全部测试与预合并检查已在精确提交 e1ad4029c90bf8459e4de852b8503b46123f2c94 验证通过。
English Verdict: APPROVE - Verified at exact head e1ad402; raising _verify_services startup readiness deadline to 45.0s prevents spurious rollbacks on 16-22s production Chat restarts while preserving fail-closed rollback semantics (72 passed, ruff, ratchet, vocabulary, and canary premerge 2/2 pass).
Summary
Allow managed LaunchAgent runtime alignment (
_verify_services) sufficient HTTP readiness wait budget for production Chat/Status runtimes:loopx/hosts/managed_service_runtime.py:_verify_servicesstartup readiness deadline from hardcoded15seconds to_SERVICE_READINESS_TIMEOUT_SECONDS = 45.0(while keepingtimeout_secondskeyword-overridable).update activate --service allfrom rolling back healthy productioncom.loopx.chatrestarts whose synchronous pre-serve initialization (resuming requests, reconciling steward executors, and starting conversation transports) exceeds 15s on large multi-binding runtime roots.tests/test_managed_service_runtime.py:test_verify_services_allows_production_startup_past_legacy_15s_cutoff_and_enforces_45s_deadlineusing a synthetic monotonic clock to prove startup completing at 22s passes and persistent failures past 45s still fail closed withservice_runtime_alignment_failed.Verification
uv run --extra test ruff check loopx/hosts/managed_service_runtime.py tests/test_managed_service_runtime.py— passedPYTHONPATH=tests uv run --extra test python -m pytest tests/test_managed_service_runtime.py tests/test_doctor_installation_scope.py -q— passeduv run --extra test python examples/control_plane/control-plane-maintainability-ratchet-smoke.py— passeduv run --extra test loopx --format json canary premerge --from-git-diff --git-diff-base origin/main— passed