Skip to content

fix: non-ASCII Codex home paths are escaped by lsof under LC_ALL=C and unlock always refuses #68

Closed

Description

@abruption

What happened

runCommand forces LC_ALL=C and LANG=C for ps and lsof. In the C locale, lsof escapes non-ASCII bytes in file names (for example \xed\x99\x88). The owner-lock lookup filters lsof names by basename only, so escaped paths pass the filter and are then passed to lstat(), which fails. The lookup returns an error, and every owner under such a Codex home is refused with owner_lock_file_lookup_failed (plus owner_holds_other_thread_locks).

Reproduced with a fixture Codex home whose path contains Hangul characters:

classification "live_owner", safeToUnlock false,
blockers ["owner_lock_file_lookup_failed", "owner_holds_other_thread_locks"]
lsof (LC_ALL=C):      n/.../\xed\x99\x88 codex/thread-writer-locks/<id>.lock
lsof (en_US.UTF-8):   n/.../<original UTF-8 path>/thread-writer-locks/<id>.lock

What you expected

Owner lock files are matched correctly for Codex homes with non-ASCII paths (for example non-ASCII user names on Linux or a custom CODEX_HOME), while still failing closed on genuinely unresolvable paths.

Environment

  • codex-unlock 0.4.0 at 6227e6c
  • macOS 27.0 arm64, Node.js 22.14.0

Source evidence

  • C locale forced for diagnostic commands:
    env: { ...process.env, LC_ALL: "C", LANG: "C" },
  • Basename-only filter, then lstat of the escaped name:

    codex-unlock/src/process.ts

    Lines 292 to 323 in 6227e6c

    }
    const candidates = result.stdout
    .split(/[\0\n]/)
    .filter((token) => token.startsWith("n"))
    .map((token) => token.slice(1))
    .filter((path) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.lock(?: \(deleted\))?$/i.test(basename(path)))
    .filter((path) => basename(dirname(path)) === "thread-writer-locks");
    let intendedCanonical: string;
    try {
    const intendedDirectory = await realpath(dirname(intendedLockPath));
    intendedCanonical = join(intendedDirectory, basename(intendedLockPath));
    } catch (error) {
    return { paths: [], error: `intended lock directory is unresolved: ${errorText(error)}` };
    }
    const paths: string[] = [];
    for (const path of candidates) {
    if (path.endsWith(" (deleted)")) {
    return { paths: [], error: `open lock path was deleted: ${path}` };
    }
    if (!isAbsolute(path)) {
    return { paths: [], error: `lsof returned a relative lock path: ${path}` };
    }
    try {
    const value = await lstat(path);
    if (value.isSymbolicLink() || !value.isFile()) {
    return { paths: [], error: `open lock path is a symlink or non-regular file: ${path}` };
    }
    const canonicalDirectory = await realpath(dirname(path));
    const canonicalPath = join(canonicalDirectory, basename(path));
    paths.push(canonicalPath === intendedCanonical ? intendedLockPath : canonicalPath);
    } catch (error) {
    return { paths: [], error: `open lock path is unresolved: ${errorText(error)}` };
  • Resulting blocker:
    if (context.ownerLockError) addOnce(blockers, "owner_lock_file_lookup_failed");

Acceptance criteria

  • Lock files are matched without relying on lsof name rendering, for example by comparing lsof -F device/inode fields with the probed lock's device/inode, or by strictly decoding lsof escapes.
  • A test covers a Codex home path with non-ASCII characters.

Scope and limitations

  • Fails in the safe direction (always refuses); no bypass was found. This is an availability defect for users with non-ASCII home paths.

Checked

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions