Repository navigation
fix(antigravity): stream Gemini compat thoughts and anchor pre-content timeout after headers - #8673
Merged
Wei-Shaw merged 1 commit intoNov 16, 2026
Conversation
…t timeout after headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Large-context streaming requests to Gemini models through Antigravity's OpenAI-compatible endpoints (
/v1/responsesand/v1/chat/completions->/v1internal:streamGenerateContent) hit two avoidablestream_timeout/ premature-abort failure modes:Missing
applyGeminiCompatThinkingConfig(includeThoughts: true) on streaming compatibility calls:buildAntigravityCompatGeminiBodyconverted Claude-shaped intermediate payloads viaconvertClaudeMessagesToGeminiGenerateContentwithout callingapplyGeminiCompatThinkingConfig(unlikeGeminiMessagesCompatServiceandGeminiChatCompletionsCompatService).gemini-4-*-highorgemini-3.8-flash-highinvoked without an explicitreasoning.effortfield) emits a short initial response and then enters a long interleaved thinking phase (~8k+ thought tokens on large uncached prompts) before a tool call, Google'sv1internalendpoint buffers all thought tokens server-side (thoughtsTokenCount > 0with zero streamedthoughtparts), leaving the SSE connection completely silent pastgateway.stream_data_interval_timeout(default 180s) and terminating the stream withstream_timeout.prepareAntigravityCompatCallderived bare Gemini thinking variants solely fromclaudeRequest.Thinking; becauseResponsesToAnthropicRequestmapseffort=low/minimal/noneintooutput_config.effortwhile leavingthinking == nil, bare Gemini models witheffort="low"fell through to-highinstead of-low.preContentDeadlinecounted HTTP response-header wait time against the SSE stream pre-content window:handleAntigravityCompatStreamcomputedpreContentDeadlinefromcall.request.startTime(recorded beforeantigravityRetryLoop, where waiting for HTTP response headers is already bounded bygateway.response_header_timeout= 600s) and cappedmaxPreContentWaitat 2 minutes even whengateway.stream_data_interval_timeoutdefaults to 180s. Any request whose header wait exceeded 2 minutes (e.g., 130s–300s prefill on large uncached prompts, or retries) was immediately aborted on arrival ofHTTP 200(stream_read_ms = 0) as an empty stream /pre-content stream timeout.What Changed
backend/internal/service/antigravity_gateway_compat.go:applyGeminiCompatThinkingConfig(body, claudeBody, mappedModel, claudeRequest != nil && claudeRequest.Stream)inbuildAntigravityCompatGeminiBody(matchingGeminiChatCompletionsCompatService), enablingincludeThoughts: trueon streaming requests while keeping non-streaming requests free of forced thought summaries and keeping tier-suffixed model IDs free of redundantthinkingLevelfields.geminiThinkingLevelFromClaudeBody(request.claudeBody, claudeRequest.Thinking)sooutput_config.effort(low/minimal/none/medium/high) is honored even whenclaudeRequest.Thinkingisnil.backend/internal/service/antigravity_gateway_compat_stream.go:preContentDeadlineat SSE stream start (whenHTTP 200headers arrive) withmax(2m, StreamDataIntervalTimeout)while preservingcall.request.startTimeforFirstTokenMs(TTFT) measurement, and still bounding comment-only SSE streams.backend/internal/service/antigravity_gateway_compat_test.go:thinkingConfigcontracts (streaming vs non-streaming,effort="low"variant selection, explicit bare modelthinkingLevel), interleavedthoughtchunks resettingStreamDataIntervalTimeout, and post-header stream completion after >2m header waits.Related Issues & PRs
applyGeminiCompatThinkingConfighelper rather than introducing a duplicate helper, enablesincludeThoughts: trueon streaming tier-suffixed Gemini calls even whenreasoning.effortis omitted (needed to keep the SSE stream alive during interleaved thinking), avoids forcingincludeThoughts: trueon non-streaming calls, fixeseffort="low"bare-model variant resolution, and fixes the post-headerpreContentDeadlinecutoff.Validation
cd backend && go test -tags=unit ./internal/pkg/antigravity/... -count=1cd backend && go test -tags=unit ./internal/service -run "^(TestAntigravity|TestGemini|TestApplyGeminiCompat)" -count=1cd backend && go test -race -tags=unit ./internal/service -run "^TestAntigravityCompat(GeminiThinkingConfig|HeaderWaitExceedingPreContentLimitDoesNotAbortStream|InterleavedThoughtChunksResetIdleTimeout)$" -count=1cd backend && go build ./...cd backend && golangci-lint run --timeout=5m ./internal/service/...(0 issues)