Files
ruflo/scripts
ruvandRuFlo cfc341706a fix(memory): #2120 — accept NULL status in memory_entries (legacy DBs) + 3.7.0 stable
Reporter @alexandrelealbess on WSL2 with alpha.81: `ruflo memory stats`
reported `Total Entries: 0` against a 251-row `.swarm/memory.db`, and
`ruflo status` falsely reported "not initialized". MCP and direct
SQLite queries both confirmed the data was intact and readable.

## Root cause

`WHERE status = 'active'` in both `bridgeListEntries`
(memory-bridge.ts:828) and `listEntries` (memory-initializer.ts:2544+)
excluded rows where the status column was NULL. Legacy DBs created
before the status column existed (or by auto-memory-bridge writes
that didn't set status) end up with NULL status after schema
migration, even though `ALTER TABLE ADD COLUMN ... DEFAULT 'active'`
SHOULD backfill — observed it doesn't in some paths.

`isInitialized()` in status.ts:47 required `.claude-flow/config.yaml`
exclusively — projects that ran only `ruflo memory init` (creates
`.swarm/memory.db` but no config.yaml) were reported as not
initialized.

## Fix (4 parts)

1. **`memory-bridge.ts:bridgeListEntries`** — `WHERE status = 'active'
   OR status IS NULL`. Treats NULL as "legacy-active" since the schema
   default is 'active' for any row inserted after the column existed.

2. **`memory-initializer.ts:listEntries`** — same NULL-acceptance in
   the raw sql.js fallback path (4 SQL prepares updated).

3. **`memory-initializer.ts:ensureSchemaColumns`** — belt-and-suspenders
   backfill: after ALTER TABLE, run `UPDATE memory_entries SET status =
   'active' WHERE status IS NULL`. Safe on already-correct DBs (0 rows
   updated).

4. **`status.ts:isInitialized`** — broadened to accept any of:
   `.claude-flow/config.yaml`, `.claude-flow/config.json`,
   `.swarm/memory.db`, `.claude/settings.json`. A project with any of
   these is meaningfully "initialized" for some flow.

## CI guard

New `scripts/smoke-memory-stats-legacy-db.mjs` builds a 251-row DB with
all-NULL status (mirroring the reporter's setup), runs `listEntries`,
and asserts:
  1. Fixture has 251 NULL-status rows
  2. `listEntries` returns total=251 (not 0)
  3. After listEntries, ensureSchemaColumns has promoted all rows to
     `status='active'`

Wired into `v3-ci.yml` as `memory-stats-legacy-db-smoke` with
path-filter on memory-bridge.ts, memory-initializer.ts, status.ts,
and the smoke itself.

## Version bump policy change

Per CLAUDE.md update on 2026-05-23 (alpha series ended at alpha.81),
this is the **first stable release: 3.7.0** — no more `-alpha.N`
suffixes. Legacy `alpha` + `v3alpha` dist-tags continue to point at
the latest stable for backward compat.

## Verification

- `npm test` in v3/@claude-flow/cli: 1999/2045 pass (46 skipped, 0 fail)
- `node scripts/smoke-memory-stats-legacy-db.mjs`: PASS — 4/4 assertions
- Build clean

Co-Authored-By: RuFlo <ruflo-bot@users.noreply.github.com>
2026-05-24 11:13:50 -04:00
..
2026-01-04 19:30:59 +00:00