Skip to content

fix(cli): recover detached background processes from checkpoint on CLI startup and shutdown - #69918

Open
mantenie wants to merge 2 commits into
NousResearch:mainfrom
mantenie:fix/process-registry-recovery-current
Open

fix(cli): recover detached background processes from checkpoint on CLI startup and shutdown#69918
mantenie wants to merge 2 commits into
NousResearch:mainfrom
mantenie:fix/process-registry-recovery-current

Conversation

@mantenie

@mantenie mantenie commented Jul 23, 2026

Copy link
Copy Markdown

Port the three approved process-registry recovery commits onto current main (origin/main @ de5ece9).

Changes

  1. tools/process_registry.py — idempotency guard in recover_from_checkpoint (skip sessions already tracked in live registry) + new recover_and_log convenience wrapper + new public flush_checkpoint() method
  2. cli.py_recover_background_processes_on_startup() called in HermesCLI.run() + final checkpoint flush in _run_cleanup() (now via flush_checkpoint() instead of private _write_checkpoint())
  3. Test files — 8 new tests across 3 files (including NIT fix: test proves CLI shutdown calls public API, not private method)

NIT fix (this round)

  • Exposed flush_checkpoint() as the public API on ProcessRegistry
  • cli.py now calls process_registry.flush_checkpoint() instead of process_registry._write_checkpoint()
  • Test updated to monkeypatch flush_checkpoint instead of _write_checkpoint

Verification

  • Tests: 120/120 process_registry + CLI recovery tests PASS
  • Regression: 83/83 watcher/notify-on-complete/gateway tests PASS
  • Round-trip: spawn → checkpoint (via flush_checkpoint()) → clear → recover → list → kill — verified
  • Diff: 3 files, +11/-2 lines

Status

  • Build passes
  • All tests green
  • Round-trip verified
  • NIT resolved

mantenie added 2 commits July 23, 2026 08:06
…I startup and shutdown

Port the three approved process-registry recovery commits onto current
main (origin/main @ de5ece9):

1. recover_from_checkpoint idempotency guard + recover_and_log wrapper
2. CLI startup recovery hook (_recover_background_processes_on_startup)
3. CLI shutdown checkpoint flush in _run_cleanup

Preserves:
- PID start-time / recycled-PID safety
- sandbox entries never recovered
- best-effort recovery that cannot block startup
- no kill-on-CLI-exit behavior
- Python 3.9 compatibility
- prompt-cache and tool-schema stability

Tests: 117/117 process_registry + 3/3 CLI recovery tests pass.
Round-trip: spawn -> checkpoint -> clear -> recover -> list -> kill verified.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard tool/terminal Terminal execution and process management sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P2 Medium — degraded but workaround exists labels Jul 23, 2026

@teknium1 teknium1 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.

Thanks for addressing a real CLI recovery gap.

Problems

  • tests/cli/test_cli_startup_recovery.py:22 calls _recover_background_processes_on_startup() directly. It does not cover the production wiring in HermesCLI.run() (cli.py:14589), so the test would still pass if the new call site were removed.

Suggested changes

  • Add a controlled startup-path test that exercises HermesCLI.run() sufficiently to assert recovery is called once before the interactive loop begins.

This is an automated hermes-sweeper review.

monkeypatch.setattr(
"tools.process_registry.process_registry.recover_and_log",
fake_recover_and_log,
)

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.

This invokes the helper directly, so it cannot catch a regression where HermesCLI.run() stops calling it. Please add a controlled run-startup behavior test that asserts the wiring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants