Skip to content

[Bug]: desktop takeover always fails on a default-bind install: tracked-runtime-inspection reads an absent record hostname as "" while resolve reports 127.0.0.1 #8181

Closed

Description

@kerthans

Client or integration

Codex App

Area

Service lifecycle

Summary

On a default-bind install (config.hostname unset), the desktop's approved takeover never succeeds. Approving the "A runtime is already listening. Take it over?" prompt ends in:

state: taking-over
reason: the guarded stop could not confirm the approved runtime:
        The approved runtime or managing CLI changed: the tracked runtime record changed; no stop was attempted.
runtime process: still running or never started

The old runtime is never signalled, so the desktop waits ~165 s and the port stays occupied. Retrying cannot help: nothing rewrites the record while the old runtime keeps serving.

The cause is two readers of the same runtime-port.json disagreeing about an absent optional field. hostname is optional in the record schema, and a default bind has no configured value to persist, so the writer drops the key. Liveness discovery then defaults it to loopback for its verdict, while the guarded stop defaults it to "" for comparison — so the guard compares "" against "127.0.0.1" and always reports drift.

Reproduction

Environment: Desktop 2.97.0 (notarized), CLI on PATH 2.97.0, the runtime it wanted to stop was 2.96.0 started by the launchd service com.opencodex.proxy, config home ~/.opencodex, port 10100 (default), config.hostname unset.

  1. Install the CLI and start the proxy through the service on a default bind:
    ocx service install && ocx service start
  2. Confirm the record has no hostname key:
    cat ~/.opencodex/runtime-port.json
    # {"pid":32333,"port":10100,"attestationSecret":"..."}   <- no hostname
  3. Launch the desktop app while that runtime is still running, and approve the takeover prompt.

Expected: the approved runtime is stopped and the desktop starts its own.
Actual: approval-changed / the tracked runtime record changed, runtime still running, and the record's mtime never changes.

Root cause, with hostname optional in the record (src/config/process-state.ts:37, and isValidRuntimePortState accepts undefined):

  • The writer drops it when nothing is configured: src/cli/index.ts:609 writes hostname: bound.config.hostname, which is undefined for a default bind, so JSON.stringify omits the key.
  • src/server/proxy-liveness.ts:525 reads absence as loopback (opts.hostname?.trim() || "127.0.0.1"), so ocx resolve --json reports liveness.hostname: "127.0.0.1" for that record.
  • src/config/tracked-runtime-inspection.ts:150 reads absence as "" (hostname: parsed.hostname ?? "").
  • The desktop forwards the discovered value as the approved expectation (desktop/src-tauri/src/runtime_stop.rs:254, --expect-hostname), and src/cli/stop-approval.ts:147-149 compares the two directly: pid and port match, "" !== "127.0.0.1", so it returns approvalChanged("the tracked runtime record changed").

Observed ocx resolve --json in the failing state (abridged):

{"liveness":{"status":"live","pid":32333,"port":10100,"source":"runtime","hostname":"127.0.0.1","version":"2.96.0"},
 "takeover":{"kind":"supported","protocolVersion":1,"minimumCliVersion":"2.61.0","token":"..."}}

Proposed fix: treat an absent record hostname as unknown rather than an empty host, compare bind scope through probeHostname only when the record carries one, and persist the scope the listener actually bound. Patch with regression tests: #8182.

Version

Desktop 2.97.0; the running proxy it refused to stop was 2.96.0.

Operating system

macOS 27.2 (26B123), arm64 (Apple M4 Max)

Provider and model

No response

Logs or error output

$ cat ~/.opencodex/runtime-port.json
{"pid":32333,"port":10100,"attestationSecret":"..."}

$ ocx resolve --json | jq '.liveness'
{"status":"live","pid":32333,"port":10100,"source":"runtime","hostname":"127.0.0.1","version":"2.96.0"}

# desktop, after approving the takeover
state: taking-over
reason: the guarded stop could not confirm the approved runtime: The approved runtime or managing CLI changed: the tracked runtime record changed; no stop was attempted.
runtime process: still running or never started

Workaround that avoids the takeover entirely: quit the desktop, ocx service stop, ocx service uninstall, reopen the app so it supervises its own runtime, then ocx restore back to re-point Codex at that proxy.

Not a duplicate of #7771: there the Windows Task Scheduler registration survives and the port is never freed. Here no manager stop is ever attempted — the guard refuses first, on a valid record that simply omits an optional field.

Screenshots and supporting files

No response

Redacted configuration

No response

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  2. added
    platform
    on Nov 5, 2026
  3. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    Issue reopened

    The report now contains the information required by the automated check. Thanks for updating it.

  4. changed the title [-][Bug][macOS] desktop takeover always fails on a default-bind install: tracked-runtime-inspection reads an absent record hostname as "" while resolve reports 127.0.0.1[/-] [+][Bug]: desktop takeover always fails on a default-bind install: tracked-runtime-inspection reads an absent record hostname as "" while resolve reports 127.0.0.1[/+] on Nov 5, 2026
  5. added
    bug
    service
    on Nov 5, 2026
  6. added a commit that references this issue on Nov 5, 2026
    4420329
  7. added a commit that references this issue on Nov 6, 2026
    250ef01
  8. lidge-jun commented on Nov 6, 2026

    @lidge-jun
    Owner

    Fixed on dev by #8221 (250ef01): an absent tracked-record hostname is no longer treated as loopback. It ships in the next release from dev.

  9. added a commit that references this issue on Nov 7, 2026
    a13d292
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

    bugplatformservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions