Skip to content

remove SessionManager and update TelegramService to handle session management directly#19

Merged
MarvelNwachukwu merged 2 commits intomainfrom
improve-session-management
Feb 16, 2026
Merged

remove SessionManager and update TelegramService to handle session management directly#19
MarvelNwachukwu merged 2 commits intomainfrom
improve-session-management

Conversation

@MarvelNwachukwu
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @MarvelNwachukwu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the Telegram bot's session management by eliminating a custom SessionManager and integrating directly with the @iqai/adk framework's session and memory services. This change centralizes session logic within the ADK ecosystem, making the system more consistent and leveraging existing framework capabilities for conversation state persistence and manipulation.

Highlights

  • Removed Custom Session Manager: The custom SessionManager class and its associated file have been completely removed, simplifying the codebase.
  • ADK Session Integration: Session management in TelegramService now directly utilizes the @iqai/adk library's BaseSessionService and MemoryService for handling conversation state.
  • Refactored Command Handling: Telegram bot commands like /new and /reset have been updated to interact directly with the ADK session lifecycle, ensuring proper creation, saving, and deletion of sessions.
  • Automated Message Tracking: The TelegramService no longer manually tracks messages in a session; instead, the runner.ask method from ADK automatically handles event tracking within the ADK session.
Changelog
  • src/services/SessionManager.ts
    • Removed the entire custom session management class and its related logic.
  • src/services/TelegramService.ts
    • Imported necessary types (BaseSessionService, EnhancedRunner, MemoryService) from @iqai/adk.
    • Removed the import of the now-defunct sessionManager.
    • Introduced a formatDuration utility function for calculating conversation length.
    • Refactored the commands object into a createCommands function to inject ADK-related dependencies.
    • Updated the /new command to save the current ADK session to memory and initiate a new one via sessionService.
    • Modified the /reset command to delete the current ADK session and create a fresh one.
    • Removed the explicit sessionManager.setDeps call as the custom manager is no longer used.
    • Eliminated manual sessionManager.getOrCreate and sessionManager.addMessage calls, relying on runner.ask for session event tracking.
  • src/services/index.ts
    • Removed the export statement for sessionManager.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR refactors session management by removing the custom SessionManager and using ADK features directly in TelegramService. This is a great simplification. The implementation is solid, but I found a potential race condition in the /new command that could cause data loss when saving sessions. My review includes a fix for this.

Comment on lines +283 to +290
const freshSession = await sessionService.getSession(
currentSession.appName,
currentSession.userId,
currentSession.id,
);
if (freshSession) {
await memoryService.addSessionToMemory(freshSession);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Fetching a 'fresh' session from sessionService is redundant and risks a race condition. The runner holds the most up-to-date session in currentSession. Re-fetching from the persistence layer could retrieve a stale session if recent events aren't persisted yet, leading to data loss when saving to memory. It's safer to use currentSession directly.

				await memoryService.addSessionToMemory(currentSession);

@MarvelNwachukwu
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully refactors the session management by removing the custom SessionManager and leveraging the ADK's built-in session lifecycle. This simplifies the codebase and aligns it better with the ADK framework. However, the current implementation introduces a shared session state across all users. While this is a major issue for privacy and correctness in multi-user or multi-group scenarios, it might be acceptable if the application is designed for single-user or paired-user contexts, as per repository guidelines (Rule 2).

currentSession.appName,
currentSession.userId,
);
runner.setSession(newSession);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Calling runner.setSession(newSession) on a shared runner instance will globally change the active session for all Telegram users. If one user triggers the /new command, it will effectively reset the conversation for every other user currently interacting with the bot. This is a significant issue if the application is intended for multi-user scenarios, where session state must be isolated per chatId. However, if this application is designed for single-user or paired-user contexts (e.g., a personal bot), this behavior might be acceptable as per repository guidelines.

References
  1. In applications designed for single-user or paired-user contexts (e.g., personal bots), using a hardcoded session user ID is acceptable, as the risks associated with multi-user data crossover are not present.

currentSession.appName,
currentSession.userId,
);
runner.setSession(newSession);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the /new command, using runner.setSession here affects the global state of the shared runner. This will cause a session reset for all users simultaneously if any single user runs the /reset command. This is a significant issue if the application is intended for multi-user scenarios, where session state must be isolated per chatId. However, if this application is designed for single-user or paired-user contexts (e.g., a personal bot), this behavior might be acceptable as per repository guidelines.

References
  1. In applications designed for single-user or paired-user contexts (e.g., personal bots), using a hardcoded session user ID is acceptable, as the risks associated with multi-user data crossover are not present.

// Get response from agent
// Get response from agent (ADK tracks events in session automatically)
try {
const response = await runner.ask(messageText);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The removal of SessionManager has eliminated the isolation of conversations between different Telegram chats. Since runner.ask() uses the session currently set on the runner, and there is only one runner instance for the entire service, all users and groups will now share the same conversation history. This is a regression from the previous implementation which used chatId to isolate sessions. This is a significant issue for privacy and correctness if the application is intended for multi-user or multi-group scenarios. To fix this while using ADK's session management, you should ensure that the runner uses a specific sessionId (e.g., the chatId) for each request, likely by using runner.runAsync(messageText, { sessionId: chatId }) and extracting the response, rather than the simplified ask() method which relies on a single global session context. However, if this application is designed for single-user or paired-user contexts (e.g., a personal bot), this shared state might be acceptable as per repository guidelines.

References
  1. In applications designed for single-user or paired-user contexts (e.g., personal bots), using a hardcoded session user ID is acceptable, as the risks associated with multi-user data crossover are not present.

@MarvelNwachukwu MarvelNwachukwu merged commit b0a6a4a into main Feb 16, 2026
1 check passed
@MarvelNwachukwu MarvelNwachukwu linked an issue Feb 17, 2026 that may be closed by this pull request
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.

Remove Custom Session Manager, switch to adk-session manager.

1 participant