Merged
Conversation
a273a44 to
dec01e1
Compare
0fcf9b8 to
e26a125
Compare
97b6da8 to
163c33d
Compare
163c33d to
a1cdc75
Compare
zhming0
approved these changes
Mar 3, 2026
agent/agent_worker.go
Outdated
Comment on lines
+427
to
+435
| // reconnInterval functions similarly to pingInterval, except we expect | ||
| // the resulting connection to last much longer. By default, attempt to | ||
| // reconnect no more than once every 10 seconds. | ||
| reconnInterval := time.Second * time.Duration(max(10, a.agent.PingInterval)) | ||
| if a.agentConfiguration.PingMode == "stream-only" { | ||
| // If it's only us, then allow reconnecting as though each stream was | ||
| // a ping. | ||
| reconnInterval = time.Second * time.Duration(a.agent.PingInterval) | ||
| } |
Contributor
There was a problem hiding this comment.
Awesome, that's the best outcome 💯
2 tasks
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.
Description
Support the upcoming streaming-ping endpoint, for faster dispatch of jobs.
Context
https://linear.app/buildkite/issue/PB-927/update-agent-to-consume-the-new-connectrpc-endpoint
Changes
The plumbing stuff (adding the .proto, the new flag, the API client method, the E2E tests) is all hopefully clear on its own.
What we want is:
That part is implemented with a "
togglebaton", which is...a channelsome channels and a mutex in a trenchcoat. The streaming side starts with thetogglebaton, and the ping loop blocks to receive thetogglebaton. If the streaming side becomes unhealthy, it gives thetogglebaton back, and the ping loop should pick it up immediately. If the streaming side becomes healthy again, it waits to take thetogglebaton back (the ping loop may be in the middle of a job).The next main complication is that the ping loop and streaming loop operate in totally different ways. Pings don't get sent while executing a job, but the stream can (at least theoretically) continue receiving messages the whole time. The stream can also (theoretically) receive multiple contradictory messages one after another, e.g. "pause, idle, pause".
This is solved by breaking apart the loops into more loops - think "actors" that are passing messages between each other.
The ping loop and streaming loop generate actions. The ping loop can wait until the action is complete, so that's what it does. The streaming loop shouldn't be made to wait, so the waiting is delegated to the debouncer, which also coalesces multiple actions from the stream loop into 0 or 1 next actions, plus deals with the
togglebaton. The action handler loop actually performs the actions. The action handler is closest to being "the agent" in the sense that "the ping loop" used to be.Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)Disclosures / Credits
No LLMs were used in the making of this PR