#4057: with encryption at rest on, `memory purge`'s sql.js fallback rewrote a
plaintext native SQLite store as an RFE1 blob and still printed [OK]; the
native bridge and every SQLite reader then rejected the file. Every whole-file
read-modify-write (purge, delete, get access-count, store, schema migration,
decay) now writes the image back in the format it read (plaintext -> plaintext,
RFE1 -> RFE1) via writeDbImagePreservingFormat. applyTemporalDecay also read
the raw bytes, so it failed on encrypted stores, and wrote plaintext: both
fixed.
#4056: `hooks post-command` stored every Bash command in full with no off
switch. Add CLAUDE_FLOW_HOOKS_RECORD_COMMANDS=0 / CLAUDE_FLOW_HOOKS_ENABLED=false /
hooks.recordCommands=false (nothing is stored when off), redact common secret
shapes and cap stored text at 2000 chars (bounded patterns, linear on hostile
input). `memory cleanup --expired-only` never saw expired rows because
listEntries hides them (TTL is a read-time rule): listEntries gains
includeExpired + expiresAt, and memory_cleanup uses it. ruflo-core 0.2.8: the
Bash shim stands down when recording is off.
Co-Authored-By: RuFlo <ruv@ruv.net>
Rebased onto main, where ControllerRegistry and AgentDBBackend build AgentDB
inside withAgentdbLockRecovery(); useHostSqliteDriver() now runs inside that
closure right after each `new AgentDB`, so the instance a stale-lock retry
creates also opens its handle with getHostSqliteDriver(). Tests drive the
retry path for both sites.
@claude-flow/memory 3.0.3 was published by 3.56.3 without the driver, so
this ships as 3.0.4 and the CLI pins 3.0.4. The #3693 memory-owner test
now reports a skip when no native addon is available instead of passing.
Follow-up to the AgentDB driver change. shared-sqlite.ts (#3693/#3883)
resolved better-sqlite3 from agentdb's location so CLI handles share
AgentDB's native copy. With AgentDB now opened through
@claude-flow/memory's better-sqlite3, that put graph-edge-writer, the
memory-initializer repair paths, backup restore, distillation, tuning and
the attestation log back on agentdb's nested 11.x: `hooks post-task` still
loaded both addons (and aborted on Node 24), and mixing copies on one file
can delete the -wal/-shm sidecars under AgentDB's live handle.
- @claude-flow/memory exports getHostSqliteDriver(), the one source of the
constructor; useHostSqliteDriver() opens AgentDB with it and reports
whether it replaced the loader.
- shared-sqlite resolves better-sqlite3 from @claude-flow/memory when the
installed memory carries agentdb-native-driver.js, else from agentdb as
before, so either memory version keeps one copy per process.
- @claude-flow/memory 3.0.3, CLI pin 3.0.3 (leaf-publish gate).
Tests: identity between AgentDB's handle constructor and
loadBetterSqlite3(); #3693 owner model for the memory holder and the
pre-3.0.3 fallback; both AgentDB construction sites; routing against a
real nested copy; a drift guard on agentdb's initializeDatabase contract.
agentic-flow 3.0.0-alpha.1/.2 call their CLI main() at the bottom of
dist/index.js with no is-main guard (2.x has one). Importing the root as a
library therefore parses the host's process.argv: with `--help` it prints
agentic-flow's help and exits the host, with `mcp start` it would start its
MCP server, and with no agentic-flow flag it runs its demo agents with
whatever model credentials are in the environment, plus a health server on
:8080 and a runtime patch that rewrites files under node_modules.
The root import was only ever a fallback or a probe for exports that no
published root has (`embeddings`, `createAgenticFlow`, `VERSION`,
`configTuning`; checked 2.0.14, 2.1.4, 3.0.0-alpha.1/.2):
- cli memory-initializer: drop the dead root `embeddings` fallback.
- cli hooks token-optimize: drop the root availability fallback; the root
re-exports the same reasoningbank module the subpath check already loads.
- integration TokenOptimizer: detect agentic-flow from the reasoningbank /
agent-booster subpaths instead of the root.
- integration AgentAdapter, SwarmAdapter, AgenticFlowBridge: stop importing
the root for a `createAgenticFlow` factory no release exports; keep the
existing local-implementation path and events.
- integration SDKBridge: use the baseline version instead of a root VERSION
export that does not exist.
- Point the "for ML embeddings" comments at agentic-flow/reasoningbank.
The regression test runs the CLI source in a child process with loader
hooks that replace the root entry with a marker, and scans v3 sources for
any root-entry import.
The status backfill set modified=true even when the UPDATE touched 0 rows, so
every open of an up-to-date store re-exported and rewrote the whole image; with
encryption at rest each write uses a fresh nonce, so read-only commands such as
'memory stats' changed the RFE1 bytes every call. Gate on getRowsModified().
Co-Authored-By: RuFlo <ruv@ruv.net>
The once-per-process warning added in the prior commit was keyed by a
single global boolean, so a process touching more than one RFE1-encrypted
dbPath (a custom dbPath passed to insertGraphEdge/queryEdgesBySource/
countGraphEdges, or any multi-store scenario) only ever warned for the
first path it happened to see — the second silently returned null with
zero diagnostic signal, reproducing the original bug's exact symptom for
that second store.
_warnedRfe1Encrypted: boolean -> _warnedRfe1EncryptedPaths: Set<string>,
keyed by path.resolve(dbPath), matching this module's existing per-path
convention (_dbPath). _resetRfe1WarningFlag() now clears the set.
Added a regression test: two distinct encrypted paths in one module
instance each get exactly one warning, and a repeat call on the first
path doesn't double-warn.
Co-Authored-By: RuFlo <ruv@ruv.net>
graph-edge-writer.ts's getBridgeDb() opened dbPath via `new BetterSqlite3(dbPath)`
with no RFE1 encryption-at-rest sniff. When CLAUDE_FLOW_ENCRYPT_AT_REST=1,
memory.db is an opaque encrypted blob; the native open throws SQLITE_NOTADB,
caught by a generic catch that returns null with zero diagnostic signal —
indistinguishable from a missing native module, a permissions failure, or
genuine corruption. Nothing stopped a caller from concluding the store was
broken and running the destructive `memory init`, which creates a fresh
EMPTY store instead of using the existing encrypted data. The underlying
corpus was never damaged, but nothing said so.
This implements only the narrow, safe guard (Option C) a prior automated
triage pass on this issue recommended as the scoped starting point. The two
bigger options are deliberately out of scope: teaching the external
@claude-flow/memory package to decrypt RFE1 natively is a different
package entirely, and an automatic decrypt-and-migrate has real
data-safety stakes that call for human judgment, not a guess.
getBridgeDb() now sniffs the file's header bytes (never buffering the
whole file — memory.db can be multi-GB) before attempting the native open,
using the existing isEncryptedBlob() primitive (encryption/vault.ts) the
same way commands/doctor.ts already does, reimplemented locally since a
memory-layer module must not depend on the command layer. If the file is
RFE1-encrypted, the native open is skipped entirely (it would only throw)
and a clear, once-per-process warning fires: the store is encrypted, this
is a known limitation not corruption, the data is NOT lost, and do NOT run
`memory init`. Every other failure mode is byte-for-byte unchanged.
Also fixed the three reachable call sites in agentdb-tools.ts
(graph-pathfinder's semantic, pagerank, and algorithm-dispatch branches)
that turned a null db handle into a hardcoded "try `memory init`" hint —
now they call the new isBridgeDbEncryptedAtRest() predicate first and
pick the correct hint. Checked hooks-tools.ts's own memory-init hint too;
it's in a vector-search fallback that never touches getBridgeDb/
insertGraphEdge, so it's unreachable from this path and was left alone.
Added graph-edge-writer-rfe1-guard-2889.test.ts (4 tests): a genuinely
RFE1-encrypted file (real encryptBuffer/getKey, not a hand-faked prefix)
never reaches the native open and warns exactly once across repeated
calls; a genuinely corrupted non-encrypted file still reaches the native
open and does NOT produce the encrypted-store warning, proving the two
failure modes are actually distinguished; a normal plaintext memory.db is
unaffected. Spot-verified the core guard test is a real regression guard
by reverting it locally and confirming the test fails, then restoring it.
Existing graph-writer-shared-sqlite-3693.test.ts passes unmodified.
Co-Authored-By: RuFlo <ruv@ruv.net>
hasNativeWalSidecars() (#2735) refused every whole-image sql.js write/list
against memory.db whenever -wal/-shm sidecars merely existed on disk, on the
assumption that sidecars are only ever present while a native better-sqlite3
WAL connection is live. ruflo doctor breaks that assumption: it opens several
readonly native connections for diagnostics and closes them with a plain
.close(), which does not checkpoint and leaves orphaned sidecars behind. Once
that happens, every later memory store/list in the project fails permanently
with a misleading "active native WAL connection" error until someone deletes
the sidecar files by hand — the tool users are told to run when something is
wrong is what causes this.
hasNativeWalSidecars() now probes liveness in two steps instead of trusting
presence alone: 1) open our own connection and run
wal_checkpoint(TRUNCATE) — busy !== 0 means a real holder has an open
transaction right now, refuse immediately (also truncates a genuinely
orphaned WAL as a side effect); 2) otherwise close our probe connection and
re-check whether the sidecars are still on disk. SQLite only deletes
-wal/-shm when the last connection closes, so if nothing else is attached,
our own close is that last close and the sidecars vanish — safe to proceed.
If they're still present after our own close, some other connection remains
attached even though idle (holding no lock, so step 1 alone would have
missed it) — still refuse. This preserves #2735's guarantee for a genuinely
live holder (including the idle-but-attached case #3397's test exercises)
while fixing the false positive from an orphan. The no-sidecar fast path is
unchanged: a couple of existsSync calls, no database connection opened.
Rewrote issue-2735's and memory-cli-mirror-removal's sidecar fixtures to use
real WAL-mode databases with genuine transactions instead of empty
touch-files, since presence-only fixtures no longer exercise anything
meaningful against a liveness-based gate. Added issue-3161-doctor-leak-
recovery.test.ts (reproduces doctor's actual leak pattern and confirms a
subsequent store/list self-heals instead of failing permanently) and
issue-3161-wal-liveness-probe.test.ts (genuine live writer still refused,
concurrent callers, probe-error fail-closed, no-sidecar fast path never
opens a connection).
Co-Authored-By: RuFlo <ruv@ruv.net>
- bridgeStorePattern no longer turns a bridgeStoreEntry {success:false} into a success receipt
- agentdb_pattern-store checks storeEntry's result in the registry-null fallback and refuses failed writes
- hooks pattern-store falls back to the direct store when the bridge write was refused
- graph writer, native recovery/repair and attestation open SQLite via the better-sqlite3 copy AgentDB resolves, so the idle close cannot strip a live AgentDB handle's WAL/SHM sidecars
Co-Authored-By: RuFlo <ruv@ruv.net>
The hook appends one bounded, masked, fail-open record per surfaced recall to
.claude-flow/data/recall-log.jsonl (digest of the prompt, ids/scores/ranks,
router pick; default on, RUFLO_RECALL_LOG=0 or recallLog.enabled=false to stop).
memory list --format json --embeddings adds each stored vector as int8+scale.
Helper manifest is NOT re-signed here; the integrator signs at release.
Co-Authored-By: RuFlo <ruv@ruv.net>
Follow-up to drakeo338's fix, closing the remaining gaps found in review:
- Keys: MCP memory_store rejected `../` in keys, but CLI `memory store`
and `memory_import` accepted it. The MCP rule (DANGEROUS_KEY_PATTERN)
is now exported through `memoryKeyError()` and used by all three;
import checks every key up front, so a bad file writes nothing. Keys
with a plain `/` (`probe/x`) stay legal.
- Purge: `purgeNamespace` used its own NAMESPACE_PATTERN, which rejected
`:`, so `team:alice` could be stored and exported but never purged. It
now uses `validateIdentifier`, like the other three operations.
- MCP memory_store: namespaces only faced the key blacklist, so
`proj/sub` was accepted there but rejected by export and purge. It now
uses `validateIdentifier` too.
Tests added to memory-store-import-namespace-3570.test.ts: each gap fails
on the prior head and passes here, plus a round-trip table asserting that
CLI store, MCP store and purge accept exactly the namespaces export
accepts.
Co-Authored-By: drakeo338 <drakeo338@users.noreply.github.com>
Co-Authored-By: RuFlo <ruv@ruv.net>
* dream(intelligence): #3394 fix inverted EMA direction in EWCConsolidator.updateFisherFromConfidences()
EWCConsolidator.updateFisherFromConfidences() (v3/@claude-flow/cli/src/memory/ewc-consolidation.ts),
the Fisher-matrix EMA update wired into production at intelligence.ts:413 after every SONA
distillLearning() pass, used globalFisher[i] = alpha*old + (1-alpha)*new with alpha=fisherDecayRate
(0.01) -- giving the new batch 99% weight and the accumulated Fisher signal only 1%, discarding
~99% of accumulated importance on every call. Inverted vs. the two sibling globalFisher-updating
methods in the same class (computeFisherMatrix(), recordGradient()), which correctly do
(1-decay)*old + decay*new. Confirmed against the standard online-EWC/EWC++ convention (Chaudhry
et al., ECCV 2018, arXiv:1801.10112).
Fixed to match the sibling sites. Added a discriminating regression test
(__tests__/ewc-fisher-ema-direction.test.ts): baseline-fails/candidate-passes verified via git
stash isolation, independently reproduced by an adversarial critic. Full @claude-flow/cli suite
byte-identical failure set both ways (96 pre-existing, unbuilt-dist class); 155/155 in EWC-adjacent
tests; tsc --noEmit identical (463 pre-existing errors, none in changed files).
Darwin skipped (binary correctness fix, no fitness gradient to search). No Flywheel state exists
in this repo; evidence retained as tests + issue + gist + stash-isolated proof, per every accepted
night since 2026-08-18.
See issue #3394 for the full evaluation receipt, adversarial critique, and witness stamp.
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_0183FfWhMHJ2EjZb2MjxZfpJ
* dream(intelligence): #3394 update ledger with 2026-09-22 row + 09-15..09-21 backlog note
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_0183FfWhMHJ2EjZb2MjxZfpJ
* dream(intelligence): #3394 harden updateFisherFromConfidences() per review
Addresses ruvnet's REJECT review on #3395 (evidence-gate review at 1cc7231):
the EMA-direction fix itself was confirmed correct (retention 1.01e-8% ->
95.099% after 5 low-signal updates), but the function had no defenses
against malformed input or a corrupted persisted state file.
- updateFisherFromConfidences(): drop a sample whose embedding or
oldConf/newConf is non-finite (NaN/Infinity) instead of letting it poison
the shared globalFisher accumulator for every other pattern in the batch;
a batch where no sample contributes (all filtered out, or every delta was
zero) now leaves globalFisher and persisted state untouched instead of
decaying accumulated importance toward an empty no-op batch and writing
that no-op to disk.
- loadFromDisk(): validate the loaded globalFisher (exact dimensions, every
entry a finite non-negative number -- Fisher values are sums of squares
and can never legitimately be negative) and quarantine (reset to zero)
the whole array if invalid, rather than silently resuming with corrupted
entries (e.g. a non-finite value that round-tripped through JSON as
`null`).
- 3 new regression tests: non-finite input dropped without poisoning state,
no-op update doesn't persist, corrupted persisted state is quarantined
on load. All 3 independently confirmed to fail against the pre-hardening
code via git stash isolation.
158/158 EWC-adjacent tests passing (153 pre-existing + 5 EMA-direction +
3 new hardening); tsc --noEmit identical (463 pre-existing errors, none in
changed files).
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_0183FfWhMHJ2EjZb2MjxZfpJ
* dream(intelligence): #3394 rebind witness to the hardened candidate commit
Addresses the last item of ruvnet's REJECT review on #3395: the original
witness bound "session commit" to the pre-session base commit
(9c61c86, computed at STEP 0 before any diff existed), which didn't
actually bind the receipt to the candidate that was reviewed. Rebound to
290959f (the hardened candidate commit from the previous push) and
recomputed the gist SHA-256 + witness stamp against it.
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_0183FfWhMHJ2EjZb2MjxZfpJ
* dream(intelligence): #3394 update ledger with post-review hardening outcome
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_0183FfWhMHJ2EjZb2MjxZfpJ
---------
Co-authored-by: Claude <noreply@anthropic.com>