Skip to content

fix(doctor): bind package update readback to its Python environment - #9009

Merged
huangruiteng merged 3 commits into
mainfrom
codex/doctor-pin-python-update-installation-20261118
Nov 19, 2026
Merged

huangruiteng merged 3 commits into
mainfrom
codex/doctor-pin-python-update-installation-20261118

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A user running loopx update apply from a specific Python environment needs the post-install Doctor to verify the executable installed in that environment. Looking up loopx on the caller's PATH can select another installation or report a failure when the updated environment is absent from PATH. The previous revision also followed a redirected console script recorded by the updated wheel and accepted the resulting path as evidence for both installations.

Change

Both Doctor entry points use the Python distribution that owns the imported module. They verify the installed file at the recorded launcher location before probing it. A shell or pipx alias can still point to the verified launcher. Missing, ambiguous and redirected recorded launchers fail the required ownership check. Full Doctor continues to report the ambient PATH separately. The existing service activation eligibility remains in place. Independent review of the previous head

Validation

  • Installed the published 2.3.0 wheel and two candidate wheels in separate macOS arm64 Python 3.12 environments. With the installed RECORD bytes unchanged, the prior Doctor accepted a redirected launcher in both deep modes. Both modes reject it on c5d6d75812e67bdf13c86f339449fe3341aa15e6 and skip its command probes. The healthy, restored and outer-alias controls pass.
  • Ran native loopx update apply from the published 2.3.0 wheel to the exact candidate wheel. File and SQLite reopened the same Goal and Todo with their lease and original receipt. Both replayed the original operation, accepted a new write and rejected a stale revision. Reinstalling 2.3.0 preserved both receipts and the lease.
  • Ran 148 focused tests with 44 skips, Ruff on changed Python files, and all 6 direct and 10 selected standard premerge checks against 9af4caa72. The three-way preview against 07722b169a reproduced the same five-file diff and passed the RFC check.
  • Ran the same upgrade and continuation through the real pipx 1.18.19 launcher on macOS arm64 with its recorded uv backend and a local wheelhouse. Update delegated to pipx, and Doctor verified 2.4.0. File and SQLite replayed the old operation, accepted a fresh write, and rejected a stale write. After pipx reinstalled 2.3.0, both stores retained the new write, both receipts, their leases and registry configuration.
  • Independent review of the new head is pending. Native Windows and LaunchAgent switching were outside the verified environment.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

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 · reasoning_effort=max

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

  • [P2] 安装专用 Doctor 在自有 launcher 不可用时仍可能通过。 将候选 wheel 安装到 venv,临时移走它的 launcher,或给 RECORD 增加第二个不同的本地 launcher,并把独立 2.3.0 环境放在 PATH 首位。实际 python -I -m loopx.cli doctor 返回 1,带 --installation-only 则返回 0,path.loopx 指向 2.3.0。这里的标量包装丢掉了“模块仍拥有诊断、launcher 不可用”这一状态,安装专用检查随后回退到 PATH。请让两个 Doctor 入口共用此判定,测试缺失和歧义两例。 入口和回退
  • [P2] 从 Python 模块更新会扩大服务切换范围。 macOS 的包更新成功后,restart_services_for_runtime_activation 会在已有管理服务绑定时读取此函数。隔离对照给两版同样的普通 Python 模块入口和服务绑定,基线为 deferred,候选把独立 venv 的 launcher 传给 align_managed_runtime。验证只记录调用目标。请将这个诊断解析留在 Doctor 路径,保留原激活选择,或先证明目标环境拥有默认服务切换权限。 激活调用方

动机 / Motivation

从 PyPI 更新 LoopX 的用户需要确认刚升级的 Python 环境已经可用。基线在虚拟环境的 bin 不在 PATH 时,安装后的 Doctor 会报找不到命令。若 PATH 先找到另一套 2.3.0,普通 Doctor 又会用它通过检查。候选的普通和 deep Doctor 都能读到实际升级的环境,但安装专用检查在自有 launcher 缺失或有歧义时仍报告另一套环境可用。显式 Python 模块还会新增系统服务切换尝试。独立验证覆盖 macOS arm64 上的 pip wheel 和 Core wheel,Windows、pipx 与真实 LaunchAgent 切换需要各自的验收。

改动思路 / Approach

用 wheel 的 RECORD 核验当前安装及 launcher,让两个 Doctor 入口共用所有权和失败状态,服务继续依据现有激活入口选择目标。本次改动应覆盖同一安装的 Doctor 读回,并保留系统服务原有的激活范围。当前环境的 launcher 用于所需核验,PATH 查找结果仍单独返回。解析方法

具体改动 / Changes

检查 head 8837c207b3d053766ed964ab831e21500ac9ea17 与 diff base f8ef1a63f12fb042c62b3f5b828a432da1b568b2,两文件共 +118/-39。按 owning-python-environment、verified-installation-readback 和 separate-runtime-activation 核对调用方可见结果。发布与读回约定 服务边界

关键代码讲解

  • _current_invocation 识别两个模块入口,_python_distribution_owning_module 核对 RECORD 与实际导入的 doctor.py,再检查 launcher 是否唯一、存在且可执行。_distribution_record_path 使用本机路径规则解释绝对记录。开发 checkout 仍按原方式查找,独立 Core 继续使用其模块路径。路径与安装元数据
  • python_distribution_install 重用同一个已确认的 distribution,供版本和包管理器判断。collect_doctor 以此决定必需检查,同时保留 loopx_on_path。安装专用入口单独消费标量路径,在缺失或歧义时会用另一套命令填补。完整检查 安装专用检查
  • 八个新增用例覆盖两个模块入口和 owned、missing、other distribution、source manifest。独立实测两套真实 pip wheel,候选普通及 deep Doctor 指向自身,缺失和歧义在普通 Doctor 被拒绝。安装专用反例和服务调用方是现有用例的空缺。测试

对主干的风险 / Risks

独立在 macOS arm64、Python 3.13 的单个 venv 里,经 pip 完成 2.3.0 → 候选 2.4.0 → 2.3.0。升到候选后,另一套 2.3.0 仍在 PATH,Doctor 确认的是当前环境的 launcher。定向源代码测试 155 项通过、44 项跳过,另有 9 项实际 Core wheel 测试通过。首次本地预检的安装 smoke 超时。基线和候选对照单跑均通过,分别为 70.46 s 和 69.52 s。随后原配置预检通过 6 项直接检查和 5 项 smoke。

语义与 CI 对齐

完整及安装专用检查需要报告同一安装的可用性。服务目标必须继续经过当前激活边界。实际生命周期切换、Windows、pipx 和 2.4.0 的同源发布迁移仍需各自证据。本轮 macOS 服务反例仅在调用边界记录拟用的路径。

我的整体评价 / Verdict

请求修改。普通更新读回的修复在真实 wheel 上成立。补齐安装专用检查的失败分支,并恢复服务目标选择的原边界后复验。复验应同时覆盖两种 Doctor 入口及已存在的服务绑定。

English verdict: REQUEST_CHANGES. The exact head fixes full Doctor for the owning wheel, but installation-only can pass using an unrelated binary and a module update can newly nominate its venv for managed service alignment.

Comment thread loopx/doctor.py Resolved
Comment thread loopx/doctor.py Resolved

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

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 · reasoning_effort=max

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

用指定 Python 升级 LoopX 的用户需要 Doctor 证明刚升级的环境与实际执行的 launcher 一致。上一头的安装专用 Doctor 在 launcher 缺失或歧义时会回退到 ambient PATH,模块调用也可能提名系统服务的切换目标。当前两项原问题已复验修复。但 RECORD 单条记录指向一个重定向后的 launcher 时,两种深度 Doctor 仍能把另一环境的 2.3.0 报作同一分发并通过。本轮验证以 macOS 隔离 wheel 和实际激活入口的调用观察为范围。

改动思路 / Approach

两条 Doctor 路径共用模块归属和 launcher 选择,系统服务继续使用原激活条件。当前选取和 deep 分发验证都预先 resolve RECORD 路径,可能把同一次重定向当成两份相符的证据。范围限于 Python 安装归属、Doctor 和原服务入口的隔离。用真实 wheel、独立 2.3.0 venv 和无 LoopX 的 PATH 做配对,健康 launcher 与重定向 launcher 使用同一 RECORD。

具体改动 / Changes

精确 head 9bb8e2bf202c3fd711d06cb16d22b405573ddd5f,diff base 1083771794744d663eb8c025788bd6c116f8c113,3 个文件 +174/-43。逐项复核 shared-doctor-selection、service-boundary、owning-python-readback。验收约定

关键代码讲解

  • 正常 runner 从安装模块和 RECORD 识别 launcher。实际 2.3.0 → 候选 2.4.0 → 2.3.0 的 pip 往返成功,候选在旧版领先 PATH 时选中自己。源码
  • collect_installation_doctor 与普通入口都拒绝无文件或歧义。独立观察现有系统服务调用边界,上一头的模块提名问题已修复,两版基线和候选在原模块场景都 deferred。源码
  • [P2] 唯一的 RECORD launcher 可被重定向到另一环境。保持 RECORD 原样,让候选脚本路径指向独立已发布的 2.3.0,同一候选解释器运行两种 deep Doctor 都返回 0,选中的 CLI 自报 2.3.0。两处 resolve 使用同一外部文件,导致同分发必需检查误过。源码
  • 深度检查用解析后路径与同样解析后的 RECORD 比较。应保留记录路径身份,在选取时核对目标实际归属,保留健康、缺失和歧义对照。源码

对主干的风险 / Risks

发布 2.3.0 和本地精确 wheel 均通过真实安装验证。163 项 Python 测试通过、4 项跳过,标准预检通过 6 项直接及 10 项选中检查。真实服务切换、pipx 与原生 Windows 未在本机执行。新反例在无 LoopX 的 PATH 上也成立。

语义与 CI 对齐

修复保留了原服务选择前提,也恢复了两个 Doctor 对是否可用的共同判定。RECORD 的单条记录能确认登记位置,外部链接目标仍需按实际分发归属验证。

我的整体评价 / Verdict

请求修改。上一轮两个问题已复验解决。额外的真实 wheel 反例仍会让两种 deep Doctor 认证另一个环境的旧 CLI。请在共用入口拒绝外部目标,并复验两个入口。

English verdict: REQUEST_CHANGES. Both prior failures are fixed. A RECORD-listed launcher retargeted to a separate 2.3.0 venv still makes both deep Doctor modes pass as the same distribution.

Comment thread loopx/doctor.py Resolved

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

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, max)

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

运行 loopx update apply 后,用户要确认这次升级所在的 Python 环境和 launcher 可用。前一 head 在 RECORD 字节保持不变但所记 launcher 指向另一套 2.3.0 时,两种 deep Doctor 都会给出通过。当前 wheel 在两种 Doctor 模式拒绝失效、歧义或重定向的 launcher。健康、修复后的 launcher 及正常外部别名仍可通过。评审范围是 Python 安装读回和受管服务目标的既有选择边界。

改动思路 / Approach

两个 Doctor 入口共享分发 owner 判定。候选验证 RECORD 的可执行文件是否仍在其登记位置,再做 deep 命令探测。普通 Doctor 单独保留 ambient PATH,系统服务入口延续原激活条件。只改变诊断路径的 launcher 选择和调用资格,原包管理器、服务绑定和退回路由沿已有实现。用实际独立安装的 2.3.0、上一 head 和本次 wheel 配对,对照同一 RECORD 的正常、重定向、缺失、歧义和恢复状态。

具体改动 / Changes

精确 head c5d6d75812e67bdf13c86f339449fe3341aa15e6,diff base 9af4caa72ec1fc319d48a92399d53827488dfa38,5 个文件 +253/-69。逐项复核 owning-python-environment、verified-installation-readback、preserve-service-boundary。验收约定

关键代码讲解

  • 两种 Doctor 共用 owning distribution 判定。launcher 缺失或不唯一时保留该 owner,避免从 PATH 取另一套包填补。源码
  • 作为 wheel RECORD 被登记的命令须解析回其登记位置。PATH 上的外部别名仍可指向这条已验证命令。源码
  • deep 检查仅探测验证后的 executable。保留 RECORD 但重定向 launcher 时,当前两种模式返回 1,并没有选中 2.3.0。源码
  • 现有 macOS 服务绑定反例继续走 deferred,诊断过程中验证的 virtualenv launcher 未传给服务对齐。源码

对主干的风险 / Risks

当前和上一 head 都从隔离的实际 wheel 启动,在 macOS arm64/Python 3.12 下配对验证。上一 head 的两个重定向 false positive 已消除。当前源码 160 个用例通过、6 个跳过,目标 base 对应 143 个通过、6 个跳过。真实系统服务切换、Windows 和 pipx 仍按各自平台验收。

语义与 CI 对齐

完整与安装专用入口均报告同一 wheel owner。服务调用边界测试观察到服务对齐未发生;实际服务和公开发行的结果仍由其现有流程读回。

我的整体评价 / Verdict

批准当前精确提交。重定向、缺失和歧义都由两种 Doctor 拒绝,恢复、自带 launcher 和外部别名可以通过。当前独立验证支持 package readback,不替代发行验收。

English verdict: APPROVE. Both installed Doctor modes refuse redirected, missing or ambiguous RECORD launchers and recover with the verified owning console. The established managed-service target boundary stays in place.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@huangruiteng
huangruiteng force-pushed the codex/doctor-pin-python-update-installation-20261118 branch from c5d6d75 to 788c598 Compare November 19, 2026 06:44

@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-5 · OpenAI · self_reported

审批结论 / Approval conclusion

动机 / Motivation

loopx update apply 从一个指定 Python 环境运行后,Doctor 必须验证这个环境安装的 launcher,而不能由 PATH 指向另一套安装。旧实现还可能把 RECORD 中重定向的 console script 当作所有权证据。候选只使用 owning distribution 的真实 launcher;缺失、歧义和重定向都 fail closed,ambient PATH 继续单列。

  • affected_caller_or_operator: Users and installers running loopx update apply, pipx updates, or deep installation Doctor checks.
  • before_after_scenario: With two Python environments and a redirected recorded launcher, the previous Doctor accepted the wrong launcher; the candidate requires the current distribution's verified launcher and skips invalid probes.
  • observable_outcome: Doctor deep checks bind command ownership to the imported distribution, retain separate PATH facts, and 31 focused installation/release tests pass.
  • non_goals: Does not switch LaunchAgents, execute native Windows, or alter service activation eligibility.

改动思路 / Approach

reason: The change uses installed RECORD metadata and existing Doctor checks, with no second installation model. current_pr_boundary: Python distribution update readback only; service activation and native host changes stay out.

doctor_invocation_path 先定位当前 imported distribution,再从 RECORD 中找到唯一 launcher。verified_distribution_console 要求 resolve 后仍位于记录的 parent,外部别名可以指向该文件,但重定向的 RECORD 不会被接受。

具体改动 / Changes

关键代码讲解

  • _current_invocation 只允许 standalone core、源码模块或 owning distribution 验证过的 launcher 成为 required command。
  • verified_distribution_console 区分记录位置与安全 alias,拒绝 redirected record。
  • _distribution_command_summary 只把 verified command 计为 ownership 成功,Doctor 和 release-candidate 共用该规则。

对主干的风险 / Risks

最强反例是外部 PATH 或 redirected symlink 冒充更新后的环境。ownership 分支不再使用 PATH 作为必需命令,redirect helper 也要求记录目录不变;31 个 focused tests 和 install/update/release smokes 通过,quick premerge 全过。

我的整体评价 / Verdict

该修复使用 Python 自身安装元数据,不增加第二份状态,也不改变 Goal/Todo 持久语义。它把 update 后的成功判定绑定到真正的 owning environment,并保留 PATH 作为独立的操作者诊断。

English verdict: APPROVE for 788c598. Both Doctor entrypoints verify the owning distribution's launcher, reject redirected or ambiguous records, and retain separate ambient PATH reporting.

@huangruiteng
huangruiteng merged commit 8b1b4ff into main Nov 19, 2026
13 of 16 checks passed
@huangruiteng
huangruiteng deleted the codex/doctor-pin-python-update-installation-20261118 branch November 19, 2026 06:56
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.

2 participants