Skip to content

fix(platform): start every Gemini CLI kick as a fresh conversation - #4025

Merged
larryro merged 3 commits into
mainfrom
fix/gemini-cli-resume-tool-turns
Oct 1, 2026
Merged

larryro merged 3 commits into
mainfrom
fix/gemini-cli-resume-tool-turns

Conversation

@larryro

@larryro larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Why

A project-agent task on Gemini CLI that ran a tool could never be continued: every later kick (a comment, an automatic retry, a mid-run comment's restart, an answered ask on an automation node) handed the exec --resume <id>, and the first model call of the resumed conversation was refused — DeepSeek-style upstreams with Messages with role 'tool' must be a response to a preceding message with 'tool_calls', Google with number of function response parts…. The retries then resumed into the same wall until the budget was spent, because the gemini parser never stamped apiErrorStatus, so the kick's "400 → start fresh" rule never fired.

Root cause is in the CLI, not the gateway: on --resume, Gemini CLI 0.59.0 (and main) replays every tool result twice — once rebuilt from the recorded toolCalls[].result, once from the user record it also writes for the same response (convertSessionToClientHistory). google-gemini/gemini-cli#29365, fix PRs #29400/#29490 open, nothing released. Reproduced with the pinned CLI against Bifrost 2.2.4 and a logging mock upstream: the live turn sends one tool message per call, the resumed one sends two with the same tool_call_id. Qwen Code 0.23.3 resumes cleanly under the same rig.

What changes

  • Harness YAML gains capabilities.resume; the schema holds it coherent with the argv resume slot (resume ⇔ slot). The eight other harnesses declare true; gemini declares false, drops its slot, and says why and when to flip it back.
  • Planners read it through one helper (harnessResumesConversations) and take their existing fresh path: the task kick (resolveTaskKickResume, box swept after a settled predecessor, kept with the inspect note after a failed one), the automation retry (workflowAgentRetryResume), the answered-ask resume, and the comment restart in the task host. The exec builder refuses a handle on such a harness, so no planner can bypass the flag.
  • Gemini parser stamps apiErrorStatus on the turn end: the code of a relayed [API Error: {"error":{"code":N…}}] body, 429 from the rate-limit sentence the CLI appends (the SDK's retries leave no body). The run's reason becomes the provider's sentence with the status instead of the JSON dump.
  • Docs (EN/DE/FR, harnesses + execution logs), manual box TASK-F59, an automation.md row, a contract debt ledger entry, and the GEMINI_CLI_VERSION note on what a pin bump needs first.

Verified

  • Unit: task_kick_resume, agent_retry, registry (schema coherence), exec-builder (refusal), golden-exec (gemini goldens re-frozen without --resume), gemini-stream (fixtures captured from the pinned 0.59.0: 400 body, 429 prose; 500 inline), agent_run_host.connector_caller (a comment on a Gemini run restarts without the handle and on the rebuilt brief; Codex control still resumes), load_system_config (every shipped harness but gemini resumes). The server project around the changed seams: 393 files green.
  • @tale/shared + @tale/platform typecheck, oxlint, oxfmt, lint:manual, lint:links, docs tests.

Not verified here

  • A real Gemini CLI task run on a deployed stack after this change (manual box TASK-F59).
  • tests/guards/frontend-entry-discovery.guard.test.ts could not run in the worktree (no knip under its root) — unrelated to this change.

The pinned Gemini CLI's `--resume` replays every tool result of the
recorded session twice (its toolCalls[].result and the user record it
also writes for the same response — google-gemini/gemini-cli#29365,
fix PRs open), so the first request of a resumed conversation that ever
ran a tool is refused by the model: Google answers "number of function
response parts…", an OpenAI-wire upstream "role 'tool' must be a
response to a preceding message with 'tool_calls'". Every later kick of
a task, every automatic retry, a mid-run comment's restart and an
answered ask all handed the exec the handle, so a Gemini task that used
a tool could never continue, and its retries died on the same wall.

Harness YAML gains `capabilities.resume`, held coherent with the argv
resume slot by the schema; gemini declares false and drops its slot.
The task kick, the automation retry, the answered-ask resume and the
comment restart read it and take their existing fresh path; the exec
builder refuses a handle on such a harness. Qwen Code resumes cleanly
and keeps its slot. Docs and the manual suite carry the exception; the
contract debt ledger carries the re-enable condition.
The gemini stream parser never set `apiErrorStatus`, so a Gemini CLI
turn the provider refused reached the run with no status: the kick's
"400/404 → start fresh" rule, the broker's 401 rotation and the 429
cooldown never applied to it, and the run's reason was the gateway's
JSON body verbatim. The CLI's `result.error.message` for a refusal is
`[API Error: {"error":{"code":N,…}}]`; for a 429 the SDK's retries
leave only the CLI's own rate-limit sentence (errorParsing.ts
getRateLimitMessage). Read the code and the provider's sentence out of
the body, recognise the 429 by its sentence, and stamp the turn end.
Fixtures captured from the pinned 0.59.0 against a loopback gateway.
larryro added a commit that referenced this pull request Oct 1, 2026
The audit-chain check read the org's rows, verified the chain, then read
the chain head in a second autocommit statement. An audit write commits
its row and the head together, so a job of another lane (or this lane's
own lockout bell) landing between the two reads left the head one row
ahead of the tail just read: `chain=true, head=false` on an intact chain
(Backend integration, PR #4025 attempt 1). Both reads now share one
repeatable-read, read-only transaction.
@larryro

larryro commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Attempt 1's one red, Backend integration → audit chain verifies — rows=2547, chain=true, head=false, was the check itself: rows and head were read in two autocommit statements, and a concurrent audit write (committed with its head update) landed between them. f6d36ec reads both from one repeatable-read snapshot; the lane passes locally (ITEST_LANES=checkLoginThrottleAndAuditChain, 23/23) against a throwaway tale-db + object store.

The audit-chain check read the org's rows, verified the chain, then read
the chain head in a second autocommit statement. An audit write commits
its row and the head together, so a job of another lane (or this lane's
own lockout bell) landing between the two reads left the head one row
ahead of the tail just read: `chain=true, head=false` on an intact chain
(Backend integration, PR #4025 attempt 1). Both reads now share one
repeatable-read, read-only transaction.
@larryro
larryro force-pushed the fix/gemini-cli-resume-tool-turns branch from f6d36ec to 386b7ad Compare October 1, 2026 03:17
@larryro
larryro merged commit 16cf83b into main Oct 1, 2026
87 of 88 checks passed
@larryro
larryro deleted the fix/gemini-cli-resume-tool-turns branch October 1, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant