Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(memory): memory export reports the tool error instead of crashing (#4204)

Rudy Celeklie379cd725c7b
diff --git a/v3/@claude-flow/cli/__tests__/memory-export-failure-4204.test.ts b/v3/@claude-flow/cli/__tests__/memory-export-failure-4204.test.ts
new file mode 100644
index 0000000000..d186acf3c3
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/memory-export-failure-4204.test.ts
@@ -0,0 +1,43 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({ call: vi.fn(), success: vi.fn(), error: vi.fn() }));
+vi.mock('../src/mcp-client.js', () => ({ callMCPTool: mocks.call, MCPClientError: class extends Error {} }));
+vi.mock('../src/output.js', () => ({
+ output: new Proxy({}, {
+ get: (_t, prop) => (prop === 'printSuccess' ? mocks.success : prop === 'printError' ? mocks.error : (value: unknown) => value),
+ }),
+}));
+vi.mock('../src/commands/memory-distill.js', () => ({ distillCommand: {} }));
+vi.mock('../src/commands/memory-backup.js', () => ({ backupCommand: {} }));
+vi.mock('../src/memory/memory-initializer.js', () => ({ resolveDbPath: (p: string) => p }));
+import { memoryCommand } from '../src/commands/memory.js';
+
+const exportCmd = memoryCommand.subcommands!.find(c => c.name === 'export')!;
+const run = () => exportCmd.action!({ args: [], flags: { output: 'out.json' } } as any);
+
+beforeEach(() => {
+ mocks.call.mockReset();
+ mocks.success.mockReset();
+ mocks.error.mockReset();
+});
+
+describe('memory export when the tool fails (#4204)', () => {
+ it('reports the tool error instead of printing success and crashing', async () => {
+ mocks.call.mockResolvedValue({ error: 'Could not read memory for export' });
+ const result = await run();
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ expect(mocks.success).not.toHaveBeenCalled();
+ expect(mocks.error).toHaveBeenCalledWith(expect.stringContaining('Could not read memory for export'));
+ expect(mocks.error).not.toHaveBeenCalledWith(expect.stringContaining('TypeError'));
+ });
+
+ it('still prints the summary when the export succeeds', async () => {
+ mocks.call.mockResolvedValue({
+ outputPath: '/tmp/out.json', format: 'json', fileSize: '1 KB',
+ exported: { entries: 2, vectors: 1, patterns: 0 },
+ });
+ const result = await run();
+ expect(result).toMatchObject({ success: true });
+ expect(mocks.success).toHaveBeenCalledWith('Exported to /tmp/out.json');
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts
index 9b92d8c269..5493fb2e17 100644
--- a/v3/@claude-flow/cli/src/commands/memory.ts
+++ b/v3/@claude-flow/cli/src/commands/memory.ts
@@ -1765,6 +1765,14 @@ const exportCommand: Command = {
includeVectors: ctx.flags.includeVectors ?? true,
});
+ // memory_export reports failure as { error } rather than throwing; without
+ // this check the command printed "Exported to undefined" and then crashed
+ // reading result.exported.entries (#4204).
+ if (!result || (result as { error?: string }).error || !result.exported) {
+ output.printError(`Export error: ${(result as { error?: string } | undefined)?.error ?? 'memory_export returned no export summary'}`);
+ return { success: false, exitCode: 1 };
+ }
+
output.printSuccess(`Exported to ${result.outputPath}`);
output.printList([
`Entries: ${result.exported.entries}`,