Skip to content

Conversation

@ultmaster
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings November 5, 2025 01:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the MockOpenAICompatibleServer to support dynamic port allocation and updates the global OPENAI_BASE_URL configuration to use the dynamically allocated port. This allows multiple test instances to run concurrently without port conflicts.

  • Modified MockOpenAICompatibleServer to accept an optional port parameter and dynamically allocate one if not provided
  • Added logic to update and restore the global OPENAI_BASE_URL when the mock server starts and stops
  • Imported the socket module to enable dynamic port allocation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +199 to +202
# Update the module-level base URL so downstream clients use the live port.
global OPENAI_BASE_URL
self._prev_openai_base_url = OPENAI_BASE_URL
OPENAI_BASE_URL = f"http://{self.host}:{self.port}/v1"
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

Modifying the global OPENAI_BASE_URL creates a race condition when multiple test instances run concurrently. If tests run in parallel, they will overwrite each other's base URLs, causing tests to connect to the wrong server instances. Consider passing the base URL as a parameter to agent functions or using thread-local storage instead of modifying a global variable.

Copilot uses AI. Check for mistakes.
Comment on lines +211 to +214
if self._prev_openai_base_url is not None:
global OPENAI_BASE_URL
OPENAI_BASE_URL = self._prev_openai_base_url
self._prev_openai_base_url = None
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The restoration of OPENAI_BASE_URL in __aexit__ does not guarantee correct cleanup in concurrent scenarios. If another test instance modified OPENAI_BASE_URL between __aenter__ and __aexit__, this will overwrite the other instance's URL with a stale value. This cleanup logic is not thread-safe.

Copilot uses AI. Check for mistakes.
@ultmaster
Copy link
Contributor Author

/ci

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

🚀 CI Watcher for correlation id-3488946253-mhled1mh triggered by comment 3488946253
🏃‍♀️ Tracking 1 workflow run(s):

✅ All runs completed.

@ultmaster ultmaster merged commit f717f99 into main Nov 5, 2025
18 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 5, 2025
@agent-lightning-bot
Copy link
Collaborator

Successfully created backport PR for stable/v0.2.x:

ultmaster added a commit that referenced this pull request Nov 5, 2025
(cherry picked from commit f717f99)

Co-authored-by: Yuge Zhang <[email protected]>
totoluo pushed a commit to totoluo/agent-lightning that referenced this pull request Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants