Skip to content

Requests session pooling#590

Open
glenn-jocher wants to merge 12 commits intomainfrom
pooling
Open

Requests session pooling#590
glenn-jocher wants to merge 12 commits intomainfrom
pooling

Conversation

@glenn-jocher
Copy link
Copy Markdown
Member

@glenn-jocher glenn-jocher commented Oct 22, 2025

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Introduce Requests session pooling for GitHub and OpenAI HTTP calls to reduce overhead and improve reliability ⚡️

📊 Key Changes

  • Add a persistent requests.Session() to GitHubUtils and route all HTTP methods through self.session.
  • Create a module-level _session = requests.Session() in openai_utils.py for OpenAI requests.
  • Update OpenAI POST to use the shared session and a tuple timeout (connect=30s, read=600s) for better control.

🎯 Purpose & Impact

  • Reduced connection overhead via TCP connection reuse, improving latency in CI workflows.
  • More reliable long-running requests to OpenAI with explicit connect/read timeouts.
  • Foundation for future enhancements like retry policies and adapter tuning within a single, pooled session.

@glenn-jocher glenn-jocher changed the title Requets session pooling Requests session pooling Oct 22, 2025
@UltralyticsAssistant UltralyticsAssistant added devops GitHub Devops or MLops enhancement New feature or request labels Oct 22, 2025
@UltralyticsAssistant
Copy link
Copy Markdown
Member

👋 Hello @username, thank you for submitting an ultralytics/actions 🚀 PR! This automated message notes your focus on Requests session pooling to improve performance and reliability in our workflows. An engineer will review shortly and assist as needed.

  • 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/actions 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 by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • 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! 🚀

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

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

Looks good—thanks for introducing shared sessions to improve connection reuse for both GitHub and OpenAI calls.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
actions/utils/github_utils.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@UltralyticsAssistant UltralyticsAssistant dismissed their stale review October 22, 2025 13:10

Superseded by new review

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review 2

Made with ❤️ by Ultralytics Actions

The session pooling looks good overall. Please add a way to close the new GitHub session to avoid leaking sockets in long-lived runs.

💬 Posted 1 inline comment

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review 3

Made with ❤️ by Ultralytics Actions

Nice step toward connection reuse. Please revisit the shared OpenAI session; using a single module-level requests.Session() can introduce thread-safety issues under concurrent load.

💬 Posted 1 inline comment

Comment thread actions/utils/openai_utils.py Outdated
Comment thread actions/utils/openai_utils.py Outdated
Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review 4

Made with ❤️ by Ultralytics Actions

Please harden the new session cleanup to avoid destructor-time exceptions; otherwise the session reuse looks good.

💬 Posted 1 inline comment

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review 5

Made with ❤️ by Ultralytics Actions

Session pooling is a nice win. Please add an explicit way to close the GitHub session instead of depending on __del__, which is unreliable during interpreter shutdown.

💬 Posted 1 inline comment

"delete": [200, 204],
}

def __del__(self):
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.

💡 MEDIUM: Relying on __del__ for resource cleanup is fragile because destructors may not run (or module globals may already be None) during interpreter shutdown. Please expose an explicit close()/context-manager path and call it from the action lifecycle instead of counting on garbage collection.

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

Labels

devops GitHub Devops or MLops enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants