Skip to content

[Bug] Remote Link discovery picks a different/stale ocx than the one serving the Child, and misses npm-prefix installs #8359

Closed

Description

@lidge-jun

Summary

Remote Link discovery (REMOTE_OCX_SCRIPT in src/link/ssh-argv.ts, OCX_CANDIDATES in src/link/remote-windows.ts) picks the first runnable ocx from a fixed candidate list. That binary is often not the one serving the Child, and common install locations are missing. ocx link probe then reports the wrong version or fails outright, even though /healthz on the Child is fine.

Observed today (three machines)

Child Serving runtime (/healthz) Probe result
macOS A, npm global with prefix ~/.local/node 2.51.0 → 2.99.0 Remote Link failed during remote OpenCodex discovery — ~/.local/node/bin is not in the candidate list nor the non-login PATH
macOS B, npm global under /opt/homebrew + old desktop app 2.99.0 (npm) ocxVersion: "2.77.0" — /Applications/OpenCodex.app/Contents/MacOS/ocx wins over PATH
Windows, npm global (%APPDATA%\npm\ocx.cmd) + an old bun global 2.96.0 (npm) ocxVersion: "2.32.1" — Get-Command ocx.exe finds ~\.bun\bin\ocx.exe; ocx.cmd is never considered

Workaround was installing the 2.99.0 desktop app/MSI on every Child so the first candidate matched. That leaves two installs (desktop CLI + npm-managed service) on each machine.

Risk beyond the confusing version: the enrollment then runs connect/restart through a different binary/version than the service manager launches.

Suggested fix

  • Prefer the binary that is actually serving: e.g. expose the executable path (or install kind) on loopback /healthz/runtime file and have the remote script use it, falling back to candidates.
  • Add npm global prefixes to the candidates ($(npm prefix -g)/bin, ~/.local/node/bin, ~/.npm-global/bin, nvm current), and on Windows %APPDATA%\npm\ocx.cmd.
  • If the chosen candidate's version differs from the serving runtime's version, warn in link probe output.

Acceptance

ocx link probe on each of the three layouts above reports the serving runtime's version without installing an extra copy.

Activity

  1. coderabbitai commented on Nov 8, 2026

    @coderabbitai
    Contributor
    🔗 Related PRs

    #7832 - feat(link): Windows Remote Link Children and Child credential/connection attestation [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. added
    cli
    on Nov 8, 2026
  3. lidge-jun commented on Nov 8, 2026

    @lidge-jun
    OwnerAuthor

    Triage notes from the issue sweep. I investigated a fix and an independent audit failed the plan, so this is the design, not a PR yet.

    Why the obvious fix is wrong: service-state.json records how the service was installed, not what is serving.

    • launcherPath is written only for launchd and systemd. Windows never records it, so the Windows npm case (bunPath + cliPath) stays unsolved.
    • After a desktop takeover, recordServiceOwner keeps the old npm bunPath/cliPath, while the desktop sidecar serves. Preferring the recorded pair would select the stopped npm install.
    • cliPath may be absent (legacy record) rather than null. A shell-side JSON scrape cannot tell the two apart and would run plain bun as if it were ocx.
    • The authoritative copy is ~/.opencodex/service-state.json; the $OPENCODEX_HOME copy is a mirror.

    Proposed direction:

    1. Runtime evidence: the running proxy writes its own invocation (absolute executable plus entry args, version, pid) to a small runtime file under its home at startup and removes it on clean shutdown.
    2. Preference: REMOTE_OCX_CANDIDATES and the Windows OCX_CANDIDATES prefer that invocation when the pid is alive and its --version matches. Otherwise they fall back to today's order.
    3. Pinned sync: REMOTE_PINNED_SYNC_SCRIPT needs its own variant that keeps the version gate and sync --expect-link "$1" --json, because its $@ differs from the generic script's.
    4. Windows: the npm layout needs a two-argument probe (OcxJob.Ok/V with an argument prefix). ocx.cmd shims cannot run under Process.Start with UseShellExecute=false or under CreateProcessW.
    5. Search paths: add npm prefixes (~/.npm-global/bin, ~/.local/node/bin, $(npm prefix -g)/bin) ahead of /usr/local/bin as a secondary improvement.
    6. Docs: structure/remote-link.md and docs-site/.../guides/remote-link.md document the candidate order and need updating.

    This overlaps the files #8276 is changing (src/link/ssh-argv.ts, src/link/remote-windows.ts), so it should land after #8276 or inside the Remote Link lane.

  4. lidge-jun commented on Nov 9, 2026

    @lidge-jun
    OwnerAuthor

    Status: the POSIX half is on dev via #8424 (f0f34d09). On macOS and Linux Children, discovery, ocx link probe inspection and pinned sync now first run the install that last started serving the Child. That install is read from the first record of serving-runtimes.json, which every ocx start that binds writes about itself. Desktop and PATH copies are the fallback. This covers the two macOS layouts in the report: a stale /Applications app, and an npm install under ~/.local/node. #8431 cleans up the reader's error handling.

    The Windows layout (npm global, [bun.exe, index.ts]) is still open. Probing that pair needs an argument-taking OcxJob.Ok/V overload in the C# helper compiled on the Child. PR CI never compiles it, and a mistake there would make every Windows Remote Link command exit 126, so it needs a change verified on a Windows host (the opt-in OCX_WINDOWS_OPENSSH_FIXTURE gate or the Windows batch lane). Keeping this issue open for that.

  5. lidge-jun commented on Nov 16, 2026

    @lidge-jun
    OwnerAuthor

    Partly fixed by #8769 (merged as 915a5c8): Windows discovery and ocx link probe now try the served install first. Still open: Windows windowsGatedOcxArgv / windowsOverwriteSyncArgv (src/link/remote-windows.ts) keep the fixed Desktop/PATH order, so ocx link sync and update planning can still pick an older bun-global ocx (step 3 of the plan above). This issue stays open for that part.

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

    cli

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions