Skip to content

fix(kg): dedupe tag/product vertex arms to stop KG Louvain job crash - #2496

Merged
jung-thomas merged 1 commit into
DEVfrom
worktree-kg-tag-vertex-dedupe
Sep 24, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
worktree-kg-tag-vertex-dedupe

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Problem

The kg-communities (Louvain) nightly job crashed on PROD (ScheduledJobFailed, 2026-09-24 03:57 UTC):

KG_LOUVAIN_GRAPH ... [4907] (range 3):
Column ...KG_PG_VERTICES_V.VERTEX_KEY contains duplicates or NULL values:
duplicate value in vertex key column

HANA's GraphEngine rejects the whole KG_PG_WORKSPACE when any VERTEX_KEY repeats, so this crashes all three nightly KG jobs (kg-pagerank, kg-communities/Louvain, kg-wcc).

Root cause

KG_PG_VERTICES_V's tag and product arms used SELECT DISTINCT, but both arms also select LABEL. Two Tags rows sharing the same NAME (or software-product> suffix) but differing in LABEL both survive DISTINCT and emit the same tag:<name> / product:<suffix> key twice — the exact trap the concept arm's header already warns about.

On PROD, sustainability for human capital management had two Tags rows whose LABEL differed only by a double space (Sustainability for... vs Sustainability for...), producing the duplicate key. (12 other tag NAMEs have multiple rows today with identical labels — masked by DISTINCT, but one label edit away from the same crash.)

Fix

Replace DISTINCT with the ROW_NUMBER() OVER (PARTITION BY ... ORDER BY LEGACYID DESC, ID) derived-table dedupe already used by the concept and teched arms — exactly one vertex per key regardless of label drift. Tags has no MODIFIEDAT, so ordering is by LEGACYID DESC, ID. The taggedWith/aboutProduct edge arms key their endpoint on NAME/suffix alone, so any surviving row keeps edge targets resolvable.

Validation (live PROD data, read-only)

Ran the rewritten arm SQL against the real prod HDI container:

Check Before After
tag arm total vs distinct keys 266 / 265 265 / 265
tag:sustainability for human capital management rows 2 1
product arm total vs distinct — 0 / 0 (no such tags in prod; guard is defense-in-depth)

Also extends test/hybrid/kg-vertex-dedupe.test.js with a tag-arm case seeding two rows (same NAME, differing LABEL) — the exact PROD shape.

Deploy note

This is an HDI view change — needs a DB deploy to take effect (the currently-deployed prod view still shows the 2× dup). Once deployed, the next KG job run recovers on its own (jobs are fail-open; no data backfill needed).

KG_PG_VERTICES_V's tag and product arms used SELECT DISTINCT, but both
arms also select LABEL. Two Tags rows sharing the same NAME (or product
suffix) but differing in LABEL therefore both survive DISTINCT and emit a
duplicate VERTEX_KEY. On PROD, 'sustainability for human capital
management' had two rows whose LABEL differed only by a double space,
producing a duplicate 'tag:<name>' key. HANA's GraphEngine rejects the
whole KG_PG_WORKSPACE on a duplicate vertex key ([4907] range 1),
crashing all three nightly KG jobs (kg-pagerank, kg-communities/Louvain,
kg-wcc). Alert: ScheduledJobFailed kg-communities, 2026-09-24.

Replace DISTINCT with the same ROW_NUMBER() OVER (PARTITION BY ...)
derived-table dedupe already used by the concept and teched arms, so
each key is emitted exactly once regardless of label drift. Tags has no
MODIFIEDAT column, so order by LEGACYID DESC, ID for determinism. The
taggedWith/aboutProduct edge arms key their tag/product endpoint on
NAME/suffix alone, so any surviving row keeps edge targets resolvable.

Validated against live PROD data: rewritten tag arm yields 265 rows /
265 distinct keys (was 266/265) and the known dup collapses to one
vertex; product arm stays consistent. Extends the hybrid dedupe test
with the exact PROD tag shape (same NAME, differing LABEL).
@jung-thomas
jung-thomas merged commit 8ea7b9a into DEV Sep 24, 2026
5 checks passed
@jung-thomas
jung-thomas deleted the worktree-kg-tag-vertex-dedupe branch September 24, 2026 12:05
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.

1 participant