Skip to content

fix(codex): distinguish a failed desktop probe from an absent app - #2593

Merged
lidge-jun merged 1 commit into
devfrom
codex/windows-restart-probe-2557
Aug 25, 2026
Merged

lidge-jun merged 1 commit into
devfrom
codex/windows-restart-probe-2557

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Aug 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #2557. Two defects on the Windows --restart-desktop-app path, and the second is
what made the first invisible.

The probe script was malformed. listPackageProcesses joined its PowerShell statements
with a space, so $ErrorActionPreference='SilentlyContinue' $root = '...' became a single
statement and PowerShell rejected the whole script. Statements are now newline-separated.

A failed probe was reported as an absent app. The resulting throw was caught and
returned [], which is indistinguishable from a successful enumeration that found nothing.
That became no_targets, and the CLI told the user "Codex desktop app is not running;
nothing to restart" — silently skipping the restart they had explicitly asked for. A failed
probe now returns null and the caller reports a new process_probe_failed reason with an
honest message.

The PID re-check (stillSameProcess) fails closed the same way. It guards a kill, so "we
could not look" must never be read as "the pid was recycled and now belongs to someone
else".

Verification

Each fix was driven red independently — reverting one fails exactly its own cases:

# newline join reverted to a space
$ bun test tests/desktop-app-restart.test.ts
 18 pass, 1 fail

# failed probe reverted to returning []
$ bun test tests/desktop-app-restart.test.ts
 17 pass, 2 fail

# both fixes in place
$ bun test tests/desktop-app-restart.test.ts
 19 pass, 0 fail, 50 expect() calls

$ bun x tsc --noEmit
(clean)

The new cases assert that a throwing probe reports process_probe_failed while terminating
nothing and relaunching nothing, that an empty enumeration still reports no_targets so the
two states stay distinguishable in both directions, and that the emitted script separates
its statements.

This is exercised through the existing io seam, so the guards are proved on any platform
rather than asserted from a comment — the convention #2292 established for this file.

Checklist

  • Targets dev
  • Based on the current dev head
  • Each fix driven red first, then green
  • Termination path still fails closed on unreadable evidence
  • Typecheck clean
  • No secrets or account identifiers in the diff

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows desktop app restart handling when running processes cannot be detected.
    • Reports process-detection failures separately from cases where no restartable processes are found.
    • Prevents termination or relaunch when process identity checks cannot be completed, avoiding unsafe restarts.

Two defects on the Windows --restart-desktop-app path.

The probe script joined its PowerShell statements with a space, so
$ErrorActionPreference='SilentlyContinue' $root = '...' became one
malformed statement and the whole script was rejected.

The resulting throw was caught and returned [], which is indistinguishable
from a successful enumeration that found nothing. That became no_targets
and the CLI told the user the app was not running, silently skipping the
restart they had asked for.

Statements are now newline-separated, a failed probe returns null, and the
caller reports the new process_probe_failed reason. The PID re-check fails
closed the same way: it guards a kill, so 'we could not look' must never
read as 'the pid was recycled'.

Both driven red first: reverting either fails exactly its own cases.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner August 25, 2026 17:27
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun merged commit c17a7b8 into dev Aug 25, 2026
8 of 9 checks passed
@lidge-jun
lidge-jun deleted the codex/windows-restart-probe-2557 branch August 25, 2026 17:27
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fe2f3194-6e46-4178-b963-2f561c8c8257

📥 Commits

Reviewing files that changed from the base of the PR and between 2fa2ba7 and 01afdfe.

📒 Files selected for processing (3)
  • src/cli/dispatch.ts
  • src/codex/desktop-app-restart.ts
  • tests/desktop-app-restart.test.ts

📝 Walkthrough

Walkthrough

Windows desktop restart handling now separates failed process probes from empty process results. PowerShell probe statements use newline separators. Process identity checks fail closed when reprobes fail. The CLI reports failed probes, with regression tests covering these cases.

Changes

Desktop restart probe handling

Layer / File(s) Summary
Process probe and restart outcomes
src/codex/desktop-app-restart.ts
At lines 46, 123, and 140–154, process probing returns null for execution failures and uses newline-separated PowerShell statements. At lines 180–184, failed identity reprobes return false. At lines 279–281, restart handling returns process_probe_failed instead of no_targets.
CLI reporting and regression coverage
src/cli/dispatch.ts, tests/desktop-app-restart.test.ts
At lines 618–626, the CLI reports failed process enumeration and provides manual restart instructions. Tests at lines 284–326 cover probe failures, empty enumerations, fail-closed behavior, and newline-separated PowerShell statements.

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

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant DesktopAppRestart
  participant PowerShell
  CLI->>DesktopAppRestart: request desktop app restart
  DesktopAppRestart->>PowerShell: enumerate desktop processes
  PowerShell-->>DesktopAppRestart: process list or probe failure
  DesktopAppRestart-->>CLI: restart result
  CLI-->>CLI: report success, no_targets, or process_probe_failed
Loading

Suggested reviewers: ingwannu

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/windows-restart-probe-2557

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

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

@github-actions github-actions Bot added the bug Something isn't working label Aug 25, 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: 01afdfe367

ℹ️ 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 on lines +180 to +183
const processes = listPackageProcesses(exec, installLocation);
// Fail CLOSED on a failed re-probe: this guards a kill, and "we could not look" must not be
// read as "the pid was recycled and is now someone else's process".
if (processes === null) return false;

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 Propagate a failed re-probe instead of marking the target stopped

When the initial enumeration succeeds but this immediate or pre-force re-probe times out or throws, null becomes false; both callers interpret false as though the process disappeared, add its PID to stopped, and eventually run Start-Process. The original desktop process may still be alive, so this unreadable-evidence path can falsely report a successful restart and relaunch alongside an unverified survivor. Preserve the probe-failure state and return process_probe_failed without relaunching.

Useful? React with 👍 / 👎.

tarunravi pushed a commit to tarunravi/opencodex that referenced this pull request Sep 14, 2026
…dge-jun#2593)

Two defects on the Windows --restart-desktop-app path.

The probe script joined its PowerShell statements with a space, so
$ErrorActionPreference='SilentlyContinue' $root = '...' became one
malformed statement and the whole script was rejected.

The resulting throw was caught and returned [], which is indistinguishable
from a successful enumeration that found nothing. That became no_targets
and the CLI told the user the app was not running, silently skipping the
restart they had asked for.

Statements are now newline-separated, a failed probe returns null, and the
caller reports the new process_probe_failed reason. The PID re-check fails
closed the same way: it guards a kill, so 'we could not look' must never
read as 'the pid was recycled'.

Both driven red first: reverting either fails exactly its own cases.
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…dge-jun#2593)

Two defects on the Windows --restart-desktop-app path.

The probe script joined its PowerShell statements with a space, so
$ErrorActionPreference='SilentlyContinue' $root = '...' became one
malformed statement and the whole script was rejected.

The resulting throw was caught and returned [], which is indistinguishable
from a successful enumeration that found nothing. That became no_targets
and the CLI told the user the app was not running, silently skipping the
restart they had asked for.

Statements are now newline-separated, a failed probe returns null, and the
caller reports the new process_probe_failed reason. The PID re-check fails
closed the same way: it guards a kill, so 'we could not look' must never
read as 'the pid was recycled'.

Both driven red first: reverting either fails exactly its own cases.
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.

1 participant