feat(memory): persist auto-memory scratchpad for skill extraction#25873
feat(memory): persist auto-memory scratchpad for skill extraction#25873SandyTao520 wants to merge 13 commits intomainfrom
Conversation
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 enhances the memory system by introducing a persistent 'memory scratchpad' that captures compact workflow hints during sessions. By storing this metadata, the skill extraction process can more effectively identify and route repeated workflows, improving the quality and reliability of extracted skills. The changes include updates to session recording, metadata persistence, and the extraction agent's prompt, supported by new evaluation tools to measure retrieval performance. 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 introduces "Memory Scratchpads," which extract lightweight workflow metadata—including tool sequences, touched paths, and validation status—from conversation sessions to improve skill extraction recall. The MemoryService and SkillExtractionAgent are updated to leverage these hints for session prioritization and routing. The PR also adds turn count and duration tracking to agent execution, supports JSONL metadata updates, and includes new evaluation tests for retrieval performance. Feedback identifies a maintainability risk due to duplicated JSONL parsing logic in sessionSummaryUtils.ts and suggests refactoring to use the shared loadConversationRecord function.
Note: Security Review did not run due to the size of the PR.
# Conflicts: # packages/core/src/services/memoryService.test.ts # packages/core/src/services/memoryService.ts # packages/core/src/services/sessionSummaryUtils.test.ts # packages/core/src/services/sessionSummaryUtils.ts
|
Size Change: +12.9 kB (+0.04%) Total Size: 33.8 MB
ℹ️ View Unchanged
|
|
✅ 55 tests passed successfully on gemini-3-flash-preview. This is an automated guidance message triggered by steering logic signatures. |
| typeof args.file_path !== 'string' | ||
| ) { | ||
| return null; | ||
| if (activity.type === 'TOOL_CALL_END') { |
There was a problem hiding this comment.
we dropped the check for tool name here no?
activity.data['name'] !== READ_FILE_TOOL_NAME should be added here and for the ERROR event too.
| const baselineScenario = createWorkflowComparisonSessions(false); | ||
| const enhancedScenario = createWorkflowComparisonSessions(true); | ||
|
|
||
| const baselineOutcome = await runExtractionAndReadState(config); |
There was a problem hiding this comment.
are these two arms running over identical rig environments?
enhanced seems to run on a fresh rig, shouldn't baseline do the same?
| summary: session.summary, | ||
| memoryScratchpad: session.memoryScratchpad, | ||
| startTime: new Date(Date.now() - 7 * 60 * 60 * 1000).toISOString(), | ||
| lastUpdated: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(), |
There was a problem hiding this comment.
shouldn't lastUpdated include timestampOffsetMinutes? Currently, every sessions gets updated with current time - 4 hours, with no offset taken into account.
| } else { | ||
| const baseLlmClient = new BaseLlmClient(contentGenerator, config); | ||
| const summaryService = new SessionSummaryService(baseLlmClient); | ||
| summary = |
There was a problem hiding this comment.
if the session summary call here fails, and summary is assigned undefined, we still write to the scraptchpad. So, hasSessionSummaryMetadata will keep returning false.
When getPreviousSession is called, we keep returning to the same session and generateAndSaveSummary retries every time (potentially issuing a wasted LLM call each time). We end up doing infinite retries.
| const VALIDATION_COMMAND_REGEX = | ||
| /\b(test|tests|vitest|jest|pytest|cargo test|npm test|pnpm test|yarn test|bun test|lint|build|check|typecheck)\b/i; | ||
| const PATH_KEY_REGEX = /(path|file|dir|directory|cwd|root)/i; | ||
| const VALIDATION_TOOL_REGEX = /(test|lint|build|check)/i; |
There was a problem hiding this comment.
regex is too broad, will capture suggest something like /(\\b(test|lint|build|check)\\b)/i
| return normalized.length > 0 ? normalized : null; | ||
| } | ||
|
|
||
| function collectPathsFromValue( |
There was a problem hiding this comment.
recursion depth here seems unbounded? Perhaps try capping it via a depth param?
| return value === null ? null : Number(value.toFixed(4)); | ||
| } | ||
|
|
||
| function average(values: number[]): number { |
There was a problem hiding this comment.
should this + other low-level functions in this file exist in a utils file (or are there any pre-existing ones we can use?)
| const enhancedSignalScore = | ||
| enhancedRelevantReads - enhancedDistractorReads; | ||
|
|
||
| expect(enhancedRun.candidateSessions).toHaveLength( |
There was a problem hiding this comment.
Looks like the eval passes even if enhanced equals baseline exactly. It doesn't validate that scratchpads actually improve anything; a no-op feature would pass.
| return undefined; | ||
| } | ||
|
|
||
| const summary = sanitizeWorkflowSummaryForScratchpad(parts.join(' | ')); |
There was a problem hiding this comment.
nit: we are running sanitization twice unnecessarily (here and in memoryService)
| if ( | ||
| session.summary && | ||
| workflowSummary && | ||
| workflowSummary.trim().length > 0 && |
There was a problem hiding this comment.
nit: this check looks to be redundant given sanitizedWorkflowSummary?.trim() in memoryService
Summary
Persist an auto-memory
memoryScratchpadinto session metadata so skill extraction can use compact workflow hints without relying only on one-line session summaries.In the 5-trial scratchpad stats eval, the scratchpad path reduced average extractor turns from
13.2to11.0(-16.7%), reduced distractor reads from3.8to2.4(-36.8%), improved precision from0.3467to0.46(+32.7%), kept recall at1.0, and reduced duration from42812.6msto40956.2ms(-4.3%).Details
memoryScratchpadthrough chat recording, session summary refreshes, and memory service session loading.loadConversationRecord()session parser instead of maintaining a second JSONL parser in summary utilities.turnCount,durationMs, andterminateReason) so scratchpad impact can be measured.preflightstays green.GEMINI_CLI_TRUST_WORKSPACE=truefor chained and nightly eval workflows so headless eval runs stay aligned with the workspace trust enforcement added in feat(cli): secure .env loading and enforce workspace trust in headless mode #25814.Related Issues
Closes #25895.
How to Validate
npm run preflight.Expected result: all workspace checks pass.
npm exec -- vitest run packages/core/src/services/sessionSummaryUtils.test.ts packages/core/src/services/memoryService.test.ts packages/core/src/agents/skill-extraction-agent.test.ts.Expected result: focused service and prompt-contract tests pass.
npm exec -- tsc -p packages/core/tsconfig.json --noEmit.Expected result: core typecheck passes.
RUN_EVALS=1 npm exec -- vitest run --config evals/vitest.config.ts -t "Session summary persists memory scratchpad for memory-saving sessions".Expected result: the eval passes and verifies
memoryScratchpadis written into the resumed session log.RUN_EVALS=1 npm exec -- vitest run --config evals/vitest.config.ts -t "memory scratchpad improves repeated-workflow recall versus summary-only index".Expected result: the eval passes and scratchpad-enabled retrieval matches or beats the summary-only baseline for the repeated workflow fixture.
RUN_EVALS=1 RUN_SCRATCHPAD_STATS=1 SCRATCHPAD_STATS_TRIALS=5 npm exec -- vitest run --config evals/vitest.config.ts -t "reports memory scratchpad retrieval statistics".Expected result: the eval passes and writes
evals/logs/skill_extraction_scratchpad_stats.json.GEMINI_MODEL=gemini-3-pro-preview GEMINI_CLI_TRUST_WORKSPACE=true npm exec -- vitest run --config evals/vitest.config.ts evals/save_memory.eval.ts -t "Agent remembers user's favorite color".Expected result: the trusted eval subprocess can call
save_memorysuccessfully.Pre-Merge Checklist