reconcileExternalRecords<V> function
Drops sidecar records whose element id is no longer live.
Mirrors the submit-time reconcile: deleting a chip's text deletes the chip, and reconciling at cleanup boundaries keeps orphans out of sends. Returns the removed records for temp-file cleanup.
Implementation
List<V> reconcileExternalRecords<V>(Map<int, V> records, Set<int> liveIds) {
final removed = <V>[];
for (final id in records.keys.toList(growable: false)) {
if (!liveIds.contains(id)) removed.add(records.remove(id) as V);
}
return removed;
}