[Bug] Camoufox tab.contents is not cleared when readResponseHead fails or stream aborts, causing next retry to fail on Rerun button and rebuild the worker
发生了什么 / What happened
Summary
When an in-flight Camoufox UI request fails or is cancelled (499 context canceled) during readResponseHead or before stream completion, tab.contents remains populated with that aborted request's contents. When the client retries the same prompt on that account, nextChatAction selects chatRerun, times out waiting 5s for button[aria-label^="Rerun" i] on the stopped/incomplete turn, and triggers WorkerFailed, unnecessarily killing and rebuilding the entire Camoufox browser process.
Observed Log Evidence (sanitized, 15 occurrences in 24h)
Almost every 等待官网 Rerun 按钮 worker rebuild in our logs immediately follows a client-cancelled (499) or failed attempt on the same account:
{"time":"2026-11-21T12:18:32.708+03:00","level":"WARN","msg":"请求已取消","source":"account_a","request":{"id":"req_1","state":"cancelled","status":499,"model":"gemini-4-hydrogen"}}
{"time":"2026-11-21T12:18:33.297+03:00","level":"INFO","msg":"等待上游响应","source":"account_a","request":{"id":"req_2","model":"gemini-4-hydrogen"}}
{"time":"2026-11-21T12:18:38.559+03:00","level":"WARN","msg":"WAA Worker 重建,重放当前请求","source":"account_a","reason":"发送 AI Studio GenerateContent: 等待官网 Rerun 按钮: context deadline exceeded"}
Same exact sequence on account_b (13:45:05 499 -> 13:45:08 retry -> 13:45:14 等待官网 Rerun 按钮 -> worker rebuild), and 13 additional times in the same 24h log.
###Root Cause Pointers internal/camoufoxnative/generate.go (generate): tab.contents = contents is set before readResponseHead(ctx, channel). If readResponseHead returns err != nil (e.g., 499 context canceled), generate calls worker.stopTurn(tab) and returns immediately, skipping if status != http.StatusOK { tab.contents = nil }. Likewise, if status == http.StatusOK but the stream is aborted/cancelled mid-response (done == false -> releaseChat(tab, false)), tab.contents is still left non-nil.
internal/camoufoxnative/generate.go (startTurn / chatRerun) & internal/aistudio/runtime_native.go (generate): When the next request has identical contents, nextChatAction picks chatRerun, hovers ms-chat-turn:last-of-type, and fails after 5s waiting for rerunButtonSelector (because the stopped/aborted turn did not render a Rerun button). NativeWorker.generate sets worker.setPhase(WorkerFailed) on any non-context error, tearing down and cold-booting a fresh Camoufox process instead of falling back to chatNew.
###Suggested Fix Only commit tab.contents = contents once the turn completes cleanly (or clear tab.contents = nil whenever readResponseHead errors or releaseChat runs with completed == false). If chatRerun fails to locate rerunButtonSelector (or lastTurnSelector), clear tab.contents = nil and fall back to chatNew (click New chat, paste, and Run) instead of failing the turn and marking the entire Camoufox worker WorkerFailed.
版本 / Version
No response