feat(core): add per-session memory extraction to SessionSummaryService#24765
feat(core): add per-session memory extraction to SessionSummaryService#24765SandyTao520 wants to merge 7 commits intomainfrom
Conversation
Add generateMemoryExtraction() to SessionSummaryService that produces structured memory notes (memoryScratchpad) alongside a 1-line summary in a single LLM call. Notes include sections for what was done, how the user works, what was learned, and what went wrong. Also fix getPreviousSession() to iterate past the current active session instead of only checking the most recent file.
|
Hi @SandyTao520, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +11 kB (+0.03%) Total Size: 34 MB
ℹ️ View Unchanged
|
Summary of ChangesHello, 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 implements a new memory extraction feature designed to consolidate session information into structured markdown notes. By leveraging a single LLM call, the system now generates both a concise summary and a detailed scratchpad containing insights on user goals, preferences, and outcomes. This change serves as a foundational step for future memory consolidation capabilities and includes robust fallback logic and improved session file discovery to ensure reliable data collection. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements a memory extraction feature within the SessionSummaryService, transitioning from simple summaries to structured markdown notes that capture session outcomes, keywords, and user preferences. The ConversationRecord interface now includes a memoryScratchpad field, and the summary utility has been updated to search for eligible sessions and perform this extraction with a fallback mechanism. Feedback focuses on enhancing security by sanitizing prompt inputs to prevent injection, ensuring Unicode-safe message truncation, and optimizing performance by limiting the number of session files scanned.
Add MEMORY_EXTRACTION and MEMORY_EXTRACTION_SKIPPED events to track extraction success/failure rates, duration, output size, and fallback usage. Emit events from sessionSummaryUtils at each decision point.
…y-extraction # Conflicts: # packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts # packages/core/src/telemetry/clearcut-logger/event-metadata-key.ts
- Revert check in getPreviousSession to look for `conversation.summary` to prevent infinite retry loops and unintended backfilling. - Add lookback window slice to avoid unbounded sequential reads of all session files. - Refactor generateSummary to use the same formatConversation function to remove code duplication. - Fix telemetry bug on extraction fallback. - Implement unicode-safe truncation. - Add memoryScratchpad to check in saveSummaryOnly race guard.
Summary
Add per-session memory extraction that generates structured notes from past conversations in a single LLM call, saving both a 1-line summary and a full markdown scratchpad (
memoryScratchpad) into the session JSON file. This is the foundation for a future memory consolidation system.Details
generateMemoryExtraction()onSessionSummaryService— reuses the same filter/window/format pattern asgenerateSummary()but with a larger message window (50 vs 20), longer truncation (2000 chars vs 500), 30s timeout, and a structured extraction prompt.#heading) and the full markdown scratchpad with sections:## What was done,## How the user works,## What we learned,## What went wrong.memoryScratchpadfield onConversationRecordstores the extraction inline in the session JSON.sessionSummaryUtils.tsupdated to callgenerateMemoryExtraction()first, falling back togenerateSummary()if extraction fails.getPreviousSession()— previously only checked the most recent session file (which is typically the current empty session). Now iterates through files to find the first eligible previous session.Related Issues
Related to #18007
How to Validate
Run unit tests:
Manual test:
memoryScratchpadpopulated.Pre-Merge Checklist