gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Unable to enter text into Gemini CLI session resumed in disconnected terminal

Open scotttw-google opened this issue 1 year ago • 19 comments

What happened?

Yesterday, I was using Gemini CLI in a terminal with cider and everything was working fine. I left and came back the next morning and had to re-cert to open that previous terminal. The Gemini CLI interface appeared, but I was unable to enter any text to communicate with Gemini.

The text "Accepting edits (shift + tab to toggle)" was displayed so I pressed shift+tab and that made the dialog disappear / reappear as I toggled it. So it seems like keyboard shortcuts work, but entering text doesn't.

Image

What did you expect to happen?

I would expect to be able to enter text and continue my session right where I left off, since it's apparently the same terminal instance. I was able to see my chat history with the CLI there.

Client information

This was using cider within Chrome on MacOS and using the cider integrated terminal.

Chrome version: Version 138.0.7204.169 (Official Build) (arm64) MacOS: Sequoia 15.5

I was unable to type /about into the "stale" gemini CLI, so this is the output of /about after starting a new gemini CLI session.

│ About Gemini CLI                                                          │
│                                                                           │
│ CLI Version               0.1.15                                          │
│ Git Commit                bcce1e7b                                        │
│ Model                     gemini-2.5-pro                                  │
│ Sandbox                   no sandbox                                      │
│ OS                        linux                                           │
│ Auth Method               gemini-api-key   

Login information

P&D API Key

Anything else we need to know?

No response

scotttw-google avatar Aug 01 '25 17:08 scotttw-google

This is impacting a lot of Cider users.

jacob314 avatar Aug 01 '25 18:08 jacob314

Reproducing is difficult as some users are able to resume if they resume with ~1 hour. I would suggest we time box work on this and consider generally making resume of old sessions seamless if there are not simple fixes to make this generically robust in the presence of resuming ssh connections.

jacob314 avatar Aug 04 '25 02:08 jacob314

I am impacted by this as well. Given other ctrl + [key] commands work (ctrl+t, ctrl+c as discussed above) can we make as a workaround a ctrl+r for refresh or something like that that refreshes the terminal display? That might solve the issue. Alternatively a ctrl+s for suspend and save chat or something....

sniemczyk-google avatar Aug 15 '25 17:08 sniemczyk-google

It is not limited to cider. I am facing the same with tmux.

FWIW, I am using tmux + iterm2 on mac with the -CC flag.

AgamAgarwal avatar Aug 20 '25 12:08 AgamAgarwal

I see this fairly frequently. If there's a good way to share more debugging info, or something I should try to verify/debunk theories I'm happy to do so. I'm a cider user.

flatfeetpete avatar Aug 24 '25 00:08 flatfeetpete

I also consistently repro in iTerm2 with shpool and tmux (either the tmux integration or tmux-proper).

This seems down to a bug in the focus reporting. iTerm2 has a "toggle" for this in Session > Terminal State > Focus Reporting and toggling that off keeps the cursor visible when the window/tab/pane is unfocused, but at least I don't lose my context window.

jonbetti avatar Aug 28 '25 15:08 jonbetti

+1

thebinaryone1 avatar Aug 28 '25 16:08 thebinaryone1

Thanks for the repo @jonbetti. That makes a ton of sense and should hopefully be easy to fix.

jacob314 avatar Aug 28 '25 21:08 jacob314

can we please get a fix for this. This bug hurts a lot while working on reasonably large feature development

vumaasha avatar Sep 03 '25 05:09 vumaasha

Lost a session to this bug this morning. Would really like to see this fixed. Re-building it's context is time consuming and there'll be things it's realized from previous turns that are just lost forever.

timothyfroehlich avatar Sep 08 '25 16:09 timothyfroehlich

@jonbetti:

I also consistently repro in iTerm2 with shpool and tmux (either the tmux integration or tmux-proper).

This seems down to a bug in the focus reporting. iTerm2 has a "toggle" for this in Session > Terminal State > Focus Reporting and toggling that off keeps the cursor visible when the window/tab/pane is unfocused, but at least I don't lose my context window.

Another Googler took your suggestion and had Gemini come up with a script to unstick it. I just tried it on my session that I mentioned in my previous comment and it worked!

Here's the bash script: (Usual disclaimers about how you should always fully understand a bash script before copying and using it yourself)

#!/bin/bash

# A small utility to re-establish focus for stuck Gemini CLI processes.

# Find all running processes named 'gemini' owned by the current user,
# filter out the grep command itself, and extract the TTY column (e.g., "pts/2").
TTY_LIST=$(ps -u $(whoami) | grep '[g]emini' | awk '{print $2}' | sort -u)

if [ -z "$TTY_LIST" ]; then
    echo "No running Gemini processes found."
    exit 0
fi

echo "Found Gemini processes on the following terminals:"
echo "$TTY_LIST"
echo "---"

for tty in $TTY_LIST; do
    # Ensure we are only targeting pseudo-terminals (like pts/0, pts/1, etc.)
    if [[ "$tty" == pts/* ]]; then
        DEVICE_PATH="/dev/$tty"
        echo "⚡ Sending focus reset to $DEVICE_PATH..."

        # Send the sequence to ENABLE focus reporting mode.
        printf '\e[?1004h' > "$DEVICE_PATH"
    fi
done

echo "---"
echo "✅ Done. Check your Gemini sessions for responsiveness."

timothyfroehlich avatar Sep 08 '25 17:09 timothyfroehlich

Fyi @deepankarsharma. Curious on your thoughts on how we might handle this more robustly. See @timothyfroehlich's very helpful workaround script that emits \e[?1004h to unstick the terminal

jacob314 avatar Sep 08 '25 18:09 jacob314

@jacob314 - will dig in to this and do some research on how to come up with a principled fix.

deepankarsharma avatar Sep 08 '25 19:09 deepankarsharma

@timothyfroehlich this is awesome. I forgot you could just do that (writing to /dev/ttyX). "Hey Gemini CLI, fix my other Gemini CLIs pls"

@jacob314 while I get that this is a polish issue with relatively high impact, it feels like the real issue here is that I have to remember to save my chats like it's a .doc in 2003. Other CLI agents have far more robust session resume support (e.g. Claude Code, sst/opencode are the ones I've used) and when those have UI hiccups or terminal disconnects, I can just resume. See #6797 for another instance of this (dup?). #3882 seems to be canonical for "autosave" / "session resume". Is this being prioritized or does Gemini CLI have a philosophical reason for not wanting this?

Another solution is to implement suspend (i.e. Ctrl-Z) support #5018 which would presumably "re-render" the UI on fg. I've done that with Claude Code when it goes full glitch mode (also uses ink...)

jonbetti avatar Sep 09 '25 04:09 jonbetti

@jonbetti:

I also consistently repro in iTerm2 with shpool and tmux (either the tmux integration or tmux-proper). This seems down to a bug in the focus reporting. iTerm2 has a "toggle" for this in Session > Terminal State > Focus Reporting and toggling that off keeps the cursor visible when the window/tab/pane is unfocused, but at least I don't lose my context window.

Another Googler took your suggestion and had Gemini come up with a script to unstick it. I just tried it on my session that I mentioned in my previous comment and it worked!

Here's the bash script: (Usual disclaimers about how you should always fully understand a bash script before copying and using it yourself)

#!/bin/bash

# A small utility to re-establish focus for stuck Gemini CLI processes.

# Find all running processes named 'gemini' owned by the current user,
# filter out the grep command itself, and extract the TTY column (e.g., "pts/2").
TTY_LIST=$(ps -u $(whoami) | grep '[g]emini' | awk '{print $2}' | sort -u)

if [ -z "$TTY_LIST" ]; then
    echo "No running Gemini processes found."
    exit 0
fi

echo "Found Gemini processes on the following terminals:"
echo "$TTY_LIST"
echo "---"

for tty in $TTY_LIST; do
    # Ensure we are only targeting pseudo-terminals (like pts/0, pts/1, etc.)
    if [[ "$tty" == pts/* ]]; then
        DEVICE_PATH="/dev/$tty"
        echo "⚡ Sending focus reset to $DEVICE_PATH..."

        # Send the sequence to ENABLE focus reporting mode.
        printf '\e[?1004h' > "$DEVICE_PATH"
    fi
done

echo "---"
echo "✅ Done. Check your Gemini sessions for responsiveness."

I confirm that this workaround works absolutely fine for me with shpool and ssh. Thanks a tone.

vumaasha avatar Sep 09 '25 09:09 vumaasha

@jacob314 while I get that this is a polish issue with relatively high impact, it feels like the real issue here is that I have to remember to save my chats like it's a .doc in 2003. Other CLI agents have far more robust session resume support (e.g. Claude Code, sst/opencode are the ones I've used) and when those have UI hiccups or terminal disconnects, I can just resume. See #6797 for another instance of this (dup?). #3882 seems to be canonical for "autosave" / "session resume". Is this being prioritized or does Gemini CLI have a philosophical reason for not wanting this?

Yes, yes, yes, please. This is one of the main reasons why Gemini-CLI is my last choice for my personal projects. Code Assist saves your sessions, GitHub Copilot saves your sessions, Cursor does it, Warp does it, Zed does it, Claude does it, and Codex doesn't but it's like only two weeks old. Gemini-CLI has been public for three months now.

It's really frustrating that a basic feature like this is being treated as an afterthought, especially while it's in a state of constant development where we're encouraged to use the nightly builds to find issues.

Basically, Stop treating session context as disposable. It's not.

timothyfroehlich avatar Sep 09 '25 14:09 timothyfroehlich

@jonbetti @timothyfroehlich Automatic saving and resuming are in progress; please see #4401 (particularly the list of linked PRs at the top) for details.

bl-ue avatar Sep 09 '25 14:09 bl-ue

@jonbetti [@timothyfroehlich](https://github.com/timothyfroehlich) Automatic saving and resuming are in progress; please see #4401 (particularly the list of linked PRs at the top) for details.

Good to see that it's close. I left a comment on the PR asking if there's anything I can do to help out.

timothyfroehlich avatar Sep 09 '25 15:09 timothyfroehlich

Likely this is due to our useFocus hook causing problems. Perhaps we have just overthought useFocus and any time a key is pressed in the terminal we should also treat that as regaining focus even if we failed to receive \e[?1004h

https://github.com/google-gemini/gemini-cli/blob/efb57e1cefcf4c395b2ee35902e0e438546b54b3/packages/cli/src/ui/hooks/useFocus.ts#L11

jacob314 avatar Sep 17 '25 18:09 jacob314