def flag_dirty_neighbors( driver: GraphDatabase, node_id: str, reason: str, ) -> list[str]: """ Flag the direct neighbors of a node for consistency recheck in the next ingestion cycle. """ with driver.session() as session: result = session.run(""" MATCH (n:Entity {id: $node_id})-[*1]-(neighbor:Entity) WHERE NOT neighbor.id = $node_id SET neighbor.dirty = true, neighbor.dirty_reason = $reason, neighbor.dirty_at = datetime() RETURN collect(DISTINCT neighbor.id) AS neighbor_ids """, node_id=node_id, reason=reason) return result.single()["neighbor_ids"]