Skip to content

Conversation

@Harsh-Microsoft
Copy link
Contributor

Purpose

This pull request removes the use of contextvars for tracking the current user ID throughout the backend orchestration and agent code. Instead, it refactors the codebase to explicitly pass user_id as a function argument or class field wherever needed. This change improves clarity, reduces hidden dependencies, and makes the user context handling more robust and maintainable.

Refactoring user context handling:

  • Removed all usages and imports of contextvars and the current_user_id variable from settings.py, router.py, agent, and orchestration modules, replacing them with explicit user_id parameters and fields. [1] [2] [3] [4] [5] [6] [7]
  • Updated all function and class signatures to require user_id as an argument, including agent creation (create_agent_from_config, get_agents), agent invocation, and orchestration manager initialization. [1] [2] [3]
  • Refactored the ProxyAgent and HumanApprovalMagenticManager classes to store and use user_id directly, removing reliance on global context. [1] [2]

WebSocket connection and messaging updates:

  • Changed connection cleanup and status update logic to use process_id and explicit user_id parameters instead of context-based retrieval. [1] [2]
  • Updated all WebSocket message sending and callback invocations to use the passed user_id rather than fetching from context, ensuring correct routing of messages to users. [1] [2] [3] [4] [5]

Background orchestration and agent initialization:

  • Simplified background task orchestration by removing context copying and instead passing user_id directly to orchestration routines and agent factories. [1] [2] [3] [4]

These changes make the user context handling explicit and more reliable, reducing the risk of subtle bugs and improving code readability.

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

@Roopan-Microsoft Roopan-Microsoft merged commit 015d2ef into dev-v3 Oct 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants