codex cli sometimes exits, saying "The cursor position could not be read within a normal duration"

Resolved 💬 2 comments Opened Aug 28, 2025 by pchalasani Closed Sep 3, 2025
💡 Likely answer: A maintainer (nornagon-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.25.0

Which model were you using?

gpt-5

What platform is your computer?

macos

What steps can reproduce the bug?

When I leave Codex unattended for a while, sometimes it randomly exits with this message:

The cursor position could not be read within a normal duration

I don't know if this makes a difference, but I'm usually inside a tmux session. I don't even know if this happens outside of tmux.

What is the expected behavior?

_No response_

What do you see instead?

_No response_

Additional information

_No response_

View original on GitHub ↗

2 Comments

kcosr · 12 months ago

I am using a custom PTY manager to spawn agent TUI sessions. I was able to work around this issue by responding to the cursor position request.

        // Auto-respond to cursor position queries when no clients are attached
        // Many TUIs send CSI 6 n ("DSR: Report Cursor Position") and expect
        // the terminal to reply with CSI row ; col R. When no web client is
        // attached, there is no terminal emulator to answer, so we synthesize
        // a safe default of 1;1.
        if (this.getConnectedClientCount() === 0 && typeof data === 'string') {
          try {
            // Match both 8-bit CSI (\x9B) and 7-bit ESC [ (\x1b[) forms
            const hasCprRequest = /(?:\x9B|\x1b\[)\??6n/.test(data);
            if (hasCprRequest && this.ptyProcess && this.is_active) {
              // Respond with "ESC [ 1 ; 1 R"
              logger.info(`Session ${this.session_id}: Detected cursor position request (CSI 6n) with no clients attached, responding with ESC[1;1R`);
              this.ptyProcess.write("\x1b[1;1R");
            }
          } catch (e) {
            // Non-fatal: ignore parsing errors
          }
        }

I am not a terminal emulation expert but it seems nonstandard to exit if there is no response to the query. Or perhaps tmux should be responding, I really don't know.

nornagon-openai contributor · 11 months ago