Summary
Gemini remote sessions can become permanently stuck after resume: every new prompt fails with The input token count exceeds the maximum number of tokens allowed 1048576, with no recovery path. HAPI surfaces the error but does not compact/retry (unlike Codex).
Observed on session "hapi - gemini windows installer" (HAPI b0a7208e-f35e-410a-b130-00adbf3dc040, Gemini dd9982b5-b3e6-4c1c-a9ab-87e4e7cfdbf3, gemini-cli 0.43.0).
Reproduction
- Run a long Gemini remote session with many tool calls (especially large shell output).
- Resume the session (
hapi gemini --resume <id> --hapi-starting-mode remote).
- Send any new message.
Result: Immediate API rejection at the 1,048,576-token hard limit. Subsequent model switches can mask the failure with quota errors.
Root cause (evidence)
| Layer |
Finding |
| HAPI DB |
~427 messages, ~161 KB (not bloated) |
| Gemini CLI transcript |
903 MB JSONL at ~/.gemini/tmp/hapi/chats/session-*-dd9982b5.jsonl |
| Trigger |
grep -r "HUB_URL" . from repo root → 4.6 MB shell output |
| Amplification |
Gemini CLI stores cumulative toolCalls with full outputs per turn; the 4.6 MB blob was duplicated 152× across turns (~228M estimated tokens vs 1M limit) |
The context error is real, not a miscount — but recovery is blocked by missing HAPI handling and upstream compression limits.
HAPI gaps (fix regardless of backend)
- No context overflow recovery —
geminiRemoteLauncher.ts logs and surfaces errors; Codex has compact-and-retry in codexRemoteLauncher.ts.
- No
/compact handling for Gemini remote sessions.
- No context budget UI for Gemini —
web/src/chat/modelConfig.ts returns null for non-Claude/Codex flavors.
- Local scanner bug —
cli/src/gemini/utils/sessionScanner.ts JSON.parse()s the entire transcript file, but Gemini writes JSONL (fails on line 2).
Antigravity CLI transition
Google is transitioning Gemini CLI to Antigravity CLI (June 2026 consumer cutoff). That migration may change the harness, but it is not guaranteed to fix:
- cumulative tool-output bloat in persisted sessions
- compression failing when context is already over limit
- HAPI-specific resume/recovery behavior
HAPI already has an Antigravity path (~/.gemini/antigravity-cli). This issue tracks fixes that should apply to both current Gemini ACP integration and the Antigravity backend — session recovery, clearer errors, context UI, and JSONL-safe local scanning.
Upstream references (same failure modes)
Proposed HAPI work
Operator mitigation (applied locally)
- Archived poisoned transcript (~903 MB)
- Set
ui.compactToolOutput: true, model.compressionThreshold: 0.5, model.maxSessionTurns: 100 in ~/.gemini/settings.json
- Do not resume poisoned Gemini session IDs — start fresh
Summary
Gemini remote sessions can become permanently stuck after resume: every new prompt fails with
The input token count exceeds the maximum number of tokens allowed 1048576, with no recovery path. HAPI surfaces the error but does not compact/retry (unlike Codex).Observed on session "hapi - gemini windows installer" (HAPI
b0a7208e-f35e-410a-b130-00adbf3dc040, Geminidd9982b5-b3e6-4c1c-a9ab-87e4e7cfdbf3, gemini-cli 0.43.0).Reproduction
hapi gemini --resume <id> --hapi-starting-mode remote).Result: Immediate API rejection at the 1,048,576-token hard limit. Subsequent model switches can mask the failure with quota errors.
Root cause (evidence)
~/.gemini/tmp/hapi/chats/session-*-dd9982b5.jsonlgrep -r "HUB_URL" .from repo root → 4.6 MB shell outputtoolCallswith full outputs per turn; the 4.6 MB blob was duplicated 152× across turns (~228M estimated tokens vs 1M limit)The context error is real, not a miscount — but recovery is blocked by missing HAPI handling and upstream compression limits.
HAPI gaps (fix regardless of backend)
geminiRemoteLauncher.tslogs and surfaces errors; Codex has compact-and-retry incodexRemoteLauncher.ts./compacthandling for Gemini remote sessions.web/src/chat/modelConfig.tsreturnsnullfor non-Claude/Codex flavors.cli/src/gemini/utils/sessionScanner.tsJSON.parse()s the entire transcript file, but Gemini writes JSONL (fails on line 2).Antigravity CLI transition
Google is transitioning Gemini CLI to Antigravity CLI (June 2026 consumer cutoff). That migration may change the harness, but it is not guaranteed to fix:
HAPI already has an Antigravity path (
~/.gemini/antigravity-cli). This issue tracks fixes that should apply to both current Gemini ACP integration and the Antigravity backend — session recovery, clearer errors, context UI, and JSONL-safe local scanning.Upstream references (same failure modes)
/compressfails when history is already too longthoughtSignature) pushing requests over limitui.compactToolOutput,model.compressionThresholdProposed HAPI work
geminiRemoteLauncher.ts; attempt compact/recovery (mirror Codex) or instruct user to start freshsessionScanner.tsto read JSONL line-by-lineOperator mitigation (applied locally)
ui.compactToolOutput: true,model.compressionThreshold: 0.5,model.maxSessionTurns: 100in~/.gemini/settings.json