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 import reports the tool error and partial failures instead of crashing

Rudy Celekli94fd5734ba5f
diff --git a/v3/@claude-flow/cli/__tests__/memory-import-failure.test.ts b/v3/@claude-flow/cli/__tests__/memory-import-failure.test.ts
new file mode 100644
index 0000000000..cfbd49efb6
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/memory-import-failure.test.ts
@@ -0,0 +1,68 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({ call: vi.fn(), success: vi.fn(), error: vi.fn(), warn: 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
+ : prop === 'printWarning' ? mocks.warn
+ : (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 importCmd = memoryCommand.subcommands!.find(c => c.name === 'import')!;
+const run = () => importCmd.action!({ args: [], flags: { input: 'in.json' } } as any);
+
+beforeEach(() => {
+ mocks.call.mockReset();
+ mocks.success.mockReset();
+ mocks.error.mockReset();
+ mocks.warn.mockReset();
+});
+
+describe('memory import when the tool fails', () => {
+ it('reports a tool error instead of printing success and crashing', async () => {
+ mocks.call.mockResolvedValue({ error: 'File not found: in.json' });
+ const result = await run();
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ expect(mocks.success).not.toHaveBeenCalled();
+ expect(mocks.error).toHaveBeenCalledWith(expect.stringContaining('File not found: in.json'));
+ expect(mocks.error).not.toHaveBeenCalledWith(expect.stringContaining('TypeError'));
+ });
+
+ it('fails when some entries were rejected, even though a summary came back', async () => {
+ mocks.call.mockResolvedValue({
+ success: false,
+ error: '1 memory write(s) failed: a: disk full',
+ failed: 1,
+ inputPath: 'in.json',
+ imported: { entries: 1, vectors: 1, patterns: 0 },
+ skipped: 0,
+ duration: 3,
+ });
+ const result = await run();
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ expect(mocks.success).not.toHaveBeenCalled();
+ expect(mocks.error).toHaveBeenCalledWith(expect.stringContaining('disk full'));
+ });
+
+ it('still prints the summary when the import succeeds', async () => {
+ mocks.call.mockResolvedValue({
+ success: true,
+ failed: 0,
+ inputPath: 'in.json',
+ imported: { entries: 2, vectors: 2, patterns: 0 },
+ skipped: 0,
+ duration: 3,
+ });
+ const result = await run();
+ expect(result).toMatchObject({ success: true });
+ expect(mocks.success).toHaveBeenCalledWith('Imported from in.json');
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts
index 9b92d8c269..202f3a16e9 100644
--- a/v3/@claude-flow/cli/src/commands/memory.ts
+++ b/v3/@claude-flow/cli/src/commands/memory.ts
@@ -1828,6 +1828,9 @@ const importCommand: Command = {
try {
const result = await callMCPTool<{
+ success?: boolean;
+ error?: string;
+ failed?: number;
inputPath: string;
imported: {
entries: number;
@@ -1843,6 +1846,22 @@ const importCommand: Command = {
dbPath: resolveDbPath(ctx.flags.path as string | undefined),
});
+ // memory_import reports a bad file as { error } rather than throwing, and
+ // a partial write as { success: false, error, imported }. Without this the
+ // command printed "Imported from undefined" and crashed on result.imported,
+ // or reported success for an import that dropped entries.
+ const failure = (result as { error?: string } | undefined)?.error;
+ if (!result || failure || result.success === false || !result.imported) {
+ output.printError(`Import error: ${failure ?? 'memory_import returned no import summary'}`);
+ if (result?.imported) {
+ output.printList([
+ `Entries imported: ${result.imported.entries}`,
+ `Failed: ${result.failed ?? 'unknown'}`,
+ ]);
+ }
+ return { success: false, exitCode: 1 };
+ }
+
output.printSuccess(`Imported from ${result.inputPath}`);
output.printList([
`Entries: ${result.imported.entries}`,