inspect method

Future<LeaseInspect> inspect(
  1. String sessionFilePath
)

Reads and classifies the current lease for sessionFilePath. Corrupt/unreadable sidecar → free (E4, with the file simply overwritten by the next acquire).

Implementation

Future<LeaseInspect> inspect(String sessionFilePath) async {
  final raw = (await _env.readTextFile(
    sidecarPath(sessionFilePath),
  )).valueOrNull;
  if (raw == null) return LeaseInspect.free();
  final SessionLease lease;
  try {
    final decoded = jsonDecode(raw);
    if (decoded is! Map<String, dynamic>) return LeaseInspect.free();
    lease = SessionLease.fromJson(decoded);
  } on FormatException {
    return LeaseInspect.free();
  } on Object {
    return LeaseInspect.free();
  }
  // Staleness on the sidecar's mtime vs the reader clock (E1): the
  // filesystem's write clock is the one clock every host on the fabric
  // shares. The injectable [now] stands in for it in tests
  // ([MemoryExecutionEnv.setMtime] moves the file side too).
  final info = (await _env.fileInfo(
    sidecarPath(sessionFilePath),
  )).valueOrNull;
  final mtimeMs = info?.mtimeMs;
  if (mtimeMs == null) return LeaseInspect.free();
  final age = _now().millisecondsSinceEpoch - mtimeMs;
  if (age >= staleAfter.inMilliseconds) {
    return LeaseInspect.expired(lease);
  }
  return LeaseInspect.live(lease);
}