Skip to content

fix(cron): yield desktop ticker to running gateway#44050

Open
izumi0uu wants to merge 2 commits into
NousResearch:mainfrom
izumi0uu:fix/cron-owner-desktop-ticker-43965
Open

fix(cron): yield desktop ticker to running gateway#44050
izumi0uu wants to merge 2 commits into
NousResearch:mainfrom
izumi0uu:fix/cron-owner-desktop-ticker-43965

Conversation

@izumi0uu

@izumi0uu izumi0uu commented Jun 11, 2026

Copy link
Copy Markdown

What does this PR do?

Prevents the Desktop dashboard cron ticker from executing profile cron jobs when a same-profile gateway already owns scheduler execution.

The fix now uses the gateway runtime lock as the scheduler-owner signal. Desktop backends still keep a fallback ticker for profiles with no live gateway, but each desktop tick explicitly opts into scheduler-level deferral whenever the gateway owner is active.

Related Issue

Fixes #43965

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • Added _gateway_scheduler_owner_active() in cron/scheduler.py to delegate scheduler-ownership checks to gateway.status.is_gateway_runtime_lock_active().
  • Extended cron.scheduler.tick(...) with defer_to_gateway_owner=False so non-gateway tickers can opt into owner-aware deferral without changing gateway behavior.
  • Updated hermes_cli/web_server.py so the desktop dashboard ticker calls cron_tick(..., defer_to_gateway_owner=True) instead of duplicating a separate gateway-liveness check.
  • Added tests/cron/test_scheduler_ownership.py to cover owner detection, fail-open behavior, early deferral before lock acquisition, and the opt-in boundary.
  • Updated tests/hermes_cli/test_web_server.py to assert that the desktop ticker requests gateway-owner deferral on every tick.

How to Test

  1. Run ./.venv/bin/pytest -q tests/cron/test_scheduler_ownership.py.
  2. Run ./.venv/bin/pytest -q tests/hermes_cli/test_web_server.py -k 'TestDesktopCronTicker'.
  3. Run ./.venv/bin/pytest -q tests/gateway/test_status.py -k 'runtime_lock or get_running_pid'.
  4. Optionally run ./.venv/bin/pytest -q tests/cron/test_parallel_pool.py tests/cron/test_scheduler_ownership.py to confirm the new tick parameter does not disturb existing scheduler dispatch behavior.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26.5.1 via focused pytest coverage in the upstream worktree

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Desktop-spawned dashboard backends should not execute profile cron ticks when a same-profile gateway is already running. The shared tick lock prevents duplicate firing, but it does not preserve the gateway-owned execution ancestry that macOS TCC/FDA-sensitive jobs rely on.

Constraint: Keep the fix issue-scoped and preserve desktop cron execution when no gateway is alive
Rejected: New cross-process scheduler owner protocol | broader than NousResearch#43965 and unnecessary for the reported regression
Confidence: high
Scope-risk: narrow
Directive: Keep dashboard ticker ownership checks aligned with gateway.status semantics for the active profile
Tested: ./.venv/bin/pytest -q tests/hermes_cli/test_web_server.py -k 'TestDesktopCronTicker'
Tested: ./.venv/bin/pytest -q tests/hermes_cli/test_web_server.py -k 'gateway_running or TestDesktopCronTicker'
Not-tested: end-to-end macOS launchd/Desktop provenance on a live TCC/FDA-protected cron job
Use the gateway runtime lock as the scheduler-owner signal for Desktop dashboard ticks instead of duplicating gateway liveness checks in the web server. This keeps desktop-only cron working, but moves ownership deferral into cron.scheduler so the owner rule lives beside tick semantics.

Constraint: Preserve existing gateway ticker behavior and keep the fix scoped to NousResearch#43965
Rejected: Keep the owner probe only in hermes_cli.web_server | smaller diff but weaker owner signal and duplicated scheduling policy
Confidence: high
Scope-risk: narrow
Directive: New non-gateway tick callers should opt into defer_to_gateway_owner rather than reimplementing gateway-owner checks
Tested: ./.venv/bin/pytest -q tests/cron/test_scheduler_ownership.py
Tested: ./.venv/bin/pytest -q tests/hermes_cli/test_web_server.py -k 'TestDesktopCronTicker'
Tested: ./.venv/bin/pytest -q tests/gateway/test_status.py -k 'runtime_lock or get_running_pid'
Tested: ./.venv/bin/pytest -q tests/cron/test_parallel_pool.py tests/cron/test_scheduler_ownership.py
Not-tested: end-to-end macOS launchd/Desktop provenance on a live TCC/FDA-protected cron job
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cron Cron scheduler and job management comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists labels Jun 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #44049 — both fix #43965 with the same approach (_gateway_scheduler_owner_active() + defer_to_gateway_owner param in cron/scheduler.py, desktop ticker opt-in in web_server.py). #44049 is the earlier of the pair.

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 comp/cron Cron scheduler and job management duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop dashboard cron ticker can execute jobs instead of launchd gateway, breaking macOS TCC/FDA provenance

2 participants