Repository navigation
fix(runtime): bound pytest deadlocks and Antigravity Stop-hook trajectory scan - #9015
loopx-agent wants to merge 1 commit into
Conversation
…tory scan 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)
已针对 PR #9015 exact head efdc510330fc04ea0de0a26558c4b07e3c98bd36 完成完整静态检验、反事实/边界单测实证与 premerge 金丝雀检查(审查结论:APPROVE,无 P0/P1/P2 阻塞问题;[VERDICT: APPROVE])。
动机 / Motivation
受影响调用方与运维者:所有在本地、Subagent 或 CI 通道运行 pytest 测试套件的开发者与自动化巡检 Agent,以及所有配置 hooks.json Stop 钩子以在网络 EOF 断流后原地恢复长程常驻会话的 Antigravity App(antigravity_app)运行方。
修改前(7bc56e7468):pyproject.toml [tool.pytest.ini_options] 未设置 faulthandler_timeout 与 faulthandler_exit_on_timeout,一旦某个测试用例发生死锁或阻塞,整个测试进程会在超过 CI 120s --ci-stall-after 诊断后仍无限期挂起(本轮 Subagent 挂起超 5 小时直至服务端重启);同时 loopx/agy_goal_mode/host_runtime.py 中 _native_input 对 GetCascadeTrajectorySteps 请求 [0, total) 全量步骤(timeout=2s)并含 3 处 Any,在长程常驻会话(步数数千至上万步)下易因超时或单页截断导致 stop_hook 静默返回 {} 无法恢复 EOF 断流。修改后(efdc510330):pyproject.toml 增加 faulthandler_timeout = 180(高于 CI 120s 协作栈快照阈值)与 faulthandler_exit_on_timeout = true 保证死锁测试在 180s 后打印全线程栈并退出;host_runtime.py 改为按 _TRAJECTORY_TAIL_WINDOW = 200 从 total 向前有界窗口扫描(总预算 _TRAJECTORY_SCAN_DEADLINE_SECONDS = 8.0,兼容旧服务端未分页全量返回)并清零全部 Any 注解(lines=280, any_count=0),保持 anchor SHA-256 与前后一致性校验完全不变。
可观测结果:exact head efdc510330 上:module_metrics 验证 loopx/agy_goal_mode/host_runtime.py (lines=280, any_count=0, dict_any_count=0);uv run --extra test mypy --strict --follow-imports=silent loopx/agy_goal_mode/host_runtime.py 与全仓 17 文件 mypy 均 0 错;ruff check 在全部修改 Python 文件上通过;8 组套件(test_antigravity_host_runtime.py、test_agy_host_surface.py、test_python_ci_workflow.py、test_ci_pytest_timing.py、test_stage2c_dependency_lock.py、test_dependency_security_boundaries.py、test_maintainability_ratchet.py、test_semantic_vocabulary_drift.py)通过:795 passed in 63.30s(0 failed, 0 skipped),其中两项新增单测实证死锁测试在超时后非零退出且长轨 5000 步下仅请求尾部 <=200 步窗口;uv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base 7bc56e74687a93ff4d5bcccb532c454bf2379c29 返回 ok=true, gate.status="passed"(direct=6/6, selected=3/3, failures=0, manual_holds=0);loopx check --scan-path ... 返回 ok=true(errors=0, warnings=0)。
非目标边界:本 PR 不改动 CI --ci-stall-after 120 观察器或 scripts/ci/pytest_timing.py 逻辑,不改变 Stop 钩子的重试次数上限(2 次)或 anchor SHA-256 生成公式,亦不修改与开放 PR #8703(module_metric_baseline.json 打包规则)或 PR #8874(bootstrap_prompt 文案与 __init__.py 模板)重迭的区域。
改动思路 / Approach
死锁兜底配置直接归属仓级 [tool.pytest.ini_options],Antigravity Stop 钩子轨迹扫描直接收敛在 loopx/agy_goal_mode/host_runtime.py 原所有者内部,复用 antigravity_adapter._observed_turn_steps 现有步序号校验契约而未引入新抽象或状态文件。
当前 PR 边界:仅包含 pyproject.toml(+3/-0)、loopx/agy_goal_mode/host_runtime.py(+57/-26)、tests/test_antigravity_host_runtime.py(+71/-0)与 tests/test_python_ci_workflow.py(+34/-0)四处高内聚改动(总计 +165/-26)。
pyproject.toml有界死锁退出(faulthandler_timeout = 180、faulthandler_exit_on_timeout = true):设置在 CI--ci-stall-after 120(120s 先打印合作式栈快照)之上,仅拦截真正超过 3 分钟卡死的单测,使其输出全部线程堆栈并失败退出。host_runtime._native_input向后尾部窗口分页 + 零Any:从total起按 200 步窗口逆向读取GetCascadeTrajectorySteps,在_TRAJECTORY_SCAN_DEADLINE_SECONDS = 8.0预算内找到最近一次CORTEX_STEP_TYPE_USER_INPUT即停止,同时保留start > 0 and len(raw) == total时对旧版未分页服务端的一次性全量兼容及调用前后GetCascadeTrajectory一致性核验。
具体改动 / Changes
本次 diff 严格限定在 4 个文件(+165 / -26):
pyproject.toml(+3 / -0,L204-206):在[tool.pytest.ini_options]下新增faulthandler_timeout = 180与faulthandler_exit_on_timeout = true,确保本地及 subagent 的pytest进程不会因单个死锁测试而无限挂起。loopx/agy_goal_mode/host_runtime.py(+57 / -26,280行,0 Any/0 dict[str, Any]):新增_TRAJECTORY_TAIL_WINDOW = 200与_TRAJECTORY_SCAN_DEADLINE_SECONDS = 8.0将_native_input改为向后有界窗口扫描,并移除全文件 3 处Any改用严格Mapping/object类型窄化。tests/test_python_ci_workflow.py(+34 / -0):新增test_pytest_config_enforces_bounded_deadlock_exit_above_ci_stall_snapshot校验配置阈值并在真实子进程用死锁用例验证非零超时退出与Timeout堆栈输出。tests/test_antigravity_host_runtime.py(+71 / -0):新增test_native_input_reads_bounded_tail_windows_on_long_trajectories验证 5000 步轨迹单窗命中、多窗回溯及全无输入返回None三条路径。
对主干的风险 / Risks
- 阈值与兼容性:
faulthandler_timeout = 180仅作用于单个卡死超过 3 分钟的测试(CI 分片现有--ci-stall-after 120在前),正常慢测试与测试套件总耗时不受影响;_native_input在旧版忽略分片范围的服务端返回全量len(raw) == total时自动一次收敛退出,不破坏既有测试双端行为。 - 并行 PR 避让:
pyproject.toml改动[tool.pytest.ini_options],host_runtime.py改动_native_input/类型注解,test_antigravity_host_runtime.py追加于文件末尾,均与在途 #8703 / #8874 行段隔离。 - 合入前提:涉及仓级测试超时策略与核心运行时钩子,需维护者合并授权与远端 CI 完成检查。
我的整体评价 / Verdict
- Long-horizon 影响:
improved— 根除本地/Subagent 测试死锁无限挂起风险,并修复长程 Antigravity 会话达到数千步后Stop钩子全量拉取轨迹超时失灵问题。 - User-experience 影响:
improved— 常驻长会话在模型 stream EOF 断流时可持续稳定触发原地恢复,且测试卡死可在 180s 内带堆栈快速暴露。 - visual_review:
not_applicable— 测试配置与运行时恢复后端,无前端/UI 表面。
定位精准、边界清晰、验证充实;待维护者合并授权与远端 CI 通过后可安全合入。
[VERDICT: APPROVE]
English verdict: APPROVE exact head efdc510 (author-owned COMMENTED approval review); bounds deadlocked pytest runs via faulthandler_timeout=180 / faulthandler_exit_on_timeout=true in pyproject.toml above CI's 120s stall observer, replaces unbounded [0, total) trajectory fetches in loopx/agy_goal_mode/host_runtime.py:_native_input with 200-step backward tail windows and eliminates all Any usages (280 lines, 0 Any), verified by 795 passed pytest tests (incl. two new deadlock/long-trajectory regression tests), strict mypy (0 issues), ruff check, quick premerge canaries (0 failures), and loopx check clean.
Summary
Fix two systemic hang/timeout failure modes discovered when subagents ran broad
pytestsweeps and long-horizon resident Antigravity sessions hit EOF recovery:pytestruns (pyproject.toml): configurefaulthandler_timeout = 180andfaulthandler_exit_on_timeout = trueunder[tool.pytest.ini_options], set cleanly above CI's--ci-stall-after 120cooperative diagnostic snapshot so hung tests dump all thread tracebacks and exit after 180s instead of freezing local/subagent/CI processes indefinitely.Stophook trajectory scans + eliminateAny(loopx/agy_goal_mode/host_runtime.py): replace unboundedGetCascadeTrajectorySteps(startIndex=0, endIndex=total)full-history fetches in_native_inputwith backward 200-step tail-window pagination (_TRAJECTORY_TAIL_WINDOW = 200,_TRAJECTORY_SCAN_DEADLINE_SECONDS = 8.0) plus legacy unpaginated server fallback, preventing RPC timeouts/truncation on long-horizon resident sessions while keeping the step anchor hash and consistency checks identical; also replace allAnyannotations with strictMapping/objecttypes (0Any).tests/test_python_ci_workflow.py::test_pytest_config_enforces_bounded_deadlock_exit_above_ci_stall_snapshottests/test_antigravity_host_runtime.py::test_native_input_reads_bounded_tail_windows_on_long_trajectoriesVerification
loopx/agy_goal_mode/host_runtime.pylines=280 any_count=0 dict_any_count=0uv run --extra test mypy --strict --follow-imports=silent loopx/agy_goal_mode/host_runtime.py:0issuesuv run --extra test mypy(17 kernel files):0issuesuv run --extra test ruff check loopx/agy_goal_mode/host_runtime.py tests/test_antigravity_host_runtime.py tests/test_python_ci_workflow.py: passedtest_antigravity_host_runtime.py,test_agy_host_surface.py,test_python_ci_workflow.py,test_ci_pytest_timing.py,test_stage2c_dependency_lock.py,test_dependency_security_boundaries.py,test_maintainability_ratchet.py,test_semantic_vocabulary_drift.py):795 passed in 63.30s(0failed,0skipped)uv run --extra test loopx --format json canary premerge --tier quick --from-git-diff --git-diff-base 7bc56e74687a93ff4d5bcccb532c454bf2379c29:ok: true,gate.status: "passed",failures: [](6direct checks,3catalog canaries)uv run --extra test loopx check --scan-path ...:ok: true,errors: 0,warnings: 0(public boundary scan clean)