Expose spawned agent identity to lifecycle hooks#4023
Draft
catkins wants to merge 4 commits into
Draft
Conversation
DrJosh9000
reviewed
Jun 23, 2026
| return filepath | ||
| } | ||
|
|
||
| func writeAgentHookScript(t *testing.T, dir, hookName, script string) string { |
Contributor
There was a problem hiding this comment.
Since all the values of script passed to this function are constants, I think they would be better of as fixtures.
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
This is the alternate existing-hook approach to #4016. Instead of adding a per-agent
post-registrationhook, this threads the registered spawned agent identity into the existing once-per-process lifecycle hooks.The
agent-startuphook already runs after all spawned workers have registered. This PR exposes the complete registered worker set to bothagent-startupandagent-shutdown, so hook consumers can set up and tear down per-agent resources without making extra API calls.Context
Changes
AgentWorkeraccessors for the registered agent ID and name.agent-startupandagent-shutdown.BUILDKITE_AGENT_IDSandBUILDKITE_AGENT_NAMESinto both hooks as comma-separated lists in spawn order.docs/agent-start.mdto document the lifecycle hook env values.Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)Local commands run:
mise exec -- go tool gofumpt -extra -w agent/agent_worker.go clicommand/agent_start.go clicommand/agent_start_test.gomise exec -- go tool gofumpt -extra -w clicommand/agent_start.go clicommand/agent_start_test.gomise exec -- go test ./clicommand -run 'TestAgentStartupHook|TestAgentStartupHookEnv|TestAgentShutdownHook'mise exec -- go test ./agent -run 'Test'mise exec -- go test ./clicommand ./agentmise exec -- go vet ./clicommand ./agentmise exec -- golangci-lint runBuildkite verification:
9bc5b7ae.Local Buildkite smoke against
https://agent.buildkite.localhost/v3:mise exec -- bin/rails server -p 3000in../buildkite.https://buildkite.localhostreturned302to/loginandhttps://agent.buildkite.localhost/v3routed through Rails.mise exec -- go run . start --endpoint https://agent.buildkite.localhost/v3 --token bkct_test --tags queue=default --hooks-path /tmp/buildkite-agent-startup-hook-smoke --build-path /tmp/buildkite-agent-startup-builds --spawn 2 --name codex-startup-smoke-%spawn --disconnect-after-idle-timeout 3 --no-feature-reporting --no-command-eval --debugPOST /v3/registerresponses andagent-startupoutput:startup ids=019ef27f-b86e-4686-921f-95ce8ec56025,019ef27f-b86e-48e3-ad77-5203e58b706estartup names=codex-startup-smoke-1,codex-startup-smoke-2POST /v3/disconnectresponses.Full
mise exec -- go test ./...was also attempted earlier, but it fails outside this change ininternal/job TestVerifyCommit/fails_when_commit_is_not_on_branch; rerunningmise exec -- go test ./internal/job -run TestVerifyCommit -count=1reproduced the same failure with git reportingorigin/feature-bas not a valid object. The transientinternal/shell TestContextCancelInterruptsfailure from the full run passed on direct rerun.Affiliation (optional, external contributors)
Buildkite employee.
Disclosures / Credits
Implemented with Codex assistance.