Admit the existing runner with an explicit guest and QEMU memory budget

This commit is contained in:
dh
2026-10-05 13:09:47 +02:00
parent bcb24e82eb
commit ec5508e978
2 changed files with 26 additions and 3 deletions
+24 -3
View File
@@ -78,6 +78,7 @@ static class NativeDiagnostic
if (recoveryFormat is not ("dmg" or "raw")) throw new ArgumentException("Recovery format must be dmg or raw.");
if (args.Contains("--validate"))
{
ValidateRunnerMemoryGate();
ValidateContracts();
ValidateBootProgress();
ValidateDiskStackCapture(output);
@@ -168,9 +169,8 @@ static class NativeDiagnostic
throw new InvalidOperationException("Existing Docker resources cannot fit this bounded 2-CPU/6-GiB diagnostic; no infrastructure change was requested.");
}
await Command("sh", ["-c", "cat /proc/meminfo; printf '\n[cgroup]\n'; cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/cpu.max 2>/dev/null || true; printf '\n[workspace disk]\n'; df -Pk ."], output, "runner-resources", deadline.Token);
var available = System.Text.RegularExpressions.Regex.Match(File.ReadAllText("/proc/meminfo"), @"(?m)^MemAvailable:\s+(\d+) kB$");
if (!available.Success || long.Parse(available.Groups[1].Value) < 5L * 1024 * 1024)
throw new InvalidOperationException("Existing runner memory has less than the 5-GiB available diagnostic budget; no infrastructure change was requested.");
if (!HasAvailableGuestMemory(File.ReadAllText("/proc/meminfo")))
throw new InvalidOperationException("Existing runner memory cannot fit the 4-GiB guest plus its 512-MiB QEMU overhead budget; no infrastructure change was requested.");
var source = Path.Combine(work, "dockur");
await Command("git", ["clone", "--no-checkout", "https://github.com/dockur/macos.git", source], output, "dockur-clone", deadline.Token);
await Command("git", ["-C", source, "checkout", "--detach", DockurCommit], output, "dockur-checkout", deadline.Token);
@@ -481,6 +481,27 @@ static class NativeDiagnostic
File.WriteAllBytes(Path.Combine(probeAssets, "build-manifest.json"), probe.Manifest);
}
static bool HasAvailableGuestMemory(string meminfo)
{
var available = System.Text.RegularExpressions.Regex.Match(meminfo, @"(?m)^MemAvailable:\s+(\d+) kB$");
return available.Success && long.TryParse(available.Groups[1].Value, out var kib) && kib >= 4L * 1024 * 1024 + 512L * 1024;
}
static void ValidateRunnerMemoryGate()
{
// Run 4204: 4-GiB guest plus 512-MiB QEMU overhead fits its captured available memory.
var cases = new[]
{
("captured-run4204", "MemTotal: 16281732 kB\nMemAvailable: 5138696 kB\n", true),
("below-guest-plus-overhead", "MemAvailable: 4194304 kB\n", false),
("missing", "MemTotal: 16281732 kB\n", false),
("invalid", "MemAvailable: unavailable kB\n", false)
};
foreach (var (name, meminfo, expected) in cases)
if (HasAvailableGuestMemory(meminfo) != expected)
throw new InvalidOperationException("Existing runner memory admission failed: " + name);
}
static readonly string RawRecoveryPreparation = """
local raw="$dest.raw" pending="$dest.raw.tmp" source_hash after_hash raw_hash
[ ! -e "$raw" ] && [ ! -e "$pending" ] && [ ! -e "$raw.json" ] || {