Skip to content

fix(cli): stop reporting hook waits and status changes that never happened - #1039

Open
kirkbrauer wants to merge 2 commits into
mainfrom
cli-fix-shell-hook-log
Open

fix(cli): stop reporting hook waits and status changes that never happened#1039
kirkbrauer wants to merge 2 commits into
mainfrom
cli-fix-shell-hook-log

Conversation

@kirkbrauer

@kirkbrauer kirkbrauer commented Aug 30, 2026

Copy link
Copy Markdown
Member

jmp shell announced "waiting for beforeLease hook" before the status monitor had polled even once, so attaching to an already-ready lease reported a wait that was not happening. The monitor then logged its first observation as a transition, so a lease that had been in the same state all along looked like it had just changed.

Waits for the first observation before reporting, and logs that first one at debug level rather than as a change.

…pened

Attaching to a lease that is already LEASE_READY printed "Waiting for
beforeLease hook to complete..." followed by "Status changed: None ->
LEASE_READY" — neither of which happened. The message was emitted before
the status monitor's first poll had returned, and the monitor treated
its first observation as a transition from nothing.

Settle the current status first and announce the wait only when there is
one, and log the first observation at debug level, keeping INFO for
genuine transitions.

Signed-off-by: Kirk Brauer <kirkebrauer@gmail.com>
@kirkbrauer kirkbrauer added bug Something isn't working python Pull requests that update python code labels Aug 30, 2026
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ffb19c67-2a7a-4c0d-831e-895ba3df550f

📥 Commits

Reviewing files that changed from the base of the PR and between d787eec and f37da41.

📒 Files selected for processing (4)
  • python/packages/jumpstarter-cli/jumpstarter_cli/shell.py
  • python/packages/jumpstarter-cli/jumpstarter_cli/shell_test.py
  • python/packages/jumpstarter/jumpstarter/client/status_monitor.py
  • python/packages/jumpstarter/jumpstarter/client/status_monitor_test.py

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The status monitor now reports when its first observation completes. The shell uses this signal before waiting for beforeLease hook target states and applies a shared 300-second deadline.

Changes

BeforeLease observation flow

Layer / File(s) Summary
Status monitor first-observation state
python/packages/jumpstarter/jumpstarter/client/status_monitor.py, python/packages/jumpstarter/jumpstarter/client/status_monitor_test.py
StatusMonitor signals first observation after a status response, unsupported-status handling, or poll-loop shutdown. Tests cover delayed responses, unsupported status, successful observation, and monitor stop.
BeforeLease hook wait integration
python/packages/jumpstarter-cli/jumpstarter_cli/shell.py, python/packages/jumpstarter-cli/jumpstarter_cli/shell_test.py
The shell waits for first observation before checking hook target states. It uses _HOOK_TIMEOUT for the deadline and logs only when further waiting is required. The fake monitor implements the new wait method.

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

Merge Risk: ⚪ Minimal · up to f37da

This PR corrects misleading hook-wait and status-change messages without introducing an actionable merge-blocking risk; it is ready to merge after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Shell
  participant StatusMonitor
  participant GetStatusRPC
  Shell->>StatusMonitor: wait_for_first_observation
  StatusMonitor->>GetStatusRPC: request first status
  GetStatusRPC-->>StatusMonitor: status response
  StatusMonitor-->>Shell: current status and observation result
  Shell->>StatusMonitor: wait for hook target status when needed
Loading

Suggested reviewers: mangelajo

Poem

A rabbit watches the status light glow
First facts arrive, then waits can flow
The hook clock ticks for three hundred beats
Ready or failed, the path completes
No early log disturbs the burrow's peace

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: it stops reporting false beforeLease hook waits and status transitions.
Description check ✅ Passed The description directly explains the false hook-wait and status-transition logs and the first-observation fix.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli-fix-shell-hook-log

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.

Comment thread python/packages/jumpstarter-cli/jumpstarter_cli/shell.py
Comment on lines +59 to +60
HOOK_TIMEOUT = 300.0
HOOK_PROBE_TIMEOUT = 2.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rename to private _HOOK_TIMEOUT: float = 300.0 and _HOOK_PROBE_TIMEOUT: float = 2.0?

The hook wait settled the exporter's status with a 2s probe before deciding
whether to announce it was waiting. That is a wall-clock guess: on a slow or
distant link — the far side of the planet over a satellite uplink, say — the
first GetStatus answer can take longer than the probe, and the announcement
comes back, which is the bug this was meant to fix.

StatusMonitor now sets an event once it has processed its first GetStatus
answer, and wait_for_first_observation waits on that. The caller waits for the
fact rather than for a duration, so the behaviour no longer depends on latency
and HOOK_PROBE_TIMEOUT is gone. The event is also set when GetStatus is
unsupported, and when the poll loop exits without ever getting an answer, so a
waiter is never left sitting out its timeout for an observation that is not
coming. The overall 300s budget is unchanged, now tracked as a deadline.

Also make the constants private and typed, per review.

Assisted-by: Claude
Signed-off-by: Kirk Brauer <kirkebrauer@gmail.com>
Comment on lines +352 to +359
await monitor.wait_for_first_observation(timeout=_HOOK_TIMEOUT)
result = monitor.current_status if monitor.current_status in targets else None

if result is None and not monitor.connection_lost:
logger.info("Waiting for beforeLease hook to complete...")
result = await monitor.wait_for_any_of(
targets, timeout=max(0.0, deadline - anyio.current_time())
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The return value of await monitor.wait_for_first_observation(timeout=_HOOK_TIMEOUT) is not captured. What if GetStatus stays UNAVAILABLE for the entire timeout budget?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch. Tracing through the code, here's the concrete scenario:

  1. wait_for_first_observation() returns True (a status was observed), but the return value is discarded.
  2. The observed status is UNAVAILABLE — not in targets, so result = None.
  3. UNAVAILABLE sets monitor.connection_lost = True, so the if result is None and not monitor.connection_lost guard is False — the wait_for_any_of call is skipped entirely.
  4. Execution falls through to the existing elif result is None block (line 349), which checks monitor.connection_lost (True) and silently returns 0, as if the lease expired gracefully.

So if GetStatus stays UNAVAILABLE for the full timeout budget, the shell exits successfully instead of raising an error — the user gets no indication that the exporter never became ready.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IDK, since this is mostly aesthetic. I'd propose that we leave this alone, and eventually tackle it when we have a FSM in rust , python or whatever :D

WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the FSM work scheduled already or somewhere deeply nested in the backlog? I think if we implement the FSM soonish, its okay to leave it as is.

async def test_releases_waiters_when_the_monitor_stops(self) -> None:
"""A stopped monitor will never observe anything, so waiters must not
sit out their whole timeout."""
stub = MockExporterStub([AioRpcError(StatusCode.UNAVAILABLE, None, None)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider using create_mock_rpc_error(StatusCode.UNAVAILABLE) for consistency.

@mangelajo
mangelajo self-requested a review September 8, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants