Skip to content

Windows: --restart-desktop-app generates invalid PowerShell and misreports probe failure #2557

Closed

Description

@lidge-jun

Summary

On Windows, ocx sync --restart-desktop-app generates an invalid PowerShell command. The desktop process probe fails with UnexpectedToken, localized stderr is garbled, and OpenCodex then incorrectly reports:

Codex desktop app is not running; nothing to restart.

The Fast/service-tier report previously included here has been split into #2558.

Environment

  • OpenCodex: 2.33.0
  • Commit inspected: ec51e42d745d2645bcb22cb67855fa053ba1778e
  • Windows 11 x64
  • Windows PowerShell 5.1
  • Locale: Korean (ko-KR)
  • Codex Desktop: 26.818.8289.0

Reproduction

From an external Windows PowerShell terminal:

ocx sync --restart-desktop-app

Observed parser errors identify these tokens:

'$root'
'$me'
'Get-CimInstance'
FullyQualifiedErrorId : UnexpectedToken

The generated command is effectively:

$ErrorActionPreference='SilentlyContinue' $root = 'C:\Program Files\WindowsApps\OpenAI.Codex_...' $me = ([Security.Principal.WindowsIdentity]::GetCurrent()).Name Get-CimInstance ...

The localized error text is also mojibake.

Root cause

In src/codex/desktop-app-restart.ts, listPackageProcesses() builds an array of PowerShell statements but joins them with a plain space:

const script = [
  "$ErrorActionPreference='SilentlyContinue'",
  `$root = '${literal}'`,
  "$me = ([Security.Principal.WindowsIdentity]::GetCurrent()).Name",
  "Get-CimInstance Win32_Process -Filter \"Name='ChatGPT.exe'\" |",
  // ...
].join(" ");

The assignments and pipeline require statement separators. Joining with a space makes the script syntactically invalid.

The same file's discoverPackage() correctly uses:

].join("; ");

When execFile throws, listPackageProcesses() catches the error and returns []. The caller converts that into no_targets, which is why a probe failure is misreported as “desktop app is not running.”

The mojibake is separate: localized Windows PowerShell 5.1 stderr uses the active Windows code page, while the subprocess output is decoded as if it were UTF-8.

Expected behavior

  • The generated PowerShell script parses successfully.
  • Codex Desktop processes under the discovered package location are found and restarted.
  • A probe/parser failure is reported as an error, not as “not running.”
  • Localized diagnostics are readable.

Suggested fix

  1. Replace .join(" ") with .join("; ") or newline joining.
  2. Do not collapse probe exceptions into an empty process list. Return a distinct process_probe_failed result with the original diagnostic.
  3. Force UTF-8 for the Windows PowerShell subprocess, or decode stdout/stderr using the active Windows code page.
  4. Add a regression test that actually asks Windows PowerShell to parse/execute the generated script.
  5. Include an install path containing spaces and a non-English locale in the test matrix.

Related behavior

Before this command, OpenCodex correctly warned that two Codex app-server processes were stale. This worked:

ocx sync --restart-codex

and stopped both PIDs. Only the desktop-app restart path fails because it uses the malformed process-probe script.

Activity

  1. added
    platform
    on Aug 25, 2026
  2. changed the title [-]Windows: Fast/Priority falls back to Default and --restart-desktop-app emits invalid PowerShell[/-] [+]Windows: --restart-desktop-app generates invalid PowerShell and misreports probe failure[/+] on Aug 25, 2026
  3. lidge-jun commented on Aug 25, 2026

    @lidge-jun
    OwnerAuthor

    리뷰 · 우선순위 67 / 80

    설명: 이 이슈는 윈도우에서 ocx sync --restart-desktop-app 이 잘못된 파워셸을 만들고, 프로브 실패를 데스크톱이 안 떠 있다고 잘못 보고한다고 적는다. 작성자는 lidge-jun 이다. 라벨은 platform 다. 보고 버전은 2.33.0 이고 검사 커밋은 origin/main 의 ec51e42 다. 지금 CURRENT dev HEAD 는 e1fb675 이다. 패키지는 2.32.1-preview.20260825 이다. 이번 시간에 origin/dev SHA 는 안 움직였다. 같은 구멍이 HEAD 에도 있다. Fast 와 service_tier 보고는 2558 로 갈라졌다. 이 이슈는 데스크톱 재시작만 본다. 구현 풀은 아직 없다. 이슈를 연다. 닫지 말 것. 라벨은 바꾸지 말 것. 내가 머지하지 않는다.

    HEAD 에서 재현 길을 읽었다. src/codex/desktop-app-restart.ts 124-139줄 listPackageProcesses 가 문장 배열을 공백으로 이어 붙인다. $ErrorActionPreference='SilentlyContinue' 다음에 $root = ... 가 구분자 없이 붙는다. 파서 토큰 root, me, Get-CimInstance, UnexpectedToken 이 그 결과다. 같은 파일 77-85줄 discoverPackage 는 세미콜론으로 잇는다. 그 길이 맞다. 프로브 execFile 이 던지면 146-147줄이 빈 배열을 돌려준다. 268-270줄 호출자는 빈 목록을 no_targets 로 바꾼다. src/cli/dispatch.ts 618-619줄은 Codex desktop app is not running; nothing to restart. 를 찍는다. 파서 실패가 미실행으로 위장된다.

    시험 tests/desktop-app-restart.test.ts 167-177줄은 Win32_Process 스크립트에 ChatGPT.exe 이름과 설치 경로와 OrdinalIgnoreCase 가 들어 있는지만 본다. 198-208줄은 GetOwner 와 WindowsIdentity 부분 문자열이다. execFile 을 목으로 가로채서 실제 파워셸 파서는 안 돌린다. 공백 join 이어도 부분 문자열은 통과한다. 그래서 HEAD 시험이 초록이어도 윈도우 5.1 에서는 UnexpectedToken 이다. 본문이 적은 회귀 시험, 곧 생성된 스크립트를 파워셸에 실제로 파싱시키는 시험이 아직 없다.

    모지바케는 다른 단이다. 지역화 윈도우 파워셸 5.1 stderr 는 활성 코드 페이지인데 서브프로세스는 utf-8 로 읽는다. 세미콜론 join 만으로는 안 고친다. 다만 우선 순위는 구분자와 no_targets 위장이다. --restart-codex 는 본문대로 앱서버 PID 를 멈췄다. 그 길은 이 프로브 스크립트를 안 쓴다. 2292 가 넣은 데스크톱 재시작 플래그의 프로세스 프로브만 깨져 있다. 2558 과 한 이슈로 다시 합치지 말 것. 이미 갈랐다.

    origin/main 의 2.33.0 과 origin/dev 의 preview 글자가 다르다. 파일 src/codex/desktop-app-restart.ts 는 두 트리 모두 같은 join 구멍을 가진다. 이 이슈를 메인 전용으로 닫지 말 것. HEAD 에도 있다. src/runtime 은 없다. default-aliases.ts 와 model-presets.ts 도 없다. 2463 2464 2465 를 닫지 말 것. types.ts 와 config.ts 가르기와는 무관하다. 프리뷰 배포가 아니다. 지금 구현 풀이 없으니 내가 구현하지 않는다.

    src/codex/desktop-app-restart.ts 139줄 HEAD - listPackageProcesses 가 문장을 공백으로 잇는다. 파서가 UnexpectedToken 을 낸다
    src/codex/desktop-app-restart.ts 85줄 HEAD - discoverPackage 는 세미콜론으로 잇는다. 같은 파일 안의 맞은 길이다
    src/codex/desktop-app-restart.ts 146-147줄 HEAD - execFile 예외를 빈 목록으로 삼킨다
    src/codex/desktop-app-restart.ts 270줄 HEAD - 빈 목록을 no_targets 로 바꾼다
    src/cli/dispatch.ts 618-619줄 HEAD - no_targets 를 데스크톱 미실행으로 보고한다
    tests/desktop-app-restart.test.ts 167-177줄 HEAD - 부분 문자열만 본다. 파워셸 파서를 안 돌린다
    2558 - Fast 오분류다. 이 이슈와 다시 합치지 말 것

    메인테이너의 판단이 필요한 지점

    • 이 이슈를 지금 닫을지. 닫지 말 것. HEAD 에 공백 join 과 no_targets 위장이 남아 있다
    • 고침을 세미콜론 join 만으로 볼지. 그것만으로는 부족하다. 프로브 실패를 no_targets 와 갈라야 한다
    • 모지바케를 같은 패치에 넣을지. 넣어도 되지만 구분자가 먼저다
    • 2558 과 다시 합칠지. 합치지 말 것
    • origin/main 2.33.0 에만 있다고 볼지. 그렇게 보지 말 것. origin/dev 에도 있다

    너의 추천
    이 이슈는 연다. 구현 풀을 기다린다. join 을 세미콜론이나 줄바꿈으로 바꾸고, 프로브 예외를 process_probe_failed 로 갈라 no_targets 위장을 없앤다. 생성된 스크립트를 파워셸이 파싱하는 회귀 시험을 넣는다. 내가 머지하지 않고 구현하지 않는다. 라벨은 그대로 둔다. 프리뷰 배포가 아니다.

    이 댓글은 grok-bot이 작성했습니다

  4. lidge-jun commented on Aug 25, 2026

    @lidge-jun
    OwnerAuthor

    Fixed on dev in #2593. Both halves were real, and the second is what hid the first.

    The probe script joined its PowerShell statements with a space, so $ErrorActionPreference='SilentlyContinue' $root = '...' became one malformed statement and the script was rejected outright. The throw was then caught and returned [] — indistinguishable from a successful enumeration that found nothing — so it became no_targets and the CLI reported the app as not running while skipping the restart you asked for.

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

    Each fix was driven red independently — reverting the join fails 1 case, reverting the probe-failure handling fails 2 — and 19 pass with both, through the existing io seam so the guards hold on any platform.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions