Repository navigation
Conversation
6705d1f to
2db67d2
Compare
e64e697 to
7aa1887
Compare
|
Gentle ping on this one when someone has time. All checks pass. Happy to change the approach if you'd rather classify the dropped connection differently. |
21a70bf to
3105fdf
Compare
…or text
RunLive's reader and sender goroutines both report into the same errChan
and the flow acts on whichever arrives first, so the two must agree on
whether a dropped connection is resumable. They did not agree on Windows.
isResumable matched substrings. Its list covers the reader's websocket
close text ("close 1006 ... unexpected EOF") and the POSIX sender text
("write: broken pipe"), but not the Windows sender text ("wsasend: An
established connection was aborted by the software in your host
machine."). When the sender won the race on Windows, the same connection
loss that would have resumed was pushed to the caller as fatal and the
session stopped after one connection.
errors.Is against the POSIX constants does not close the gap, because Go
does not map WSA error numbers onto them. The chain is *net.OpError ->
*os.SyscallError -> syscall.Errno(10053).
Match the transport failure by type instead. Any *net.OpError reaching
this path is a failed read or write on an already-established live
socket, since the dial is handled separately above, so it is resumable
on every platform. The substring checks stay for the websocket-level
cases (1006, 1008, GoAway), which are not *net.OpError.
isResumable moves from a closure inside RunLive to a package-level
function so it can be tested directly. Behaviour is otherwise unchanged.
Fixes google#1602
3105fdf to
2c1e340
Compare
karolpiotrowicz
left a comment
There was a problem hiding this comment.
Nothing here blocks merging. Matching the transport failure by type fixes the Windows case from #1602, and it lines up with adk-python, which decides the same question by exception type on both send and receive (_live_llm_flow.py:765-810).
I left two small notes on the lines, both about the doc comment and the test table rather than the behavior.
One thing outside this change, for context only. The tool-response send at base_flow.go:704-708 and the history send at base_flow.go:541-551 don't go through isResumable, so a connection that drops while a tool is running still ends the session on every platform. That predates this PR and doesn't need to change here.
jjsasha63
left a comment
There was a problem hiding this comment.
I found no blocking or important issues.
I reset a gorilla websocket from the server side over ws:// and wss:// and checked what reaches errChan. On a dropped socket the write error stays a *net.OpError through gorilla, genai and googlellm.LiveConnection: hideTempErr only rewrites errors whose Temporary() is true, and 10053 and 10054 are not. So the new check fires on real connections, not only on the synthesized errors. With the errors.As block removed, the four Windows-errno TestIsResumable cases and TestIsResumableAgreesAcrossReaderAndSender/windows fail.
The other newly resumable errors either cannot reach the select or end the connection anyway. net.ErrClosed cannot arrive while the loop is listening, because cleanup cancels connCtx before closing the socket. TLS alerts end the connection regardless, and the reconnect budget bounds the retries.
adk-python also reconnects on the websockets ConnectionClosed type for both send and receive (src/google/adk/live/_live_llm_flow.py:765-793), so classifying by type matches it.
|
@karolpiotrowicz thanks, both notes were right. The comment and the test table are fixed in #1750, including a wss:// row built through a real TLS connection. I left the tool-response and history sends for a separate issue since that one changes behavior. |
* fix(runner): preserve buffered live events at stream end (#1547) (cherry picked from commit 6576191) * fix(llminternal): classify a dropped live connection by type, not error text (#1603) (cherry picked from commit ec1b74c) * fix(runner): drop nil parts from live requests (#1795) (cherry picked from commit 893687b)
Fixes #1602.
What was broken
RunLiveruns a reader goroutine and a sender goroutine against one live connection. Both report failures into the same unbufferederrChanand the flow's select consumes exactly one, so whichever arrives first decides whether the session resumes or dies.isResumablemade that call by matching substrings of the error text, and the two goroutines do not produce the same text for the same event.Measured with a probe that kills the peer and then calls each path directly:
isResumablewrite tcp ...: write: broken pipetruewrite tcp ...: wsasend: An established connection was aborted by the software in your host machine.falseThe reader's error is the websocket layer's close (
close 1006 (abnormal closure): unexpected EOF) and is the same on both, so it matchedEOFand resumed. On Windows the sender's error matched nothing in the list, so an identical connection loss was pushed to the caller as fatal and the session stopped after one connection. Which goroutine noticed first decided whether a Windows live session survived a transient drop.errors.Isagainst the POSIX constants does not close the gap. Go does not map WSA error numbers ontosyscall.ECONNABORTED/ECONNRESET, verified directly:What the fix does
Classifies the transport failure by type instead of by text:
Any
*net.OpErrorreaching this path is a failed read or write on an already-established live socket, because the dial has its own error path higher up that returns before this loop. The substring checks stay for the websocket-level cases (1006, 1008, GoAway), which are not*net.OpError, so no existing behaviour changes.isResumablemoves from a closure insideRunLiveto a package-level function, which is what makes it testable. Nothing else about it changed: theio.EOFcheck and the substring list are byte-identical to before.How it surfaced
TestRunLiveNoGoroutineLeak/realtime_sender_error_after_connection_loss_does_not_leakfails intermittently on Windows:connection count = 1, want 2is the tell: the flow never opened the second connection. Despite the test's name this is not a leak.Being straight about that repro: I saw it once in roughly 550 runs of the test binary, and only under heavy CPU load, which is what makes the sender win the race often enough to observe. I did not try to turn that into a regression test, because a 1-in-550 race would be a flake in CI rather than a guard. The new unit test pins the mechanism instead, which is deterministic.
Testing Plan
Failing first, and on the real defect rather than on a missing symbol. Since
isResumabledid not exist as a callable symbol before, running the new test against unmodifiedmainonly producesundefined: isResumable, which proves nothing. So the extraction was applied on its own, without the*net.OpErrorcheck, and the new tests were run against that:With the
*net.OpErrorcheck restored, all 16 subtests pass.The test synthesizes the error shapes (
*net.OpErrorwrapping*os.SyscallErrorwrapping an explicit errno) rather than relying on the host's own spelling, so a Linux CI runner exercises the Windows cases. Confirmed: the same 16 subtests pass on linux/amd64 (WSL2) as well as windows/amd64.Gates run on this branch, windows/amd64, Go 1.26.6:
go test ./internal/llminternal/ -count=1okgo test -race ./internal/llminternal/ -count=1ok, and 20 further runs as separate processes, 0 failuresgo vet ./internal/llminternal/cleango test -race -mod=readonly -count=1 -shuffle=on work: 5 packages fail, and the same 5 fail on pristinemainat f7e16e0. Failure sets extracted and diffed rather than eyeballed, and they are identical:cmd/adkgo/internal/deploy/agentengine,cmd/adkgo/internal/deploy/cloudrun,internal/configurable/conformance/replayplugin,internal/telemetry/functionaltest,runner. All are Windows-only and none isinternal/llminternalgolangci-lint run: 0 issues, exit 0. It flagged one real gofumpt violation in the new test file first, which is fixed.Worth recording for anyone else reproducing locally: with a stale
GOLANGCI_LINT_CACHEthis run instead reports 6 spuriousSA5011findings in unrelated test files, and the files it names change between runs on an unmodified tree. That is exactly the failure mode theskip-cache: truecomment in.github/workflows/go.ymldescribes, and pointingGOLANGCI_LINT_CACHEat a fresh directory gives0 issues.I had it backwards at first and am noting it in case it saves someone the same detour.One thing worth flagging separately, since it cost me time and is not caused by this change:
-count=NwithN > 1is not usable on this package.TestLoggingSpanIDPropagationfails on every repeat after the first because it depends on process-global logger state, 19 failures out of 20 on pristinemainwith no changes applied. Repeated runs here have to be separate processes.Environment
Windows 11 / windows-amd64, Go 1.26.6, cross-checked on linux/amd64 under WSL2.