readCurrentPatch method

Future<SankofaCurrentPatch?> readCurrentPatch()

Returns metadata for the patch currently believed to be live on this device. The SDK reads the last_good/patch.skdp envelope — the patch that survived a notifyKbcPatchReady confirmation — and surfaces its label.

Returns null when no patch has ever been promoted (the app is running its baseline AOT code).

final current = await Sankofa.instance.deploy?.readCurrentPatch();
setState(() => _patchLabel = current?.label ?? 'baseline');

Implementation

Future<SankofaCurrentPatch?> readCurrentPatch() async {
  final path = await _kbcSlotPath(_kbcSlotLastGood);
  final file = File(path);
  if (!file.existsSync()) return null;
  try {
    final bytes = await file.readAsBytes();
    final env = parseKbcEnvelope(bytes);
    final label = env.metadata['label']?.toString();
    if (label == null || label.isEmpty) return null;
    final releaseId = env.metadata['release_id']?.toString();
    final stamped = env.metadata['issued_at_unix_ms'];
    DateTime? appliedAt;
    if (stamped is num) {
      appliedAt = DateTime.fromMillisecondsSinceEpoch(stamped.toInt());
    }
    return SankofaCurrentPatch(
      label: label,
      releaseId: releaseId,
      appliedAt: appliedAt,
    );
  } catch (e) {
    if (kDebugMode) {
      debugPrint('[Sankofa.deploy] readCurrentPatch: $e');
    }
    return null;
  }
}