Skip to content

Wake the local On Premise worker from every SDK client - #132

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

glenn-jocher merged 2 commits into
mainfrom
feat/sdk-wake-hooks

Conversation

@glenn-jocher

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

Copy link
Copy Markdown
Member

Summary

#131 made the ul CLI wake a local On Premise worker (GET http://127.0.0.1:8765/wake) after it creates an ingest or training job. This moves that wake into the generated SDK through ultralytics/openapi#60's python.hooksProvider, so Platform and AsyncPlatform users get instant pickup too, and the CLI keeps it with no code of its own.

  • hooks.py (new, hand-written, copied to _hooks.py):
    • response_hook and an async twin async_response_hook.
    • Same trigger as before: a 2xx POST ending in /ingest or /training/start.
    • Same call: a headers-only stream, 0.5 s timeout, trust_env=False, every httpx.HTTPError suppressed. Neither hook can raise.
    • Origin is the scheme and host of the request that created the job, which is exactly what the worker checks, including for Platform(base_url=...) users.
  • cli.py: deletes wake_worker and the CLI's own httpx.Client; dispatch() uses the generated Platform, whose client carries the hook.
  • openapi.config.json: "hooksProvider": "hooks.py".
  • Regenerated from the generator's main (3aba4be) and synced; the drift check is clean. CI, AGENTS.md and README list hooks.py next to auth.py.

No version bump.

Validation

  • pytest tests -v: 7 passed. The CLI wire test still sees exactly 2 wakes, now through the generated hook. The new async test runs AsyncPlatform against a loopback fake API with a listener on 8765: a GET, a failed ingest, a training start and an ingest give exactly 2 wakes with the right Origin. Stubbing the async hook fails it.
  • With no listener, four job creations (sync and async) return normally in 0.05 s total.
  • ruff format --check and ruff check are clean on sdk/python, tests, cli.py, auth.py and hooks.py.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Added response hooks to the generated Python SDK clients so successful ingest and training-start requests wake a local On Premise worker, while the CLI now uses the same SDK behavior.

📊 Key Changes

  • Added synchronous and asynchronous hooks that send a best-effort wake request after successful POST requests to paths ending in /ingest or /training/start.
  • The wake request targets http://127.0.0.1:8765/wake, uses the originating request’s scheme and host in its Origin header, and has a 0.5-second timeout.
  • Configured the hooks through python.hooksProvider and attached them to SDK-created HTTP clients.
  • Removed the CLI’s separate wake implementation; its Platform client now provides the behavior.

🎯 Purpose & Impact

  • Users of default Platform and AsyncPlatform clients can trigger the local worker without using the CLI.
  • Custom HTTP clients are used as provided and do not receive these configured hooks.

@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 hook integration, CLI migration, generated client changes, and tests. The default-client path appears correct, but custom HTTP clients bypass the wake hooks, leaving a gap in the SDK-wide behavior.

💬 Posted 1 inline comment
  • 💡 MEDIUM sdk/python/src/ultralytics_platform/_client.py:130 When callers provide http_client, this branch uses it unchanged, so response_hook is never registered; the async branch has the same behavior. Successful ingest or training requests through the supported custom-client path therefore do not wake the local worker. Preserve any existing hooks while registering the wake hook on supplied clients too, so the feature covers Platform and AsyncPlatform instances that use custom clients.

@glenn-jocher
glenn-jocher merged commit a8468f2 into main Oct 30, 2026
8 checks passed
@glenn-jocher
glenn-jocher deleted the feat/sdk-wake-hooks branch October 30, 2026 11:10
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 Thanks @glenn-jocher for merging this PR! Default Platform and AsyncPlatform clients now best-effort wake the local On Premise worker after successful ingest and training-start requests, and the CLI uses the same SDK behavior.

“A journey of a thousand miles begins with a single step.” — Lao Tzu

A small, shared SDK hook makes that worker wake-up available beyond the CLI.

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