Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep uncertain catalog identities separate (#7901)
[._.]/ Adam Eivy884f1244d002
diff --git a/docs/features/catalog-ingest.md b/docs/features/catalog-ingest.mdindex d820475374..19b9f21fa1 100644--- a/docs/features/catalog-ingest.md+++ b/docs/features/catalog-ingest.md@@ -52,7 +52,10 @@ never successful empty drafts. Truly empty arrays are valid.## Chunk reconciliationChunk IDs are remapped before edges are combined. Type/name equality alone-never merges candidates. Only distinctive source identities or explicit,+never merges candidates. Generic source phrases and determiner-only aliases+never authorize a merge. A source identity needs at least two distinguishing+words beyond the entry labels and grammatical words; otherwise it stays a+separate candidate. Only distinctive source identities or explicit,unambiguous aliases can reconcile repeats; competing same-chunk candidates stayseparate. Supported fields/evidence are unioned, and a field conflict or capthat would lose information leaves separate review candidates instead.diff --git a/server/lib/catalogExtractionDraft.js b/server/lib/catalogExtractionDraft.jsindex 77ea76825b..191c64fba2 100644--- a/server/lib/catalogExtractionDraft.js+++ b/server/lib/catalogExtractionDraft.js@@ -62,6 +62,18 @@ export const emptyCatalogDraft = () => ({});const normalize = value => String(value || '').trim().replace(/\s+/g, ' ').toLowerCase();const unique = values => [...new Set(values)];+// A determiner, generic noun or single adjective is not a source identity.+// Require at least two distinguishing words beyond the candidate's own labels+// (e.g. an explicit owner or origin phrase). Uncertain repeats stay separate.+const IDENTITY_GLUE = new Set('a an the this that these those his her their its my our your of from to with at in on and by for'.split(' '));+const words = value => normalize(value).match(/[\p{L}\p{N}]+/gu) || [];+const aliasKey = value => normalize(value).replace(/^(?:a|an|the|this|that|his|her|their|its|my|our|your)\s+/, '');+function sourceIdentityKey(entry) {+ const identity = normalize(entry.sourceIdentity);+ const labels = new Set([entry.name, ...(entry.aliases || [])].flatMap(words));+ const distinguishing = new Set(words(identity).filter(word => !labels.has(word) && !IDENTITY_GLUE.has(word)));+ return distinguishing.size >= 2 ? identity : '';+}function sanitizeEntry(raw, type, factual) {const entry = type.extractionShape === 'bible'@@ -122,6 +134,7 @@ export function parseCatalogDraft(content, { corpus, factual = false, finishReasfunction mergeEntries(first, next, type) {const merged = { ...first };+ if (!merged.sourceIdentity && next.sourceIdentity) merged.sourceIdentity = next.sourceIdentity;for (const [key, value] of Object.entries(next)) {if (['draftId', 'sourceIdentity', 'name'].includes(key) || value == null || value === '') continue;const prev = merged[key];@@ -158,10 +171,10 @@ export function dedupDrafts(drafts = []) {})));const buckets = new Map();for (const node of nodes) {- const identity = normalize(node.entry.sourceIdentity);+ const identity = sourceIdentityKey(node.entry);const hints = [- ...(identity && identity !== normalize(node.entry.name) ? [`identity:${identity}`] : []),- ...unique([node.entry.name, ...(node.entry.aliases || [])].map(normalize)).filter(Boolean).map(value => `alias:${value}`),+ ...(identity ? [`identity:${identity}`] : []),+ ...unique([node.entry.name, ...(node.entry.aliases || [])].map(aliasKey)).filter(Boolean).map(value => `alias:${value}`),];for (const hint of hints) {if (!buckets.has(hint)) buckets.set(hint, []);@@ -172,7 +185,7 @@ export function dedupDrafts(drafts = []) {for (const [hint, bucket] of buckets) {// A repeated token in ONE chunk names multiple candidates: ambiguous.if (bucket.length < 2 || new Set(bucket.map(node => node.chunk)).size !== bucket.length) continue;- if (hint.startsWith('alias:') && !bucket.some(node => (node.entry.aliases || []).some(alias => `alias:${normalize(alias)}` === hint))) continue;+ if (hint.startsWith('alias:') && !bucket.some(node => (node.entry.aliases || []).some(alias => aliasKey(alias) !== aliasKey(node.entry.name) && `alias:${aliasKey(alias)}` === hint))) continue;const identities = unique(bucket.map(node => normalize(node.entry.sourceIdentity)).filter(Boolean));if (identities.length > 1) continue;for (const node of bucket) {diff --git a/server/lib/catalogExtractionDraft.test.js b/server/lib/catalogExtractionDraft.test.jsindex 6ce250a5a3..a16b77c6a1 100644--- a/server/lib/catalogExtractionDraft.test.js+++ b/server/lib/catalogExtractionDraft.test.js@@ -20,20 +20,41 @@ describe('catalog chunk graph identity', () => {expect(nameOnly.objects).toHaveLength(4);});+ it('does not use generic grounded identity phrases or determiner-only aliases to merge objects', () => {+ const make = description => parsed({ objects: [{ draftId: 'pistol', name: 'Pistol', aliases: ['the pistol'],+ sourceIdentity: 'the pistol', description, evidence: ['the pistol'] }] }, 'the pistol');+ const out = dedupDrafts([make('A guard’s pistol.'), make('A different traveler’s pistol.')]);+ expect(out.objects).toHaveLength(2);+ expect(out.objects.map(entry => entry.description)).toEqual(['A guard’s pistol.', 'A different traveler’s pistol.']);+ });++ it('retains an acquired identity so a later alias cannot bridge conflicting identities', () => {+ const make = (name, aliases, sourceIdentity) => parsed({ objects: [{ draftId: 'x', name, aliases,+ ...(sourceIdentity ? { sourceIdentity } : {}), evidence: ['source'] }] },+ 'source. First Label. Second Label. Third Label. pistol inherited from an aunt. pistol stolen from a guard.');+ const out = dedupDrafts([+ make('First Label', ['Second Label', 'Third Label']),+ make('Second Label', [], 'pistol inherited from an aunt'),+ make('Third Label', [], 'pistol stolen from a guard'),+ ]);+ expect(out.objects).toHaveLength(2);+ expect(out.objects.map(entry => entry.sourceIdentity)).toEqual(['pistol inherited from an aunt', 'pistol stolen from a guard']);+ });+it('unions supported facts/evidence and remaps repeated local IDs and duplicate edges', () => {const first = parsed({characters: [{ draftId: 'person', name: 'Example Captain', aliases: ['Rook'], evidence: ['Example Captain owns the inherited pistol'] }],- objects: [{ draftId: 'item', name: 'Pistol', sourceIdentity: 'inherited pistol', description: 'Inherited from an aunt.', evidence: ['inherited pistol'] }],+ objects: [{ draftId: 'item', name: 'Pistol', sourceIdentity: 'pistol inherited from an aunt', description: 'Inherited from an aunt.', evidence: ['inherited pistol'] }],relationships: [{ fromDraftId: 'item', toDraftId: 'person', kind: 'owned-by', evidence: 'Example Captain owns the inherited pistol' }],- }, 'Example Captain owns the inherited pistol. Example Captain is called Rook.');+ }, 'Example Captain owns the inherited pistol. Example Captain is called Rook. The pistol inherited from an aunt.');const second = parsed({characters: [{ draftId: 'person', name: 'Rook', background: 'Returns to the station.', evidence: ['Rook still owns the inherited pistol'] }],- objects: [{ draftId: 'item', name: 'Pistol', sourceIdentity: 'inherited pistol', description: 'Used to signal the train.', evidence: ['inherited pistol signals the train'] }],+ objects: [{ draftId: 'item', name: 'Pistol', sourceIdentity: 'pistol inherited from an aunt', description: 'Used to signal the train.', evidence: ['inherited pistol signals the train'] }],relationships: [{ fromDraftId: 'item', toDraftId: 'person', kind: 'owned-by', evidence: 'Rook still owns the inherited pistol' },{ fromDraftId: 'item', toDraftId: 'person', kind: 'owned-by', evidence: 'Rook still owns the inherited pistol' },],- }, 'Rook still owns the inherited pistol. The inherited pistol signals the train.');+ }, 'Rook still owns the inherited pistol. The inherited pistol signals the train. The pistol inherited from an aunt.');const out = dedupDrafts([first, second]);expect(out.characters).toHaveLength(1);expect(out.characters[0].background).toBe('Returns to the station.');@@ -48,8 +69,8 @@ describe('catalog chunk graph identity', () => {});it('keeps complete candidates when a merge would lose facts at a field cap', () => {- const make = letter => parsed({ objects: [{ draftId: 'x', name: 'Pistol', sourceIdentity: 'inherited pistol',- significance: letter.repeat(800), evidence: ['inherited pistol'] }] }, 'inherited pistol');+ const make = letter => parsed({ objects: [{ draftId: 'x', name: 'Pistol', sourceIdentity: 'pistol inherited from an aunt',+ significance: letter.repeat(800), evidence: ['inherited pistol'] }] }, 'inherited pistol. The pistol inherited from an aunt.');const out = dedupDrafts([make('a'), make('b')]);expect(out.objects).toHaveLength(2);expect(out.objects.map(entry => entry.significance)).toEqual(['a'.repeat(800), 'b'.repeat(800)]);