Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix: keep workers running after end_date while submissions are pending - #5185

Open
cursor[bot] wants to merge 3 commits into
masterfrom
cursor/critical-bug-management-5f96
Open

Fix: keep workers running after end_date while submissions are pending#5185
cursor[bot] wants to merge 3 commits into
masterfrom
cursor/critical-bug-management-5f96

Conversation

@cursor

@cursor cursor Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

scripts/monitoring/auto_scale_workers.py (and the EC2/EKS siblings) treated end_date < now as an unconditional scale-down signal via pending_submissions == 0 or end_date < now. That undid the pending-aware cleanup work in #5179/#5183: the challenge-cleanup Lambda keeps the worker stack up past end_date so queued/running/resuming submissions can drain, but the next monitoring cron tick stopped those workers and left pending work without consumers (ensure_workers_for_submission only runs on new submits).

Trigger scenario

  1. Challenge reaches end_date with submissions still queued/running/resuming.
  2. Cleanup Lambda correctly skips ECS deletion and reschedules (fix(worker): don't delete challenge workers with pending submissions #5179).
  3. Monitoring cron runs auto_scale_workers.py.
  4. Old condition stops workers because end_date < now, even though pending_submissions > 0.
  5. In-flight evaluations are killed; remaining queue has no consumers until something else restarts workers.

Changes

  • Scale down only when pending_submissions == 0.
  • If the challenge has ended but still has pending work, leave workers/EC2/EKS capacity running to drain (log and skip).
  • Same fix in auto_scale_ec2_workers.py and auto_scale_eks_nodes.py.
  • Regression tests for the Fargate auto-scale decision paths.

Test plan

  • pytest tests/unit/monitoring/test_auto_scale_workers.py — 4 passed
  • pytest tests/unit/monitoring/ — 32 passed
  • black --check / isort --check on changed files
Open in Web View Automation 

Note

Medium Risk
Changes production cron behavior for worker lifecycle across ECS, EC2, and EKS; incorrect logic could strand submissions or leave capacity running longer, but the change is narrowly scoped to the scale decision and covered by new unit tests.

Overview
Monitoring auto-scale crons no longer tear down capacity just because a challenge passed end_date. They now scale down only when pending_submissions == 0 (queued/running/submitted/resuming). If the challenge has ended but work is still pending, the scripts log and skip stop/scale-down so evaluations can drain—aligning with the cleanup Lambda’s pending-aware behavior (#5179).

The same decision split is applied in auto_scale_workers.py (ECS/Fargate), auto_scale_ec2_workers.py, and auto_scale_eks_nodes.py. Previously, pending == 0 or end_date < now stopped workers/nodegroups/instances even with pending work, killing in-flight evals and leaving the queue without consumers.

Adds tests/unit/monitoring/test_auto_scale_workers.py with four regression tests for ended-vs-active challenges and pending vs idle metrics.

Reviewed by Cursor Bugbot for commit 0518656. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Autoscaling now keeps workers and nodes running after a challenge ends when submissions are still pending.
    • Pending work is allowed to drain before infrastructure scales down.
    • Challenges without pending submissions continue to scale down as expected.
  • Tests

    • Added coverage for ended and active challenges with and without pending submissions.

cursoragent and others added 2 commits August 4, 2026 11:05
…d_date

The auto_scale_* cron scripts treated end_date < now as an unconditional
scale-down signal. That undid #5179/#5183: the cleanup Lambda keeps the
worker stack up past end_date while queued/running/resuming submissions
drain, but the next cron tick stopped those workers and left pending work
without consumers.

Only scale down when pending_submission_count is 0; if the challenge has
ended but still has pending work, leave capacity running to drain.

Co-authored-by: Rishabh Jain <[email protected]>
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.36%. Comparing base (73c71ce) to head (0518656).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5185   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files         115      115           
  Lines        9054     9054           
=======================================
  Hits         8272     8272           
  Misses        782      782           
Flag Coverage Δ
backend 93.91% <ø> (ø)
frontend 87.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Accounts & Authentication 97.40% <ø> (ø)
Challenges Management 96.26% <ø> (ø)
Job Processing 90.20% <ø> (ø)
Participants & Teams 99.54% <ø> (ø)
Challenge Hosts 100.00% <ø> (ø)
Analytics 100.00% <ø> (ø)
Web Interface 100.00% <ø> (ø)
Frontend (Gulp) 87.54% <ø> (ø)
All Models 97.37% <ø> (ø)
All Views 100.00% <ø> (ø)
All Serializers 98.20% <ø> (ø)
Utility Functions 97.37% <ø> (ø)
Core Configuration 78.94% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73c71ce...0518656. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RishabhJain2018
RishabhJain2018 marked this pull request as ready for review August 10, 2026 20:20
@RishabhJain2018

Copy link
Copy Markdown
Member

@coderabbitai Please review this.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

@RishabhJain2018 I will review the changes in #5185.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Autoscaling now keeps EC2 workers, EKS nodes, and shared workers running when ended challenges have pending submissions. Scale-down remains enabled when no submissions are pending. Unit tests cover ended and active challenge states.

Changes

Autoscaling drain behavior

Layer / File(s) Summary
Pending-submission scale-down rules
scripts/monitoring/auto_scale_*.py
The autoscaling scripts require zero pending submissions before scale-down. Ended challenges with pending submissions remain running and log a drain-status message.
Regression coverage
tests/unit/monitoring/test_auto_scale_workers.py
Tests load the cron script directly and verify scaling for ended and active challenges with and without pending submissions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: rishabhjain2018

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: workers remain running after challenge end while submissions are pending.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/critical-bug-management-5f96

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/monitoring/auto_scale_workers.py`:
- Around line 160-168: Ensure ended challenges with pending submissions restart
capacity when it is zero: in scripts/monitoring/auto_scale_workers.py lines
160-168, call scale_up_workers when pending_submissions > 0 and num_workers ==
0; in scripts/monitoring/auto_scale_ec2_workers.py lines 113-121, call
start_instance when pending submissions exist and the instance is stopped; in
scripts/monitoring/auto_scale_eks_nodes.py lines 224-234, scale up when pending
submissions exist and original_desired_size == 0. In
tests/unit/monitoring/test_auto_scale_workers.py lines 58-76, add an
ended-challenge case with pending submissions and workers=0 asserting
scale_up_workers is called.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c9cd4a47-c92f-4607-a17e-24c1ab60667d

📥 Commits

Reviewing files that changed from the base of the PR and between 73c71ce and 0518656.

📒 Files selected for processing (4)
  • scripts/monitoring/auto_scale_ec2_workers.py
  • scripts/monitoring/auto_scale_eks_nodes.py
  • scripts/monitoring/auto_scale_workers.py
  • tests/unit/monitoring/test_auto_scale_workers.py

Comment on lines +160 to +168
if pending_submissions == 0:
scale_down_workers(challenge, num_workers)
elif challenge_ended:
print(
"Challenge ID: {}, Title: {} has ended but still has {} "
"pending submission(s); leaving workers running to drain.".format(
challenge["id"], challenge["title"], pending_submissions
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Start capacity when an ended challenge has pending submissions and zero capacity.

If capacity is already zero, each ended-challenge branch only logs and performs no start or scale-up action. Pending submissions then have no consumer and cannot drain. Ensure each script starts capacity when pending submissions exist and capacity is stopped or zero.

  • scripts/monitoring/auto_scale_workers.py#L160-L168: call scale_up_workers when pending_submissions > 0 and num_workers == 0, including after end_date.
  • scripts/monitoring/auto_scale_ec2_workers.py#L113-L121: call start_instance when pending submissions exist and the instance is stopped, including after end_date.
  • scripts/monitoring/auto_scale_eks_nodes.py#L224-L234: scale up when pending submissions exist and original_desired_size == 0, including after end_date.
  • tests/unit/monitoring/test_auto_scale_workers.py#L58-L76: add an ended-challenge case with pending submissions and workers=0 that asserts scale_up_workers is called.

As per path instructions, **/test_*.py must “cover edge cases.”

📍 Affects 4 files
  • scripts/monitoring/auto_scale_workers.py#L160-L168 (this comment)
  • scripts/monitoring/auto_scale_ec2_workers.py#L113-L121
  • scripts/monitoring/auto_scale_eks_nodes.py#L224-L234
  • tests/unit/monitoring/test_auto_scale_workers.py#L58-L76
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/monitoring/auto_scale_workers.py` around lines 160 - 168, Ensure
ended challenges with pending submissions restart capacity when it is zero: in
scripts/monitoring/auto_scale_workers.py lines 160-168, call scale_up_workers
when pending_submissions > 0 and num_workers == 0; in
scripts/monitoring/auto_scale_ec2_workers.py lines 113-121, call start_instance
when pending submissions exist and the instance is stopped; in
scripts/monitoring/auto_scale_eks_nodes.py lines 224-234, scale up when pending
submissions exist and original_desired_size == 0. In
tests/unit/monitoring/test_auto_scale_workers.py lines 58-76, add an
ended-challenge case with pending submissions and workers=0 asserting
scale_up_workers is called.

Source: Path instructions

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