Skip to content

fix(update-manager): fix npm registry fallback schema and env-less npm path discovery - #1343

Merged
iruriQ merged 1 commit into
mainfrom
fix/npm-update-fallback-and-env-discovery
Nov 28, 2026
Merged

iruriQ merged 1 commit into
mainfrom
fix/npm-update-fallback-and-env-discovery

Conversation

@iruriQ

@iruriQ iruriQ commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix two npm update failures reproduced in end-to-end isolated update testing:

  1. P0 — npm registry fallback failed updateCheckResultSchema validation:
    • When GitHub Release discovery was unavailable or rate-limited and fell back to fetchLatestNpmRelease(), returning releaseNotesUrl: "" violated githubReleaseNotesUrlSchema.nullable() in updateCheckResultSchema, causing Web RPC and codexhost update to fail with a Zod invalid_format error.
  2. P2 — npm installations launched directly via platform bin/codexhost failed update checks:
    • When CODEXHOST_NPM_* environment variables were absent (such as when Desktop Shell invokes bin/codexhost directly instead of the bin/codexhost.js wrapper), update checks failed with CODEXHOST_NPM_NODE_PATH must be an absolute path and reported version 0.0.0.

Changes

  • packages/update-manager/src/github-release.ts & packages/update-manager/src/npm-registry.ts: Change CodexhostLatestRelease.releaseNotesUrl to string | null and return releaseNotesUrl: null from fetchLatestNpmRelease().
  • packages/update-manager/src/distribution.ts & packages/update-manager/src/index.ts: Export resolveNpmRuntimePaths() and use it in resolveInstalledUpdateContext(). Explicitly provided invalid CODEXHOST_NPM_* values (empty, relative, or mismatched package root) remain strictly rejected; only unset variables fall back to deriving paths from standard @codexhost/cli-* flat or nested global npm layouts (resolving regular non-symlink npm-cli.js files).
  • packages/console-server/src/updates.ts: Reuse resolveNpmRuntimePaths() so standalone Console / codexhost update also works without CODEXHOST_NPM_* env vars.
  • packages/update-manager/test/npm-registry.test.ts, packages/update-manager/test/distribution.test.ts, packages/host-runtime/test/update-coordinator.test.ts, packages/console-server/test/updates.test.ts: Add focused regression tests validating real fetchLatestNpmRelease() output through updateCheckResultSchema.parse(), testing flat/nested/custom-prefix env-less npm discovery, and verifying explicit invalid CODEXHOST_NPM_* env vars are still rejected.

Visual Changes

No visual changes: backend update-manager, host-runtime, and console-server npm update discovery and runtime path resolution fixes only.

Validation

  • tsc -b packages/update-manager packages/console-server: passed (implementation session; verified all CodexhostLatestRelease / releaseNotesUrl consumers across the workspace).
  • Focused Vitest suite (packages/update-manager/test/, packages/host-runtime/test/update-coordinator.test.ts, packages/console-server/test/updates.test.ts): 11 test files, 123 passed, 1 platform-skipped (implementation session; verified npm fallback regression failed before the fix).
  • pre-commit Prettier formatting check on all 9 changed files: passed.
  • Full-repo lint/typecheck/test delegated to CI per AGENTS.md.

…m path discovery

Fixes two real npm update failures reproduced during end-to-end isolated update testing:

1. Allow CodexhostLatestRelease.releaseNotesUrl to be null and return null (instead of "") from fetchLatestNpmRelease(). Previously, when GitHub Release discovery failed or hit rate limits and fell back to the npm registry, releaseNotesUrl: "" failed updateCheckResultSchema validation (which requires a valid GitHub Release URL or null), breaking npm update checks and updates.
2. Add resolveNpmRuntimePaths() in @codexhost/update-manager and reuse it in both resolveInstalledUpdateContext() and console-server updates. When CODEXHOST_NPM_* environment variables are unset (for example when Desktop Shell launches the platform bin/codexhost directly without bin/codexhost.js), derive packageRoot, @codexhost/cli/bin/codexhost.js, node, and npm-cli.js from standard global npm layouts (flat or nested), while continuing to strictly reject explicitly set invalid CODEXHOST_NPM_* values.
@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能

    • npm 安装的更新检查现在可自动发现所需运行时路径,减少对手动配置路径的依赖。
    • GitHub 发布信息不可用时,npm 安装仍可查询稳定版本。
  • 错误修复

    • 缺少发布说明链接时返回空值,而非空字符串。
    • 更新结果现可在无发布说明链接的情况下通过校验。

新增 npm 运行时路径发现,并将其用于控制台更新检查、更新准备和 npm 注册表回退。npm 注册表查询没有发行说明 URL 时,结果现在使用 null,相关类型和测试也已更新。

Changes: npm 更新运行时

层 / 文件 摘要
npm 运行时路径解析
packages/update-manager/src/distribution.ts, packages/update-manager/src/index.ts, packages/update-manager/test/distribution.test.ts
新增 resolveNpmRuntimePaths,从 npm 包布局及环境中解析 Node、npm CLI、launcher 和 package root 路径。已安装更新上下文改用此解析器。测试覆盖全局安装布局、自定义前缀和无效显式路径。
控制台更新集成
packages/console-server/src/updates.ts, packages/console-server/test/updates.test.ts
控制台使用解析出的路径检查 npm 安装、准备更新,并在 GitHub Release 查询失败时查询 npm 注册表。测试覆盖未设置 CODEXHOST_NPM_* 变量的全局安装场景。
npm 回退发行说明契约
packages/update-manager/src/github-release.ts, packages/update-manager/src/npm-registry.ts, packages/update-manager/test/npm-registry.test.ts, packages/console-server/test/updates.test.ts, packages/host-runtime/test/update-coordinator.test.ts
releaseNotesUrl 类型允许 null,npm 注册表查询无发行说明 URL 时返回 null。相关更新检查测试使用 schema 验证结果。

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ConsoleUpdates
  participant GitHubRelease
  participant resolveConsoleNpmPaths
  participant NpmRegistry
  ConsoleUpdates->>GitHubRelease: 查询最新发行版
  GitHubRelease-->>ConsoleUpdates: 返回 HTTP 403 或 429
  ConsoleUpdates->>resolveConsoleNpmPaths: 解析目标安装的 npm 路径
  resolveConsoleNpmPaths-->>ConsoleUpdates: 返回 Node 和 npm CLI 路径
  ConsoleUpdates->>NpmRegistry: 使用解析出的路径查询最新版本
  NpmRegistry-->>ConsoleUpdates: 返回版本和可空的发行说明 URL
Loading

Possibly related PRs

  • BytePioneer-AI/codex-host#1259:该 PR 添加 GitHub Release 查询失败时的 npm 注册表回退;本 PR 更新了该回退结果的运行时路径解析和发行说明 URL 契约。
  • BytePioneer-AI/codex-host#1197:该 PR 实现 GitHub Release 查询失败时的 npm 回退;本 PR 修改了同一回退路径使用的发行说明 URL 契约。

Suggested reviewers: bytepioneer-ai, koeria

Merge Risk: Minimal · up to 58e67

This change lets npm-installed updates find their runtime paths without the environment variables, and lets the npm registry fallback report no release notes link instead of failing validation. No concrete merge-blocking risk remains. Normal CI should still run before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(update-manager): fix npm registry fallback schema and env-less npm path discovery”与变更集高度相关。变更包括:npm 注册表回退返回的 releaseNotesUrl 改为 null 以通过 updateCheckResultSchema 校验;新增 resolveNpmRuntimePaths 以在未…
Description check Passed 描述说明了两个已复现的 npm 更新故障:GitHub Release 不可用时 npm 回退返回空字符串导致 Zod 校验失败,以及未设置 CODEXHOST_NPM_* 环境变量时更新检查失败。描述列出的受影响文件(github-release.ts、npm-registry.ts、distribution.ts、index.ts、updates.ts 及对应测试)与变更集一致,并说明了显式无…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“fix(update-manager): fix npm registry fallback schema and env-less npm path discovery”与变更集高度相关。变更包括:npm 注册表回退返回的 releaseNotesUrl 改为 null 以通过 updateCheckResultSchema 校验;新增 resolveNpmRuntimePaths 以在未设置 CODEXHOST_NPM_* 环境变量时发现 npm 运行时路径。标题准确概括了两项主要修复。

Full details: Description check

Explanation

描述说明了两个已复现的 npm 更新故障:GitHub Release 不可用时 npm 回退返回空字符串导致 Zod 校验失败,以及未设置 CODEXHOST_NPM_* 环境变量时更新检查失败。描述列出的受影响文件(github-release.ts、npm-registry.ts、distribution.ts、index.ts、updates.ts 及对应测试)与变更集一致,并说明了显式无效值仍被拒绝的行为。

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cfc33ca and 58e67bb.

Files selected for processing: 9

  • packages/console-server/src/updates.ts
  • packages/console-server/test/updates.test.ts
  • packages/host-runtime/test/update-coordinator.test.ts
  • packages/update-manager/src/distribution.ts
  • packages/update-manager/src/github-release.ts
  • packages/update-manager/src/index.ts
  • packages/update-manager/src/npm-registry.ts
  • packages/update-manager/test/distribution.test.ts
  • packages/update-manager/test/npm-registry.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Recent review details

Context from checks skipped due to timeout: 7

  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
  • GitHub Check: Check macos-26
  • GitHub Check: Static checks
  • GitHub Check: Vitest
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 2

AGENTS.md — auto-discovered
CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: Host Runtime loads installed plugins through public contracts, not direct imports of concrete Adapter packages.

CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/host-runtime/test/update-coordinator.test.ts
Learnings: 1

Learning: 2026-11-23T12:41:30.268Z

Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-23T12:41:30.268Z
Learning: Source excerpt:
# Repository Guidelines

## Boundary Rules

- Use package public exports for cross-package dependencies. Read `tools/check-boundaries.mjs` before changing dependency directions; it is the executable boundary check run by `npm run lint`.

Applied to files:

  • packages/console-server/src/updates.ts
ESLint

packages/console-server/test/updates.test.ts

[error] 20-20: '_nodePath' is defined but never used.

(@typescript-eslint/no-unused-vars)

[error] 21-21: '_npmCliPath' is defined but never used.

(@typescript-eslint/no-unused-vars)

[error] 135-135: Forbidden non-null assertion.

(@typescript-eslint/no-non-null-assertion)

[error] 188-188: Forbidden non-null assertion.

(@typescript-eslint/no-non-null-assertion)

packages/host-runtime/test/update-coordinator.test.ts

[error] 25-25: '_nodePath' is defined but never used.

(@typescript-eslint/no-unused-vars)

[error] 25-25: '_npmCliPath' is defined but never used.

(@typescript-eslint/no-unused-vars)

[error] 245-245: Forbidden non-null assertion.

(@typescript-eslint/no-non-null-assertion)

Additional comments: 1

packages/update-manager/src/distribution.ts: 1

336-336: Data Integrity & Integration

更新器的 Rust 预检会拒绝该情况,因此不会将新版本安装到 /B。

resolveNpmRuntimePaths 可能返回 /B 的 npm,同时保留 /A 的 packageRoot。随后 preflight 会将该 packageRoot 与 npm 的全局根目录比较。在 /A 平台包与 /B 的 npm 组合下,global_installation 返回 None,preflight 因此报错,install_npm 不会执行。

只有 npm 的全局根目录包含该平台包,或者包含对应的嵌套 CLI 布局时,安装才会继续。在这种情况下,npm 的默认全局前缀就是目标位置,因此安装不会写入其他前缀。

@iruriQ
iruriQ merged commit 1a45591 into main Nov 28, 2026
5 of 8 checks passed
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