Skip to content

fix(cli): status/doctor use identity-verified live proxy - #642

Merged
Wibias merged 4 commits into
lidge-jun:devfrom
Wibias:fix/618-status-live-proxy
Jul 29, 2026
Merged

fix(cli): status/doctor use identity-verified live proxy#642
Wibias merged 4 commits into
lidge-jun:devfrom
Wibias:fix/618-status-live-proxy

Conversation

@Wibias

@Wibias Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • ocx status --json and ocx doctor prefer findLiveProxy() over ocx.pid alone so a healthy Task Scheduler proxy is not reported stopped.
  • Missing PID file remains a separate concern; verified live proxies report running: true.

Test plan

  • bun run typecheck
  • CI green

Closes #618

Summary by CodeRabbit

  • Bug Fixes
    • Improved ocx status accuracy by verifying proxy liveness through health checks and runtime information.
    • Corrected reported proxy status and process IDs when stale or missing PID files are encountered.
    • Enhanced ocx doctor diagnostics to identify live proxies more reliably.
    • Prevented memory checks and restart guidance from relying on outdated proxy information.
    • Improved detection and recovery of running proxies when runtime records or PID files are incomplete.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

ocx status and ocx doctor now use identity-verified proxy liveness from findLiveProxy, including orphaned runtime records. LiveProxy identifies its discovery source, while status PID/health output and doctor runtime diagnostics derive from the verified live result.

Changes

Proxy diagnostics

Layer / File(s) Summary
LiveProxy discovery source and coverage
src/server/proxy-liveness.ts, tests/proxy-liveness.test.ts
LiveProxy reports whether discovery used runtime metadata or configured-port probing, with tests covering runtime, orphan recovery, fallback, and PID verification cases.
Status liveness precedence
src/cli/status.ts, tests/cli-status-json.test.ts
collectStatus() prefers findLiveProxy() results, preserves authoritative null PIDs, avoids duplicate health probing, and derives labels and JSON fields from verified liveness.
Doctor liveness diagnostics
src/cli/doctor.ts
runDoctor uses verified liveness for runtime data, process environment lookup, memory collection, and restart-hint state and port selection.

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

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 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 is concise and accurately summarizes the main fix: status/doctor now rely on identity-verified live proxy discovery.
Linked Issues check ✅ Passed status and doctor now prefer findLiveProxy() for verified liveness, preserve missing-PID warnings, and avoid incorrect restart hints.
Out of Scope Changes check ✅ Passed The new proxy-liveness source field and tests directly support the status/doctor liveness fix, with no unrelated changes visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review
@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Wibias, I’ll review the changes in #642, with particular attention to live-proxy verification, status/doctor behavior, and missing-PID-file edge cases.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions github-actions Bot added the bug Something isn't working label Jul 28, 2026

@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: e87deb20e1

ℹ️ 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".

Comment thread src/cli/status.ts Outdated
const listen = selectListenTarget(config, pid, pid ? readRuntimePort(pid) : null);
const health = await checkProxyHealth(listen);
// Prefer identity-verified liveness (runtime-port + /healthz) over ocx.pid alone (#618).
const live = await findLiveProxy();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep status and doctor on the read-only config path

When the config is malformed, these new findLiveProxy() calls default their configFn to loadConfig(), which invokes warnAndBackupInvalidConfig; consequently, even with no PID/runtime record, ocx status --json and ocx doctor now create a new config.json.invalid-* file and emit a warning to stderr. This breaks the explicit read-only behavior covered by tests/cli-status-json.test.ts:244-271 and can accumulate backups every time diagnostics are run. Pass the already-read diagnostics config into findLiveProxy (and do likewise for the call in doctor.ts) or provide a non-mutating config reader.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

Comment thread src/cli/status.ts Outdated
// Prefer identity-verified liveness (runtime-port + /healthz) over ocx.pid alone (#618).
const live = await findLiveProxy();
const pidFile = readPid();
const pid = live?.pid ?? pidFile;

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 Preserve a null PID from orphan liveness checks

When an orphaned runtime record answers with a legacy, PID-less health response while ocx.pid names a different still-running Ocx-shaped process, findLiveProxy() deliberately returns pid: null so the stale PID is not attributed to that listener, but this nullish fallback immediately restores pidFile. The label and JSON then claim the verified live proxy has that unrelated PID, and the analogous fallbacks in doctor.ts:724,732 inspect that process as the proxy. Use live ? live.pid : pidFile so a live result's authoritative null is preserved, and cover this caller behavior with a focused regression test.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

Comment thread src/cli/status.ts Outdated
? {
port: live.port,
hostname: live.hostname,
source: "runtime" as const,

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 Preserve config as the source of fallback listen targets

If both PID/runtime metadata are absent or unusable but the proxy answers on config.port, findLiveProxy() succeeds through its configured-port fallback; this branch nevertheless reports listen.source as "runtime". That makes the documented JSON runtime/config source inaccurate precisely in the missing-state scenario this change handles. Have liveness return its discovery source, or retain "config" when the successful target came from the configured fallback.

AGENTS.md reference: AGENTS.md:L96-L97

Useful? React with 👍 / 👎.

Wibias added 3 commits July 28, 2026 19:54
Keep doctor on the read-only diagnostics config path. Preserve authoritative
null live pids, surface runtime vs config listen source from findLiveProxy,
and cover resolveStatusPid.
@Wibias

Wibias commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed remaining Codex review on latest dig:

  • P1 doctor now passes diagnostics configFn (status already did in e172a3ec)
  • P2 resolveStatusPid / doctor use live ? live.pid : pidFile so authoritative null is kept
  • P2 findLiveProxy returns source: "runtime" | "config"; status JSON uses it

Focused tests: proxy-liveness, cli-status-json (+ typecheck).

@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 `@tests/cli-status-json.test.ts`:
- Around line 288-293: Strengthen the consumer-level regressions for an
identity-verified live proxy with a missing or stale PID file: in
tests/cli-status-json.test.ts:288-293, add a collectStatus() case asserting
running state, health/dashboard URLs, resolved PID, fallback port, and
listen.source; keep src/cli/status.ts:143-169 focused on the liveness-first
branch and ensure src/cli/status.ts:263-280 reports the verified proxy as
running. Add the matching doctor regression in src/cli/doctor.ts:722-736,
asserting at src/cli/doctor.ts:758-761 that diagnostics use the verified live
port and at src/cli/doctor.ts:824-825 that no unnecessary proxy-restart hint is
emitted.
🪄 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: f6c93a91-92eb-466e-915f-53cc96ca4e8d

📥 Commits

Reviewing files that changed from the base of the PR and between a4fb284 and a53f6a4.

📒 Files selected for processing (5)
  • src/cli/doctor.ts
  • src/cli/status.ts
  • src/server/proxy-liveness.ts
  • tests/cli-status-json.test.ts
  • tests/proxy-liveness.test.ts

Comment on lines +288 to +293
test("resolveStatusPid preserves an authoritative null from live orphan checks", () => {
expect(resolveStatusPid({ pid: null }, 4242)).toBeNull();
expect(resolveStatusPid({ pid: 1111 }, 4242)).toBe(1111);
expect(resolveStatusPid(null, 4242)).toBe(4242);
expect(resolveStatusPid(null, null)).toBeNull();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Add consumer-level regressions for verified live proxies without a usable PID file.

The new unit test only validates resolveStatusPid; it cannot catch incorrect status JSON/URLs or doctor restart and memory behavior when findLiveProxy() discovers an orphaned runtime record.

  • tests/cli-status-json.test.ts#L288-L293: add a collectStatus() regression with a missing/stale PID file and identity-verified runtime-record proxy; assert running, health/dashboard URLs, resolved PID, fallback port, and listen.source.
  • src/cli/status.ts#L143-L169: keep the status regression focused on the liveness-first branch.
  • src/cli/status.ts#L263-L280: assert the returned JSON reports the verified proxy as running even without a valid PID file.
  • src/cli/doctor.ts#L722-L736: add a doctor regression for the same scenario.
  • src/cli/doctor.ts#L758-L761: assert doctor fetches runtime diagnostics from the verified live port.
  • src/cli/doctor.ts#L824-L825: assert doctor does not emit an unnecessary proxy-restart hint.

As per path instructions, “A behavior change in src/ should come with a focused regression test near the existing tests for that subsystem.”

📍 Affects 3 files
  • tests/cli-status-json.test.ts#L288-L293 (this comment)
  • src/cli/status.ts#L143-L169
  • src/cli/status.ts#L263-L280
  • src/cli/doctor.ts#L722-L736
  • src/cli/doctor.ts#L758-L761
  • src/cli/doctor.ts#L824-L825
🤖 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 `@tests/cli-status-json.test.ts` around lines 288 - 293, Strengthen the
consumer-level regressions for an identity-verified live proxy with a missing or
stale PID file: in tests/cli-status-json.test.ts:288-293, add a collectStatus()
case asserting running state, health/dashboard URLs, resolved PID, fallback
port, and listen.source; keep src/cli/status.ts:143-169 focused on the
liveness-first branch and ensure src/cli/status.ts:263-280 reports the verified
proxy as running. Add the matching doctor regression in
src/cli/doctor.ts:722-736, asserting at src/cli/doctor.ts:758-761 that
diagnostics use the verified live port and at src/cli/doctor.ts:824-825 that no
unnecessary proxy-restart hint is emitted.

Source: Path instructions

@Wibias
Wibias merged commit e6169b0 into lidge-jun:dev Jul 29, 2026
11 checks passed
Wibias added a commit that referenced this pull request Jul 29, 2026
@Wibias

Wibias commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Transition complete:

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.

[Bug]: status and doctor ignore an identity-verified live proxy when ocx.pid is missing

1 participant