Skip to content

fix(doctor): survive unreadable skill roots and project state - #9746

Open
mojunzi wants to merge 3 commits into
loopx-project:mainfrom
mojunzi:codex/doctor-unreadable-paths
Open

mojunzi wants to merge 3 commits into
loopx-project:mainfrom
mojunzi:codex/doctor-unreadable-paths

Conversation

@mojunzi

@mojunzi mojunzi commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Self-contained reproduced diagnostic defect on Python 3.11–3.13 under host sandboxes (direct PR; external issue optional per CONTRIBUTING.md).
  • Goal/source and gap: On Python 3.11–3.13, Path.exists() and Path.is_file() raise PermissionError when a parent directory cannot be searched (Python 3.14 returns False). loopx doctor probes ~/.codex/skills/<id>/SKILL.md, project-scoped skill names, the Antigravity config skill root, the selected registry path, and skill-install readback entries; a sandbox denying one of those directories aborted the entire doctor run with a traceback.
  • Observable before → after, with the validation row that proves it: Before: loopx --format json doctor (and doctor --agent-type agy) aborted with a PermissionError traceback when skill roots or project .loopx were chmod 000 on Python 3.13. After: unsearchable paths are treated as absent in those probes (matching Python 3.14 behavior), so doctor completes and outputs its structured JSON report without a traceback (proved by tests/test_doctor_installation_scope.py row below).
  • Issue/task and intended base: Direct bug fix targeting main.

Author Declaration

  • Written by: human_operator (Wang, Xiang-Han) with AI coding assistant assistance (Anthropic Claude, Google Gemini)

Implemented against

  • Specification and revision: no written specification; the reproduced PermissionError crash in loopx doctor on Python 3.11–3.13 is the basis
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
doctor survives unreadable ~/.codex/skills and project .loopx without traceback implemented _path_exists, installed_skill_summary, collect_doctor (loopx/doctor.py), inspect_skill_install_readback (loopx/skill_install_readback.py) python -m pytest -q tests/test_doctor_installation_scope.py
doctor --agent-type agy survives unreadable Antigravity skill root without traceback implemented _path_exists, collect_doctor (loopx/doctor.py) python -m pytest -q tests/test_doctor_installation_scope.py
  • Self-check before submission: Ran targeted subprocess and unit tests on Python 3.13.5, ruff, git diff --check, and loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick. Verified both new subprocess tests failed with PermissionError traceback on unpatched code before passing on the patched checkout. Full-repo pytest matrix is deferred to remote GitHub CI.

Scope And Continuation

  • Completed scope and remaining work: Complete within this scope (doctor.py and skill_install_readback.py unreadable path probes).
  • Slice boundary / successor: N/A — self-contained diagnostic resilience fix.

Validation

  • Tested revision: a0bcd30b2d4ea871346667d41999fc99fd63a9d4
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
real_entrypoint passed uv run --offline --extra test python -m pytest -q tests/test_doctor_installation_scope.py — 35 passed (3.74s); includes POSIX chmod 000 subprocess tests of python -m loopx.entrypoint --format json doctor and doctor --agent-type agy.
static passed uv run --offline --extra test python -m ruff check loopx/doctor.py loopx/skill_install_readback.py tests/test_doctor_installation_scope.py and git diff --check origin/main..HEAD — exit 0.
regression_parity passed uv run --offline --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick — ok=true, merge_gate_passed=true, 0 advisory failures (all direct checks plus install-local-smoke.py, codex-cli-packaged-install-smoke.py, and loopx-update-smoke.py passed).
unit not_run Full-repo pytest suite deferred to remote GitHub CI (python-tests.yml). POSIX permission tests are skipped on Windows / root hosts.
  • Coverage and gaps: Exercises real CLI subprocess execution against unreadable POSIX directories and preserves all 33 existing doctor installation-scope checks. Full-suite regression coverage runs in remote CI.

See validation disclosure guidance.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

On Python 3.11-3.13 `Path.exists()` raises PermissionError when a parent
cannot be searched (3.14 returns False). Doctor probes
`~/.codex/skills/<id>/SKILL.md`, project-scoped skill names under each
skill root, the selected registry path, and the Antigravity config skill
root; its skill-install readback also probes each required skill with
`is_file()`. A host sandbox that denies one of those roots therefore
aborted the whole doctor run with a traceback, in the one command meant
to diagnose such an environment.

Treat an unsearchable path as absent in those probes, as 3.14 already
does, so doctor completes and reports the affected checks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立评审(native Windows)——通过,暂不给正式批准

精确核对 head:a0bcd30b2。修复模式(OSError → False 的 _path_exists / materialized,对齐 Python 3.14 行为)在五个 doctor 探点和 skill readback 一致应用;Windows 上 chmod 不映射 ACL,崩溃场景本身无法复现,验证以代码审查与测试为主:

  • tests/test_doctor_installation_scope.py → 32 passed / 1 failed / 2 skipped。失败的 test_installation_scope_preserves_required_checks_without_opening_user_state[None] 在未修改 main 上同样失败(Windows 环境既有问题,与本 PR 无关);两个新 POSIX 测试按 skipif 在 Windows 跳过(本机无法执行 chmod 000 场景)。
  • usage_ping 导入与 os.geteuid 的短路(os.name == "nt" 先真)都核对过,Windows 收集安全。

一个完整性问题请作者确认:doctor.py 在本 head 仍有约 15 处裸 .exists()/.is_file()。多数明显无关(命令探测、安装脚本、legacy AGY home),但三处贴近被拒面,值得逐一确认"拒绝场景不可达"或一并转换:

  • doctor.py:562 — skill_path.exists():当候选循环因 _path_exists 全部落空时,回退到 primary_root / skill_name / "SKILL.md",若 primary_root 恰是被拒目录仍会抛出;
  • doctor.py:663, 682-694 — goals_dir / runtime_index 探针(project .loopx 被拒时的可达性);
  • skill_install_readback.py 其余裸点(:164/:175/:211/:217/:274)若同样服务 doctor 路径,属同一面。

您的新测试证明已转换的主路径在 chmod 000 下闭环;以上残留点若确认不可达(或在后续 PR 处理),不阻塞本次合并。

CI:该 head 的 Python 分片按两级门控策略跳过,无完整套件结果,按惯例不给正式批准。

Guard skill_has_required_phrases, latest_promotion_readiness_event, and Antigravity config file checks in loopx/doctor.py against OSError on unsearchable or unreadable targets, and have hash_skill_tree in loopx/skill_install_readback.py return its unavailable state instead of raising or silently hashing an unreadable skill directory as empty.

Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>
@mojunzi
mojunzi force-pushed the codex/doctor-unreadable-paths branch from cc008a4 to 42a7ce0 Compare December 3, 2026 06:17
@mojunzi

mojunzi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review on a0bcd30b2, @BigDataDZ! Pushed follow-up commit 42a7ce01e to address the remaining read-only probes in this surface:

  • loopx/doctor.py: hardened skill_has_required_phrases (catching OSError on read_text), latest_promotion_readiness_event (using _path_exists / _path_is_file and OSError guard around glob), and the Antigravity config file .is_file() checks (mcp_config_exists, hooks_config_exists, sidecar_config_exists, legacy_cli_loopx_skill_exists) via _path_is_file. (_promotion_artifact_exists at L663 already wrapped path.exists() in try/except (OSError, RuntimeError).)
  • loopx/skill_install_readback.py: updated hash_skill_tree (called by inspect_skill_install_readback) to walk with os.walk(..., onerror=...) and return its available=False state on OSError (since Path.rglob("*") silently yields empty on chmod 000 directories). Left retire_alternate_managed_skills (:164/:175/:211/:217) fail-closed as it is a write/cleanup path not called by doctor.
  • tests/test_doctor_installation_scope.py: added POSIX chmod 000 coverage for AGY_HOME itself, latest_promotion_readiness_event, skill_has_required_phrases, and hash_skill_tree.

Note on Package Smoke / loopx-core: the failure at Qualify a clean install of the matched split release (No module named 'loopx.cli') is the pre-existing main issue from #9656 where installed_loopx_distribution() selects the empty loopx metapackage instead of loopx-core (tracked in #9646). Keeping that out of scope here; I will rebase once #9646 lands.

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

在受限的 POSIX 目录或宿主沙箱中运行 Doctor 的 Python 3.11–3.13 用户。 旧版探测不可搜索的 skill 或 registry 父目录时,可能以 PermissionError 退出,拿不到结构化诊断。 真实 Python 3.13 CLI 对相同权限夹具返回 JSON;不可读的技能树报告 unavailable。 范围限于只读诊断。现有技能目录清理与安装权限仍由原入口执行。

改动思路 / Approach

范围是 Doctor 的路径探测和已有技能 readback。 在原读取入口捕获文件系统错误,从完整遍历决定技能树摘要是否可用,避免返回部分树的有效指纹。 输入仍为本地探测,错误转成已有的缺失或不可用状态,未加入修改权限或写配置。 可读取路径仍按原规则判断和散列。

具体改动 / Changes

按 PR #9746 的缺陷描述,基线 250932eee1eafd0c926cd2d498f5a11870c78432,核对 受限路径仍有 Doctor JSON 与 技能树不可用 两项。

对主干的风险 / Risks

同一份四项 pytest 真实权限案例用 CPython 3.13.16 对照基线与受审头,另比较可读和受限子树。 基线四项失败,三个到达真实 CLI。额外一组可读树摘要相同;子树被拒后,基线给出部分摘要,受审头返回 unavailable。75 项 Python 3.13 测试通过,quick premerge 的 6 项直接和 3 项选定检查通过。 权限反例在 macOS 上实际运行。此次独立验证未覆盖原生 Windows ACL。 当前主干的三方合并干净。

我的整体评价 / Verdict

批准。 受限目录不会中断整份报告,无法完整读取时也不会把部分树标成有效。验证已覆盖普通 CLI、AGY 配置根和运行账本。改动只影响 CLI 与只读技能诊断。

英文简短结论

English verdict: APPROVE at 42a7ce0. The real Python 3.13 CLI returns structured diagnostics for the denied-path fixtures, and incomplete skill trees no longer yield usable digests.

@mergify

mergify Bot commented Dec 4, 2026

Copy link
Copy Markdown

Hi @mojunzi, the DCO Sign-off check did not pass. Please inspect
its details first: checkout, fetch, timeout or infrastructure errors
need their own recovery, not a rewrite of otherwise signed commits.

If the log confirms a missing Signed-off-by trailer, amend the
affected commit with git commit --amend -s; for multiple commits,
use an interactive rebase against the current base from the correct
base-repository remote and sign off each affected commit. Push the
rewritten PR branch with git push --force-with-lease origin HEAD.

…le-paths

Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>
@mojunzi
mojunzi force-pushed the codex/doctor-unreadable-paths branch from 133421a to db1aff6 Compare December 4, 2026 16:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants