supertag-cli icon indicating copy to clipboard operation
supertag-cli copied to clipboard

Field-value references (Connected To, Related Project, etc.) not indexed as graph edges

Open evielync opened this issue 5 months ago • 1 comments

Version: 2.5.10

Description

Field-value node references — fields like Connected To, Related Project, Related People, Arena, Task Arena — are stored correctly in the field_values table but are never added to the references table. This means tana_related returns no connections for any relationship established via a reference-type field, even when those connections are clearly visible in Tana.

Steps to reproduce

  1. In Tana, create a node (e.g. an #issue) and set its Connected To field to a #thread node
  2. Call tana_related with the issue node's ID
  3. Observe: the thread connection does not appear in results

Root cause

The references table is only populated with inline_ref type entries (nodes mentioned inline in text as [[Node]]). Reference-type field values — where field_values.value_node_id points to another node — are not indexed here.

Scale of the gap:

-- Inline refs indexed (all that's currently in references table)
SELECT COUNT(*) FROM references WHERE reference_type = 'inline_ref';
-- Result: 5,793

-- Field-value references NOT indexed (missing graph edges)
SELECT COUNT(*) 
FROM field_values fv
JOIN nodes n_from ON fv.parent_id = n_from.id
JOIN nodes n_to ON fv.value_node_id = n_to.id
WHERE fv.value_node_id != '' AND fv.value_node_id != fv.value_text;
-- Result: 552,178

Top missing reference fields by count:

  • Related People: 5,486
  • Related Project: 4,069
  • Arena / Task Arena: 6,798 combined
  • Connected To: 307
  • Project: 217

Expected behaviour

tana_related should surface connections made via reference-type fields, not just inline text mentions. If I've explicitly connected an issue to a thread via the Connected To field, that relationship should be traversable.

Workaround

I'm currently running a post-sync script that injects field-value references into the references table as inline_ref edges after supertag sync index rebuilds it:

INSERT OR IGNORE INTO references (from_node, to_node, reference_type)
SELECT DISTINCT fv.parent_id, fv.value_node_id, 'inline_ref'
FROM field_values fv
JOIN nodes n_from ON fv.parent_id = n_from.id
JOIN nodes n_to ON fv.value_node_id = n_to.id
WHERE fv.value_node_id != '' AND fv.value_node_id != fv.value_text;

This injects ~550K edges and tana_related correctly surfaces field-value connections after. But it needs to run after every full reindex.

Suggested fix

During supertag sync index, when building the references table, also iterate field_values and add a field_ref (or separate type) entry for each row where value_node_id is a valid node reference. Ideally with the field name encoded so graph traversal can filter by relationship type (e.g. CONNECTED TO "thread" VIA "Connected To").

evielync avatar Jun 21 '26 03:06 evielync

Fixed in #121 (merged as 8c695a8). It ships in the next release.

What we found: the traversal already read reference-field values from field_values (parent_id → value_node_id) for both tana_related and gquery, so plain field connections were reachable without copying them into references. The real gaps:

  • CONNECTED TO <tag> VIA <field> checked that an edge was a field edge but never compared the field name, so VIA didn't filter anything. It now matches the field name, case-insensitively, in both directions. For example, FIND meeting CONNECTED TO person VIA Attendees now returns only attendees.
  • tana_related results didn't say which field an edge came from. Field edges now carry relationship.field (for example "Attendees").
  • Inverse field lookups (value_node_id = ?) had no index. There is one now, created on the next sync.

You shouldn't need the post-sync script that copies field_values into references, and it would make field edges show up as reference edges. If tana_related still misses a field connection after you upgrade, please reopen with the node ID and the field name.

jcfischer avatar Oct 21 '26 18:10 jcfischer