fix: keep workers when end_date is moved past with pending submissions - #5189
fix: keep workers when end_date is moved past with pending submissions#5189cursor[bot] wants to merge 2 commits into
Conversation
handle_end_date_change previously called delete_workers whenever end_date was set to the past, even with queued/running submissions. That bypassed the pending-aware drain policy from the cleanup Lambda (#5179) and could kill in-flight evaluations after a host/admin shortened end_date. Skip delete when pending submissions exist and schedule a delayed cleanup re-check instead (cannot point EventBridge at the already-past end_date). Co-authored-by: Rishabh Jain <[email protected]>
Co-authored-by: Rishabh Jain <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5189 +/- ##
==========================================
- Coverage 91.30% 91.30% -0.01%
==========================================
Files 115 115
Lines 8996 9001 +5
==========================================
+ Hits 8214 8218 +4
- Misses 782 783 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
@coderabbitai Please review this! |
|
✅ Action performedReview finished.
|
WalkthroughEventBridge cleanup scheduling now uses shared create/update logic and centralized naming. Expired challenges check for pending submissions. Cleanup retries while submissions remain pending and deletes workers after submissions finish. ChangesChallenge cleanup lifecycle
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant ChallengeModel
participant AWSUtils
participant EventBridge
participant Workers
ChallengeModel->>AWSUtils: Check pending submissions
alt Submissions remain pending
AWSUtils->>EventBridge: Create one-hour cleanup retry
else No submissions remain pending
ChallengeModel->>Workers: Delete challenge workers
end
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/unit/challenges/test_aws_utils.py (1)
5707-5767: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAdd direct coverage for the pending-submission predicate.
These tests patch
challenge_has_pending_submissions. They only test the model-handler branches. They do not test the new query inapps/challenges/aws_utils.pyat Line 817. Add focused tests that verify each pending status returnsTrueand a terminal status returnsFalse. Otherwise, a status-list regression can delete active workers or defer cleanup after work completes.As per path instructions, “Test code. Check that tests actually assert behavior, cover edge cases, and are not silently passing.”
🤖 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 `@tests/unit/challenges/test_aws_utils.py` around lines 5707 - 5767, Add focused unit tests for challenge_has_pending_submissions, covering every pending submission status as True and at least one terminal status as False. Exercise the predicate’s actual query behavior without mocking it, and assert the returned boolean so status-list regressions are detected independently of handle_end_date_change_for_challenge.Sources: Path instructions, Linters/SAST tools
🤖 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.
Outside diff comments:
In `@tests/unit/challenges/test_aws_utils.py`:
- Around line 5707-5767: Add focused unit tests for
challenge_has_pending_submissions, covering every pending submission status as
True and at least one terminal status as False. Exercise the predicate’s actual
query behavior without mocking it, and assert the returned boolean so
status-list regressions are detected independently of
handle_end_date_change_for_challenge.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 27d2f8e7-cd39-41dc-88ee-0580b8215004
📒 Files selected for processing (3)
apps/challenges/aws_utils.pyapps/challenges/models.pytests/unit/challenges/test_aws_utils.py
Summary
handle_end_date_change_for_challengecalleddelete_workerswheneverend_datewas moved into the past, with no check for pending submissions. That bypassed the pending-aware drain policy from the cleanup Lambda (#5179): a host/admin shorteningend_date(challenge.yml / admin) could tear down the ECS stack while submissions were stillqueued/running/resuming, killing in-flight eval and leaving queued work with no consumers.Trigger scenario
end_dateto a time in the past (config update or admin edit).delete_workers.ensure_workers_for_submission.Changes
end_date, check the same pending statuses as the cleanup Lambda /pending_submission_countAPI.now + 60m). EventBridge cannot be pointed at the already-pastend_date._put_challenge_cleanup_scheduleso retry scheduling can pass an explicitrun_at.Test plan
pytestfocused suites:TestHandleEndDateChange,TestScheduleChallengeCleanupRetry,TestUpdateChallengeCleanupSchedule,TestScheduleChallengeCleanup,TestDeleteChallengeCleanupSchedule— 21 passedblack --check --line-length=79/isort --check --profile=black --line-length=79on changed filesSummary by CodeRabbit