refactor: extract serve() into composable methods - #947
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe exporter refactors ChangesExporter lifecycle
Estimated code review effort: 4 (Complex) | ~40 minutes Possibly related PRs
Poem
🚥 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.
🧹 Nitpick comments (1)
python/packages/jumpstarter/jumpstarter/exporter/exporter.py (1)
1091-1106: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCompute
session_was_createdfrom the local lease context.
_on_lease_releasedcaptureslease_ctxat Line 1092, but Line 1100 readsself._lease_contextagain after the shielded wait.handle_leaseclearsself._lease_contextin its own fallback path onceafter_lease_hook_doneis set, soself._lease_contextcan already beNonehere. The 0.2s session-close delay is then skipped for a lease that did create a session. Read the captured reference instead to make the check deterministic.♻️ Proposed refactor
async def _on_lease_released(self, previous_leased: bool) -> None: """Handle not-leased status: signal handle_lease on transition, clean up context.""" logger.info("Currently not leased") - if previous_leased and self._lease_context: - lease_ctx = self._lease_context + lease_ctx = self._lease_context + if previous_leased and lease_ctx: logger.info("Lease ended, signaling handle_lease to run afterLease hook") lease_ctx.lease_ended.set() with CancelScope(shield=True): await lease_ctx.after_lease_hook_done.wait() logger.info("afterLease hook completed") - session_was_created = ( - self._lease_context is not None and self._lease_context.session is not None - ) + session_was_created = lease_ctx is not None and lease_ctx.session is not None self._lease_context = None🤖 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 `@python/packages/jumpstarter/jumpstarter/exporter/exporter.py` around lines 1091 - 1106, Update _on_lease_released so session_was_created checks the captured lease_ctx reference rather than rereading self._lease_context after the shielded wait. Preserve the existing session presence condition and 0.2-second delay for leases that created a session.
🤖 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.
Nitpick comments:
In `@python/packages/jumpstarter/jumpstarter/exporter/exporter.py`:
- Around line 1091-1106: Update _on_lease_released so session_was_created checks
the captured lease_ctx reference rather than rereading self._lease_context after
the shielded wait. Preserve the existing session presence condition and
0.2-second delay for leases that created a session.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8079b322-b9f9-4673-a7a0-9956d424a1bf
📒 Files selected for processing (1)
python/packages/jumpstarter/jumpstarter/exporter/exporter.py
mangelajo
left a comment
There was a problem hiding this comment.
a couple of nits, I think the sleep(0.2) comment is actually the important one if the types are passing the type checker.
| self._status_drain_active = False | ||
| clear_log_context() | ||
|
|
||
| async def _run_control_plane(self, status_tx, status_rx): |
There was a problem hiding this comment.
nit: status_tx and status_rx are missing type annotations, unlike the other new methods which all have proper signatures. Consider:
async def _run_control_plane(
self,
status_tx: MemoryObjectSendStream[jumpstarter_pb2.StatusResponse],
status_rx: MemoryObjectReceiveStream[jumpstarter_pb2.StatusResponse],
) -> None:| self._lease_context = None | ||
| clear_log_context() | ||
| if session_was_created: | ||
| await sleep(0.2) |
There was a problem hiding this comment.
The old code had useful context here explaining why this non-obvious delay exists:
# Brief delay to ensure session is fully closed before next lease
# This prevents SSL corruption from overlapping connections
await sleep(0.2)Worth preserving -- without the comment this looks like an arbitrary magic sleep that someone might remove in a future cleanup.
- serve() → serve / _run_control_plane / _apply_status - Transition handlers: _on_lease_acquired, _on_lease_update, _on_lease_released, _check_stop_requested - Removes the C901 suppression - Status transitions are now unit-testable without task-group scaffolding" Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assited-by: claude-opus-4.6
_on_lease_released, _check_stop_requested
Next: #948