agents/proxy: fix red replay tests and a crash-class race in failAllTrackedTurns - #1895
Closed
ElanHasson wants to merge 1 commit into
Closed
Conversation
…rackedTurns The agentproxytest harness only registered the data-plane .../events route, but godo sends replay-only reads to the control plane at .../stream?replay_only=true. Every --replay test therefore 404'd, leaving all four of M5's replay tests red. Register the route handleStream already knows how to serve. failAllTrackedTurns aliased f.turns instead of copying it under f.mu, then ranged the live map while finishTurn deleted from it. A concurrent turn/start or a --replay goroutine's own finishTurn racing that open iterator is a "concurrent map iteration and map write" fatal error, which locking on only the writer's side cannot prevent. Copy under the lock, and add a -race regression test. Also fixes gofmt on harness.go's import block. Co-authored-by: Cursor <cursoragent@cursor.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on top of #1893 (base:
juliaye/doctl-proxy2). Two mechanical fixes found while reviewing that PR; both are verified, and neither changes intended behavior.1. All four
--replaytests are currently redagentproxytest.Harnessonly registers the data-plane route:but godo's
StreamSessionsends replay-only reads to the control plane at.../stream?replay_only=true(seehostedAgentSessionStreamPath, andStreamSession's own doc comment about the two SSE surfaces). So every replay test 404s:handleStreamalready branches onreplay_onlyandQueueReplayHistoryalready documents serving it, so only the route registration was missing. This looks like a merge artifact: the.../eventsmigration landed onfeat/agents-subcommands, and the merge kept the base's route list while the branch's new replay code needs.../stream. Registering it makes all four pass.The stale comment claiming
.../streamis "deliberately not registered" is updated to describe what the harness actually does.2.
failAllTrackedTurnscan crash the processturnsaliasesf.turns, so this ranges the live map. MeanwhilefinishTurndeletes from it, a concurrentturn/startinserts into it viatrackTurn, and a--replaygoroutine's ownfinishTurndeletes from it too — all underf.mu, but holding the lock on only the writer's side does not protect an open iterator. That'sfatal error: concurrent map iteration and map write: an unrecoverable crash, not a benign stale read. It fires precisely on the connection-loss path, which is where users are least able to afford one.Confirmed under
-race:Fixed by copying the map under
f.mu— chosen over detaching withf.turns = nil, which would have widened the existing window where aturn/startracingrunEventLoop's exit registers a turn into a map that the deferred cleanup then discards. The copy is a pure race fix with no behavior change.Added
TestFacade_FailAllTrackedTurns_ConcurrentTurnsWrite, which fails under-racewithout the fix and passes with it.3.
gofmtharness.go'sgodoimport was inside the stdlib group;gofmt -lflagged the file.Test plan
go test -race ./internal/agentproxy/...— green (was 4 failures)-racewith thefailAllTrackedTurnsfix revertedgofmt -l internal/agentproxy/— cleanGOOS=windows go build ./commands/— buildsRemaining review findings on #1893 (attach-race regression, shared-
Facadenotifier race, replayed HITL re-prompts) are behavioral/design calls and are left to the author; they're written up in a review comment there rather than changed here.Made with Cursor