Skip to content

fix(cli): make doctor runtime-origin aware for OPENCODEX_BUN_PATH guidance (#848) - #898

Closed
Yuxin-Qiao wants to merge 1 commit into
lidge-jun:devfrom
Yuxin-Qiao:codex/doctor-bun-override-awareness
Closed

fix(cli): make doctor runtime-origin aware for OPENCODEX_BUN_PATH guidance (#848)#898
Yuxin-Qiao wants to merge 1 commit into
lidge-jun:devfrom
Yuxin-Qiao:codex/doctor-bun-override-awareness

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 2, 2026

Copy link
Copy Markdown

Summary

ocx doctor on Windows told users to set OPENCODEX_BUN_PATH even when the running service already uses that override, making the guidance circular (#848).

  • GET /api/system/memory now reports the service process's own runtime source (bundled / override / process) as a scalar enum, never the runtime path.
  • The doctor "Memory / runtime" section shows the Bun revision and, for an active override, identifies the override as active but unvalidated for automatic eager relay, without repeating the "set OPENCODEX_BUN_PATH" instruction. Bundled known-bad guidance is unchanged.
  • Docs: the windows-memory troubleshooting page is updated in all five locales.

Verification

  • bun run typecheck - passed
  • Focused: bun scripts/test.ts tests/doctor.test.ts tests/memory-watchdog.test.ts - 41 pass / 0 fail, including the new [Bug]: doctor repeats OPENCODEX_BUN_PATH guidance when a Bun canary override is already active #848 regression tests
  • Full: bun scripts/test.ts - 6869 pass, 8 skip; the 16 unique failing tests reproduce on a pristine origin/dev checkout with identical counts (environmental: bun missing from PATH in the isolated test env, missing gui/node_modules, provider-validation baseline); none touch changed files
  • bun run privacy:scan - passed
  • git diff --check - clean

Checklist

  • Scope stays focused on the doctor/API surface and avoids unrelated cleanup.
  • Docs updated where needed (English plus zh-cn, ja, ko, ru).
  • No new secrets or auth surfaces; the payload addition is a scalar enum.

Summary by CodeRabbit

  • New Features

    • ocx doctor now reports the Bun revision and whether the runtime is bundled or overridden through OPENCODEX_BUN_PATH.
    • Windows memory diagnostics provide clearer guidance when a runtime override is active.
  • Bug Fixes

    • Prevented duplicate or misleading upgrade instructions for active runtime overrides.
    • Clarified that memory metrics alone do not confirm a leak on the bundled runtime.
  • Documentation

    • Updated troubleshooting guidance in English, Japanese, Korean, Russian, and Simplified Chinese.

…dance (lidge-jun#848)

ocx doctor told Windows users to set OPENCODEX_BUN_PATH even when the
service already runs on that override, making the guidance circular.

- GET /api/system/memory now reports the service process's own runtime
  source (bundled/override/process) as a scalar enum; never the path.
- doctor's Memory/runtime section shows the Bun revision and identifies
  an active override instead of re-suggesting the env var; bundled
  known-bad guidance is unchanged.
- regression tests cover both bundled and override runtimes reporting
  the same version, plus endpoint-level override detection.
@github-actions github-actions Bot added the bug Something isn't working label Aug 2, 2026
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The memory endpoint now returns Bun runtime-source metadata. ocx doctor displays the Bun revision and identifies active OPENCODEX_BUN_PATH overrides. Windows guidance and localized documentation reflect the bundled and override runtime cases.

Changes

Bun runtime diagnostics

Layer / File(s) Summary
Runtime metadata endpoint
src/server/management/system-routes.ts, tests/memory-watchdog.test.ts
The memory endpoint returns runtime.source. Tests cover supported sources and active OPENCODEX_BUN_PATH overrides.
Doctor runtime guidance
src/cli/doctor.ts, tests/doctor.test.ts
ocx doctor accepts and displays Bun revision and runtime-source metadata. Windows guidance distinguishes active overrides from bundled runtimes.
Localized runtime documentation
docs-site/src/content/docs/*/troubleshooting/windows-memory.md
Windows memory documentation describes Bun revision, runtime source, active overrides, and bundled-runtime heap-counter behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making CLI doctor guidance aware of the runtime origin for OPENCODEX_BUN_PATH.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be761e7925

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

platform: process.platform,
// Scalar enum only, never the runtime path: lets diagnostics tell a
// bundled runtime from an OPENCODEX_BUN_PATH override (#848).
runtime: { source: durableBunRuntime().source },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive the runtime source from the running executable

When a user follows the documented service workflow—sets OPENCODEX_BUN_PATH only in the install shell and reruns ocx service install—the Windows wrapper/WinSW definition bakes that path as the executable but does not propagate OPENCODEX_BUN_PATH into the service environment. Consequently, this call reevaluates the now-absent environment variable, reports bundled, and ocx doctor repeats the same circular override guidance that this change is intended to remove. Determine the source from process.execPath versus the bundled/override paths, or persist a non-sensitive source marker in the service definition; the new test currently masks the defect by setting the variable inside the already-running process.

AGENTS.md reference: docs-site/AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/doctor.ts`:
- Around line 526-527: Preserve the BunRuntimeSource contract by exporting and
reusing a union for bundled, override, and process values, and validate the
doctor response before storing it. Update formatServiceMemoryLines to handle all
three valid sources plus absent or invalid values so process is not treated as
bundled and unknown values remain safe. Add regression coverage for each valid
source and invalid input, and update the five Windows-memory pages if process
becomes user-visible.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4bd63f1f-5c1e-48d3-85e2-6d7a8a05d3f9

📥 Commits

Reviewing files that changed from the base of the PR and between f9b9440 and be761e7.

📒 Files selected for processing (9)
  • docs-site/src/content/docs/ja/troubleshooting/windows-memory.md
  • docs-site/src/content/docs/ko/troubleshooting/windows-memory.md
  • docs-site/src/content/docs/ru/troubleshooting/windows-memory.md
  • docs-site/src/content/docs/troubleshooting/windows-memory.md
  • docs-site/src/content/docs/zh-cn/troubleshooting/windows-memory.md
  • src/cli/doctor.ts
  • src/server/management/system-routes.ts
  • tests/doctor.test.ts
  • tests/memory-watchdog.test.ts

Comment thread src/cli/doctor.ts
Comment on lines +526 to +527
bunRevision?: string;
runtime?: { source: string };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
rg -n -C 4 \
  'durableBunRuntime|runtime.*source|source.*override|source.*process|OPENCODEX_BUN_PATH' \
  src tests docs-site

Repository: lidge-jun/opencodex

Length of output: 50376


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- doctor outline ---'
ast-grep outline src/cli/doctor.ts --match 'ServiceMemoryData' --view expanded || true

printf '%s\n' '--- doctor type/fetch/format regions ---'
rg -n -C 12 'type ServiceMemoryData|interface ServiceMemoryData|fetchServiceMemory|formatServiceMemoryLines|runtime\.source|source ===' src/cli/doctor.ts

printf '%s\n' '--- runtime definition ---'
cat -n src/lib/bun-runtime.ts | sed -n '20,75p'

printf '%s\n' '--- doctor tests around runtime guidance ---'
cat -n tests/doctor.test.ts | sed -n '330,465p'

printf '%s\n' '--- all source and test references ---'
rg -n -C 3 'runtime:\s*\{[^}]*source|runtime\.source|source:\s*"(bundled|override|process)"|source === "(bundled|override|process)"' src tests

Repository: lidge-jun/opencodex

Length of output: 39901


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- doctor imports and report types ---'
cat -n src/cli/doctor.ts | sed -n '1,45p'
cat -n src/cli/doctor.ts | sed -n '515,550p'

printf '%s\n' '--- durable runtime call sites and service artifact behavior ---'
rg -n -C 8 'durableBunRuntime\(\)|durableBunPath\(\)|buildWindowsServiceScript|process\.execPath' src tests

printf '%s\n' '--- language-page runtime wording ---'
for f in docs-site/src/content/docs/troubleshooting/windows-memory.md \
         docs-site/src/content/docs/ja/troubleshooting/windows-memory.md \
         docs-site/src/content/docs/ko/troubleshooting/windows-memory.md \
         docs-site/src/content/docs/ru/troubleshooting/windows-memory.md \
         docs-site/src/content/docs/zh-cn/troubleshooting/windows-memory.md; do
  if [ -f "$f" ]; then
    printf '\n--- %s ---\n' "$f"
    rg -n -C 2 'bundled runtime|bundled|OPENCODEX_BUN_PATH|运行时|ランタイム|рантайм|런타임' "$f" | head -80
  else
    printf '%s\n' "MISSING: $f"
  fi
done

printf '%s\n' '--- standalone behavior verifier ---'
python3 - <<'PY'
from pathlib import Path
import re

doctor = Path("src/cli/doctor.ts").read_text()
runtime = Path("src/lib/bun-runtime.ts").read_text()

assert 'runtime?: { source: string };' in doctor
assert 'typeof body.runtime.source === "string"' in doctor
assert 'd.runtime?.source === "override"' in doctor
assert '"process"' in runtime

def parsed_source(value):
    # Mirrors fetchServiceMemory's present-string acceptance.
    return value if isinstance(value, str) else None

def guidance_branch(source):
    # Mirrors formatServiceMemoryLines's Windows auto-known-bad branch.
    return "override" if source == "override" else "bundled-guidance"

for value in ("bundled", "override", "process", "future", 17, None):
    accepted = parsed_source(value)
    print(f"input={value!r} stored={accepted!r} branch={guidance_branch(accepted)!r}")

assert guidance_branch("process") == "bundled-guidance"
assert guidance_branch("future") == "bundled-guidance"
assert parsed_source("future") == "future"
print("deterministic behavior matches the source branches")
PY

Repository: lidge-jun/opencodex

Length of output: 50376


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- Windows memory documentation files and runtime statements ---'
find docs-site/src/content/docs -type f -path '*/troubleshooting/windows-memory.md' -print
for f in $(find docs-site/src/content/docs -type f -path '*/troubleshooting/windows-memory.md' | sort); do
  printf '\n--- %s ---\n' "$f"
  rg -n -C 1 'bundled runtime|bundled|OPENCODEX_BUN_PATH' "$f" | head -40
done

printf '%s\n' '--- service script runtime selection ---'
cat -n src/service.ts | sed -n '45,53p'
cat -n src/service.ts | sed -n '1261,1315p'

printf '%s\n' '--- standalone behavior verifier ---'
python3 - <<'PY'
from pathlib import Path

doctor = Path("src/cli/doctor.ts").read_text()
runtime = Path("src/lib/bun-runtime.ts").read_text()

assert 'runtime?: { source: string };' in doctor
assert 'typeof body.runtime.source === "string"' in doctor
assert 'd.runtime?.source === "override"' in doctor
assert 'source: "process"' in runtime

def fetch_stores(value):
    return value if isinstance(value, str) else None

def format_branch(value):
    stored = fetch_stores(value)
    return "override branch" if stored == "override" else "non-override branch"

for value in ("bundled", "override", "process", "future", 17, None):
    print(f"{value!r}: stored={fetch_stores(value)!r}, {format_branch(value)}")

assert fetch_stores("future") == "future"
assert format_branch("process") == "non-override branch"
assert format_branch("future") == "non-override branch"
print("source acceptance and formatting branches match the implementation")
PY

Repository: lidge-jun/opencodex

Length of output: 11308


Preserve and validate the BunRuntimeSource contract.

src/lib/bun-runtime.ts:23-26,55-60 emits "bundled", "override", or "process". src/cli/doctor.ts:527,585 widens this value to string and accepts unknown strings. formatServiceMemoryLines handles only "override" at lines 633 and 666-670. Therefore "process" and unknown values omit the source label and show bundled-runtime guidance. "process" uses process.execPath when the bundled Bun binary is unavailable, so it is not necessarily bundled.

Export and reuse a BunRuntimeSource union. Validate the response before storing it. Handle "bundled", "override", "process", and absent or invalid values separately. Add regression tests for all three valid values and invalid input. Update the five Windows-memory pages if "process" becomes user-visible.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/doctor.ts` around lines 526 - 527, Preserve the BunRuntimeSource
contract by exporting and reusing a union for bundled, override, and process
values, and validate the doctor response before storing it. Update
formatServiceMemoryLines to handle all three valid sources plus absent or
invalid values so process is not treated as bundled and unknown values remain
safe. Add regression coverage for each valid source and invalid input, and
update the five Windows-memory pages if process becomes user-visible.

Source: Path instructions

@lidge-jun

Copy link
Copy Markdown
Owner

Closing as a duplicate: the #848 fix already landed in #892 via the wt5 workstream. On codex/wt2-zero-leak-impl, doctor reads the launch-time provenance marker (bunRuntimeSource: override / missing / process|bundled) and never tells the user to set OPENCODEX_BUN_PATH when that override is already active — see src/cli/doctor.ts:665-679 on that branch, which names #848 explicitly. The provenance pair (source+path) is recorded through every launcher, with legacy payloads read as unknown. Thanks for the clean write-up; the API-payload variant here lost out to the launch-marker approach because it cannot be spoofed by a stale service response.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants