fix: PriorityJobQueue follow-ups from #100 review (#103) - #104
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughQueue dependency checks now use job statuses. Queue events are collected under the lock and dispatched after unlocking. Cancellation, priority, completion, and listener behavior receive updated test coverage and changelog entries. ChangesQueue behavior updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
cli/tests/test_queue.py (2)
155-160: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover every dependency-satisfaction case.
This test does not verify that
SKIPPEDsatisfiesneeds. It also does not verify that a missing dependency remains unmet.Add assertions for both cases. The resolver contract requires an existing dependency in
PASSEDorSKIPPEDstatus.🤖 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 `@cli/tests/test_queue.py` around lines 155 - 160, Add coverage in the dependency-status test around resolver.all_dependencies_met: assert that an existing upstream dependency with QueuedJobStatus.SKIPPED satisfies the downstream need, and assert that a missing dependency remains unmet. Preserve the existing PASSED, FAILED, and CANCELLED assertions.
259-270: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winMake the deadlock regression fail instead of hang.
If callbacks run while
self._lockis held again,queue.enqueue(...)blocks insidelistener. The subsequentacquired.wait(timeout=5)never runs, so this test can hang CI indefinitely.Run
enqueuein a daemon worker thread. Join with a timeout, then assert that the worker completed.Proposed fix
queue.add_listener(listener) - queue.enqueue(make_job("Job 2", priority=1, index=1)) - assert acquired.wait(timeout=5) + worker = threading.Thread( + target=lambda: queue.enqueue(make_job("Job 2", priority=1, index=1)), + daemon=True, + ) + worker.start() + worker.join(timeout=5) + + assert not worker.is_alive() + assert acquired.is_set()🤖 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 `@cli/tests/test_queue.py` around lines 259 - 270, Update test_listener_can_acquire_lock_during_callback to execute the second queue.enqueue call in a daemon worker thread. Join that thread with a timeout, assert it completed, then assert acquired.wait(timeout=5) so a lock-held callback causes a bounded test failure rather than hanging CI.
🤖 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 `@cli/localci/core/queue.py`:
- Around line 189-193: Update _prepare_emit to capture the job’s state while
self._lock is held, so each JobEvent contains an immutable snapshot or
transition state rather than the mutable QueuedJob reference. Ensure later queue
operations and listeners cannot alter the status observed by previously prepared
events, preserving the event’s state at emission time.
- Around line 195-201: Update the queue event flow around _dispatch_emits so
emitted events are appended to a queue-owned FIFO while self._lock is held,
rather than dispatched from operation-local pending lists. After releasing
self._lock, drain that shared FIFO through a single dispatcher, preserving
enqueue/transition order across concurrent operations; do not rely on a
dispatcher mutex protecting only local pending lists.
- Around line 186-187: Update add_listener to acquire self._lock before
appending the callback to _listeners, ensuring registration is synchronized with
_prepare_emit’s listener snapshots while preserving the existing callback
registration behavior.
---
Nitpick comments:
In `@cli/tests/test_queue.py`:
- Around line 155-160: Add coverage in the dependency-status test around
resolver.all_dependencies_met: assert that an existing upstream dependency with
QueuedJobStatus.SKIPPED satisfies the downstream need, and assert that a missing
dependency remains unmet. Preserve the existing PASSED, FAILED, and CANCELLED
assertions.
- Around line 259-270: Update test_listener_can_acquire_lock_during_callback to
execute the second queue.enqueue call in a daemon worker thread. Join that
thread with a timeout, assert it completed, then assert acquired.wait(timeout=5)
so a lock-held callback causes a bounded test failure rather than hanging CI.
🪄 Autofix (Beta)
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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0b18e742-73ae-48f3-876d-ce34ae3673ad
📒 Files selected for processing (3)
CHANGELOG.mdcli/localci/core/queue.pycli/tests/test_queue.py
Summary
Addresses the three remaining review items from #100 / merged #101 that were not included before that PR closed:
cancel_allemitsJOB_CANCELLEDfor each cancelled job, matchingcancel().self._lock- snapshot listeners under the lock and dispatch callbacks after release so listeners can safely call back into the queue.all_dependencies_mettreatsFAILEDandCANCELLEDas unmet - onlyPASSEDandSKIPPEDsatisfyneedsdependencies; dependents no longer become ready after a failed or cancelled upstream job.Closes #100
Test plan
pytest tests/test_queue.py(34 passed)pre-commit run --files cli/localci/core/queue.py cli/tests/test_queue.py CHANGELOG.mdNotes
Issue #103 scope updated from release-only work to these queue follow-ups; v0.1.0 release prep remains on
release/v0.1.0(PR #103 on that branch).Summary by CodeRabbit
New Features
Bug Fixes
Documentation