Replaying two same-time max_count rivals flips the current relation under supersede

Aperta
#338 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
databases

Direzione di ricerca

Start in src/selfgraph/_ops.py at _reasserts and trace how replayed relations with equal effective and invalidation times are handled; then check how Contradictions.settle ranks the tied rivals. Reproduce with the supplied script for both omitted and shared event_time. Done when repeated identical inserts keep the same relation current, with a regression test covering both cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

approved-for-pr area: write bug effort: S P2

What happens

Under contradiction="supersede", inserting the same facts again flips which relation is current at a max_count endpoint when two rival relations in the batch share an effective time. Each replay writes a new revision of the loser, which then wins, so the current fact alternates between runs.

This happens both when the relations have no event_time (the usual case for extracted text) and when they share one through the insert's event_time. With distinct event times the replay is stable.

docs/schema.md, "Reading and reasserting a retired relation", says replaying the same inputs is idempotent. Related to #48, but here nothing is restated with a different date: the input is identical every time.

Reproduce

On main (5a277c9), embedded Kuzu:

import asyncio, tempfile
from selfgraph import KuzuStore, SelfGraph

SCHEMA = {
    "entities": [{"name": "Person"}, {"name": "Company"}],
    "relations": [{"type": "WORKS_AT", "from": {"types": ["Person"], "max_count": 1}, "to": {"types": ["Company"]}}],
}
FACTS = {
    "entities": [{"type": "Person", "name": "Ann"}, {"type": "Company", "name": "Acme"},
                 {"type": "Company", "name": "Globex"}],
    "relations": [
        {"from_entity": "person:ann", "type": "WORKS_AT", "to_entity": "company:acme"},
        {"from_entity": "person:ann", "type": "WORKS_AT", "to_entity": "company:globex"},
    ],
}

async def main():
    with tempfile.TemporaryDirectory() as tmp:
        async with SelfGraph(store=KuzuStore(f"{tmp}/g.kuzu"), schema=SCHEMA, contradiction="supersede") as g:
            for i in range(3):
                await g.insert.facts(FACTS)
                rels = (await g.relations.list(include_invalidated=True)).items
                print(i, sorted((r.to_entity, r.revision, r.is_current) for r in rels))

asyncio.run(main())

Output:

0 [('company:acme', 1, False), ('company:globex', 1, True)]
1 [('company:acme', 2, True), ('company:globex', 1, False)]
2 [('company:acme', 2, False), ('company:globex', 2, True)]

insert.facts(FACTS, event_time="2024-01-01") prints the same sequence.

Cause

src/selfgraph/_ops.py, _reasserts: effective >= prev.invalidated_at counts a replay at the same time as a reassertion, so the retired rival comes back as a new revision. Contradictions.settle then ranks the tie the other way and retires the other one.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.