Skip to content

Gemini API provider hangs indefinitely during login and run despite valid API key #660

Open

Description

@Alexander-321

Summary

The gemini-api provider appears to hang indefinitely, even though the API key is valid and works outside of jcode.

Environment

  • jcode: v0.61.1
  • macOS
  • Provider: gemini-api

What happens

  1. Create a valid Gemini API key.
  2. Save it to:
    ~/Library/Application Support/jcode/gemini.env

Contents:

GEMINI_API_KEY=YOUR_KEY

  1. Run:

jcode login --provider gemini-api

or

jcode --provider gemini-api run "Say hello"

Both commands hang indefinitely and never return.

Expected behavior

The provider should authenticate successfully and respond to the prompt.

What has already been verified

The API key is valid.

Running this directly with curl works immediately:

curl -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=MY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "contents":[{"parts":[{"text":"Say hi"}]}]
}'

Thank you so much for working on this issue and I hope it will be fixed soon.

Activity

  1. 1jehuang commented on Jul 29, 2026

    @1jehuang
    Owner

    Thanks for the detailed report, and especially for the working curl check. That narrowed this a lot.

    I found two real defects on the path you describe, though I want to be straight with you about what I could and could not confirm.

    What I fixed

    1. The prompt gives no feedback whatsoever. jcode login --provider gemini-api calls read_secret_line, which enables terminal raw mode. Raw mode suppresses the terminal's own echo, and the function then echoed nothing itself. So typing or pasting your key produced zero screen change, which is genuinely indistinguishable from a hung process. It now echoes one * per character (and erases one on backspace), so the secret still never appears on screen but you can see the prompt responding.

    2. Login never told you your saved key was found. Because you had already written gemini.env yourself, the correct outcome was "you are done, nothing to do", but the prompt looked identical to the never-configured case. Login now says which credential it resolved and from where (the env var when that wins, otherwise the full config-file path), plus how to keep it.

    Your path is right, by the way: ~/Library/Application Support/jcode/gemini.env is exactly where app_config_dir() resolves on macOS, and GEMINI_API_KEY is the name the gemini-api profile reads. Your setup was correct.

    What I could not verify

    I could not reproduce an indefinite hang. On a Linux host, login --provider gemini-api with a saved key returns immediately. So while items 1 and 2 fully explain "the login command appears to hang forever", I cannot prove they explain your run "Say hello" case, which is a different code path from login. Two questions that would settle it:

    • After the login prompt appears, does pressing Enter (or Ctrl+C) return you to a shell? If yes, it was the invisible prompt.
    • For the run hang, could you attach ~/.jcode/logs/jcode-<today>.log from a hung attempt? That will show whether the request is issued and stalls, or never gets built at all.

    This is on the triage branch with 5 new tests. Leaving the issue open until you can confirm the run case.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  2. added
    bug
    priority: medium
    triage: reproducible
    needs-info
    on Jul 29, 2026
  3. 1jehuang commented on Jul 30, 2026

    @1jehuang
    Owner

    Closing the verification loop properly, since my earlier "verified" claims were thinner than they sounded. Two gaps found and fixed, plus an audit that shows this branch is now clean.

    The #660 masking had no test at all

    read_secret_line only masks on the raw-mode TTY branch. Under cargo test stdin is not a terminal, so every possible unit test takes the piped-line fallback and exercises none of the fix. The reporter's actual symptom was unguarded.

    Fixed with a real pty test (secret_input_pty_tests.rs): forks a child running the function with a pty slave as stdin, types at it, and asserts on the bytes the terminal received. Mutation-verified both ways, and confirmed end to end against built binaries:

    Binary Bytes echoed while typing 15 chars
    pre-fix '' — zero, which is precisely "hangs indefinitely"
    fixed '***************' — 15 masks, key saved intact

    The test also pins that the secret never reaches the screen, that masking does not corrupt the returned value, and that backspace erases one mask and one character.

    The extracted hint strings were not pinned

    Moving the next-step hints into next_step turned three eprintln! literals into \-continued strings. A continuation swallows the following indentation, so a mis-indented line changes user-facing text while still compiling, and nothing would have caught it. Added exact-equality assertions against the strings login.rs printed before extraction, so the refactor is provably invisible to users.

    Audit of this branch against master

    After the stale-file incident I checked mechanically rather than by eye.

    Every line this branch removes from master (210 of them): all accounted for as intentional edits or baseline numbers. rate_limit_notice_with_nudge was moved, not deleted, and its caller in server_events.rs:1254 still resolves.

    Every baseline I raised (26 code-size, 5 test-size), attributed by comparing against master's own file lengths:

    • 29 of 31 match master's current content exactly, i.e. master's growth, not mine.
    • 2 apparent exceptions are files this branch makes smaller than master: tui/app.rs 2516 → 2508 and tui_lifecycle.rs 1302 → 1296, from removing the orphaned pinned_todos_* fields.
    • The one genuine increase of mine is scroll_copy_02/part_01.rs (+23), and all 23 lines are the clipboard assertions those tests were missing.

    So no gate was loosened to accommodate my own code.

    Current test state

    Still red and still not mine, both reproduced on clean origin/master: the missing frame_meter.rs / scroll_profile.rs, and test_configured_palette_recolors_a_real_rendered_frame.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  4. 1 remaining item

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

    bugneeds-infopriority: mediumtriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions