Skip to content

fix: explicit check-update fails when the cache directory is not writable #62

Closed

Description

@abruption

What happened

An explicit codex-unlock check-update fails with exit 3 and update check failed: cache_directory_unavailable when the cache directory cannot be created or written, without contacting the registry at all.

refreshUpdateCache acquires the refresh lease, which requires a private cache directory, before fetching. An unavailable lease returns an error immediately. A successful fetch followed by a failed cache write is also reported as an error.

Reproduction: XDG_CACHE_HOME=<dir with mode 0500> codex-unlock check-update --json → exit 3. With a writable cache location it returns status: ok, exit 0.

What you expected

docs/update-security.md defines the cache as advisory. A user-requested network check should succeed when the registry is reachable, even if the result cannot be cached (for example on a read-only home, a sandbox, or a filesystem that cannot represent mode 0700). A cache write failure should at most be reported as a warning.

Environment

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

Source evidence

  • Lease required before fetch; write failure becomes error:

    codex-unlock/src/update.ts

    Lines 662 to 687 in 6227e6c

    export async function refreshUpdateCache(
    options: RefreshUpdateCacheOptions = {},
    ): Promise<RefreshUpdateCacheResult> {
    const location = options.location ?? updateCacheLocation();
    const leaseAttempt = acquireUpdateRefreshLease(location);
    if (leaseAttempt.status === "contended") {
    return { status: "skipped", reason: "refresh_in_progress" };
    }
    if (leaseAttempt.status === "unavailable") {
    return { status: "error", reason: leaseAttempt.reason };
    }
    try {
    const fetched = await fetchNpmLatest(options);
    if (fetched.status === "error") return fetched;
    const written = writeUpdateCache(
    fetched.record.latest,
    location,
    Date.parse(fetched.record.checkedAt),
    );
    return written.status === "written"
    ? { status: "updated", record: written.record }
    : written;
    } finally {
    leaseAttempt.lease.release();
    }
    }
  • CLI converts it to exit 3:

    codex-unlock/src/cli.ts

    Lines 264 to 278 in 6227e6c

    async function checkUpdate(json: boolean): Promise<number> {
    const refreshed = await refreshUpdateCache();
    const observation = refreshed.status === "updated"
    ? { status: "fresh" as const, record: refreshed.record }
    : refreshed.status === "skipped"
    ? readUpdateCache()
    : null;
    if (observation?.status !== "fresh") {
    const reason = refreshed.status === "error"
    ? refreshed.reason
    : refreshed.status === "skipped"
    ? "refresh_in_progress"
    : "update_check_failed";
    throw new Error(`update check failed: ${reason}`);
    }

Acceptance criteria

  • check-update fetches and reports the latest version when the lease or cache write is unavailable (lease contention may still skip).
  • Cache unavailability does not change the exit code or JSON status of an otherwise successful check.
  • A test covers an unwritable cache directory.

Scope and limitations

  • Functional reliability only; automatic advisory notices are unaffected by design.

Checked

Activity

  1. added
    bug
    on Sep 28, 2026
  2. added this to the v0.4.1 milestone on Sep 28, 2026
  3. added a commit that references this issue on Sep 29, 2026
    d15c9f3
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions