newShellJobId function

String newShellJobId(
  1. int n
)

Globally-unique background job id: several fa processes share one workspace, so per-process counters alone (sh-1, sh-2) would make them append to the SAME .fah/bash_jobs/<id>.log and interleave each other's captured output. The microsecond stamp plus a random tail makes cross-process collisions practically impossible.

Implementation

String newShellJobId(int n) {
  final micros = DateTime.now().microsecondsSinceEpoch.toRadixString(36);
  // dart2js: shifts are 32-bit — `1 << 32` == 0, so nextInt(0) would throw
  // on web and kill every bash call (issue #1074). Spell the bound literally.
  final rand = _shellJobRandom.nextInt(0xFFFFFFFF).toRadixString(36);
  return 'sh-$n-$micros$rand';
}