t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Pi turns with Gemini 4 Neon show repeated "(empty response)" rows between tool calls

Open harshit97 opened this issue 1 week ago • 1 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

What happens

Running a multi-step tool-use turn with Pi on google/gemini-4-neon shows repeated (empty response) rows between almost every tool call on web and desktop.

Root cause

In Pi's Google stream parser (google-generative-ai.ts#L124-L182), part.text !== undefined matches empty text parts on tool-use turns, so Pi emits text_start, text_delta with delta: "", and later text_end with content: "". Pi's google-vertex.ts has the same check, and Pi cannot drop all empty text parts unconditionally because Gemini can attach a required thoughtSignature to an empty text part (google-shared.ts#L290-L294).

In T3 Code's Pi adapter, there is a 50ms flush race:

  1. message_update for text_delta (packages/provider-pi/src/server/adapter.ts#L2382-L2390) calls streamItemFor and scheduleStreamFlush even when delta and item.text are empty.
  2. scheduleStreamFlush (adapter.ts#L1320-L1333) waits STREAM_FLUSH_MS = 50 (adapter.ts#L92) and calls emitStreamItem(turn, item, true) without checking whether the item is still empty and unpublished.
  3. If text_end arrives before the 50ms flush fires, completeStreamItem (adapter.ts#L1360-L1369) sees item.text.length === 0 && !item.published and drops it.
  4. If the flush fires first, emitStreamItem publishes an empty assistant_message and sets item.published = true, so completeStreamItem then finalizes it as a completed empty message. In one real 18-step tool-use turn, 16 of the 18 steps took 52ms to 475ms and turned into empty assistant_message rows.
  5. Web and desktop then render each completed empty assistant_message as (empty response) in TimelineAssistantRows.tsx#L38.

Steps to reproduce

Deterministic repro for packages/provider-pi/src/server/adapter.test.ts:

  1. Start a Pi turn and emit message_start with role: "assistant".
  2. Emit message_update with text_start, then text_delta with delta: "".
  3. Wait longer than STREAM_FLUSH_MS (50ms), then emit text_end with content: "" and message_end.
  4. An empty assistant_message turn item and message are emitted.

Live repro:

  1. Run a multi-step tool-use prompt in T3 Code using Pi with google/gemini-4-neon.
  2. Watch (empty response) rows appear between tool calls.
t3code-pi-empty-response-redacted

Expected behavior

An unpublished stream item with empty text should not be flushed or finalized as an assistant_message, matching how ProviderTextDeltaCoalescer in the Claude and Codex adapters ignores empty appends.

Fix notes

  • Keep completeStreamItem's item.published check so an already-published block that restarts empty still clears stale text (see #38335 and adapter.test.ts#L6389-L6449).
  • Guarding inside scheduleStreamFlush to skip emitStreamItem when item.completed || (item.text.length === 0 && !item.published) (using exact zero length, not trim()) covers both empty text_delta events and the case where a non-empty delta schedules a flush and a reconnect text_start resets restarted.text = "" (adapter.ts#L2376-L2380) before the timer fires.

Impact

Minor bug or occasional failure

Version or commit

T3 Code 0.1.11, still present on main @ 20a3bed880

Environment

macOS desktop client connected to Linux t3 serve host, Pi 1.6.0, google/gemini-4-neon

harshit97 avatar Nov 25 '26 08:11 harshit97

I tried to reproduce this on the current build and could not.

Commit: origin/main @ 2fbb071e0c. Deterministic: added a test to packages/provider-pi/src/server/adapter.test.ts (branch factory/repro-42689, 53d876cb5d) that drives the real Pi adapter with a fake Pi RPC process: message_start(assistant), text_start + text_delta with delta "" on contentIndex 0, a tool_execution_start as the milestone that shows the delta was handled, TestClock.adjust(120ms) (past STREAM_FLUSH_MS = 50), text_end with content "", message_end, then a second assistant message whose text_end content is "Answer", then agent_settled. On main the emitted message.updated texts are ['', '', 'Answer'] (an empty running message from the flush timer, then a completed empty message); expected ['Answer']. With the reporter's guard added temporarily to scheduleStreamFlush (skip emit when item.completed || (item.text.length === 0 && !item.published)), the new test and all 187 tests in the file pass, including the #38335 restart test; the guard was reverted and only the test is on the branch. Live attempt: Pi 1.6.0 in json/print mode with a scratch PI_CODING_AGENT_DIR pointing the google provider at the hub, models google/gemini-4-neon, gemini-4-hydrogen and gemini-3.8-flash, on a multi-step read-tool prompt. Every attempt failed with hub 429 'Individual quota reached' (model_cooldown; Neon resets in about 116h), so Gemini's real stream was never observed and the app was not run end to end with Pi+Gemini.

Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

juliusmarminge avatar Nov 25 '26 08:11 juliusmarminge