Skip to content

feat: validate active Codex home and normalize same-host reply routes #61

Closed

Description

@abruption

Context

Parent roadmap: #45. Follow-up to the duplicate-home guard shipped in #55 / v0.6.1.

Two related routing gaps were reproduced while consulting abruption/codex-unlock main e779c2d:

  1. session-peer can enumerate a bounded set of default, Orca, and configured Codex homes, but it only compares saved rows in state_5.sqlite. When the same UUID exists in several homes it cannot distinguish the live writer and always requires --codex-home.
  2. A local message advertises the sender's own Tailscale MagicDNS address in its generated Reply: command. A receiver on the same machine then tries to SSH back to itself, which can fail on host-key or authentication policy even though direct local delivery is available.

codex-unlock --codex-home does not discover homes. Its reusable contribution is the evidence model used after a candidate home is known: an exact UUID-specific writer-lock path, an independent kernel lock probe, stable lsof owner correlation, canonical paths, and structured unknown/ambiguous reasons.

Proposed behavior

Codex home resolution

  • Keep candidate discovery bounded to the selected/default home, existing macOS Orca account homes, and SESSION_PEER_CODEX_HOMES. Do not scan arbitrary directories.
  • Canonicalize aliases before evaluating candidates.
  • For an implicit Codex send that has competing saved copies, inspect each exact <home>/thread-writer-locks/<uuid>.lock on the destination machine.
  • Treat a home as active only when the kernel reports the lock held and two observations correlate it with the same same-user Codex owner. lsof presence alone is not proof of a held lock.
  • If exactly one candidate has a stable live writer, select and revalidate that home immediately before invoking codex queue. If zero or several candidates qualify, fail closed without queueing and retain the explicit --codex-home remedy.
  • Preserve explicit --codex-home as authoritative. Do not read or expose full process environments or argument strings, signal processes, delete locks, or apply codex-unlock's termination-only safeToUnlock/task_complete rules to messaging.
  • Run all process and lock inspection inside the SSH destination. Unsupported platforms, missing lsof, permission failures, and changing evidence remain unknown rather than silently selecting a home.

Expose an additive structured result on Codex dry-run/send responses and structured JSON failures, for example:

{
  "codexHomeResolution": {
    "status": "selected",
    "selected": "/path/to/home",
    "reason": "single_stable_live_writer",
    "candidates": [
      {
        "codexHome": "/path/to/home",
        "savedThread": true,
        "writerLock": "held",
        "ownerPid": 123
      }
    ]
  }
}

The contract must distinguish at least explicit, selected, ambiguous, and unknown, with stable reason codes. It must not claim delivery or consumption.

Same-host reply normalization

  • When session-peer sends to a local target and generates the Reply-To route automatically, emit a local reply command without --host.
  • Keep the agent-qualified From: header and target unchanged.
  • Preserve an explicitly supplied --reply-to and preserve SSH reply routes for actual remote sends.
  • Avoid probing or modifying SSH configuration merely to answer a same-machine session.

Acceptance criteria

  • Two saved copies with exactly one stable live UUID writer select that writer's canonical home and queue only there.
  • Zero/multiple live writers, stale/free locks, missing lsof, permission errors, PID changes, and lock inode changes fail closed without queueing.
  • Explicit home selection and single-home compatibility remain intact.
  • Local and remote JSON include the destination-side codexHomeResolution; error JSON preserves candidate status and reason codes.
  • Process arguments and environment values are absent from the public result.
  • Local auto-generated replies omit --host; remote replies and explicit reply hosts keep it.
  • Tests use fixtures for duplicate default/Orca homes, real or faithfully isolated advisory locks, stable/changing owners, SSH destination execution, and same-host reply generation.
  • README/help document evidence, fallbacks, and the difference between home selection, queue submission, and consumption.

Related: #29, #31, #45, #55.

Activity

  1. added
    enhancement
    on Sep 15, 2026
  2. abruption commented on Sep 15, 2026

    @abruption
    OwnerAuthor

    SSH username resolution and authentication failure diagnostics were split into #62 so they can be implemented and reviewed independently from Codex home activity and same-host Reply-To normalization.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions