Skip to content

PTY leak when enableInteractiveShell=true causes system-wide PTY exhaustion on macOS #27628

Description

@jeffery9

What happened?

PTY leak when enableInteractiveShell=true causes system-wide PTY exhaustion on macOS

Environment

  • Gemini CLI: 0.44.x
  • Node.js: 24.x
  • macOS: (please fill in exact version)
  • Running mode: gemini -r
  • MCP enabled (Context7 MCP)
  • enableInteractiveShell=true

Summary

After running Gemini CLI for an extended period with interactive shell enabled, the process appears to leak PTY-related resources.

Eventually the entire macOS user session becomes unable to allocate new pseudo-terminals.

At that point, not only Gemini fails, but all PTY consumers fail system-wide.

Symptoms

Gemini starts failing with:

forkpty: Device not configured
posix_openpt failed: Device not configured

Then unrelated tools also fail:

script /tmp/test.log

returns:

script: openpty: Device not configured

Python:

import pty
pty.spawn('/bin/bash')

returns:

OSError: out of pty devices

Even sudo becomes unusable:

sudo lsof

returns:

sudo: unable to allocate pty: Device not configured

Diagnostics

Active TTY usage appears low:

lsof | grep /dev/ttys | wc -l

Output:

58

System tty devices:

ls /dev/ttys* | wc -l

Output:

527

Gemini process:

lsof -p <gemini_pid> | wc -l

Output:

1537

Gemini is holding both the current terminal and an internal PTY:

/dev/ttys009
/dev/ttys238

Observed child processes:

bash
bash
tail -f /dev/null

Reproduction

  1. Enable interactive shell
  2. Run Gemini in long-lived mode:
gemini -r
  1. Use the agent for an extended period

  2. Eventually PTY allocation starts failing

  3. Failure propagates to:

    • Gemini
    • script
    • python pty.spawn()
    • sudo

Workaround

Disable interactive shell:

{
  "tools": {
    "shell": {
      "enableInteractiveShell": false
    }
  }
}

After disabling interactive shell and restarting the user session, the problem disappears.

Expected behavior

Interactive shell sessions should fully release PTY resources after command completion and should not cause system-wide PTY exhaustion.

Additional notes

This may be related to the recent node-pty issues reported in 0.44.x. The issue becomes significantly more visible when running:

  • gemini -r
  • MCP servers enabled
  • long-lived agent sessions
  • Node.js 24.x

What did you expect to happen?

no error, no run out of the resources.

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here

Login information

No response

Anything else we need to know?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status
    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions