Skip to content

[Swarming] Dispatch each utask_main Pub/Sub queue independently in run_bot - #5639

Draft
JuanMBriones wants to merge 1 commit into
queues_mac_arm64from
mac_arm64_utask_main_dispatch
Draft

JuanMBriones wants to merge 1 commit into
queues_mac_arm64from
mac_arm64_utask_main_dispatch

Conversation

@JuanMBriones

@JuanMBriones JuanMBriones commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why we need this change?

Previously, schedule_utask_mains() in run_bot.py pulled messages from utask_main and utask_main-swarming sequentially (each waiting up to 150s), combined all tasks into a single list, and only then leased and dispatched them together. With per-platform Swarming queues (utask_main-swarming + utask_main-swarming-mac-arm64, per go/queuescf4macarm64), that combined loop creates three production risks:

  1. Pub/Sub ack-deadline creep & head-of-line blocking (b/517517107): Holding pulled messages from earlier queues while sequentially waiting 150s per additional queue pushes messages toward Pub/Sub's 600s ack deadline and lets one platform stall another.
  2. Staged rollout breakage: Pulling a platform subscription before Terraform/Pub/Sub has provisioned utask_main-swarming-mac-arm64 raises RuntimeError, which would abort dispatch for existing queues.
  3. Unnecessary client churn: Creating a fresh RemoteTaskGate per queue is avoidable overhead.

This PR (Part 2 of 4, consumer first) refactors schedule_utask_mains() to pull, lease, and dispatch each queue independently using a 30s pull window for Swarming queues while gracefully skipping unprovisioned subscriptions — making it safe to land before any producers publish to utask_main-swarming-mac-arm64.

Code Changes

  • Add SWARMING_UTASK_QUEUE_PULL_SECONDS = 30 and an optional pull_seconds parameter to tasks.get_utask_mains() in base/tasks/__init__.py (defaulting to UTASK_QUEUE_PULL_SECONDS = 150 for non-Swarming queues).
  • Extract _schedule_utask_main_queue() in src/python/bot/startup/run_bot.py to pull, lease, and dispatch each queue independently, reusing a single RemoteTaskGate instance and catching RuntimeError to log and skip unprovisioned subscriptions during staged rollouts.
  • Iterate over pub_sub_task_queue.get_all_swarming_utask_main_queues() when SWARMING_REMOTE_EXECUTION is enabled.
  • Update and expand schedule_utask_mains unit tests in run_bot_test.py (including missing-subscription tolerance).

Tests

  • python butler.py py_unittest -t core -p run_bot_test.py

Bug: 565469156


Stack created with GitHub Stacks CLI • Give Feedback 💬

@smolkaj smolkaj 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.

Thanks for the PR! A few questions/nits.


def get_utask_mains(queue_name: str) -> List[PubSubTask]:
def get_utask_mains(queue_name: str,
pull_seconds: int = UTASK_QUEUE_PULL_SECONDS

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.

Add documentation for the arguments

SUBQUEUE_IDENTIFIER = ':'

UTASK_QUEUE_PULL_SECONDS = 150
SWARMING_UTASK_QUEUE_PULL_SECONDS = 30

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.

Add documentation

pub_sub_task_queue.SWARMING_UTASK_MAIN_QUEUE.name)
logs.info(f'Found {len(swarming_utask_mains)} swarming utask mains.')
utask_mains.extend(swarming_utask_mains)
def _schedule_utask_main_queue(queue_name: str,

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.

Add documentation for arguments

utask_mains = tasks.get_utask_mains(queue_name)
else:
utask_mains = tasks.get_utask_mains(queue_name, pull_seconds=pull_seconds)
except RuntimeError as e:

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.

Why this change?

@IvanBM18 IvanBM18 Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IIUC, this is to avoid the scheduling bot from failing with an error if a queue doesn't exist.

Which seems fair, but with this change we are introducing a new silent failure, i feel like its better that a CF bot crashes loudly when a queue doesn't exists rather than failing silently to schedule things.

Mainly because, if i have a brand new CF instance i would prefeer to it not work because my queues are not well defined, rather than seeing no 'failures' nor tasks being scheduled, and having to dig in the logs to find out why

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.

What's our plan for validating these changes? Both for this PR and the PR chain in general, since I suspect you may not be able to validate things one-by-one.

Please also document the plan in the PR description.

@IvanBM18 IvanBM18 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Steffens comments + the silent failure. I feel its best to crash CF rather than having to debug the logs

…n_bot

Refactor schedule_utask_mains() to pull, lease, and dispatch each
utask_main queue independently so platform-specific Swarming queues
(such as utask_main-swarming-mac-arm64) cannot block each other or push
leased messages past Pub/Sub's 600s ack deadline (b/517517107).

Changes:
* Add SWARMING_UTASK_QUEUE_PULL_SECONDS = 30 and an optional pull_seconds
  parameter to tasks.get_utask_mains().
* Extract _schedule_utask_main_queue() in run_bot.py and iterate over
  pub_sub_task_queue.get_all_swarming_utask_main_queues(), reusing a
  single RemoteTaskGate instance and catching RuntimeError for
  unprovisioned subscriptions during staged rollouts.
* Update and expand schedule_utask_mains unit tests in run_bot_test.py.

Tests:
* python butler.py py_unittest -t core -p run_bot_test.py

Bug: 565469156
Signed-off-by: Manuel Briones <manuelbriones@google.com>
@JuanMBriones
JuanMBriones force-pushed the mac_arm64_utask_main_dispatch branch from 8e3410d to 4ee51f4 Compare November 25, 2026 17:48

This branch has not been deployed

No deployments
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.

3 participants