Frontmatter
| id | 7864 |
| title | Refactor SessionService for better error handling and config management |
| state | Closed |
| labels | enhancementai |
| assignees | tobiu |
| createdAt | Nov 22, 2025, 8:03 PM |
| updatedAt | Nov 22, 2025, 8:17 PM |
| githubUrl | https://github.com/neomjs/neo/issues/7864 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Nov 22, 2025, 8:17 PM |
Refactor SessionService for better error handling and config management
tobiu assigned to @tobiu on Nov 22, 2025, 8:05 PM

tobiu
Nov 22, 2025, 8:16 PM
Input from Gemini:
✦ Refactoring completed.
Summary of Changes:
- Config Management: Added
summarizationBatchLimittoconfig.mjs(default: 2000) to control database fetch sizes.- Robust Database Scanning:
- Updated
findSessionsToSummarizeto use pagination loops with safety breaks (maxIterations: 1000).- Ensured database queries use dynamically built configuration objects to avoid
where: undefinederrors.- Removed internal
try/catchfromfindSessionsToSummarizeto allow errors to propagate correctly.- Tool Error Handling:
- Updated
summarizeSessions(the public tool method) to wrap logic in atry/catchblock.- On failure, it now returns a structured error object (
{ error, message, code }) instead of crashing or returning misleading empty results.The service is now consistent with the project's error handling patterns and safe for large-scale deployments.
tobiu closed this issue on Nov 22, 2025, 8:17 PM
During a self-review of
ai/mcp/server/memory-core/services/SessionService.mjs, the following potential improvements were identified:findSessionsToSummarizeperforms multiple database calls (memory fetch loop, summary fetch loop) without internaltry/catchblocks. While the caller (summarizeSessions->initAsync) likely handles errors, a failure in the memory fetch loop (e.g., partial network failure) currently causes the entire process to abort. Consider if granular error handling or retry logic is needed here.const limit = 2000;) is hardcoded inside the method. This should be moved toai/mcp/server/memory-core/config.mjsto allow for environment-based tuning (e.g., smaller batches for memory-constrained environments).hasMoreis controlled bybatch.ids.length < limit, adding a safety break (max iterations) could prevent infinite loops in case of weird driver behavior where it keeps returning full pages of the same data (though unlikely withoffset).Goal: Refactor
SessionService.mjsto address these code quality and robustness points.