test(agent): move the agent suites onto the memory contract (P1.5)
Rewrites the orchestrator, recall, compaction, save_memory and assembler suites for MemoryStore (createInMemoryMemoryStore; mem0 with the word embedder for the M3b integration test), string ids, async prompt building and setWorkspace(). Creation times are set with fake timers, since a write cannot set its own. Stores of Waggle's own data (identity, traces) are built on WaggleDB; the session-manager stubs use the new create() signature. Kept behaviour: importance lane (cap, active scope, temporary exclusion), profile and event lanes, date window and its fallback, catch-up, injection blocking of recall and preloaded context, autosave safety, decision consent, compaction update-in-place, reranker wiring. New tests: recall with a workspace active versus personal only; fetchRecentMemories ordering; toRecallFrame; context loader; save_memory routing, dedup, rate limit, dramatic-claim downgrade and contradiction scope; search_memory and search_all_workspaces; pattern write-back kinds, scopes and sign gate; read_other_workspace; reranker off unless WAGGLE_RERANKER=1, wider rerank pool, failure fallbacks. Deleted, because the behaviour is gone: - w46-rawdetail-recall.test.ts: the raw-turn (RAWDETAIL) recall lane. - orchestrator.test.ts, query_knowledge (3 tests) and the recall-hardening M4 "Key Knowledge" test: the knowledge graph is not in v1 (ADR-0002). - orchestrator-context-frames "profile override": scoring profiles. - Assertions on I/P frame types, GOP sessions, FTS rows, the "Memory Facts" lane, cognify stages and session/entity counts were replaced by the equivalent contract-level checks.
This commit is contained in:
@@ -1,43 +1,29 @@
|
||||
/**
|
||||
* R5 / R2 closure — the memory-loop sign gate must be closed *end to end*.
|
||||
*
|
||||
* R2 (commit 5592727) wired `isSelfIncapacityAssertion()` into the autoSave
|
||||
* `save()` chokepoint so DEFECT-2 poison is coerced to `temporary` importance.
|
||||
* Its stated contract (orchestrator.ts:751-757, memory-sign-gate.ts:14-18) is
|
||||
* that `temporary` frames are *recall-excluded* — "the recall path already
|
||||
* excludes `temporary` (see getRecentFrames)".
|
||||
* R2 wired `isSelfIncapacityAssertion()` into the autoSave `save()` chokepoint
|
||||
* so DEFECT-2 poison is coerced to `temporary` importance. Its contract
|
||||
* (memory-sign-gate.ts) is that `temporary` memories are *recall-excluded*.
|
||||
*
|
||||
* That is only true for the narrow `fetchRecentFrames` SQL path (catch-up /
|
||||
* workspace-recent). The dominant prompt recall path is `recallMemory()`'s
|
||||
* normal branch → `HybridSearch.search()`, which fetches frames with only
|
||||
* optional *temporal* filtering and applies `importance` as a scoring weight,
|
||||
* never an exclusion. So a sign-gated poison frame is still semantically
|
||||
* retrievable and re-enters the prompt — the loop the unit test never proved
|
||||
* closed because it only tested the classifier, not the round trip.
|
||||
*
|
||||
* This is the live, behavioral proof of the closed loop (TDD: RED on the
|
||||
* pre-fix code, GREEN after recallMemory excludes non-authoritative
|
||||
* importance).
|
||||
* Search ranks by relevance and does not filter on importance, so a
|
||||
* sign-gated memory is still retrievable by search; recallMemory must drop it
|
||||
* before it re-enters the prompt. This is the behavioral proof of the closed
|
||||
* loop, not just of the classifier.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { MindDB } from '@waggle/core';
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { createInMemoryMemoryStore, PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
|
||||
import { Orchestrator } from '../src/orchestrator.js';
|
||||
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
|
||||
|
||||
describe('R2 sign-gate is closed end-to-end (temporary excluded from semantic recall)', () => {
|
||||
let db: MindDB;
|
||||
let memory: MemoryStore;
|
||||
let orchestrator: Orchestrator;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new MindDB(':memory:');
|
||||
orchestrator = new Orchestrator({ db, embedder: new MockEmbedder() });
|
||||
memory = createInMemoryMemoryStore();
|
||||
orchestrator = new Orchestrator({ memory });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('does not surface a sign-gated (temporary) DEFECT-2 frame via recallMemory, but still recalls the authoritative decision', async () => {
|
||||
it('does not surface a sign-gated (temporary) DEFECT-2 memory via recallMemory, but still recalls the authoritative decision', async () => {
|
||||
// A self-incapacity assertion — the R2 save-side gate coerces this exact
|
||||
// class to `temporary` (orchestrator.ts:757). Seed it at the importance the
|
||||
// gate produces.
|
||||
@@ -57,20 +43,21 @@ describe('R2 sign-gate is closed end-to-end (temporary excluded from semantic re
|
||||
// Precondition: seeds landed at the intended importances (fences off the
|
||||
// save_memory dramatic-claim downgrade / dedup confounds — if either fired
|
||||
// this fails here with a clear signal rather than passing vacuously).
|
||||
const rows = db
|
||||
.getDatabase()
|
||||
.prepare('SELECT content, importance FROM memory_frames ORDER BY id')
|
||||
.all() as Array<{ content: string; importance: string }>;
|
||||
const poison = rows.find(r => r.content.includes('npm install -g @modelcontextprotocol'));
|
||||
const decision = rows.find(r => r.content.includes('connector is installed and wired'));
|
||||
expect(poison?.importance, 'poison frame must be stored as temporary').toBe('temporary');
|
||||
expect(decision?.importance, 'decision frame must be stored as important').toBe('important');
|
||||
const records = await memory.list({ scopes: [PERSONAL_SCOPE] });
|
||||
const poison = records.find(r => r.text.includes('npm install -g @modelcontextprotocol'));
|
||||
const decision = records.find(r => r.text.includes('connector is installed and wired'));
|
||||
expect(poison?.importance, 'poison memory must be stored as temporary').toBe('temporary');
|
||||
expect(decision?.importance, 'decision memory must be stored as important').toBe('important');
|
||||
|
||||
// The search itself still finds the poison; only recall may drop it.
|
||||
const hits = await memory.search('how do I install the mcp filesystem connector', { scopes: [PERSONAL_SCOPE] });
|
||||
expect(hits.some(h => h.text.includes('npm install -g @modelcontextprotocol'))).toBe(true);
|
||||
|
||||
const result = await orchestrator.recallMemory(
|
||||
'how do I install the mcp filesystem connector',
|
||||
);
|
||||
|
||||
// The closed-loop invariant: a sign-gated frame must NOT re-enter the
|
||||
// The closed-loop invariant: a sign-gated memory must NOT re-enter the
|
||||
// prompt as authoritative recall…
|
||||
expect(result.text).not.toContain('run npm install -g @modelcontextprotocol');
|
||||
// …while legitimate, authoritative memory on the same query still surfaces.
|
||||
|
||||
Reference in New Issue
Block a user