Skip to content

Wake the local On Premise worker after the CLI creates its job - #131

Merged
glenn-jocher merged 2 commits into
mainfrom
feat/onprem-wake
Oct 30, 2026
Merged

glenn-jocher merged 2 commits into
mainfrom
feat/onprem-wake

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Platform's On Premise workers pick up jobs on a 2 s poll. The worker's local server now has a GET http://127.0.0.1:8765/wake endpoint, so whoever creates a job on the same machine can make the worker claim it immediately. The Platform page calls it after creating an On Premise ingest or training job. This PR does the same for the ul CLI.

  • cli.py: a response event hook on the CLI's Platform client. After a successful POST …/ingest or POST /api/training/start, it sends a best-effort wake with Origin set to the Platform URL, a 0.5 s timeout, trust_env=False (so a proxy can't capture loopback), and every httpx.HTTPError suppressed. Return values never change.
  • Neither response says where the job runs, and a retry ingest carries no reference, so every successful ingest or training start sends a wake. A hosted job just costs a local worker, if one is running, one extra claim round. With no worker, the connection is refused in about 10 ms.
  • The CLI's client is built with timeout=60.0, the generated default, because passing http_client would otherwise fall back to httpx's 5 s default.
  • sdk/python/src/ultralytics_platform/cli.py is regenerated from the generator's main; the drift check passes.

The Python SDK classes (Platform/AsyncPlatform) are fully generated and have no hand-written hook point. Covering them needs the generator's new python.hooksProvider (ultralytics/openapi#60); that follow-up is separate.

No version bump.

Validation

  • pytest tests -v: 6 passed. The CLI wire test runs a failed start, a successful start and an ingest against a listener on 8765, and asserts exactly 2 wakes with the Platform Origin. With the hook removed it fails.
  • ruff format --check and ruff check: clean.
  • Against the worker's real /wake handler:
    • matching Origin: the wake is set in 2.8 ms
    • wrong Origin: 403, swallowed
    • old worker answering 404: swallowed in 10 ms
    • no listener: 10 ms
    • a listener that never answers: 507 ms, then swallowed
    • HTTP_PROXY set: the call still reaches loopback

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

The CLI now signals the local On Premise worker after successful ingest and training-start requests so it can claim jobs without waiting for its polling interval.

📊 Key Changes

  • Added a response hook to the CLI’s Platform client for successful POST requests ending in /ingest or /training/start.
  • The hook sends GET http://127.0.0.1:8765/wake with the Platform URL as Origin, bypasses environment proxies, and suppresses HTTP errors after a 0.5-second timeout.
  • Configured the CLI’s HTTP client with a 60-second request timeout and applied the change to the generated SDK CLI.
  • Added a CLI wire test that checks successful job requests wake the worker, while a failed training start does not.

🎯 Purpose & Impact

  • A local worker can be prompted to claim a newly created job instead of waiting for its next poll. Wake failures do not change the CLI request’s result; successful ingest and training starts trigger a wake even when the job is hosted rather than On Premise.

@UltralyticsAssistant UltralyticsAssistant added the enhancement New feature or request label Oct 30, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @glenn-jocher, thank you for submitting a ultralytics/sdk 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • ✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • ✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/sdk main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • ✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • ✅ Update Documentation: Update the relevant documentation for any new or modified features.
  • ✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • ✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR; the CLA check will comment with signing instructions if needed.
  • ✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant left a comment

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.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed the CLI response hook, regenerated CLI, and wire test. Successful ingest and training-start responses trigger a best-effort local wake without changing API return handling. No actionable issue found; LGTM. The wake can add up to 0.5 seconds to those CLI requests when the local worker does not respond.

@glenn-jocher
glenn-jocher merged commit 545f03d into main Oct 30, 2026
8 checks passed
@glenn-jocher
glenn-jocher deleted the feat/onprem-wake branch October 30, 2026 10:53
@UltralyticsAssistant

Copy link
Copy Markdown
Member

Excited to see this PR merged—thank you, @glenn-jocher! The wake signal helps the local On Premise worker claim successful ingest and training-start jobs without waiting for its next poll.

“Alone we can do so little; together we can do so much.” — Helen Keller

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants