MemPalace/mempalace · error · ValueError
at={boundary!r} is before valid_from={valid_from!r}; an inve
Error message
at={boundary!r} is before valid_from={valid_from!r}; an inverted interval would be invisible to every KG query What it means
Raised by KnowledgeGraph.supersede() when the `boundary` timestamp that should close the old fact precedes that old fact's stored valid_from. supersede() closes the open old triple at `boundary` and opens the successor at the same instant; a boundary before the old start would create an inverted, query-invisible interval.
Source
Thrown at mempalace/knowledge_graph.py:443
for name, eid in ((subject, sub_id), (new_obj, new_id)):
conn.execute(
"INSERT OR IGNORE INTO entities (id, name) VALUES (?, ?)",
(eid, name),
)
# Reject a boundary that precedes the old fact's start — an
# inverted interval would be invisible to every KG query.
rows = conn.execute(
"SELECT valid_from FROM triples "
"WHERE subject=? AND predicate=? AND object=? AND valid_to IS NULL",
(sub_id, pred, old_id),
).fetchall()
for row in rows:
valid_from = row["valid_from"]
if valid_from is not None and _temporal_end_key(boundary) < _temporal_start_key(
valid_from
):
raise ValueError(
f"at={boundary!r} is before valid_from={valid_from!r}; "
"an inverted interval would be invisible to every KG query"
)
# Close the open old fact at the shared boundary.
conn.execute(
"UPDATE triples SET valid_to=? "
"WHERE subject=? AND predicate=? AND object=? AND valid_to IS NULL",
(boundary, sub_id, pred, old_id),
)
# Open the successor at the same instant (idempotent if already open).
existing = conn.execute(
"SELECT id FROM triples "
"WHERE subject=? AND predicate=? AND object=? AND valid_to IS NULL",
(sub_id, pred, new_id),
).fetchone()
if existing:View on GitHub (pinned to 06cb6987f0)
Solutions
- Look up the open old-fact triple's valid_from before superseding
- Set `at` to a boundary >= that valid_from (typically the real-world transition date)
- If the old fact's start is itself wrong, repair the triple directly rather than superseding with an invalid boundary
Example fix
# before
kg.supersede("Alice", "works_at", "Acme", "BizCo", at="2023-01-01") # old fact started 2024-01-01
# after
kg.supersede("Alice", "works_at", "Acme", "BizCo", at="2024-07-01") # boundary >= old valid_from Defensive patterns
Strategy: validation
Validate before calling
# before superseding, ensure boundary >= old fact's start
old = kg.get_open_triple(subject, predicate, old_obj) # returns valid_from
if old and old.valid_from and at < old.valid_from:
raise ValueError(f"boundary {at} precedes old start {old.valid_from}")
kg.supersede(subject, predicate, old_obj, new_obj, at=at) Try / catch
try:
kg.supersede(...)
except ValueError as e:
if "inverted interval" in str(e):
# old fact started later than `at`; fix the boundary or repair the old triple
...
raise Prevention
- Choose supersede boundaries from the same source timeline as the original facts
- For out-of-order event replays, sort events by timestamp before superseding
- Unit-test supersede with boundary == valid_from (allowed) and boundary < valid_from (rejected)
When it happens
Trigger: kg.supersede("Alice", "works_at", "Acme", "BizCo", at="2023-01-01") when the open Acme triple has valid_from="2024-01-01".
Common situations: Correcting history with an effective date earlier than the originally recorded start; timezone or date-precision mismatches between the boundary and the stored start; replaying an event log out of order so a later supersede carries an earlier timestamp.
Related errors
- {field_name} must be a string
- {field_name}={value!r} is not a valid ISO-8601 date or UTC d
- valid_to={valid_to!r} is before valid_from={valid_from!r}; a
- valid_to={ended!r} is before valid_from={valid_from!r}; an i
- {type(self).name} does not advertise supports_namespace_isol
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/41567611b5f9d35a.
Report an issue: GitHub.