Skip to content

fix(antigravity): finish empty terminal streams and continue model turns - #7899

Open
ResidualBlood wants to merge 8 commits into
Wei-Shaw:mainfrom
ResidualBlood:fix/antigravity-finish-reason-continuation
Open

ResidualBlood wants to merge 8 commits into
Wei-Shaw:mainfrom
ResidualBlood:fix/antigravity-finish-reason-continuation

Conversation

@ResidualBlood

Copy link
Copy Markdown
Contributor

Summary

Two Antigravity compat-stream behaviors that showed up together on a local 0.2.13 deployment (3040209), plus the model-turn 400 that follows an empty finished step.

Does not replace #7753. That PR still owns the #7751 failover change: a signature-only MALFORMED_FUNCTION_CALL should switch accounts immediately instead of burning same-account retries. This branch keeps that packet on the existing empty-stream failover path.

What we hit locally

Image running: patched weishaw/sub2api on top of 3040209, POST /v1/chat/completions, models gemini-3.8-flash-low and gemini-3.8-flash-medium, OpenCode as the client.

  1. Empty STOP was retried and the account was temp-unscheduled. A candidate with finishReason=STOP and no text / thinking / functionCall was classified as empty_stream. Ops showed repeated 502s on accounts 3 and 5, then a short unschedule. That matches the storm in Antigravity empty_stream storms: a terminal finishReason with no content is retried and unschedules the account #7895. A non-content-filter terminal finishReason is now a finished step. SAFETY and the other content-filter reasons still fail over. Usage-only and unparseable streams still fail over.

  2. The next turn then got 400 Requests ending with a model turn are not supported. The client writes the empty assistant message into history and sends the next request ending on a model turn. The same 400 already happened before the finish-reason change (8 times earlier the same day), so it is an existing Antigravity restriction. wrapV1InternalRequest now appends {role:user, parts:[{text:"[Continue]"}]} when the last contents entry is model or assistant. A request that already ends on user is unchanged. Both the OpenAI compat path and native ForwardGemini go through this wrapper. This is the same guard the OpenCode plugin @cortexkit/opencode-antigravity-auth applies at its wire boundary.

  3. A first cut of (1) also treated MALFORMED_FUNCTION_CALL as a finished step. That regressed [Bug] Antigravity: MALFORMED_FUNCTION_CALL falls through to stop_reason=end_turn and returns HTTP 200 with empty content #7081 / fix(antigravity): trigger failover retry on empty stream caused by MALFORMED_FUNCTION_CALL #7607. OpenCode session ses_eeb3938f0ffe52itIOlyOtaBpF (explore, gemini-3.8-flash-low) ended with finish: stop and no text after the gateway logged MALFORMED_FUNCTION_CALL. The parent planner recorded an empty subagent result. The follow-up commit puts a content-less MALFORMED_FUNCTION_CALL back on the empty-stream failover path. STOP and MAX_TOKENS still finish.

  4. After that correction, the remaining failure is Antigravity MALFORMED_FUNCTION_CALL empty stream retries the same account, then finishes as HTTP 200 after keepalive #7751, unchanged. OpenCode session ses_eeb1dfefeffe3Zo5RC5JEnMJXZ (coder, gemini-3.8-flash-medium) ended with {"message":"empty_stream","type":"upstream_error"}. Request 0a289c07, account 3, waited about 33s, then got a signature-only MALFORMED_FUNCTION_CALL. The 15s pre-content keepalive had already committed HTTP 200, so failover could not switch accounts. Gateway log: empty Antigravity compatibility stream after keepalive, HTTP 200. This branch does not change that committed-200 behavior. fix(antigravity): switch accounts on malformed empty streams #7753 is the open fix for switching accounts before the response is committed.

Related

Test plan

  • TestAntigravityCompatTerminalFinishReasonIsFinishedStep (empty STOP, chat completions and responses)
  • TestAntigravityCompatMalformedFunctionCallStillFailovers (RetryableOnSameAccount=true, no finish_reason: stop)
  • TestAntigravityCompatContentFilterFinishReasonStillFailovers
  • TestWrapV1InternalRequest_AppendsContinuationAfterModelTurn
  • TestWrapV1InternalRequest_LeavesUserEndingUntouched
  • Fork CI on ResidualBlood/sub2api branch fix/antigravity-finish-reason-continuation is green after afc1e6cb4

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@ResidualBlood

Copy link
Copy Markdown
Contributor Author

Follow-up on the running instance: empty compatibility streams must not switch accounts.

After the malformed-call correction, a content-less MALFORMED_FUNCTION_CALL went back onto the empty-stream failover path. That path is RetryableOnSameAccount, and once those retries are spent it switches accounts and temp-unschedules the current one. On a small Antigravity pool that walks every account for one bad tool-call body.

9282e1b64 keeps the same-account retries, then stops. NextAccountAction is NextAccountStop, and RequestScopedTransient skips the temp unschedule. Other failover errors still switch accounts.

This also means #7753 should not be merged as written. Switching accounts on a signature-only MALFORMED_FUNCTION_CALL is the pool-piercing behavior we are turning off. #7751's committed-200 SSE empty_stream is unchanged.

A candidate finishReason with no text, thinking, or function call was
classified as an empty stream, retried, and temp-unscheduled. Treat a
non-content-filter finishReason as a finished step instead.

Antigravity rejects the next request when that empty model turn is last.
Append a [Continue] user turn in wrapV1InternalRequest.
golangci-lint errcheck rejects unchecked map type assertions.
A signature-only MALFORMED_FUNCTION_CALL was treated as a finished step
and returned stop to the client. Keep that reason on the empty-stream
failover path. STOP and MAX_TOKENS still finish.
An empty compatibility stream was retried on the same account and then
failed over, which walks the pool and temp-unschedules each account.
Retry the current account only, then stop. Do not unschedule it.
@ResidualBlood
ResidualBlood force-pushed the fix/antigravity-finish-reason-continuation branch from 9282e1b to 027e24f Compare October 7, 2026 06:03
riofutab pushed a commit to riofutab/sub2api that referenced this pull request Oct 8, 2026
- 合入上游 Wei-Shaw#7899:Antigravity 空 STOP 收尾的流正常结束,最后一轮为 model 时追加续写提示,避免上游 400
- compat 空流错误改为同账号重试,不换号也不临时停用账号
- 本仓修正:finishReason 检测先做子串判断再用 gjson 取值,避免每行 SSE 完整 JSON 解码
- 本仓修正:MALFORMED_FUNCTION_CALL 在本仓输出可见提示文本,相应测试改为断言该行为

测试:service、handler、antigravity、apicompat unit 测试通过。
riofutab pushed a commit to riofutab/sub2api that referenced this pull request Oct 8, 2026
- 同步上游 v0.2.14:易支付回调签名复用伪造入账修复(Wei-Shaw#7888)、新装实例不再使用可猜测的管理员凭据(Wei-Shaw#7893)、前端依赖审计修复
- 安全:拒绝顶层重复 model 键(Wei-Shaw#7909),本仓补充大小写不敏感比较并并入已有请求体遍历
- 性能:剥离 namespace 时按需重建 input(Wei-Shaw#7910)
- Antigravity 空收尾流正常结束并续写(Wei-Shaw#7899),本仓修正 finishReason 检测性能与测试
- 前端小修:RPM 覆盖数值(Wei-Shaw#7900)、透传规则开关(Wei-Shaw#7902)、用户名编辑(Wei-Shaw#7903)

测试:go build、go test -tags=unit ./... 全部通过,golangci-lint 0 issues;前端 lint、typecheck、vitest 全量通过;集成测试交 CI。
ResidualBlood added a commit to ResidualBlood/sub2api that referenced this pull request Oct 8, 2026
joesonhub added a commit to joesonhub/sub2api that referenced this pull request Oct 12, 2026
joesonhub added a commit to joesonhub/sub2api that referenced this pull request Oct 16, 2026
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 10, 2026
- 同一请求在不同账号上用尽同账号重试时,只冷却第一个账号,其余账号只排除并记录 gateway.failover_temp_unschedule_skipped
- 只取 failover 循环部分;Antigravity MALFORMED_FUNCTION_CALL 部分不合,fork 的 Wei-Shaw#7899 已把兼容空流视为请求级错误且不换号
- fork 的 NextAccountStop 早返回保留在冷却逻辑之前
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 20, 2026
- 带入上游 11-17 至 11-18 已合的 PR,同步基准更新为 2af3f1e:GPT-6.2 Sol/Astra(Wei-Shaw#8906)、Ultra Fast 分组强制与渠道倍率(Wei-Shaw#8812 Wei-Shaw#8914)、首字前空闲换号受预算约束(Wei-Shaw#8920)、缓存创建 TTL 明细(Wei-Shaw#8174)及两项性能优化;Wei-Shaw#8577 与 Wei-Shaw#8598 fork 已有等价实现。
- 缓存创建 TTL 改用上游 Wei-Shaw#8174,撤回 fork 先前带入的 Wei-Shaw#8237;冲突处保留 fork 的 advisor 用量解析。
- 合入 19 个开放 PR:VS Code IDE 上下文(Wei-Shaw#8929)、Claude Code CCH 签名恢复(Wei-Shaw#8889,默认关闭)、等响应头时发 ping(Wei-Shaw#8964)、408 换号、账号恢复调度与批量编辑等修复,以及 Antigravity 假 429、裸 429 冷却范围、容量 503 换号、空流不冷却(Wei-Shaw#8975 含 Wei-Shaw#8627 新版)。
- compat 空流与 MALFORMED_FUNCTION_CALL 保留 fork 带的 Wei-Shaw#7899 行为,相关上游测试按 fork 行为调整;GPT-6.2 模型名后缀的推理档位补上校验。
- 后端全量 unit、golangci-lint、前端 lint/typecheck/vitest 与 CI 集成测试通过。
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