def store_decision(dr_id, metadata, ancestors, descendants):
    # RocksDB writes
    rocks.put(f"meta:{dr_id}", serialize(metadata))

    for anc in ancestors:
        rocks.append_list(f"rev:{dr_id}", anc)
        rocks.append_list(f"fwd:{anc}", dr_id)

    # WAL append for sync
    wal.write({
        "type": "decision",
        "id": dr_id,
        "metadata": metadata,
        "ancestors": ancestors,
        "descendants": descendants
    })


def sync_to_sqlite():
    while True:
        batch = wal.read_batch(limit=100)
        if not batch:
            break
        with sqlite_conn:
            for entry in batch:
                if entry["type"] == "decision":
                    # Upsert into decisions table
                    sqlite_conn.execute("""
                        INSERT INTO decisions (id, statement, lifecycle_state, role_exposure, tags, timestamp)
                        VALUES (?, ?, ?, ?, ?, ?)
                        ON CONFLICT(id) DO UPDATE SET
                            statement=excluded.statement,
                            lifecycle_state=excluded.lifecycle_state,
                            role_exposure=excluded.role_exposure,
                            tags=excluded.tags,
                            timestamp=excluded.timestamp
                    """, (
                        entry["id"],
                        entry["metadata"]["statement"],
                        entry["metadata"]["lifecycle_state"],
                        json.dumps(entry["metadata"]["role_exposure"]),
                        json.dumps(entry["metadata"]["tags"]),
                        entry["metadata"]["timestamp"]
                    ))

                    # Edges
                    for anc in entry["ancestors"]:
                        sqlite_conn.execute("""
                            INSERT OR IGNORE INTO edges (source_id, target_id, relation)
                            VALUES (?, ?, ?)
                        """, (anc, entry["id"], "influences"))

                    for desc in entry["descendants"]:
                        sqlite_conn.execute("""
                            INSERT OR IGNORE INTO edges (source_id, target_id, relation)
                            VALUES (?, ?, ?)
                        """, (entry["id"], desc, "influences"))
        wal.mark_batch_complete(batch)
