Skip to content

fix(worker): Only publish occupancy between first task and drain - #796

Merged
enochtangg merged 2 commits into
mainfrom
enochtang/stream-1843-make-taskworker-occupancy-robust-to-pod-churn
Sep 25, 2026
Merged

enochtangg merged 2 commits into
mainfrom
enochtang/stream-1843-make-taskworker-occupancy-robust-to-pod-churn

Conversation

@enochtangg

Copy link
Copy Markdown
Contributor

Pods that are not handling traffic still publish occupancy, which pulls the KEDA pool average down during rollouts and blocks scale-up. This limits publishing to the window where a pod's slots actually reflect pool load.

Change

A pod now waits until it accepts its first task before it publishes occupancy. A push worker can only receive a task after it is SERVING and the broker is routing to it. So publishing starts once the pod is actually doing work, not when its first child finishes warming up.

A pod stops publishing occupancy as soon as it starts draining. Instead of leaving the last value in place, the worker removes the Prometheus series, so Prometheus marks it stale and it drops out of the average. Only the metrics thread writes the gauge, and it removes the series on every flush once draining has started.

Draining starts as soon as the worker sees the file /tmp/taskworker-draining. The pod's preStop hook creates this file when the pod is deleted, which currently is set to 15 seconds before SIGTERM arrives. That change is in a separate ops PR.

A new metric, taskworker.worker.occupancy.withheld, counts the times a pod skips publishing, tagged with the reason (no_task_yet or stopped). This makes the new behaviour easy to check during a rollout.

@enochtangg
enochtangg requested a review from a team as a code owner September 24, 2026 19:46
@linear-code

linear-code Bot commented Sep 24, 2026

Copy link
Copy Markdown

STREAM-1843

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ef07cd0. Configure here.

Comment thread clients/python/src/taskbroker_client/worker/worker.py Outdated
Comment thread clients/python/src/taskbroker_client/worker/worker.py Outdated
@enochtangg enochtangg changed the title feat(taskbroker): Signal draining to push taskworkers from preStop fix(worker): Only publish occupancy between first task and drain Sep 24, 2026
@enochtangg
enochtangg merged commit b2dfa6f into main Sep 25, 2026
29 checks passed
@enochtangg
enochtangg deleted the enochtang/stream-1843-make-taskworker-occupancy-robust-to-pod-churn branch September 25, 2026 17:35
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