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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(store): index the legacy fact probe [B29,C7]
Corey Olsonc602d1361d7b
diff --git a/src/fact-identity.js b/src/fact-identity.jsindex 3fd71a54..d0c4e1a0 100644--- a/src/fact-identity.js+++ b/src/fact-identity.js@@ -32,8 +32,14 @@ export function ensureFactIdentityIndexes(db) {*/export function factIdentityExists(db, id) {const tables = factTables(db);- const legacy = tables.some((table) => db.prepare(`SELECT 1 FROM ${table}- WHERE event_kind = 'fact' AND NOT json_valid(event_detail) LIMIT 1`).get());+ 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')) {diff --git a/test/query-plans.test.js b/test/query-plans.test.jsindex bde7ca1f..49b34419 100644--- a/test/query-plans.test.js+++ b/test/query-plans.test.js@@ -83,6 +83,14 @@ test('a new fact id is checked by index across current, legacy and archived fact.run(clock.now().toISOString(), 'coordinator', 'fact', second, JSON.stringify({ id: 'legacy-0', text: 'Historical duplicate retained' }));recordSchemaStamp(legacy, SCHEMA_DIGEST);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'));+ } 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,'read-only open never installs an additive index');