[Bug] createMemoryCommand ignores options.memoryManager when constructing SummarizerService, causing /memory accept to write to detached store
Description
Summary
In source/commands/memory.tsx, createMemoryCommand(options) allows callers to inject a custom memoryManager via options.memoryManager. However, when memoryManager is provided without an explicit options.summarizerService, the command instantiates SummarizerService using the no-arg constructor new SummarizerService().
Because SummarizerService defaults its constructor parameter to a new SemanticMemoryManager(), /memory accept saves accepted proposals to a disconnected default manager instead of the injected options.memoryManager.
Location
source/commands/memory.tsx#L185-L197
export function createMemoryCommand(
options: MemoryCommandOptions = {},
): Command {
let memoryManager = options.memoryManager;
let summarizerService = options.summarizerService;
if (!memoryManager) {
const manager = new SemanticMemoryManager();
memoryManager = manager;
summarizerService ??= new SummarizerService(manager);
} else {
summarizerService ??= new SummarizerService(); // <--- BUG HERE
}
Root Cause
- In
source/memory/summarizer-service.ts,SummarizerService's constructor is:export class SummarizerService { constructor( private readonly memoryManager = new SemanticMemoryManager(), private readonly isMemoryEnabled: () => boolean = getSemanticMemoryEnabled, ) {} - When a custom
options.memoryManageris passed intocreateMemoryCommand({ memoryManager }), theelsebranch increateMemoryCommandexecutes:summarizerService ??= new SummarizerService(); - This creates a
SummarizerServicebound to an unconfigured, defaultSemanticMemoryManagerinstance rather than the caller-providedmemoryManager. - When a user runs
/memory accept <number>,createMemoryCommanddelegates to:const memory = await summarizerService.acceptProposal( proposal, metadata.sessionId, );summarizerService.acceptProposalcallsthis.memoryManager.addMemory(...), saving the accepted memory into the default store. - In contrast,
/memory list,/memory delete, and/memory clearall operate onmemoryManager(options.memoryManager). - As a result, the accepted proposal never appears in
/memory liston the configured manager, causing silent data desynchronization.
Steps to Reproduce / Reproduction Test Case
import test from 'ava';
import { createMemoryCommand } from './memory';
import { SemanticMemoryManager } from '@/memory/semantic-memory-manager';
test('createMemoryCommand binds summarizerService to the injected memoryManager', async t => {
const customManager = new SemanticMemoryManager();
const command = createMemoryCommand({ memoryManager: customManager });
// Propose and accept a memory
await command.handler(['propose'], [
{ role: 'user', content: 'We must always use UTF-8 encoding.' },
{ role: 'assistant', content: 'Understood, will always enforce UTF-8.' }
], { sessionId: 'test-session' } as any);
await command.handler(['accept', '1'], [], { sessionId: 'test-session' } as any);
// List from the injected memory manager
const memories = await customManager.listMemories();
t.is(memories.length, 1, 'Injected memoryManager should contain the accepted memory');
});
Expected: customManager.listMemories() returns 1 memory.
Actual: customManager.listMemories() returns 0 memories because the accepted proposal was saved to the default SemanticMemoryManager instantiated inside new SummarizerService().
Suggested Fix
Simplify and properly pass memoryManager when constructing SummarizerService:
export function createMemoryCommand(
options: MemoryCommandOptions = {},
): Command {
- let memoryManager = options.memoryManager;
- let summarizerService = options.summarizerService;
- if (!memoryManager) {
- const manager = new SemanticMemoryManager();
- memoryManager = manager;
- summarizerService ??= new SummarizerService(manager);
- } else {
- summarizerService ??= new SummarizerService();
- }
+ const memoryManager = options.memoryManager ?? new SemanticMemoryManager();
+ const summarizerService =
+ options.summarizerService ?? new SummarizerService(memoryManager);
once confirmed,will raise the PR