Skip to content

fix: ignore conn errors in SSE writer#272

Merged
mtojek merged 1 commit into
mainfrom
fix-injected-tools-trace-flake
Apr 17, 2026
Merged

fix: ignore conn errors in SSE writer#272
mtojek merged 1 commit into
mainfrom
fix-injected-tools-trace-flake

Conversation

@mtojek
Copy link
Copy Markdown
Member

@mtojek mtojek commented Apr 17, 2026

When aibridge finishes the inner loop and ProcessRequest returns, the deferred context cancel fires. The mock upstream may still be writing SSE data at that point and gets a broken pipe. This is expected, use eventstream.IsConnError to detect it and stop writing instead of failing the test.

Spotted in: https://github.com/coder/aibridge/actions/runs/24564893487/job/71822444524

--- FAIL: TestInjectedToolsTrace (0.00s)
    --- FAIL: TestInjectedToolsTrace/anthr_streaming (0.01s)
        t.go:111: 2026-04-17 12:25:34.330 [debu]  mcp client initialized  trace=05962868f63f9ab9a5cd2da4ca72f92a  span=e6598f31df9a1f49  name="Mock coder MCP server"  server_version=1.0.0
        t.go:111: 2026-04-17 12:25:34.331 [debu]  interception started  trace=2106871eb2c2b71133a31486e2121924  span=5113920ce52aa0fd  route=/v1/messages  provider=anthropic  interception_id=4ce0eadd-d53c-4a64-88be-18ff19d90aee  user_agent=Go-http-client/1.1  streaming=true  credential_kind=centralized  credential_hint=a...y  credential_length=7
        t.go:111: 2026-04-17 12:25:34.331 [debu]  streaming: using api key auth  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  api_key_hint=a...y
        t.go:111: 2026-04-17 12:25:34.332 [debu]  streaming.sse-sender: stream initiated  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  model=claude-sonnet-4-20250514
        t.go:111: 2026-04-17 12:25:34.333 [debu]  injected tool invoked  trace=2106871eb2c2b71133a31486e2121924  span=272b9be33b3adfb8  name=coder_list_workspaces  server=coder  input="{\"owner\":\"admin\"}"  duration_sec=0.000480635  error=<nil>
        t.go:111: 2026-04-17 12:25:34.334 [debu]  streaming.sse-sender: request context canceled  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  model=claude-sonnet-4-20250514  error="context canceled"
        t.go:111: 2026-04-17 12:25:34.334 [debu]  streaming: stream terminated  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  model=claude-sonnet-4-20250514  error="context canceled"
        t.go:111: 2026-04-17 12:25:34.334 [debu]  streaming.sse-sender: shutdown initiated  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  model=claude-sonnet-4-20250514  outstanding_events=0
        t.go:111: 2026-04-17 12:25:34.334 [warn]  streaming: event stream shutdown  trace=2106871eb2c2b71133a31486e2121924  span=63f4f77342e0d1c9  model=claude-sonnet-4-20250514 ...
            error= shutdown ended prematurely with 0 outstanding events:
                       github.com/coder/aibridge/intercept/eventstream.(*EventStream).Shutdown
                           /home/runner/work/aibridge/aibridge/intercept/eventstream/eventstream.go:210
                     - context canceled
        t.go:111: 2026-04-17 12:25:34.334 [debu]  interception ended  trace=2106871eb2c2b71133a31486e2121924  span=5113920ce52aa0fd  route=/v1/messages  provider=anthropic  interception_id=4ce0eadd-d53c-4a64-88be-18ff19d90aee  user_agent=Go-http-client/1.1  streaming=true  credential_kind=centralized  credential_hint=a...y  credential_length=7
        mockupstream.go:174: 
            	Error Trace:	/home/runner/work/aibridge/aibridge/internal/integrationtest/mockupstream.go:225
            	            				/home/runner/work/aibridge/aibridge/internal/integrationtest/mockupstream.go:174
            	            				/opt/hostedtoolcache/go/1.25.6/x64/src/net/http/server.go:2322
            	            				/opt/hostedtoolcache/go/1.25.6/x64/src/net/http/server.go:3340
            	            				/opt/hostedtoolcache/go/1.25.6/x64/src/net/http/server.go:2109
            	            				/opt/hostedtoolcache/go/1.25.6/x64/src/runtime/asm_amd64.s:1693
            	Error:      	Received unexpected error:
            	            	write tcp 127.0.0.1:36743->127.0.0.1:43848: write: broken pipe
            	Test:       	TestInjectedToolsTrace/anthr_streaming
FAIL
FAIL	github.com/coder/aibridge/internal/integrationtest	3.268s

…njectedToolsTrace

When aibridge finishes the inner agentic loop and ProcessRequest returns,
the deferred context cancel fires. The mock upstream may still be writing
SSE data at that point and gets a broken pipe. This is expected — use
eventstream.IsConnError to detect it and stop writing instead of failing
the test.
@mtojek mtojek requested a review from dannykopping April 17, 2026 12:46
@mtojek mtojek marked this pull request as ready for review April 17, 2026 12:46
Copy link
Copy Markdown
Collaborator

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@mtojek mtojek merged commit c0d28d0 into main Apr 17, 2026
4 checks passed
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.

2 participants