Skip to content

[cli] fix: guard service-stop against late sessions - #244

Merged
Wangmerlyn merged 1 commit into
mainfrom
codex/service-stop-active-session-guard
Jul 1, 2026
Merged

[cli] fix: guard service-stop against late sessions#244
Wangmerlyn merged 1 commit into
mainfrom
codex/service-stop-active-session-guard

Conversation

@Wangmerlyn

Copy link
Copy Markdown
Owner

Summary

  • tighten non-force keep-gpu service-stop so a non-empty stopped, timed_out, or failed stop_keep result blocks daemon signaling
  • add a final all-session status recheck before _stop_service_process() to catch sessions that appear after stop_keep returns cleanly
  • document the stricter non-force daemon shutdown contract in AGENTS and CLI docs

Verification

  • PYTHONPATH=src pytest tests/test_cli_service_commands.py::test_service_stop_rejects_newly_stopped_session_before_stopping_daemon -q (RED before fix, then pass)
  • PYTHONPATH=src pytest tests/test_cli_service_commands.py::test_service_stop_rechecks_status_after_clean_stop_keep_before_stopping_daemon -q (RED before fix, then pass)
  • PYTHONPATH=src pytest tests/test_cli_service_commands.py -q -> 226 passed
  • PYTHONPATH=src pytest tests -q -> 921 passed, 11 skipped
  • mkdocs build --strict
  • pre-commit run --all-files --show-diff-on-failure
  • local subagent review: no critical/important/minor issues after adding malformed-final-status coverage

README/Zenodo badge untouched.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Wangmerlyn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c856c79a-9f02-4bdb-932d-d92bb286a74b

📥 Commits

Reviewing files that changed from the base of the PR and between c29491b and 05856f8.

📒 Files selected for processing (6)
  • AGENTS.md
  • docs/guides/cli.md
  • docs/plans/service-stop-active-session-guard.md
  • docs/reference/cli.md
  • src/keep_gpu/cli.py
  • tests/test_cli_service_commands.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/service-stop-active-session-guard

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request tightens the non-force shutdown sequence for the KeepGPU daemon by introducing a final status check after stopping sessions to ensure no new active sessions have appeared before signaling the process. The reviewer recommends wrapping the subsequent RPC calls in a try-except block to gracefully handle potential ServiceUnreachableError exceptions and maintain consistent, user-friendly error messages.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/keep_gpu/cli.py
Comment on lines +1335 to +1341
_require_no_active_jobs_for_service_stop(status)
stop_result = _rpc_call("stop_keep", {}, host, port, timeout=45.0)
stop_result = _validate_stop_keep_result(stop_result)
_require_clean_stop_keep_for_service_stop(stop_result)
status = _rpc_call("status", {}, host, port)
status = _validate_status_result(status, single_job=False)
_require_no_active_jobs_for_service_stop(status)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If the service becomes unreachable during the stop_keep call or the final status recheck, a ServiceUnreachableError will be raised. Since these calls are outside the initial try...except ServiceUnreachableError block, the error will propagate to the outer handler as a generic exception, missing the helpful context that explains why the non-force shutdown failed and suggesting the use of --force.

Consider wrapping the entire RPC sequence (including stop_keep and the final status check) in a try...except ServiceUnreachableError block to ensure consistent and user-friendly error messages if the daemon becomes unresponsive mid-shutdown.

Suggested change
_require_no_active_jobs_for_service_stop(status)
stop_result = _rpc_call("stop_keep", {}, host, port, timeout=45.0)
stop_result = _validate_stop_keep_result(stop_result)
_require_clean_stop_keep_for_service_stop(stop_result)
status = _rpc_call("status", {}, host, port)
status = _validate_status_result(status, single_job=False)
_require_no_active_jobs_for_service_stop(status)
_require_no_active_jobs_for_service_stop(status)
try:
stop_result = _rpc_call("stop_keep", {}, host, port, timeout=45.0)
stop_result = _validate_stop_keep_result(stop_result)
_require_clean_stop_keep_for_service_stop(stop_result)
status = _rpc_call("status", {}, host, port)
status = _validate_status_result(status, single_job=False)
_require_no_active_jobs_for_service_stop(status)
except ServiceUnreachableError as exc:
raise RuntimeError(
f"KeepGPU service is unavailable at {host}:{port}. Non-force service-stop must verify no tracked keep sessions before stopping the daemon. "
"For an unresponsive auto-started daemon, run `keep-gpu service-stop --force`."
) from exc

@Wangmerlyn
Wangmerlyn merged commit 1e7cc52 into main Jul 1, 2026
6 checks passed
@Wangmerlyn
Wangmerlyn deleted the codex/service-stop-active-session-guard branch July 1, 2026 13:02
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.

1 participant