Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xK3vin MegaMemory Timeline Reconstruction

From Leeroopedia
Knowledge Sources
Domains Timeline, Temporal_Queries, Data_Reconstruction
Last Updated 2026-10-27 12:00 GMT

Overview

A reconstruction technique that builds a chronological event timeline by merging explicitly logged events with synthetic events inferred from entity timestamps, then supports point-in-time graph reconstruction.

Description

Timeline reconstruction combines two sources of historical data: (1) an explicit timeline table where each tool call logs a row (tool name, params, result summary, affected IDs, timestamp), and (2) synthetic entries reconstructed from entity timestamp fields (created_at, updated_at, removed_at). The two sources are merged and deduplicated by (tool, affected_id) — real timeline entries take precedence, and synthetic entries fill gaps where logging was absent (e.g., older data pre-dating the timeline table). The same timestamp infrastructure enables time-travel: reconstructing the graph as it existed at any past point.

Problem solved: A pure event log misses history that wasn't explicitly logged (legacy data, direct DB edits). A pure timestamp-inference approach misses the richness of logged params and results. Merging both gives the most complete timeline. Time-travel (point-in-time reconstruction) lets users see what the graph looked like at any moment, which is valuable for understanding how a project evolved.

Context: MegaMemory's buildMergedTimelineEntries (src/web.ts) merges real timeline table rows with synthetic entries from getAllNodesRaw timestamps. Deduplication filters out synthetic create/update/remove entries when a real entry with the same (tool, affected_id) exists. The source field reports which data contributed ("merged", "timeline", "node_timestamps"). Point-in-time reconstruction uses db.getNodesAtTime(t) (nodes where created_at <= t AND (removed_at IS NULL OR removed_at > t)) and db.getEdgesAtTime(t) (edges whose both endpoints were active at t).

Usage

Use this principle when:

  • You have an explicit event log but also entities with timestamps, and want a complete timeline
  • You need to reconstruct the state of a graph at an arbitrary past timestamp (time-travel)
  • Real log entries should take precedence over inferred entries (deduplication)
  • Legacy or externally-modified data lacks explicit logs but has timestamps to infer from

Theoretical Basis

Merged timeline: Let R be the set of real logged events and S the set of synthetic events inferred from timestamps. The merged timeline is:

T=R∪{s∈S:¬∃r∈R,key(r)=key(s)}

where Failed to parse (syntax error): {\displaystyle \text{key}(e) = (\text{tool}(e), \text{affected\_id}(e))} .

Point-in-time reconstruction: The graph at time t consists of nodes and edges active at t:

Failed to parse (syntax error): {\displaystyle N(t) = \{n : n.\text{created\_at} \leq t \wedge (n.\text{removed\_at} = \text{null} \vee n.\text{removed\_at} > t)\} }

Failed to parse (syntax error): {\displaystyle E(t) = \{e : e.\text{created\_at} \leq t \wedge e.\text{from} \in N(t) \wedge e.\text{to} \in N(t)\} }

Pseudo-code:

# Abstract merge (NOT real implementation)
def merged_timeline():
    real = db.get_timeline_entries()
    synthetic = []
    for node in db.get_all_nodes_raw():
        if node.created_at: synthetic.append(event("create_concept", node, node.created_at))
        if node.updated_at and node.updated_at != node.created_at:
            synthetic.append(event("update_concept", node, node.updated_at))
        if node.removed_at: synthetic.append(event("remove_concept", node, node.removed_at))
    # Dedup: drop synthetic if real has same (tool, affected_id)
    real_keys = {(e.tool, e.affected_id) for e in real}
    merged = real + [s for s in synthetic if (s.tool, s.affected_id) not in real_keys]
    return sort_by_timestamp(merged)

def graph_at_time(t):
    nodes = [n for n in db.all_nodes if n.created_at <= t
             and (n.removed_at is None or n.removed_at > t)]
    edges = [e for e in db.all_edges if e.created_at <= t
             and e.from in nodes and e.to in nodes]
    return nodes, edges

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment