Skip to content

ENG-2373 Share the relation triple matching rule in packages/database - #1527

Merged
maparent merged 2 commits into
mainfrom
eng-2373-share-the-relation-triple-matching-rule-in-packagesdatabase
Oct 7, 2026
Merged

maparent merged 2 commits into
mainfrom
eng-2373-share-the-relation-triple-matching-rule-in-packagesdatabase

Conversation

@maparent

@maparent maparent commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

https://entire.io/gh/DiscourseGraphs/discourse-graph/trails/76

Reviewer brief

  • Result: one copy of the relation triple matching rule, shared by both importers. ENG-2340 Import cross-space relations into Roam #1524 (ENG-2340) and ENG-2372 build on it.
  • Review focus: the matching rule in tripleMatching.ts. Two node types match strongly on the same RID, the same local id, or an import origin that links them (one imported from the other, or both from the same source); otherwise they match weakly on the normalized name. A candidate triple must match on both ends, the one with more strong matches wins, and a tie picks nothing. Then ROAM_DEFAULT_NODE_TYPE_IDS: Roam's default type ids are the same in every graph, so they match only by name. The list replaces Roam's INITIAL_NODE_VALUES import, and a guard test in ENG-2340 Import cross-space relations into Roam #1524 keeps the two equal.

Loom video

https://www.loom.com/share/93c233a0522c4542a159230a80f3e3a1

Scope check

  • Ran $scope-check against ENG-2373 and the final diff.
  • Scope beyond Done When: None.

Standards check

  • Ran $dg-pr-adherence-check against the final diff and PR metadata.

Local delegated full review

  • Ran a comprehensive review of the entire final diff in a subagent with a fresh context. Use $dg-delegated-full-review when no other full-review workflow is available.

https://linear.app/discourse-graphs/issue/ENG-2373/share-the-relation-triple-matching-rule-in-packagesdatabase


Devin Review

@linear-code

linear-code Bot commented Oct 7, 2026

Copy link
Copy Markdown

ENG-2373

@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
discourse-graph Ready Ready Preview Oct 7, 2026 4:56pm UTC

Request Review

@supabase

supabase Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +35 to +36
(sameValue(a.localId, b.localId) &&
!ROAM_DEFAULT_NODE_TYPE_IDS.has(a.localId!)) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Conflicting schema IDs select wrong triples

When distinct schemas reuse a non-default local ID, matchNodeTypes ranks them as a strong match despite conflicting RIDs. pickTripleCandidate can then prefer the wrong triple over a name-matched candidate.

Learn more

A RID identifies a schema together with its space, while a local ID only identifies it within one space. The matcher treats equal non-default local IDs as strong even when both available RIDs identify different schemas. The scorer then favors that candidate over a legitimate name match. The existing import matcher in findLocalNodeTypeMatch also reuses bare IDs, but this new matcher has both qualified identities available and uses its score to decide which source triple to select.

Example: The endpoint has {rid: 'orn:spaceA.schema:x', localId: 'x', name: 'Evidence'}. Candidate one has {rid: 'orn:spaceB.schema:x', localId: 'x', name: 'Question'}; candidate two has {rid: 'orn:spaceB.schema:y', localId: 'y', name: 'Evidence'}. Candidate one wins on ID despite its explicitly different RID and name.

Recommended fix: Restrict bare local-ID matches to cases without conflicting qualified RID or origin evidence; use matching RIDs and origin links to establish a strong cross-space match. Add a test with conflicting RIDs and equal local IDs.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


const normalizeName = (name: string): string => name.trim().toLowerCase();

// The same in every Roam graph; keep in sync with `type` in Roam's `defaultDiscourseNodes`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now defining these IDs in two places, so changes to Roam's defaults could leave this list out of sync. Could we use a single source of truth? If you decide to go this route, please request review again.

If we keep them separate, can we at least add a note in defaultDiscourseNodes.ts pointing here so it's clear both need updating? If we do that, let's also add the full path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept them separate and added a note with the full path on both sides. A test in ENG-2340 (apps/roam/src/utils/tests/roamDefaultNodeTypeIds.test.ts) checks that the two lists match.

@maparent
maparent merged commit 8fe68a7 into main Oct 7, 2026
11 of 12 checks passed
@maparent
maparent deleted the eng-2373-share-the-relation-triple-matching-rule-in-packagesdatabase branch October 7, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants