-
Notifications
You must be signed in to change notification settings - Fork 0
Session management #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Updates session creation and verification to use GET requests instead of POST. This change streamlines the session handling process, especially for the frontend, by enabling session verification upon app initialization and ensuring backend sessions are active before allowing user interaction. Removes unnecessary MCP session manager initialization from the session route, and moves the MCP tool initialization to the agent initialization. This makes the session routes more responsible. Adds tests for the updated session creation and verification flow.
Ensures MCP tools are initialized when a new agent instance is created for a session. This prevents issues where tools were not available immediately after a session was created. It also moves the MCP initialization from the session creation route to the agent creation logic, streamlining the initialization process. The get_agent_instance function now uses async to ensure the MCP tools are initialized before returning the agent, preventing race conditions. Adds a "Verifying Session" loading state in the UI to indicate that the backend session is being verified. Removes old testing files.
Enhances the chat input field by disabling it and displaying a "Please wait..." message while the application is in a loading state. This provides clear visual feedback to the user, preventing them from sending messages during background operations such as session verification, tool loading, or message sending. Also fixes an issue where send button could be enabled during session creation.
Refactors session handling to use dependency injection for agent creation and retrieval, improving testability and maintainability. Adds new GET endpoints for session creation and verification, aligning with the updated frontend session lifecycle. Isolates debug events per session, ensuring correct debug information is displayed for each active session.
There was a problem hiding this 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 refactors session management end-to-end—making agent and tool setup fully asynchronous, switching session endpoints from POST to GET, and improving the frontend’s visual feedback during session creation, tool loading, message sending, and session verification.
- Agent now asynchronously initializes MCP tools on creation.
- Session routes use GET
/api/session/{session_id}(including"new") instead of POST. - UI updates in
chat.tsandstyles.cssintroduce loading spinners, disable inputs, and add a session-verification state. - Tests were updated across the suite to reflect the GET-based session flows and new loading-state logic.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/agent.py | Made get_agent_instance and tool initialization async. |
| src/api/routes.py | Replaced POST /session/new with GET /session/{session_id} and updated responses. |
| src/ui/chat.ts | Added isVerifyingSession, session-verification methods, and loading-state management. |
| src/ui/styles.css | Defined CSS for loading states and session verification UI. |
| tests/test_loading_states.py | Added tests for the new .session-verification-loading CSS and logic. |
| tests/test_frontend_session_integration.py | Updated to use GET endpoints and new session-verify flow. |
| tests/test_frontend_debug_session_switching.py | Updated setup to use create_app() and added auth_headers fixture. |
| tests/test_frontend_debug_session_isolation.py | Same as above—refactored to match updated router and fixtures. |
| tests/test_api_session_routes.py | Adapted to GET routes and debug-capture injection. |
| tests/test_agent_session_management.py | Made agent tests async and patched new initialize_mcp_tools. |
| @pytest.fixture | ||
| def mock_agent_deps(self): | ||
| with patch("api.routes.get_agent_instance") as mock_get_agent: | ||
| def auth_headers(self): |
Copilot
AI
Jun 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The auth_headers helper isn’t marked as a pytest fixture. Add @pytest.fixture above it so tests injecting auth_headers will receive the value.
| def client(self, app): | ||
| return TestClient(app) | ||
|
|
||
| @pytest.fixture |
Copilot
AI
Jun 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The auth_headers helper isn’t marked as a pytest fixture. Add @pytest.fixture above it so tests injecting auth_headers will receive the value.
| @pytest.fixture | |
| @pytest.fixture | |
| @pytest.fixture |
This pull request introduces significant updates to enhance session management, tool initialization, and user interface responsiveness in the agent and chat application. Key changes include refactoring session handling to support asynchronous initialization, improving backend session verification, and adding UI feedback for loading states.
Backend Updates: Session Management and MCP Tool Initialization
Session Management Enhancements:
get_agent_instanceto initialize MCP tools asynchronously during agent creation. This ensures tools are properly set up before processing queries. (src/agent.py, src/agent.pyL155-R182)add_toolandrun_conversationfunctions to be asynchronous, aligning with the new MCP initialization flow. (src/agent.py, src/agent.pyL175-R205)GETfor session initialization and verification, replacing the previousPOSTmethod for creating new sessions. (src/api/routes.py, src/api/routes.pyL12-R27)MCP Tool Initialization:
initialize_mcp_toolsmethod inAgentclass to dynamically load tools from the MCP configuration file. Tools are now added to the agent instance during initialization. (src/agent.py, src/agent.pyR121-R135)Frontend Updates: Improved Feedback and Session Verification
Session Verification:
verifyBackendSessionmethod to check the existence of backend sessions. If a session is invalid, it clears the session ID and prepares for a new session. (src/ui/chat.ts, src/ui/chat.tsR1319-R1371)src/ui/chat.ts, [1];src/ui/styles.css, [2]Enhanced User Feedback:
updateSendButtonStateto disable input fields and buttons during asynchronous operations like session creation, tool loading, or message sending. Provides placeholder text and visual cues for loading states. (src/ui/chat.ts, [1] [2];src/ui/styles.css, [3]src/ui/chat.ts, [1] [2]Code Style and Refactoring
GETinstead ofPOSTfor consistency with new API design. (src/ui/chat.ts, [1] [2]src/api/routes.py. (src/api/routes.py, src/api/routes.pyL3)These changes collectively improve the application's functionality, responsiveness, and maintainability, ensuring smoother interactions for both developers and end-users.