Skip to content

fix: update custom token provider functions for copilot review#867

Merged
Avijit-Microsoft merged 2 commits into
devfrom
Copilot_Review_Akhileswar
Jun 5, 2026
Merged

fix: update custom token provider functions for copilot review#867
Avijit-Microsoft merged 2 commits into
devfrom
Copilot_Review_Akhileswar

Conversation

@Akhileswara-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This pull request simplifies authentication handling for Azure OpenAI clients by removing custom token provider functions and passing the credential object directly. It also includes a minor update to a regular expression for improved agent handoff detection.

Authentication handling improvements:

  • Replaced custom get_token provider functions with direct use of self._credential when initializing OpenAIChatCompletionClient in both orchestrator.py and title_service.py, reducing code duplication and improving maintainability.
  • Removed the now-unnecessary TOKEN_ENDPOINT constant from title_service.py.

Regex update:

  • Updated the agent handoff detection regex in _check_input_for_harmful_content to better match agent names containing hyphens, improving pattern coverage.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

Other Information

This pull request refactors how Azure OpenAI authentication credentials are provided to the chat client across the codebase. The main change is to pass the credential object directly instead of a token-providing function, simplifying authentication logic and reducing code duplication. Additionally, an unused constant is removed, and some regular expressions are slightly adjusted.

Azure OpenAI Authentication Refactor:

  • Replaces the use of custom get_token functions with direct passing of the credential object (self._credential) to OpenAIChatCompletionClient in both orchestrator and title service modules. This simplifies the authentication flow and reduces redundant code.
  • Removes the TOKEN_ENDPOINT constant from src/backend/services/title_service.py as it is no longer needed after refactoring.
  • Updates log messages to reflect the new authentication approach, removing references to the token provider function.

Regular Expression Update:

  • Adjusts regular expressions in _check_input_for_harmful_content to better match agent handoff instructions by expanding the character class for agent names.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
src/backend
   orchestrator.py56210980%37–39, 576, 718, 752–753, 762, 764–765, 767, 773–775, 777, 809–810, 835, 855–857, 864–865, 867–868, 871–873, 875, 885–888, 892–893, 895–896, 904–906, 931, 1032–1034, 1120, 1146, 1188–1190, 1192–1194, 1224–1227, 1310–1312, 1328–1330, 1332–1334, 1348–1351, 1387–1388, 1411, 1459, 1463, 1501, 1533, 1535–1540, 1543, 1568–1569, 1571–1573, 1609, 1612, 1618–1620, 1653, 1689, 1693, 1698, 1777–1785, 1815–1817
src/backend/services
   title_service.py70888%37, 53–54, 73–75, 121–122
src/tests
   test_title_generation_service.py1400100% 
src/tests/services
   test_orchestrator.py1346499%1063, 1080, 1618, 1671
TOTAL769637195% 

Tests Skipped Failures Errors Time
426 0 💤 0 ❌ 0 🔥 11.901s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors Azure OpenAI authentication setup to reduce duplication by passing the Azure credential object directly into OpenAIChatCompletionClient, and it slightly broadens a system-prompt leakage detection regex to better recognize hyphenated agent names.

Changes:

  • Replace per-request get_token() callables with direct self._credential usage when creating OpenAIChatCompletionClient (orchestrator + title service).
  • Remove the unused TOKEN_ENDPOINT constant from title_service.py.
  • Update system-prompt leakage detection patterns to better match hyphenated agent handoff strings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/backend/services/title_service.py Simplifies title service client initialization by passing the Azure credential directly and removing the unused token endpoint constant.
src/backend/orchestrator.py Simplifies chat client credential wiring in both Foundry and Direct modes; expands handoff leakage regex to match hyphenated agent names.

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

Comment thread src/backend/orchestrator.py
Comment thread src/backend/services/title_service.py
…ed agent names and initialize wiring in TitleService
@Avijit-Microsoft Avijit-Microsoft merged commit b0bd21b into dev Jun 5, 2026
5 checks passed
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants