Skip to content

fix: bound list transcript scans to prevent file-descriptor exhaustion #87

Closed

Description

@abruption

Description

listThreads() starts one inspectThread() per native lock filename with an unbounded Promise.all. Each inspection recursively scans both transcript trees, twice. The recursive walker keeps the parent directory handle open while awaiting a child directory.

With a modest file-descriptor limit, these overlapping scans can exhaust descriptors. walkForTranscript() rethrows EMFILE, so the error propagates through the aggregate Promise.all and fails the entire list. The repeated full-tree scans also add work proportional to the number of listed threads times the transcript-tree size.

This is a practical diagnostic-availability/reliability issue. No unsafe unlock, privilege escalation, or remote trigger was demonstrated.

Steps to reproduce

The following source-function reproduction isolates the transcript scanning used by list; it does not invoke the complete CLI or native lock probes.

  1. Use source at bed34a7aeca90275a1b3e3d838e9c1b77b9fe325 (0.4.2). Copy src/transcript.ts, src/util.ts, and src/types.ts into a temporary directory and emit adjacent .js files using Node's built-in stripTypeScriptTypes from node:module. No dependency installation is needed for these modules.
  2. In a temporary synthetic home, create sessions/2026/10/03/ and an empty archived_sessions/. Create 100 files named rollout-<synthetic UUID>.jsonl under the day directory, each containing one synthetic event_msg/task_complete record.
  3. In a subshell with ulimit -n 256, import findTranscriptCandidates from the emitted transcript.js and run:
const results = await Promise.allSettled(
  ids.map(id => findTranscriptCandidates(syntheticHome, id))
);
const failures = results.filter(result => result.status === "rejected");
console.log({
  total: results.length,
  succeeded: results.length - failures.length,
  failed: failures.length,
  errorCodes: [...new Set(failures.map(result => result.reason.code))]
});
  1. Repeat with the same fixture and descriptor limit, awaiting each call sequentially as a control.

Expected vs actual

  • Expected: Listing many saved thread-lock entries does not fail because the tool itself launches too many concurrent directory traversals. The number of concurrent filesystem operations and diagnostic subprocesses remains bounded.
  • Actual: The isolated concurrent scan produced 38 successful calls and 62 EMFILE failures. The sequential control completed all 100 calls without errors. Exact concurrent counts depend on scheduling and available descriptors.

The production failure path is established by source inspection: listThreads() uses Promise.all, rather than the harness's Promise.allSettled, and one rejected scan therefore rejects the aggregate list.

Environment

  • OS / architecture: isolated Linux x64 environment
  • codex-unlock version: 0.4.2 source, commit bed34a7aeca90275a1b3e3d838e9c1b77b9fe325
  • Node.js version: 24.19.0
  • Codex version: not applicable; synthetic fixtures only
  • Command: source-function reproduction of list transcript traversal
  • File-descriptor limit: 256

Diagnostic output

Concurrent: total=100, succeeded=38, failed=62, errorCodes=["EMFILE"]
Sequential: total=100, succeeded=100, failed=0

Only generated fixture data was used. No real Codex home, private transcript, credential, or process diagnostic was accessed or included.

Source evidence

  • Unbounded inspection fan-out:
    const threadIds = unique(
    names
    .filter((name) => name.endsWith(".lock"))
    .map((name) => name.slice(0, -".lock".length))
    .filter((id) => isThreadId(id))
    .map((id) => id.toLowerCase()),
    ).sort();
    const sessions = await Promise.all(threadIds.map((id) => inspectThread(id, options)));
  • Recursive directory handles and non-ENOENT error propagation:
    async function walkForTranscript(
    root: string,
    expectedName: string,
    output: string[],
    ): Promise<void> {
    let directory;
    try {
    directory = await opendir(root);
    } catch (error) {
    if ((error as NodeJS.ErrnoException).code === "ENOENT") {
    return;
    }
    throw error;
    }
    for await (const entry of directory) {
    const path = join(root, entry.name);
    if (entry.isDirectory()) {
    await walkForTranscript(path, expectedName, output);
    } else if (entry.isFile() && entry.name.endsWith(expectedName)) {
    output.push(path);
    }
    }
    }
  • Both transcript roots traversed for each thread:
    export async function findTranscriptCandidates(
    codexHome: string,
    threadId: string,
    ): Promise<string[]> {
    const expectedName = `-${threadId}.jsonl`;
    const output: string[] = [];
    await Promise.all([
    walkForTranscript(join(codexHome, "sessions"), expectedName, output),
    walkForTranscript(join(codexHome, "archived_sessions"), expectedName, output),
    ]);
    return output.sort();

Suggested fix and acceptance criteria

  • Bound concurrent thread inspections and diagnostic subprocesses.
  • Consider a transcript index shared within each observation pass instead of rescanning the full history for every thread.
  • Preserve independent before/after observations and all unlock revalidation checks; do not reuse an old index across safety boundaries without revalidation.
  • Add a low-FD-limit regression with at least 100 synthetic thread/transcript entries.
  • Keep filesystem errors fail closed and retain the documented JSON/error contract.

Scope and limitations

  • The actual source function was exercised after built-in TypeScript stripping; the complete packaged CLI and macOS behavior were not tested.
  • No native lock was acquired and no process was signaled.
  • No attacker is required: a populated home and a limited descriptor budget are sufficient for the demonstrated scan failure. Deliberately inflating the selected home would require filesystem write access.
  • Security severity is low; the demonstrated impact is diagnostic availability.

Checked

Activity

  1. added
    bug
    on Oct 3, 2026
  2. added this to the v0.4.3 milestone on Oct 4, 2026
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