Skip to content

Report graceful agent stops to Buildkite - #4270

Open
scadu wants to merge 2 commits into
mainfrom
lukasz/disconnecting_graceful_shutdown_sup-7869
Open

Report graceful agent stops to Buildkite#4270
scadu wants to merge 2 commits into
mainfrom
lukasz/disconnecting_graceful_shutdown_sup-7869

Conversation

@scadu

@scadu scadu commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Description

Graceful signal shutdowns currently drain the worker locally, but the control plane shows it as CONNECTED until it disconnects.

This reports a non-forced /stop using the worker's existing session, giving us STOPPING while jobs drain and STOPPED after disconnect. Reporting is best-effort and limited to five seconds.

It's enabled by default and can be disabled with BUILDKITE_AGENT_REPORT_GRACEFUL_STOP=false. Ungraceful shutdown paths, including standard agent-stack-k8s termination, remain unchanged.

I considered handling this through the scaler or Stacks API, but that would need broader credentials and agent-to-instance mapping. The worker already has everything it needs.

Context

buildkite/elastic-ci-stack-for-aws#1861

Changes

  • Report graceful stops once per worker before disconnecting.
  • Add the default-on --report-graceful-stop flag and environment variable.
  • Cover authentication, payload, ordering, failures, opt-out, and ungraceful shutdowns.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Affiliation (optional, external contributors)

Also tested the lifecycle on Elastic Stack with three workers: all moved to STOPPING while their jobs continued, then reached STOPPED after finishing.

Disclosures / Credits

Report signal-driven graceful shutdowns by default, producing STOPPING
while jobs drain and STOPPED after disconnect.

Keep reporting best-effort and allow opting out with
BUILDKITE_AGENT_REPORT_GRACEFUL_STOP=false.
@scadu
scadu requested review from a team as code owners August 25, 2026 13:00
@scadu scadu added enhancement feature New user-facing feature! labels Aug 25, 2026

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The added control-plane call and synchronization alter the core worker shutdown lifecycle, so this needs human review under the current approval policy. I found no code issues to call out.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 20918, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

About buildsworth

Model: gpt-5.6-sol with xhigh thinking.

How to request a review: Comment @buildsworth-bk review on the PR, or request buildsworth-bk as a reviewer.

Risk labels (how buildsworth classifies risk) — buildsworth classifies risk itself from the diff. Unless repository policy already allows L2 approval, grant it by mentioning @buildsworth-bk (see approval ceiling and L2 approval grant):

  • L1 — Low risk (dep bumps, docs/copy, lockfiles, small presentational fixes). buildsworth may approve by default.
  • L2 — Standard risk (new UI, additive API fields, refactors). Approved only when repository policy or a verified grant allows it; otherwise comment-only.
  • L3 — High risk (auth, migrations, payments, secrets, perf-critical paths). Human review always required.

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The added control-plane call and synchronization alter the core worker shutdown lifecycle, so this still needs human review under the current L1 approval policy. I found no code issues to call out.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 22034, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement feature New user-facing feature!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant