Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(core): index legacy fact identities without scans [B29,C7]

Corey Olson57bbddc39104
diff --git a/src/board.js b/src/board.js
index e9b990c6..e93b7ecf 100644
--- a/src/board.js
+++ b/src/board.js
@@ -142,6 +142,7 @@ import {
ensureFactIdentityIndexes,
factIdentityExists,
missingFactIdentityIndexes,
+ requireFactIdentityIndexes,
} from './fact-identity.js';
import { NEXT_STEPS } from './next-step-words.js';
import { boardWriteBusyError } from './board-busy.js';
@@ -1883,6 +1884,7 @@ export { itemThread } from './board-query.js';
* The internal factId is set from a sealed move's identity during replay, rather than replica-local sequence ids; a never-again with its cause is the person's alone, and rigor lists it at once (#713) [D1].
*/
export function appendFact(board, id, { agentId, kind, text, ref = null, supersedes = null, factId = randomUUID(), implies, cause = null, neverAgain = false, asPerson = false, channel = 'terminal' }) {
+ if (board.readOnly) requireFactIdentityIndexes(board.db);
return atomic(board, () => {
const item = current(board, itemById(board, id));
if (!board.db.prepare('SELECT 1 FROM agent WHERE agent_id = ?').get(agentId)) throw new Refused('NO_AGENT', `no registered agent ${agentId}; join a worktree before appending a fact`);
diff --git a/src/fact-identity.js b/src/fact-identity.js
index d0c4e1a0..0cd3cf6b 100644
--- a/src/fact-identity.js
+++ b/src/fact-identity.js
@@ -1,53 +1,78 @@
-/** Indexed global fact identities, preserving the original lookup for unindexed legacy JSON [B29,C7]. */
+/** Indexed global fact identities, including supported legacy JSON5 and SQLite JSONB [B29,C7]. */
+import { Refused } from './refused.js';
-/** Declare safe, nonunique indexes without rejecting legacy duplicate ids or invalid JSON. */
-export function factIdentityIndexSql(table) {
+const warnedUnknown = new WeakSet();
+
+/** Accept only the two physical history partitions when constructing additive index names. */
+function indexNames(table) {
if (!['event', 'event_archive'].includes(table)) throw new TypeError('fact identity indexes require an event table');
- return `CREATE INDEX IF NOT EXISTS ${table}_fact_identity ON ${table} (json_extract(event_detail, '$.id'))
- WHERE event_kind = 'fact' AND json_valid(event_detail);
- CREATE INDEX IF NOT EXISTS ${table}_fact_legacy ON ${table} (event_id)
- WHERE event_kind = 'fact' AND NOT json_valid(event_detail);`;
+ return { identity: `${table}_fact_identity_v2`, malformed: `${table}_fact_malformed_v2`, unknown: `${table}_fact_unknown_v2` };
+}
+
+/** Index readable identities and bounded error/unknown sentinels without parsing malformed rows. */
+export function factIdentityIndexSql(table) {
+ const names = indexNames(table);
+ return `CREATE INDEX IF NOT EXISTS ${names.identity} ON ${table} (json_extract(event_detail, '$.id'), event_id)
+ WHERE event_kind = 'fact' AND json_valid(event_detail, 10);
+ CREATE INDEX IF NOT EXISTS ${names.malformed} ON ${table} (event_id)
+ WHERE event_kind = 'fact' AND typeof(event_detail) = 'text' AND NOT json_valid(event_detail, 10);
+ CREATE INDEX IF NOT EXISTS ${names.unknown} ON ${table} (event_id)
+ WHERE event_kind = 'fact' AND typeof(event_detail) <> 'text' AND NOT json_valid(event_detail, 10);`;
}
-/** Discover only the two supported physical partitions; archived identities remain globally reserved. */
+/** List physical partitions in the original history lookup's hot-then-cold order. */
function factTables(db) {
return db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('event', 'event_archive') ORDER BY name")
.all().map(({ name }) => name);
}
-/** Find additive indexes missing from a legacy board without executing any DDL. */
+/** Old strict-JSON indexes never satisfy the current legacy-compatible readiness requirement. */
export function missingFactIdentityIndexes(db) {
- return factTables(db).filter((table) => db.prepare("SELECT count(*) AS n FROM sqlite_master WHERE type = 'index' AND name IN (?, ?)")
- .get(`${table}_fact_identity`, `${table}_fact_legacy`).n !== 2);
+ return factTables(db).filter((table) => {
+ const names = indexNames(table);
+ return db.prepare("SELECT count(*) AS n FROM sqlite_master WHERE type = 'index' AND tbl_name = ? AND name IN (?, ?, ?)")
+ .get(table, names.identity, names.malformed, names.unknown).n !== 3;
+ });
}
-/** Install additive indexes only when the owning writable opener calls the hot-index path. */
+/** Install additive indexes only through the owning writable opener's existing atomic restamp. */
export function ensureFactIdentityIndexes(db) {
for (const table of missingFactIdentityIndexes(db)) db.exec(factIdentityIndexSql(table));
}
+/** Refuse indexless appends without hidden nonowner DDL or a per-append history scan. */
+export function requireFactIdentityIndexes(db) {
+ if (missingFactIdentityIndexes(db).length) {
+ throw new Refused('FACT_INDEX_NOT_READY', 'fact identity indexes are missing; have the owning main checkout open this board once, then retry the original move');
+ }
+}
+
/**
- * Look up an identity without parsing every valid fact. Strict-invalid JSON can include legacy JSON5;
- * retain the original query for that history rather than silently ignoring it or changing its errors.
+ * Seek identities globally, retaining the original malformed-TEXT versus duplicate precedence.
+ * Unsupported corrupt non-TEXT history has unknown identity and one diagnostic per connection;
+ * native writers emit JSON text, and valid legacy JSON text BLOBs/JSONB remain indexed normally.
*/
-export function factIdentityExists(db, id) {
- const tables = factTables(db);
- const legacy = tables.some((table) => {
- // SQLite can prefer the broad kind index even when the partial legacy index is empty.
- // Older/non-owning stores may not have this additive index yet; keep their original lookup.
- const indexed = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = ? AND tbl_name = ?")
- .get(`${table}_fact_legacy`, table);
- return db.prepare(`SELECT 1 FROM ${table}${indexed ? ` INDEXED BY ${table}_fact_legacy` : ''}
- WHERE event_kind = 'fact' AND NOT json_valid(event_detail) LIMIT 1`).get();
- });
- if (legacy) {
- let history = 'event';
- if (tables.includes('event_archive')) {
- history = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'view' AND name = 'event_history'").get()
- ? 'event_history' : '(SELECT * FROM event UNION ALL SELECT * FROM event_archive)';
+export function factIdentityExists(db, id, { onDiagnostic = console.warn } = {}) {
+ requireFactIdentityIndexes(db);
+ for (const table of factTables(db)) {
+ const names = indexNames(table);
+ const unknown = db.prepare(`SELECT 1 FROM ${table} INDEXED BY ${names.unknown}
+ WHERE event_kind = 'fact' AND typeof(event_detail) <> 'text' AND NOT json_valid(event_detail, 10) LIMIT 1`).get();
+ if (unknown && !warnedUnknown.has(db)) {
+ warnedUnknown.add(db);
+ onDiagnostic('[FACT_ID_UNKNOWN] unsupported corrupt non-text fact history has an unknown identity; its stored event is unchanged');
+ }
+ const match = db.prepare(`SELECT CAST(event_id AS TEXT) AS event_id FROM ${table} INDEXED BY ${names.identity}
+ WHERE event_kind = 'fact' AND json_valid(event_detail, 10) AND json_extract(event_detail, '$.id') = ?
+ ORDER BY ${table}.event_id LIMIT 1`).get(id);
+ const malformed = db.prepare(`SELECT CAST(event_id AS TEXT) AS event_id FROM ${table} INDEXED BY ${names.malformed}
+ WHERE event_kind = 'fact' AND typeof(event_detail) = 'text' AND NOT json_valid(event_detail, 10)
+ ORDER BY ${table}.event_id LIMIT 1`).get();
+ if (malformed && (!match || BigInt(malformed.event_id) < BigInt(match.event_id))) {
+ db.prepare(`SELECT json_extract(event_detail, '$.id') FROM ${table} WHERE event_id = ?`).get(malformed.event_id);
+ throw new Error('malformed-text fact sentinel unexpectedly parsed; preserve the board and inspect its indexes');
}
- return Boolean(db.prepare(`SELECT 1 FROM ${history} WHERE event_kind = 'fact' AND json_extract(event_detail, '$.id') = ?`).get(id));
+ if (match) return true;
}
- return tables.some((table) => Boolean(db.prepare(`SELECT 1 FROM ${table}
- WHERE event_kind = 'fact' AND json_valid(event_detail) AND json_extract(event_detail, '$.id') = ?`).get(id)));
+ return false;
}
diff --git a/src/moves/appendFact.js b/src/moves/appendFact.js
index 3a0bce6e..482eeab8 100644
--- a/src/moves/appendFact.js
+++ b/src/moves/appendFact.js
@@ -25,6 +25,7 @@ export default Object.freeze({ operation: "appendFact", order: 40, engine: 1,
"BAD_FACT_ID": "upgrade to the current Pullboard engine, then retry the original fact operation",
"BAD_FACT_KIND": "use a supported kind, such as note: pullboard fact <id> note \"<what you observed>\"",
"EMPTY_FACT": "give nonempty fact text: pullboard fact <id> note \"<what you saw>\"",
+ "FACT_INDEX_NOT_READY": "have the owning main checkout open this board once, then retry the original fact operation",
"FACT_JUDGEMENT": "use a nonjudgement fact kind such as note, or ask the coordinator to record a judgement: pullboard fact <id> note \"<what you observed>\"",
"NO_AGENT": "create and join a lane worktree: pullboard worktree <lane> --model \"<model name>\"",
"NO_FACT": "name a fact id from pullboard show <id> --json"
diff --git a/test/query-plans.test.js b/test/query-plans.test.js
index 227e9d21..0d29351a 100644
--- a/test/query-plans.test.js
+++ b/test/query-plans.test.js
@@ -22,6 +22,10 @@ import { runFixtureChild, runFixtureGit } from './fixture-child.js';
import { applyEngineMove, prepareEngineMove } from '../src/engine.js';
import { recordSchemaStamp } from '../src/board-migrate.js';
import { SCHEMA_DIGEST } from '../src/board-schema-source.js';
+import {
+ ensureFactIdentityIndexes,
+ factIdentityExists,
+} from '../src/fact-identity.js';
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
const SERVE = pathToFileURL(resolve(import.meta.dirname, '../src/serve.js')).href;
@@ -55,7 +59,7 @@ test('a new fact id is checked by index across current, legacy and archived fact
const prepare = board.db.prepare.bind(board.db);
/** Record plans for actual duplicate checks without substituting their SQLite results. */
board.db.prepare = (sql) => {
- if (/^SELECT 1\b/iu.test(sql) && /json_(?:extract|valid)/u.test(sql)) {
+ if (/^SELECT\b/iu.test(sql) && /json_(?:extract|valid)/u.test(sql)) {
const bindings = sql.includes('?') ? ['fresh-identity'] : [];
plans.push({ sql, plan: prepare(`EXPLAIN QUERY PLAN ${sql}`).all(...bindings).map((row) => row.detail) });
}
@@ -67,8 +71,8 @@ test('a new fact id is checked by index across current, legacy and archived fact
assert.ok(identityPlans.length > 0, 'the real appendFact executed its identity lookup');
assert.ok(identityPlans.every(({ plan }) => plan.some((detail) => /SEARCH event\b.*<expr>=\?/u.test(detail))),
`new fact identity must search an expression index, not scan every fact: ${JSON.stringify(plans)}`);
- const legacyPlans = plans.filter(({ sql }) => sql.includes('NOT json_valid'));
- assert.ok(legacyPlans.length > 0 && legacyPlans.every(({ plan }) => plan.some((detail) => /USING (?:COVERING )?INDEX event_fact_legacy\b/u.test(detail))),
+ const legacyPlans = plans.filter(({ sql }) => sql.includes('NOT json_valid') && sql.includes("typeof(event_detail) = 'text'"));
+ assert.ok(legacyPlans.length > 0 && legacyPlans.every(({ plan }) => plan.some((detail) => /USING (?:COVERING )?INDEX event_fact_malformed_v2\b/u.test(detail))),
`legacy detection must read only its partial legacy index: ${JSON.stringify(plans)}`);
assert.throws(() => store.appendFact(board, second, options('fresh-identity')), { code: 'BAD_FACT_ID' }, 'identity is global across items');
assert.throws(() => store.appendFact(board, second, options('legacy-399')), { code: 'BAD_FACT_ID' });
@@ -76,7 +80,10 @@ test('a new fact id is checked by index across current, legacy and archived fact
store.closeBoard(board);
const legacy = new DatabaseSync(file);
// A synthetic physical cold partition exercises compatibility without importing unlanded retention code.
- legacy.exec('CREATE TABLE event_archive AS SELECT * FROM event WHERE 0; DROP INDEX event_fact_identity; DROP INDEX event_fact_legacy');
+ legacy.exec(`CREATE TABLE event_archive AS SELECT * FROM event WHERE 0;
+ DROP INDEX event_fact_identity_v2; DROP INDEX event_fact_malformed_v2;
+ CREATE INDEX event_fact_identity ON event(json_extract(event_detail,'$.id')) WHERE event_kind='fact' AND json_valid(event_detail);
+ CREATE INDEX event_fact_legacy ON event(event_id) WHERE event_kind='fact' AND NOT json_valid(event_detail);`);
legacy.prepare("INSERT INTO event_archive (event_id,event_at,event_by,event_kind,item_id,event_detail) VALUES (?,?,?,?,?,?)")
.run(900000, clock.now().toISOString(), 'coordinator', 'fact', first, JSON.stringify({ id: 'cold-identity', text: 'Cold legacy note' }));
legacy.prepare("INSERT INTO event (event_at,event_by,event_kind,item_id,event_detail) VALUES (?,?,?,?,?)")
@@ -85,21 +92,49 @@ test('a new fact id is checked by index across current, legacy and archived fact
legacy.close();
const older = store.openBoard(file, clock, { isMain: false });
try {
- assert.throws(() => store.appendFact(older, second, options('cold-identity')), { code: 'BAD_FACT_ID' },
- 'an older indexless store still reserves cold identities');
- store.appendFact(older, second, options('before-index-install'));
+ const before = older.db.prepare('SELECT * FROM event ORDER BY event_id').all();
+ const schema = older.db.prepare('SELECT type,name,sql FROM sqlite_master ORDER BY type,name').all();
+ assert.throws(() => store.appendFact(older, second, options('cold-identity')), { code: 'FACT_INDEX_NOT_READY' });
+ assert.throws(() => store.appendFact(older, second, options('before-index-install')), { code: 'FACT_INDEX_NOT_READY' });
+ assert.deepEqual(older.db.prepare('SELECT * FROM event ORDER BY event_id').all(), before, 'readiness refusal writes no native event');
+ assert.deepEqual(older.db.prepare('SELECT type,name,sql FROM sqlite_master ORDER BY type,name').all(), schema, 'nonowner append performs no index DDL');
} finally {
store.closeBoard(older);
}
const readonly = store.openBoardReadOnly(file);
- assert.equal(readonly.prepare("SELECT count(*) AS n FROM sqlite_master WHERE type='index' AND name LIKE '%_fact_%'").get().n, 0,
+ assert.equal(readonly.prepare("SELECT count(*) AS n FROM sqlite_master WHERE type='index' AND name LIKE '%_fact_%_v2'").get().n, 0,
'read-only open never installs an additive index');
readonly.close();
+ const reader = store.openBoardForRead(file, clock);
+ try {
+ assert.ok(store.listItems(reader).length >= 2, 'legacy reads require no fact index');
+ assert.throws(() => store.appendFact(reader, second, options('readonly-before-index-install')), { code: 'FACT_INDEX_NOT_READY' },
+ 'an explicit readonly append receives the owning-open step before attempting a write transaction');
+ } finally { store.closeBoard(reader); }
+ const beforeUpgrade = new DatabaseSync(file);
+ const upgradeSchema = beforeUpgrade.prepare('SELECT type,name,sql FROM sqlite_master ORDER BY type,name').all();
+ const upgradeEvents = beforeUpgrade.prepare('SELECT * FROM event ORDER BY event_id').all();
+ const upgradeMeta = beforeUpgrade.prepare('SELECT * FROM board_meta ORDER BY meta_key').all();
+ beforeUpgrade.close();
+ const originalExec = DatabaseSync.prototype.exec;
+ /** Fail the cold-partition install only after the hot indexes were really created in its transaction. */
+ DatabaseSync.prototype.exec = function (sql) {
+ if (sql.includes('CREATE INDEX IF NOT EXISTS event_archive_fact_identity_v2')) throw new Error('synthetic cold index install failure');
+ return originalExec.call(this, sql);
+ };
+ try { assert.throws(() => store.openBoard(file, clock), /synthetic cold index install failure/u); }
+ finally { DatabaseSync.prototype.exec = originalExec; }
+ const failedUpgrade = new DatabaseSync(file);
+ assert.deepEqual(failedUpgrade.prepare('SELECT type,name,sql FROM sqlite_master ORDER BY type,name').all(), upgradeSchema,
+ 'failed install rolls back every new hot/cold index');
+ assert.deepEqual(failedUpgrade.prepare('SELECT * FROM board_meta ORDER BY meta_key').all(), upgradeMeta, 'failed install preserves the schema stamp');
+ failedUpgrade.close();
board = store.openBoard(file, clock);
+ assert.deepEqual(board.db.prepare('SELECT * FROM event ORDER BY event_id').all(), upgradeEvents, 'owning-open upgrade preserves every native event');
assert.equal(board.db.prepare('PRAGMA user_version').get().user_version, 3, 'index upgrade preserves the existing data schema version');
assert.throws(() => store.appendFact(board, second, options('cold-identity')), { code: 'BAD_FACT_ID' }, 'cold identity remains reserved');
store.appendFact(board, second, options('after-migration'));
- const coldPlans = board.db.prepare("EXPLAIN QUERY PLAN SELECT 1 FROM event_archive WHERE event_kind='fact' AND json_valid(event_detail) AND json_extract(event_detail,'$.id')=?")
+ const coldPlans = board.db.prepare("EXPLAIN QUERY PLAN SELECT 1 FROM event_archive WHERE event_kind='fact' AND json_valid(event_detail,10) AND json_extract(event_detail,'$.id')=?")
.all('cold-identity').map((row) => row.detail);
assert.ok(coldPlans.some((detail) => /SEARCH event_archive\b.*<expr>=\?/u.test(detail)), JSON.stringify(coldPlans));
@@ -177,6 +212,79 @@ test('legacy fact SQL formats preserve parser outcomes [B29,C7]', (t) => {
console.log(JSON.stringify({ sqlite: db.prepare('SELECT sqlite_version() AS version').get().version, legacyFormatObservations: observations }));
});
+
+test('indexed legacy fact outcomes match the original lookup [B29,B31,C7]', (t) => {
+ /** Preserve the original SQL outcome, including native SQLite errors rather than a rewritten refusal. */
+ const outcome = (work) => {
+ try { return { value: work() }; }
+ catch (error) { return { code: error.code, errcode: error.errcode, message: error.message }; }
+ };
+ const cases = [
+ ['duplicate first', [[1, '{"id":"same"}'], [2, '{broken']], [], 'same'],
+ ['malformed first', [[1, '{broken'], [2, '{"id":"same"}']], [], 'same'],
+ ['new ID with malformed', [[1, '{"id":"other"}'], [2, '{broken']], [], 'new'],
+ ['JSON5 duplicate first', [[1, "{id:'same'}"], [2, '{broken']], [], 'same'],
+ ['hot duplicate before cold malformed', [[9, '{"id":"same"}']], [[1, '{broken']], 'same'],
+ ['hot malformed before cold duplicate', [[9, '{broken']], [[1, '{"id":"same"}']], 'same'],
+ ['cold duplicate first', [[9, '{"id":"other"}']], [[1, '{"id":"same"}'], [2, '{broken']], 'same'],
+ ['cold malformed first', [[9, '{"id":"other"}']], [[1, '{broken'], [2, '{"id":"same"}']], 'same'],
+ ['numeric duplicate order', [[2, '{"id":"same"}'], [3, '{broken'], [10, '{"id":"same"}']], [], 'same'],
+ ['numeric malformed order', [[2, '{broken'], [3, '{"id":"same"}'], [10, '{broken']], [], 'same'],
+ ['large event IDs', [[9007199254740993n, '{"id":"same"}'], [9007199254740994n, '{broken']], [], 'same'],
+ ['JSON text BLOB', [[2, Buffer.from('{"id":"same"}')]], [], 'same'],
+ ['native JSONB hot', [[2, { jsonb: '{"id":"same"}' }]], [], 'same'],
+ ['native JSONB cold', [], [[2, { jsonb: '{"id":"same"}' }]], 'same'],
+ ['JSON5 text BLOB', [], [[2, Buffer.from("{id:'same'}")]], 'same'],
+ ['valid scalar and absent identity', [[2, 'null'], [3, '42'], [10, '{"text":"kept"}']], [], 'new'],
+ ];
+ const observations = [];
+ for (const [name, rows, archive, id] of cases) {
+ const db = new DatabaseSync(':memory:');
+ t.after(() => db.close());
+ db.exec(`CREATE TABLE event(event_id INTEGER PRIMARY KEY,event_kind TEXT,event_detail TEXT NOT NULL);
+ CREATE INDEX event_kind_id ON event(event_kind,event_id);`);
+ if (archive.length) db.exec(`CREATE TABLE event_archive(event_id INTEGER PRIMARY KEY,event_kind TEXT,event_detail TEXT NOT NULL);
+ CREATE INDEX event_archive_kind_id ON event_archive(event_kind,event_id);`);
+ for (const [table, data] of [['event', rows], ['event_archive', archive]]) {
+ if (table === 'event_archive' && !archive.length) continue;
+ for (const [eventId, detail] of data) {
+ const value = detail?.jsonb ? db.prepare('SELECT jsonb(?) AS value').get(detail.jsonb).value : detail;
+ db.prepare(`INSERT INTO ${table} VALUES (?,'fact',?)`).run(eventId, value);
+ }
+ }
+ const history = archive.length ? '(SELECT * FROM event UNION ALL SELECT * FROM event_archive)' : 'event';
+ const old = outcome(() => Boolean(db.prepare(`SELECT 1 FROM ${history} WHERE event_kind='fact' AND json_extract(event_detail,'$.id')=?`).get(id)));
+ const native = db.prepare('SELECT CAST(event_id AS TEXT) AS event_id,event_kind,event_detail FROM event ORDER BY event.event_id').all();
+ ensureFactIdentityIndexes(db);
+ const indexed = outcome(() => factIdentityExists(db, id));
+ observations.push({ name, old, indexed });
+ assert.deepEqual(indexed, old, name);
+ assert.deepEqual(db.prepare('SELECT CAST(event_id AS TEXT) AS event_id,event_kind,event_detail FROM event ORDER BY event.event_id').all(), native,
+ `${name}: installing and looking up the index preserves native rows`);
+ }
+ const unknown = new DatabaseSync(':memory:');
+ t.after(() => unknown.close());
+ unknown.exec(`CREATE TABLE event(event_id INTEGER PRIMARY KEY,event_kind TEXT,event_detail TEXT NOT NULL);
+ CREATE TABLE event_archive(event_id INTEGER PRIMARY KEY,event_kind TEXT,event_detail TEXT NOT NULL);`);
+ const jsonb = unknown.prepare("SELECT jsonb(?) AS value").get('{"id":"unsupported-id","unused":{"tail":123}}').value;
+ const corrupt = Uint8Array.from(jsonb);
+ corrupt[corrupt.length - 1] = 255;
+ unknown.prepare("INSERT INTO event VALUES (2,'fact',?)").run(corrupt);
+ unknown.prepare("INSERT INTO event_archive VALUES (10,'fact',?)").run(corrupt);
+ const messages = [];
+ ensureFactIdentityIndexes(unknown);
+ const unsupportedBefore = unknown.prepare('SELECT * FROM event').all();
+ const observe = { onDiagnostic: line => messages.push(line) };
+ assert.equal(factIdentityExists(unknown, 'unsupported-id', observe), false, 'coordinator27318: corrupt non-TEXT identity is unknown');
+ assert.equal(factIdentityExists(unknown, 'another-id', observe), false);
+ assert.equal(messages.length, 1, 'one named line per open connection, no diagnostic flood');
+ assert.match(messages[0], /^\[FACT_ID_UNKNOWN\]/u);
+ assert.deepEqual(unknown.prepare('SELECT * FROM event').all(), unsupportedBefore, 'unsupported history stays immutable');
+ const plans = unknown.prepare("EXPLAIN QUERY PLAN SELECT 1 FROM event INDEXED BY event_fact_unknown_v2 WHERE event_kind='fact' AND typeof(event_detail)<>'text' AND NOT json_valid(event_detail,10) LIMIT 1").all();
+ assert.ok(plans.some(row => /USING (?:COVERING )?INDEX event_fact_unknown_v2/u.test(row.detail)), JSON.stringify(plans));
+ console.log(JSON.stringify({ legacyOutcomeOracle: observations }));
+});
+
after(() => {
for (const dir of sandboxes) rmSync(dir, { recursive: true, force: true });
});