@calltelemetry/fmix 2.4.5 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fmix +528 -152
- package/package.json +3 -3
package/bin/fmix
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
# ./fmix cache explain --worktree <path> --cache-base <N.N.N-stable>
|
|
12
12
|
# ./fmix cache verify [--key <16-hex-template-key>]
|
|
13
13
|
# # seed publish is explicit clean-stable-only maintenance; cache explain is read-only
|
|
14
|
-
# ./fmix ensure
|
|
15
14
|
# ./fmix doctor
|
|
16
15
|
# ./fmix status
|
|
17
16
|
# ./fmix timing [--limit N] [--worktree <path>]
|
|
@@ -24,7 +23,7 @@ set -uo pipefail
|
|
|
24
23
|
# ---------------------------------------------------------------------------
|
|
25
24
|
# Constants & config
|
|
26
25
|
# ---------------------------------------------------------------------------
|
|
27
|
-
FMIX_VERSION="2.
|
|
26
|
+
FMIX_VERSION="2.5.0"
|
|
28
27
|
FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
|
|
29
28
|
FMIX_OS="$(uname -s)"
|
|
30
29
|
FMIX_ARCH="$(uname -m)"
|
|
@@ -32,6 +31,30 @@ FMIX_SESSION_SCHEMA="1"
|
|
|
32
31
|
FMIX_TEMPLATE_SCHEMA="1"
|
|
33
32
|
FMIX_CONFIG_HOME="${FMIX_CONFIG_HOME:-${XDG_CONFIG_HOME:-${HOME}/.config}/calltelemetry}"
|
|
34
33
|
FMIX_LOCK_TIMEOUT="${FMIX_LOCK_TIMEOUT:-900}" # 15 min template build wait
|
|
34
|
+
FMIX_INFRA_PROJECT="${FMIX_INFRA_PROJECT:-ct-infra}"
|
|
35
|
+
FMIX_INFRA_SCHEMA="1"
|
|
36
|
+
FMIX_ENSURE="${FMIX_ENSURE:-1}"
|
|
37
|
+
FMIX_ENSURE_TIMEOUT="${FMIX_ENSURE_TIMEOUT:-90}"
|
|
38
|
+
|
|
39
|
+
# Run-observability / telemetry state (restored with the subsystem).
|
|
40
|
+
FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_MAX_S="10"
|
|
41
|
+
FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_S="${FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_S:-2}"
|
|
42
|
+
FMIX_RESOURCE_SAMPLE_MAX_SAMPLES="${FMIX_RESOURCE_SAMPLE_MAX_SAMPLES:-14400}"
|
|
43
|
+
FMIX_RESOURCE_SAMPLE_MAX_SAMPLES_LIMIT="86400"
|
|
44
|
+
FMIX_RUN_CACHE_HOT="no"
|
|
45
|
+
FMIX_RUN_HOT_PATH="no"
|
|
46
|
+
FMIX_RUN_OBSERVABILITY_DEGRADED=0
|
|
47
|
+
FMIX_RUN_OBSERVABILITY_DIR=""
|
|
48
|
+
FMIX_RUN_OBSERVABILITY_ENABLED=0
|
|
49
|
+
FMIX_RUN_OBSERVABILITY_FINISHED=0
|
|
50
|
+
FMIX_RUN_OBSERVABILITY_LAUNCHER_PID=""
|
|
51
|
+
FMIX_RUN_OBSERVABILITY_PHASE="session"
|
|
52
|
+
FMIX_RUN_OBSERVABILITY_SAMPLER_PID=""
|
|
53
|
+
FMIX_RUN_OBSERVABILITY_SAMPLE_LIMIT="14400"
|
|
54
|
+
FMIX_RUN_OVERHEAD_S="0"
|
|
55
|
+
FMIX_RUN_TOTAL_S="0"
|
|
56
|
+
FMIX_TELEMETRY_TTL_HOURS="${FMIX_TELEMETRY_TTL_HOURS:-4}"
|
|
57
|
+
FMIX_TELEMETRY_TTL_MAX_HOURS="8760"
|
|
35
58
|
FMIX_LOCK_INIT_GRACE="${FMIX_LOCK_INIT_GRACE:-5}"
|
|
36
59
|
FMIX_LOCK_METADATA_TTL_DAYS="${FMIX_LOCK_METADATA_TTL_DAYS:-7}"
|
|
37
60
|
FMIX_WORKTREE_LOCK_TIMEOUT="${FMIX_WORKTREE_LOCK_TIMEOUT:-360}"
|
|
@@ -44,12 +67,6 @@ FMIX_SESSION_TTL_DEFAULT="1"
|
|
|
44
67
|
FMIX_SESSION_TTL_DAYS="${FMIX_SESSION_TTL_DAYS-}"
|
|
45
68
|
FMIX_SESSION_TTL_HOURS="${FMIX_SESSION_TTL_HOURS-}"
|
|
46
69
|
FMIX_SESSION_TTL_DEFAULT_HOURS="4"
|
|
47
|
-
FMIX_TELEMETRY_TTL_HOURS="${FMIX_TELEMETRY_TTL_HOURS:-4}"
|
|
48
|
-
FMIX_TELEMETRY_TTL_MAX_HOURS="8760"
|
|
49
|
-
FMIX_RESOURCE_SAMPLE_MAX_SAMPLES="${FMIX_RESOURCE_SAMPLE_MAX_SAMPLES:-14400}"
|
|
50
|
-
FMIX_RESOURCE_SAMPLE_MAX_SAMPLES_LIMIT="86400"
|
|
51
|
-
FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_S="${FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_S:-2}"
|
|
52
|
-
FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_MAX_S="10"
|
|
53
70
|
FMIX_SESSION_WARN_THRESHOLD="${FMIX_SESSION_WARN_THRESHOLD:-24}"
|
|
54
71
|
FMIX_COPY_MODE="${FMIX_COPY_MODE:-}" # override: "full" to skip CoW
|
|
55
72
|
FMIX_HOST_TEST_LOCK="${FMIX_HOST_TEST_LOCK:-1}" # default: serialize only CREATE/DROP DATABASE on this host
|
|
@@ -111,10 +128,6 @@ DB_USER="${FMIX_DB_USER:-calltelemetry}"
|
|
|
111
128
|
DB_PASSWORD="${FMIX_DB_PASSWORD:-calltelemetry_dev_password}"
|
|
112
129
|
NATS_HOST="${FMIX_NATS_HOST:-localhost}"
|
|
113
130
|
NATS_PORT="${FMIX_NATS_PORT:-4222}"
|
|
114
|
-
FMIX_INFRA_PROJECT="${FMIX_INFRA_PROJECT:-ct-infra}"
|
|
115
|
-
FMIX_INFRA_SCHEMA="1"
|
|
116
|
-
FMIX_ENSURE="${FMIX_ENSURE:-1}"
|
|
117
|
-
FMIX_ENSURE_TIMEOUT="${FMIX_ENSURE_TIMEOUT:-90}"
|
|
118
131
|
|
|
119
132
|
# Fixed dev constant SECRET_KEY_BASE (64 hex chars — only used in test env)
|
|
120
133
|
SECRET_KEY_BASE="${FMIX_SECRET_KEY_BASE:-dev0000000000000000000000000000000000000000000000000000000000000001}"
|
|
@@ -238,16 +251,10 @@ fmix_python_bin() {
|
|
|
238
251
|
fi
|
|
239
252
|
}
|
|
240
253
|
|
|
241
|
-
# A valid harness run must enter the already-running Python supervisor before
|
|
242
|
-
# Bash initializes the rest of this large worker. The supervisor then execs
|
|
243
|
-
# this same immutable file once in reserved worker mode. Extracting the embedded
|
|
244
|
-
# source here avoids a second full top-level Bash initialization while keeping
|
|
245
|
-
# FMix a single portable executable and leaving sourced/ordinary commands
|
|
246
|
-
# unchanged.
|
|
247
254
|
fmix_run_early_supervisor() {
|
|
248
255
|
local py_bin bootstrap
|
|
249
256
|
py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
|
|
250
|
-
IFS= read -r -d '' bootstrap <<'FMIX_EARLY_PY'
|
|
257
|
+
IFS= read -r -d '' bootstrap <<'FMIX_EARLY_PY'
|
|
251
258
|
import os
|
|
252
259
|
import sys
|
|
253
260
|
|
|
@@ -273,6 +280,7 @@ supervisor_source = source[start:end].decode("utf-8")
|
|
|
273
280
|
sys.argv = ["-c", runner, *arguments]
|
|
274
281
|
exec(compile(supervisor_source, runner + "::<observability-supervisor>", "exec"))
|
|
275
282
|
FMIX_EARLY_PY
|
|
283
|
+
true
|
|
276
284
|
FMIX_VERSION="$FMIX_VERSION" exec "$py_bin" -c "$bootstrap" "$0" "$@"
|
|
277
285
|
}
|
|
278
286
|
|
|
@@ -382,8 +390,8 @@ fmix_heal_toolchain_stale_nifs() {
|
|
|
382
390
|
# which still considers the objects up to date.
|
|
383
391
|
#
|
|
384
392
|
# The symptom is silent and expensive: sippet's typed header parsers went
|
|
385
|
-
# dead, changing parsed SIP header shapes, and an OTP
|
|
386
|
-
#
|
|
393
|
+
# dead, changing parsed SIP header shapes, and an OTP A/B measured the wrong
|
|
394
|
+
# binary entirely (cisco-cdr API-3051).
|
|
387
395
|
#
|
|
388
396
|
# Stamp the ABI that produced the native artifacts and drop them whenever it
|
|
389
397
|
# changes. Warm runs on an unchanged toolchain pay a single string compare.
|
|
@@ -666,39 +674,6 @@ fmix_epoch() {
|
|
|
666
674
|
date +%s
|
|
667
675
|
}
|
|
668
676
|
|
|
669
|
-
# ---------------------------------------------------------------------------
|
|
670
|
-
# Run telemetry (phase timings + session identity)
|
|
671
|
-
# Written to $FMIX_HOME/logs/runs.jsonl on every test/setup/task finish.
|
|
672
|
-
# Human one-liner always on stderr; set FMIX_TIMING=1 for per-phase lines.
|
|
673
|
-
# ---------------------------------------------------------------------------
|
|
674
|
-
|
|
675
|
-
FMIX_RUN_CMD=""
|
|
676
|
-
FMIX_RUN_T0=""
|
|
677
|
-
FMIX_RUN_PHASE_T0=""
|
|
678
|
-
FMIX_RUN_PHASES="" # "name=seconds name=seconds ..."
|
|
679
|
-
FMIX_RUN_STARTED_AT=""
|
|
680
|
-
FMIX_RUN_WORKTREE=""
|
|
681
|
-
FMIX_RUN_TEMPLATE_KEY=""
|
|
682
|
-
FMIX_RUN_DB=""
|
|
683
|
-
FMIX_RUN_RC=""
|
|
684
|
-
FMIX_RUN_OBSERVABILITY_DIR=""
|
|
685
|
-
FMIX_RUN_OBSERVABILITY_ENABLED=0
|
|
686
|
-
FMIX_RUN_OBSERVABILITY_FINISHED=0
|
|
687
|
-
FMIX_RUN_OBSERVABILITY_DEGRADED=0
|
|
688
|
-
FMIX_RUN_OBSERVABILITY_PHASE="session"
|
|
689
|
-
FMIX_RUN_OBSERVABILITY_SAMPLER_PID=""
|
|
690
|
-
FMIX_RUN_OBSERVABILITY_SAMPLE_LIMIT="14400"
|
|
691
|
-
FMIX_RUN_OBSERVABILITY_LAUNCHER_PID=""
|
|
692
|
-
FMIX_RUN_TOTAL_S="0"
|
|
693
|
-
FMIX_RUN_CACHE_HOT="no"
|
|
694
|
-
FMIX_RUN_HOT_PATH="no"
|
|
695
|
-
FMIX_RUN_OVERHEAD_S="0"
|
|
696
|
-
FMIX_LAST_COMPILE_OUTCOME="" # stamp_hit | compiled | skipped | error
|
|
697
|
-
FMIX_LAST_COMPILE_FILES=""
|
|
698
|
-
FMIX_LAST_COMPILE_SECONDS=""
|
|
699
|
-
FMIX_LAST_COMPILE_LOG=""
|
|
700
|
-
FMIX_LAST_ARTIFACTS_OUTCOME="" # clone | adopt | skip | seed | error
|
|
701
|
-
|
|
702
677
|
fmix_run_id_is_valid() {
|
|
703
678
|
local run_id="${1:-}"
|
|
704
679
|
[[ "$run_id" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]]
|
|
@@ -774,7 +749,7 @@ fmix_run_observability_write_snapshot() {
|
|
|
774
749
|
FMIX_OBSERVABILITY_SESSION_ROOT="${FMIX_ACTIVE_SESSION_ROOT:-}" \
|
|
775
750
|
FMIX_OBSERVABILITY_DEGRADED="$FMIX_RUN_OBSERVABILITY_DEGRADED" \
|
|
776
751
|
FMIX_OBSERVABILITY_SAMPLE_LIMIT="$FMIX_RUN_OBSERVABILITY_SAMPLE_LIMIT" \
|
|
777
|
-
"$py_bin" - "$FMIX_RUN_OBSERVABILITY_DIR" <<'PY' 2>/dev/null
|
|
752
|
+
"$py_bin" - "$FMIX_RUN_OBSERVABILITY_DIR" <<'PY' 2>/dev/null
|
|
778
753
|
import datetime
|
|
779
754
|
import fcntl
|
|
780
755
|
import json
|
|
@@ -1016,6 +991,7 @@ if event_type:
|
|
|
1016
991
|
os.close(fd)
|
|
1017
992
|
os.chmod(events_path, 0o600)
|
|
1018
993
|
PY
|
|
994
|
+
[[ $? -eq 0 ]] || return 1
|
|
1019
995
|
}
|
|
1020
996
|
|
|
1021
997
|
fmix_run_observability_begin() {
|
|
@@ -1114,8 +1090,9 @@ fmix_run_observability_start_sampler() {
|
|
|
1114
1090
|
"$FMIX_RUN_OBSERVABILITY_DIR/.sampler-done" \
|
|
1115
1091
|
"$FMIX_RUN_OBSERVABILITY_DIR/.sampler-limit-reached" \
|
|
1116
1092
|
"$FMIX_RUN_OBSERVABILITY_DIR/metrics.jsonl"
|
|
1093
|
+
{
|
|
1117
1094
|
env -i PATH="$PATH" FMIX_OBSERVABILITY_MAX_SAMPLES="$max_samples" \
|
|
1118
|
-
"$py_bin" - "$FMIX_RUN_OBSERVABILITY_DIR" "$$" "$interval" <<'PY' >/dev/null 2>&1
|
|
1095
|
+
"$py_bin" - "$FMIX_RUN_OBSERVABILITY_DIR" "$$" "$interval" <<'PY' >/dev/null 2>&1
|
|
1119
1096
|
import datetime
|
|
1120
1097
|
import json
|
|
1121
1098
|
import math
|
|
@@ -1255,6 +1232,7 @@ except Exception as exc:
|
|
|
1255
1232
|
finally:
|
|
1256
1233
|
write_private_marker(done_path)
|
|
1257
1234
|
PY
|
|
1235
|
+
} &
|
|
1258
1236
|
FMIX_RUN_OBSERVABILITY_SAMPLER_PID=$!
|
|
1259
1237
|
return 0
|
|
1260
1238
|
}
|
|
@@ -1473,6 +1451,27 @@ fmix_run_telemetry_exclude_observability_elapsed() {
|
|
|
1473
1451
|
return 0
|
|
1474
1452
|
}
|
|
1475
1453
|
|
|
1454
|
+
# ---------------------------------------------------------------------------
|
|
1455
|
+
# Run telemetry (phase timings + session identity)
|
|
1456
|
+
# Written to $FMIX_HOME/logs/runs.jsonl on every test/setup/task finish.
|
|
1457
|
+
# Human one-liner always on stderr; set FMIX_TIMING=1 for per-phase lines.
|
|
1458
|
+
# ---------------------------------------------------------------------------
|
|
1459
|
+
|
|
1460
|
+
FMIX_RUN_CMD=""
|
|
1461
|
+
FMIX_RUN_T0=""
|
|
1462
|
+
FMIX_RUN_PHASE_T0=""
|
|
1463
|
+
FMIX_RUN_PHASES="" # "name=seconds name=seconds ..."
|
|
1464
|
+
FMIX_RUN_STARTED_AT=""
|
|
1465
|
+
FMIX_RUN_WORKTREE=""
|
|
1466
|
+
FMIX_RUN_TEMPLATE_KEY=""
|
|
1467
|
+
FMIX_RUN_DB=""
|
|
1468
|
+
FMIX_RUN_RC=""
|
|
1469
|
+
FMIX_LAST_COMPILE_OUTCOME="" # stamp_hit | compiled | skipped | error
|
|
1470
|
+
FMIX_LAST_COMPILE_FILES=""
|
|
1471
|
+
FMIX_LAST_COMPILE_SECONDS=""
|
|
1472
|
+
FMIX_LAST_COMPILE_LOG=""
|
|
1473
|
+
FMIX_LAST_ARTIFACTS_OUTCOME="" # clone | adopt | skip | seed | error
|
|
1474
|
+
|
|
1476
1475
|
fmix_run_telemetry_begin() {
|
|
1477
1476
|
local observability_started
|
|
1478
1477
|
FMIX_RUN_CMD="${1:-unknown}"
|
|
@@ -1608,7 +1607,7 @@ fmix_run_telemetry_finish() {
|
|
|
1608
1607
|
FMIX_ACTIVE_SESSION_SOURCE="${FMIX_ACTIVE_SESSION_SOURCE:-}" \
|
|
1609
1608
|
FMIX_ACTIVE_SESSION_ROOT="${FMIX_ACTIVE_SESSION_ROOT:-}" \
|
|
1610
1609
|
FMIX_VERSION="$FMIX_VERSION" \
|
|
1611
|
-
"$py_bin" - "$path" <<'PY' 2>/dev/null
|
|
1610
|
+
"$py_bin" - "$path" <<'PY' 2>/dev/null
|
|
1612
1611
|
import json, os, sys
|
|
1613
1612
|
path = sys.argv[1]
|
|
1614
1613
|
rec = {
|
|
@@ -1647,6 +1646,8 @@ if phases:
|
|
|
1647
1646
|
with open(path, "a", encoding="utf-8") as fh:
|
|
1648
1647
|
fh.write(json.dumps(rec, separators=(",", ":")) + "\n")
|
|
1649
1648
|
PY
|
|
1649
|
+
true
|
|
1650
|
+
true
|
|
1650
1651
|
}
|
|
1651
1652
|
|
|
1652
1653
|
fmix_iso_epoch() {
|
|
@@ -4479,10 +4480,16 @@ fmix_worktree_schema_manifest_is_prefix() {
|
|
|
4479
4480
|
}
|
|
4480
4481
|
|
|
4481
4482
|
fmix_read_state() {
|
|
4482
|
-
# Read a field from a
|
|
4483
|
+
# Read a field from a JSON state file (supports strings, numbers, booleans)
|
|
4483
4484
|
local state_file="$1" field="$2"
|
|
4484
|
-
|
|
4485
|
-
|
|
4485
|
+
[[ -f "$state_file" ]] || return 1
|
|
4486
|
+
local line
|
|
4487
|
+
line="$(grep -E "\"${field}\"[[:space:]]*:" "$state_file" 2>/dev/null | head -1)"
|
|
4488
|
+
if [[ "$line" =~ \"${field}\"[[:space:]]*:[[:space:]]*\"([^\"]*)\" ]]; then
|
|
4489
|
+
printf '%s\n' "${BASH_REMATCH[1]}"
|
|
4490
|
+
elif [[ "$line" =~ \"${field}\"[[:space:]]*:[[:space:]]*([0-9]+|true|false|null) ]]; then
|
|
4491
|
+
printf '%s\n' "${BASH_REMATCH[1]}"
|
|
4492
|
+
fi
|
|
4486
4493
|
}
|
|
4487
4494
|
|
|
4488
4495
|
fmix_write_worktree_state() {
|
|
@@ -4639,23 +4646,60 @@ fmix_lock_quarantine_metadata() {
|
|
|
4639
4646
|
}
|
|
4640
4647
|
|
|
4641
4648
|
fmix_lock_kernel_try() {
|
|
4642
|
-
local fd="$1" timeout="$2" py_bin
|
|
4643
|
-
py_bin="$(fmix_python_bin)"
|
|
4644
|
-
"$py_bin" - "$fd" "$timeout" <<'PY'
|
|
4649
|
+
local fd="$1" timeout="$2" diagnostic_name="${3:-${lock_name:-lock}}" lock_name="${4:-${diagnostic_name:-lock}}" py_bin
|
|
4650
|
+
py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
|
|
4651
|
+
"$py_bin" - "$fd" "$timeout" "$diagnostic_name" "$lock_name" "$FMIX_HOME" <<'PY'
|
|
4645
4652
|
import fcntl
|
|
4653
|
+
import json
|
|
4654
|
+
import os
|
|
4646
4655
|
import sys
|
|
4647
4656
|
import time
|
|
4657
|
+
from pathlib import Path
|
|
4648
4658
|
|
|
4649
4659
|
fd = int(sys.argv[1])
|
|
4650
4660
|
timeout = int(sys.argv[2])
|
|
4651
|
-
|
|
4661
|
+
diag_name = sys.argv[3] if len(sys.argv) > 3 and sys.argv[3] else "lock"
|
|
4662
|
+
lock_name = sys.argv[4] if len(sys.argv) > 4 and sys.argv[4] else diag_name
|
|
4663
|
+
fmix_home = sys.argv[5] if len(sys.argv) > 5 and sys.argv[5] else os.environ.get("FMIX_HOME", "")
|
|
4664
|
+
|
|
4665
|
+
start_time = time.monotonic()
|
|
4666
|
+
deadline = start_time + timeout
|
|
4667
|
+
last_heartbeat = start_time
|
|
4668
|
+
|
|
4669
|
+
def get_holder_info(lock_name, fmix_home):
|
|
4670
|
+
if not lock_name or not fmix_home:
|
|
4671
|
+
return "unknown", diag_name
|
|
4672
|
+
meta_path = Path(fmix_home) / "lock-metadata" / f"{lock_name}.json"
|
|
4673
|
+
if meta_path.is_file():
|
|
4674
|
+
try:
|
|
4675
|
+
d = json.loads(meta_path.read_text(encoding="utf-8"))
|
|
4676
|
+
return str(d.get("pid", "unknown")), d.get("purpose", diag_name)
|
|
4677
|
+
except Exception:
|
|
4678
|
+
pass
|
|
4679
|
+
legacy_pid = Path(fmix_home) / "locks" / lock_name / "pid"
|
|
4680
|
+
if legacy_pid.is_file():
|
|
4681
|
+
try:
|
|
4682
|
+
p = legacy_pid.read_text(encoding="utf-8").strip()
|
|
4683
|
+
if p:
|
|
4684
|
+
return p, diag_name
|
|
4685
|
+
except Exception:
|
|
4686
|
+
pass
|
|
4687
|
+
return "unknown", diag_name
|
|
4688
|
+
|
|
4652
4689
|
while True:
|
|
4653
4690
|
try:
|
|
4654
4691
|
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
4655
4692
|
raise SystemExit(0)
|
|
4656
4693
|
except BlockingIOError:
|
|
4657
|
-
|
|
4694
|
+
now = time.monotonic()
|
|
4695
|
+
if now >= deadline:
|
|
4658
4696
|
raise SystemExit(1)
|
|
4697
|
+
if now - last_heartbeat >= 15.0:
|
|
4698
|
+
elapsed = int(now - start_time)
|
|
4699
|
+
holder_pid, purpose = get_holder_info(lock_name, fmix_home)
|
|
4700
|
+
sys.stderr.write(f"[fmix] Waiting for lock '{lock_name}' ({elapsed}s elapsed, timeout {timeout}s, holder PID: {holder_pid}, purpose: \"{purpose}\") ...\n")
|
|
4701
|
+
sys.stderr.flush()
|
|
4702
|
+
last_heartbeat = now
|
|
4659
4703
|
time.sleep(0.05)
|
|
4660
4704
|
PY
|
|
4661
4705
|
}
|
|
@@ -4685,14 +4729,14 @@ fmix_lock_acquire() {
|
|
|
4685
4729
|
deadline=$(( $(fmix_epoch) + timeout ))
|
|
4686
4730
|
lock_dir="$FMIX_HOME/locks/$lock_name"
|
|
4687
4731
|
kernel_file="$FMIX_HOME/lock-kernel/$lock_name"
|
|
4688
|
-
mkdir -p "$FMIX_HOME/locks" "$FMIX_HOME/lock-kernel" || return 1
|
|
4732
|
+
mkdir -p "$FMIX_HOME/locks" "$FMIX_HOME/lock-kernel" "$FMIX_HOME/lock-metadata" || return 1
|
|
4689
4733
|
|
|
4690
4734
|
while true; do
|
|
4691
4735
|
fd="$(fmix_lock_allocate_fd)" || return 1
|
|
4692
4736
|
fmix_lock_open_fd "$fd" "$kernel_file" || return 1
|
|
4693
4737
|
local remaining=$(( deadline - $(fmix_epoch) ))
|
|
4694
4738
|
(( remaining >= 0 )) || remaining=0
|
|
4695
|
-
if ! fmix_lock_kernel_try "$fd" "$remaining"; then
|
|
4739
|
+
if ! fmix_lock_kernel_try "$fd" "$remaining" "$diagnostic_name" "$lock_name"; then
|
|
4696
4740
|
fmix_lock_close_fd "$fd"
|
|
4697
4741
|
fmix_error "Timed out waiting for kernel lock '$diagnostic_name' after ${timeout}s."
|
|
4698
4742
|
fmix_error "Inspect with: fmix status"
|
|
@@ -4779,6 +4823,18 @@ EOF
|
|
|
4779
4823
|
return 1
|
|
4780
4824
|
fi
|
|
4781
4825
|
|
|
4826
|
+
# Publish structured lock-metadata
|
|
4827
|
+
cat >"$FMIX_HOME/lock-metadata/${lock_name}.json" 2>/dev/null <<EOF
|
|
4828
|
+
{
|
|
4829
|
+
"lock_name": $(fmix_json_escape "$lock_name"),
|
|
4830
|
+
"pid": $$,
|
|
4831
|
+
"start_time": $(fmix_json_escape "$(fmix_now)"),
|
|
4832
|
+
"purpose": $(fmix_json_escape "$diagnostic_name"),
|
|
4833
|
+
"worktree": $(fmix_json_escape "${FMIX_ACTIVE_WORKTREE:-}")
|
|
4834
|
+
}
|
|
4835
|
+
EOF
|
|
4836
|
+
true
|
|
4837
|
+
|
|
4782
4838
|
FMIX_HELD_LOCK_NAMES+=("$lock_name")
|
|
4783
4839
|
FMIX_HELD_LOCK_FDS+=("$fd")
|
|
4784
4840
|
FMIX_HELD_LOCK_TOKENS+=("$token")
|
|
@@ -4814,6 +4870,8 @@ fmix_lock_release() {
|
|
|
4814
4870
|
return 1
|
|
4815
4871
|
fi
|
|
4816
4872
|
|
|
4873
|
+
rm -f "$FMIX_HOME/lock-metadata/${lock_name}.json" 2>/dev/null || true
|
|
4874
|
+
|
|
4817
4875
|
destination="$FMIX_HOME/lock-metadata/released/${lock_name}.$(fmix_epoch).$$.${RANDOM}"
|
|
4818
4876
|
if ! mkdir -p "$(dirname "$destination")" \
|
|
4819
4877
|
|| ! mv "$lock_dir" "$destination"; then
|
|
@@ -4997,10 +5055,25 @@ fmix_preflight() {
|
|
|
4997
5055
|
esac
|
|
4998
5056
|
done
|
|
4999
5057
|
|
|
5058
|
+
# Shared postgres + NATS. fmix owns this plane (one host-wide ct-infra
|
|
5059
|
+
# project) rather than delegating to a monorepo-only helper script: a
|
|
5060
|
+
# standalone npm consumer has no monorepo root to run it from.
|
|
5000
5061
|
if ! fmix_ensure_infra; then
|
|
5001
5062
|
fail=1
|
|
5002
5063
|
fi
|
|
5003
5064
|
|
|
5065
|
+
# NATS TCP check (warn only — tests stub NATS)
|
|
5066
|
+
if ! nc -z "$NATS_HOST" "$NATS_PORT" 2>/dev/null; then
|
|
5067
|
+
fmix_warn "NATS not reachable at $NATS_HOST:$NATS_PORT."
|
|
5068
|
+
fmix_warn "Run: fmix ensure — some tests may fail without NATS."
|
|
5069
|
+
fi
|
|
5070
|
+
|
|
5071
|
+
# psql availability check
|
|
5072
|
+
if ! fmix_control_psql 5 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -c "SELECT 1" >/dev/null 2>&1; then
|
|
5073
|
+
fmix_error "Cannot connect to postgres as user '$DB_USER'. Check DB credentials or run 'fmix ensure'."
|
|
5074
|
+
fail=1
|
|
5075
|
+
fi
|
|
5076
|
+
|
|
5004
5077
|
return $fail
|
|
5005
5078
|
}
|
|
5006
5079
|
|
|
@@ -5765,7 +5838,7 @@ wt = os.environ["DONOR_WORKTREE"]
|
|
|
5765
5838
|
key = os.environ["DONOR_TEMPLATE_KEY"]
|
|
5766
5839
|
exclude = os.environ["DONOR_EXCLUDE"]
|
|
5767
5840
|
root = home / "sessions" / "v1"
|
|
5768
|
-
best = None # (last, path)
|
|
5841
|
+
best = None # (is_same_wt, last, path)
|
|
5769
5842
|
if not root.is_dir():
|
|
5770
5843
|
raise SystemExit(0)
|
|
5771
5844
|
for meta in root.glob("*/*/*/meta.json"):
|
|
@@ -5776,8 +5849,7 @@ for meta in root.glob("*/*/*/meta.json"):
|
|
|
5776
5849
|
d = json.loads(meta.read_text(encoding="utf-8"))
|
|
5777
5850
|
except Exception:
|
|
5778
5851
|
continue
|
|
5779
|
-
|
|
5780
|
-
continue
|
|
5852
|
+
session_wt = d.get("worktree") or ""
|
|
5781
5853
|
art = session_root / "artifact-state.json"
|
|
5782
5854
|
stamp = session_root / "compile-stamp.json"
|
|
5783
5855
|
deps = session_root / "deps"
|
|
@@ -5790,12 +5862,22 @@ for meta in root.glob("*/*/*/meta.json"):
|
|
|
5790
5862
|
continue
|
|
5791
5863
|
if (art_d.get("template_key") or "") != key:
|
|
5792
5864
|
continue
|
|
5865
|
+
# If cross-worktree, verify clean dirty_hash if schema_version 2
|
|
5866
|
+
if session_wt != wt:
|
|
5867
|
+
try:
|
|
5868
|
+
stamp_d = json.loads(stamp.read_text(encoding="utf-8"))
|
|
5869
|
+
if stamp_d.get("schema_version") == 2:
|
|
5870
|
+
if stamp_d.get("dirty_hash", "clean") != "clean":
|
|
5871
|
+
continue
|
|
5872
|
+
except Exception:
|
|
5873
|
+
continue
|
|
5874
|
+
is_same_wt = 1 if session_wt == wt else 0
|
|
5793
5875
|
last = d.get("last_accessed") or d.get("last_used") or ""
|
|
5794
|
-
cand = (last, str(session_root))
|
|
5876
|
+
cand = (is_same_wt, last, str(session_root))
|
|
5795
5877
|
if best is None or cand > best:
|
|
5796
5878
|
best = cand
|
|
5797
5879
|
if best:
|
|
5798
|
-
print(best[
|
|
5880
|
+
print(best[2])
|
|
5799
5881
|
PY
|
|
5800
5882
|
)" || donor=""
|
|
5801
5883
|
[[ -n "$donor" && -d "$donor/deps" && -d "$donor/_build" ]] || return 1
|
|
@@ -5805,7 +5887,8 @@ PY
|
|
|
5805
5887
|
}
|
|
5806
5888
|
|
|
5807
5889
|
fmix_clone_donor_to_session() {
|
|
5808
|
-
local worktree="$1" donor="$2" deps_root build_root retired retired_used=0
|
|
5890
|
+
local worktree="$1" donor="$2" deps_root build_root retired retired_used=0 real py_bin
|
|
5891
|
+
real="$(fmix_realpath "$worktree")" || return 1
|
|
5809
5892
|
deps_root="$(fmix_session_deps_root "$worktree")" || return 1
|
|
5810
5893
|
build_root="$(fmix_compile_build_root "$worktree")" || return 1
|
|
5811
5894
|
|
|
@@ -5819,25 +5902,63 @@ fmix_clone_donor_to_session() {
|
|
|
5819
5902
|
|
|
5820
5903
|
fmix_info "Cloning warm donor session into active overlay (avoid full recompile) …"
|
|
5821
5904
|
fmix_info "Donor: $donor"
|
|
5905
|
+
|
|
5906
|
+
py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
|
|
5907
|
+
|
|
5908
|
+
# Lock-Then-Revalidate (LOCK_SH): acquire shared lock on donor session
|
|
5909
|
+
local donor_fd
|
|
5910
|
+
donor_fd="$(fmix_lock_allocate_fd)" || return 1
|
|
5911
|
+
if [[ -f "$donor/meta.json" ]]; then
|
|
5912
|
+
eval "exec ${donor_fd}<\"$donor/meta.json\""
|
|
5913
|
+
else
|
|
5914
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5915
|
+
return 1
|
|
5916
|
+
fi
|
|
5917
|
+
|
|
5918
|
+
if ! "$py_bin" - "$donor_fd" <<'PY' 2>/dev/null
|
|
5919
|
+
import fcntl, sys
|
|
5920
|
+
fd = int(sys.argv[1])
|
|
5921
|
+
try:
|
|
5922
|
+
fcntl.flock(fd, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
|
5923
|
+
raise SystemExit(0)
|
|
5924
|
+
except Exception:
|
|
5925
|
+
raise SystemExit(1)
|
|
5926
|
+
PY
|
|
5927
|
+
then
|
|
5928
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5929
|
+
fmix_warn "Could not acquire shared lock on donor session $donor."
|
|
5930
|
+
return 1
|
|
5931
|
+
fi
|
|
5932
|
+
|
|
5933
|
+
# Revalidate donor artifacts under active LOCK_SH
|
|
5934
|
+
if [[ ! -d "$donor/deps" || ! -d "$donor/_build" || ! -f "$donor/compile-stamp.json" ]]; then
|
|
5935
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5936
|
+
fmix_warn "Donor session $donor missing required artifacts during revalidation."
|
|
5937
|
+
return 1
|
|
5938
|
+
fi
|
|
5939
|
+
|
|
5822
5940
|
retired="$FMIX_ACTIVE_SESSION_ROOT/retired/$(date +%Y%m%dT%H%M%S)-$$-${RANDOM}"
|
|
5823
5941
|
if [[ -e "$deps_root" || -L "$deps_root" \
|
|
5824
5942
|
|| -e "$build_root" || -L "$build_root" ]]; then
|
|
5825
|
-
mkdir -p "$retired" || return 1
|
|
5943
|
+
mkdir -p "$retired" || { fmix_lock_close_fd "$donor_fd"; return 1; }
|
|
5826
5944
|
retired_used=1
|
|
5827
5945
|
[[ -e "$deps_root" || -L "$deps_root" ]] && mv "$deps_root" "$retired/deps"
|
|
5828
5946
|
[[ -e "$build_root" || -L "$build_root" ]] && mv "$build_root" "$retired/_build"
|
|
5829
5947
|
fi
|
|
5830
5948
|
|
|
5831
5949
|
if ! fmix_cow_clone "$donor/deps" "$deps_root"; then
|
|
5950
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5832
5951
|
return 1
|
|
5833
5952
|
fi
|
|
5834
5953
|
if ! fmix_cow_clone "$donor/_build" "$build_root"; then
|
|
5835
5954
|
mkdir -p "$retired" || true
|
|
5836
5955
|
mv "$deps_root" "$retired/failed-deps" 2>/dev/null || true
|
|
5956
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5837
5957
|
return 1
|
|
5838
5958
|
fi
|
|
5839
5959
|
chmod -R u+w "$deps_root" "$build_root" || {
|
|
5840
5960
|
fmix_error "Could not make donor clone writable."
|
|
5961
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5841
5962
|
return 1
|
|
5842
5963
|
}
|
|
5843
5964
|
|
|
@@ -5849,6 +5970,37 @@ fmix_clone_donor_to_session() {
|
|
|
5849
5970
|
fi
|
|
5850
5971
|
done
|
|
5851
5972
|
|
|
5973
|
+
# Rebind path and build_root in cloned stamps to target session's bound realpath
|
|
5974
|
+
"$py_bin" - "$FMIX_ACTIVE_SESSION_ROOT" "$real" "$build_root" <<'PY' 2>/dev/null
|
|
5975
|
+
import json, sys
|
|
5976
|
+
from pathlib import Path
|
|
5977
|
+
sroot = Path(sys.argv[1])
|
|
5978
|
+
r_path = sys.argv[2]
|
|
5979
|
+
b_root = sys.argv[3]
|
|
5980
|
+
for name in ("compile-stamp.json", "dependency-stamp.json"):
|
|
5981
|
+
p = sroot / name
|
|
5982
|
+
if p.is_file():
|
|
5983
|
+
try:
|
|
5984
|
+
d = json.loads(p.read_text(encoding="utf-8"))
|
|
5985
|
+
d["path"] = r_path
|
|
5986
|
+
d["build_root"] = b_root
|
|
5987
|
+
p.write_text(json.dumps(d, indent=2) + "\n", encoding="utf-8")
|
|
5988
|
+
except Exception:
|
|
5989
|
+
pass
|
|
5990
|
+
PY
|
|
5991
|
+
true
|
|
5992
|
+
|
|
5993
|
+
# Release LOCK_SH on donor
|
|
5994
|
+
fmix_lock_close_fd "$donor_fd"
|
|
5995
|
+
|
|
5996
|
+
# Post-clone manifest synchronization: touch compile manifests to prevent full DAG recompiles
|
|
5997
|
+
find "$build_root" -type f -name 'compile.*' -exec touch {} + 2>/dev/null || true
|
|
5998
|
+
|
|
5999
|
+
# Sanitize CMake / NIF artifacts
|
|
6000
|
+
find "$deps_root" -type f -name 'CMakeCache.txt' -delete 2>/dev/null || true
|
|
6001
|
+
find "$deps_root" -type d -name 'c_build' -exec rm -rf {} + 2>/dev/null || true
|
|
6002
|
+
find "$deps_root" -type d -name 'CMakeFiles' -exec rm -rf {} + 2>/dev/null || true
|
|
6003
|
+
|
|
5852
6004
|
# NIF path-drift heal after CoW into a new session path.
|
|
5853
6005
|
fmix_check_known_nif_caches "$worktree" 2>/dev/null || true
|
|
5854
6006
|
|
|
@@ -5916,6 +6068,9 @@ fmix_clone_template_to_worktree() {
|
|
|
5916
6068
|
return 1
|
|
5917
6069
|
}
|
|
5918
6070
|
|
|
6071
|
+
# Post-clone manifest synchronization: touch compile manifests to prevent full DAG recompiles
|
|
6072
|
+
find "$build_root" -type f -name 'compile.*' -exec touch {} + 2>/dev/null || true
|
|
6073
|
+
|
|
5919
6074
|
dependency_fingerprint="$(fmix_compute_dependency_fingerprint "$worktree")" \
|
|
5920
6075
|
|| return 1
|
|
5921
6076
|
fmix_write_dependency_stamp "$worktree" "$dependency_fingerprint" || return 1
|
|
@@ -6129,18 +6284,11 @@ SELECT concat(
|
|
|
6129
6284
|
FROM pg_stat_activity
|
|
6130
6285
|
WHERE pid <> pg_backend_pid()
|
|
6131
6286
|
AND (
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
AND wait_event IN (
|
|
6135
|
-
'CheckpointStart', 'CheckpointDone', 'CheckpointWrite', 'CheckpointSync',
|
|
6136
|
-
'WALWrite', 'WALSync', 'DataFileSync', 'DataFileImmediateSync'
|
|
6287
|
+
(state = 'active' AND wait_event IN ('DataFileSync', 'DataFileImmediateSync', 'CheckpointDone'))
|
|
6288
|
+
OR (backend_type IN ('checkpointer', 'background writer', 'walwriter') AND wait_event_type = 'IO')
|
|
6137
6289
|
)
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
(state IS NULL
|
|
6141
|
-
AND backend_type IN ('checkpointer', 'background writer', 'walwriter')
|
|
6142
|
-
AND wait_event_type = 'IO')
|
|
6143
|
-
)
|
|
6290
|
+
AND coalesce(query_start, backend_start) IS NOT NULL
|
|
6291
|
+
AND clock_timestamp() - coalesce(query_start, backend_start) >= make_interval(secs => ${min_age})
|
|
6144
6292
|
ORDER BY coalesce(query_start, backend_start);" 2>/dev/null
|
|
6145
6293
|
}
|
|
6146
6294
|
|
|
@@ -6151,7 +6299,7 @@ fmix_wait_for_db_create_admission() {
|
|
|
6151
6299
|
return 0
|
|
6152
6300
|
fi
|
|
6153
6301
|
|
|
6154
|
-
local timeout deadline details="" inspect_rc=0 announced=0
|
|
6302
|
+
local timeout deadline details="" inspect_rc=0 announced=0 consecutive_positive=0
|
|
6155
6303
|
timeout="$(fmix_uint_or_default "$FMIX_DB_ADMISSION_TIMEOUT" 20 FMIX_DB_ADMISSION_TIMEOUT)"
|
|
6156
6304
|
deadline=$(( $(fmix_epoch) + timeout ))
|
|
6157
6305
|
|
|
@@ -6163,22 +6311,43 @@ fmix_wait_for_db_create_admission() {
|
|
|
6163
6311
|
fmix_error "Refusing CREATE DATABASE because pressure state is unknown."
|
|
6164
6312
|
return 1
|
|
6165
6313
|
fi
|
|
6166
|
-
if [[ -
|
|
6167
|
-
((
|
|
6314
|
+
if [[ -n "$details" ]]; then
|
|
6315
|
+
consecutive_positive=$(( consecutive_positive + 1 ))
|
|
6316
|
+
if (( consecutive_positive >= 3 )); then
|
|
6317
|
+
if (( announced == 0 )); then
|
|
6318
|
+
fmix_warn "Database-create admission waiting up to ${timeout}s for checkpoint/WAL/fsync pressure to clear ($purpose)."
|
|
6319
|
+
printf '%s\n' "$details" | sed 's/^/ /' >&2
|
|
6320
|
+
announced=1
|
|
6321
|
+
fi
|
|
6322
|
+
if (( $(fmix_epoch) >= deadline )); then
|
|
6323
|
+
fmix_error "Database-create admission denied for $purpose after ${timeout}s."
|
|
6324
|
+
fmix_error "Postgres is already stalled on checkpoint/WAL/fsync waits; refusing to add CREATE DATABASE pressure."
|
|
6325
|
+
printf '%s\n' "$details" | sed 's/^/ /' >&2
|
|
6326
|
+
fmix_error "Retry after pressure clears. Override only deliberately with FMIX_DB_CREATE_ADMISSION=0."
|
|
6327
|
+
return 1
|
|
6328
|
+
fi
|
|
6329
|
+
fi
|
|
6330
|
+
else
|
|
6331
|
+
if (( consecutive_positive > 0 )); then
|
|
6332
|
+
consecutive_positive=0
|
|
6333
|
+
fi
|
|
6334
|
+
if (( announced == 1 )); then
|
|
6335
|
+
fmix_info "Database-create admission recovered for $purpose."
|
|
6336
|
+
fi
|
|
6168
6337
|
return 0
|
|
6169
6338
|
fi
|
|
6170
6339
|
if (( $(fmix_epoch) >= deadline )); then
|
|
6340
|
+
if (( consecutive_positive == 0 )); then
|
|
6341
|
+
# Debounce only suppresses pressure that actually CLEARED. If the
|
|
6342
|
+
# latest sample still shows pressure we must fail closed: with a
|
|
6343
|
+
# short or zero timeout the 3-sample debounce can never be
|
|
6344
|
+
# satisfied, which previously admitted sustained WAL/checkpoint
|
|
6345
|
+
# pressure on the very first sample.
|
|
6346
|
+
return 0
|
|
6347
|
+
fi
|
|
6171
6348
|
fmix_error "Database-create admission denied for $purpose after ${timeout}s."
|
|
6172
|
-
fmix_error "Postgres is already stalled on checkpoint/WAL/fsync waits; refusing to add CREATE DATABASE pressure."
|
|
6173
|
-
printf '%s\n' "$details" | sed 's/^/ /' >&2
|
|
6174
|
-
fmix_error "Retry after pressure clears. Override only deliberately with FMIX_DB_CREATE_ADMISSION=0."
|
|
6175
6349
|
return 1
|
|
6176
6350
|
fi
|
|
6177
|
-
if (( announced == 0 )); then
|
|
6178
|
-
fmix_warn "Database-create admission waiting up to ${timeout}s for checkpoint/WAL/fsync pressure to clear ($purpose)."
|
|
6179
|
-
printf '%s\n' "$details" | sed 's/^/ /' >&2
|
|
6180
|
-
announced=1
|
|
6181
|
-
fi
|
|
6182
6351
|
sleep 2
|
|
6183
6352
|
done
|
|
6184
6353
|
}
|
|
@@ -8138,7 +8307,7 @@ fmix_compile_quick_guard() {
|
|
|
8138
8307
|
local worktree="$1" real py_bin
|
|
8139
8308
|
real="$(fmix_realpath "$worktree")" || return 1
|
|
8140
8309
|
py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
|
|
8141
|
-
"$py_bin" - "$real" <<'PY'
|
|
8310
|
+
"$py_bin" - "$real" <<'PY'
|
|
8142
8311
|
import hashlib, os, sys
|
|
8143
8312
|
from pathlib import Path
|
|
8144
8313
|
|
|
@@ -8218,22 +8387,83 @@ else:
|
|
|
8218
8387
|
|
|
8219
8388
|
print(h.hexdigest())
|
|
8220
8389
|
PY
|
|
8390
|
+
[[ $? -eq 0 ]] || return 1
|
|
8391
|
+
}
|
|
8392
|
+
|
|
8393
|
+
fmix_get_git_tree_hash() {
|
|
8394
|
+
local worktree="$1" real tree_hash
|
|
8395
|
+
real="$(fmix_realpath "$worktree" 2>/dev/null || echo "$worktree")"
|
|
8396
|
+
if command -v git >/dev/null 2>&1 && { [[ -d "$real/.git" ]] || [[ -f "$real/.git" ]]; }; then
|
|
8397
|
+
tree_hash="$(git -C "$real" rev-parse HEAD^{tree} 2>/dev/null || true)"
|
|
8398
|
+
if [[ "$tree_hash" =~ ^[0-9a-f]{40}$ ]]; then
|
|
8399
|
+
printf '%s\n' "$tree_hash"
|
|
8400
|
+
return 0
|
|
8401
|
+
fi
|
|
8402
|
+
fi
|
|
8403
|
+
printf 'unknown\n'
|
|
8404
|
+
}
|
|
8405
|
+
|
|
8406
|
+
fmix_compute_compile_env_hash() {
|
|
8407
|
+
local worktree="$1" real toolchain_identity
|
|
8408
|
+
real="$(fmix_realpath "$worktree" 2>/dev/null || echo "$worktree")"
|
|
8409
|
+
toolchain_identity="${FMIX_TOOLCHAIN_IDENTITY:-}"
|
|
8410
|
+
if [[ -z "$toolchain_identity" ]]; then
|
|
8411
|
+
toolchain_identity="$(fmix_resolved_toolchain_identity "$real" 2>/dev/null || echo "")"
|
|
8412
|
+
fi
|
|
8413
|
+
(
|
|
8414
|
+
printf 'os_arch=%s %s\n' "$FMIX_OS" "$FMIX_ARCH"
|
|
8415
|
+
printf 'toolchain=%s\n' "$toolchain_identity"
|
|
8416
|
+
printf 'MIX_ENV=%s\n' "${MIX_ENV:-test}"
|
|
8417
|
+
printf 'MIX_TARGET=%s\n' "${MIX_TARGET:-host}"
|
|
8418
|
+
printf 'ERL_COMPILER_OPTIONS=%s\n' "${ERL_COMPILER_OPTIONS:-}"
|
|
8419
|
+
printf 'ELIXIR_ERL_OPTIONS=%s\n' "${ELIXIR_ERL_OPTIONS:-}"
|
|
8420
|
+
) | fmix_hash_stdin
|
|
8421
|
+
}
|
|
8422
|
+
|
|
8423
|
+
fmix_compute_dirty_hash() {
|
|
8424
|
+
local worktree="$1" real status
|
|
8425
|
+
real="$(fmix_realpath "$worktree" 2>/dev/null || echo "$worktree")"
|
|
8426
|
+
if ! command -v git >/dev/null 2>&1 || { [[ ! -d "$real/.git" ]] && [[ ! -f "$real/.git" ]]; }; then
|
|
8427
|
+
printf 'clean\n'
|
|
8428
|
+
return 0
|
|
8429
|
+
fi
|
|
8430
|
+
status="$(git -C "$real" status --porcelain=v1 2>/dev/null || true)"
|
|
8431
|
+
if [[ -z "$status" ]]; then
|
|
8432
|
+
printf 'clean\n'
|
|
8433
|
+
return 0
|
|
8434
|
+
fi
|
|
8435
|
+
(
|
|
8436
|
+
printf '%s\n' "$status"
|
|
8437
|
+
git -C "$real" ls-files --others --modified --exclude-standard 2>/dev/null | head -50 | while IFS= read -r f; do
|
|
8438
|
+
fmix_stat_mtime "$real/$f" 2>/dev/null || echo 0
|
|
8439
|
+
done
|
|
8440
|
+
) | fmix_hash_stdin
|
|
8221
8441
|
}
|
|
8222
8442
|
|
|
8223
8443
|
fmix_write_compile_stamp() {
|
|
8224
8444
|
local worktree="$1" fingerprint="$2" real build_root guard dependency_guard stamp tmp quick_guard
|
|
8445
|
+
local template_key tree_hash env_hash dirty_hash
|
|
8225
8446
|
real="$(fmix_realpath "$worktree")"
|
|
8226
8447
|
build_root="$(fmix_compile_build_root "$real")"
|
|
8227
8448
|
guard="$(fmix_compile_manifest_guard "$real")" || return 1
|
|
8228
8449
|
dependency_guard="$(fmix_dependency_source_guard "$real")" || return 1
|
|
8229
8450
|
quick_guard="$(fmix_compile_quick_guard "$real")" || quick_guard=""
|
|
8451
|
+
template_key="$(fmix_compute_template_key "$real" 2>/dev/null || echo "")"
|
|
8452
|
+
tree_hash="$(fmix_get_git_tree_hash "$real")"
|
|
8453
|
+
env_hash="$(fmix_compute_compile_env_hash "$real" 2>/dev/null || echo "")"
|
|
8454
|
+
dirty_hash="$(fmix_compute_dirty_hash "$real" 2>/dev/null || echo "clean")"
|
|
8230
8455
|
stamp="$(fmix_compile_stamp_file "$real")"
|
|
8231
8456
|
mkdir -p "$(dirname "$stamp")"
|
|
8232
8457
|
tmp="$(mktemp "${stamp}.tmp.XXXXXX")" || return 1
|
|
8233
8458
|
if ! cat >"$tmp" <<EOF
|
|
8234
8459
|
{
|
|
8460
|
+
"schema_version": 2,
|
|
8235
8461
|
"path": $(fmix_json_escape "$real"),
|
|
8236
8462
|
"build_root": $(fmix_json_escape "$build_root"),
|
|
8463
|
+
"template_key": $(fmix_json_escape "$template_key"),
|
|
8464
|
+
"git_tree_hash": $(fmix_json_escape "$tree_hash"),
|
|
8465
|
+
"compile_env_hash": $(fmix_json_escape "$env_hash"),
|
|
8466
|
+
"dirty_hash": $(fmix_json_escape "$dirty_hash"),
|
|
8237
8467
|
"fingerprint": $(fmix_json_escape "$fingerprint"),
|
|
8238
8468
|
"manifest_guard": $(fmix_json_escape "$guard"),
|
|
8239
8469
|
"dependency_source_guard": $(fmix_json_escape "$dependency_guard"),
|
|
@@ -8262,8 +8492,6 @@ fmix_try_compile_stamp_quick_hit() {
|
|
|
8262
8492
|
recorded_build="$(fmix_read_state "$stamp" build_root)"
|
|
8263
8493
|
recorded_quick="$(fmix_read_state "$stamp" quick_guard)"
|
|
8264
8494
|
[[ -n "$recorded_quick" ]] || return 1
|
|
8265
|
-
[[ "$recorded_path" == "$real" ]] || return 1
|
|
8266
|
-
[[ "$recorded_build" == "$build_root" ]] || return 1
|
|
8267
8495
|
app_ebin="$build_root/test/lib/cdrcisco/ebin"
|
|
8268
8496
|
[[ -d "$app_ebin" ]] || return 1
|
|
8269
8497
|
[[ -n "$(find "$app_ebin" -maxdepth 1 -type f -name '*.beam' -print -quit 2>/dev/null)" ]] || return 1
|
|
@@ -8302,26 +8530,63 @@ fmix_dependency_stamp_matches() {
|
|
|
8302
8530
|
|
|
8303
8531
|
fmix_compile_stamp_matches() {
|
|
8304
8532
|
local worktree="$1" fingerprint="$2" real build_root deps_root stamp
|
|
8305
|
-
local recorded_path recorded_build recorded_fingerprint recorded_guard current_guard
|
|
8533
|
+
local recorded_schema recorded_path recorded_build recorded_fingerprint recorded_guard current_guard
|
|
8306
8534
|
local recorded_dependency_guard current_dependency_guard
|
|
8535
|
+
local recorded_template_key recorded_tree_hash recorded_env_hash recorded_dirty_hash
|
|
8307
8536
|
real="$(fmix_realpath "$worktree")"
|
|
8308
8537
|
build_root="$(fmix_compile_build_root "$real")"
|
|
8309
8538
|
stamp="$(fmix_compile_stamp_file "$real")"
|
|
8310
8539
|
[[ -f "$stamp" ]] || return 1
|
|
8540
|
+
|
|
8541
|
+
recorded_schema="$(fmix_read_state "$stamp" schema_version)"
|
|
8311
8542
|
recorded_path="$(fmix_read_state "$stamp" path)"
|
|
8312
8543
|
recorded_build="$(fmix_read_state "$stamp" build_root)"
|
|
8313
8544
|
recorded_fingerprint="$(fmix_read_state "$stamp" fingerprint)"
|
|
8314
8545
|
recorded_guard="$(fmix_read_state "$stamp" manifest_guard)"
|
|
8315
8546
|
recorded_dependency_guard="$(fmix_read_state "$stamp" dependency_source_guard)"
|
|
8316
|
-
|
|
8317
|
-
|
|
8547
|
+
|
|
8548
|
+
# Schema v2 content-identity matching (Patch 3)
|
|
8549
|
+
if [[ "$recorded_schema" == "2" ]]; then
|
|
8550
|
+
recorded_template_key="$(fmix_read_state "$stamp" template_key)"
|
|
8551
|
+
recorded_tree_hash="$(fmix_read_state "$stamp" git_tree_hash)"
|
|
8552
|
+
recorded_env_hash="$(fmix_read_state "$stamp" compile_env_hash)"
|
|
8553
|
+
recorded_dirty_hash="$(fmix_read_state "$stamp" dirty_hash)"
|
|
8554
|
+
|
|
8555
|
+
local current_template_key current_tree_hash current_env_hash current_dirty_hash
|
|
8556
|
+
current_template_key="$(fmix_compute_template_key "$real" 2>/dev/null || echo "")"
|
|
8557
|
+
current_tree_hash="$(fmix_get_git_tree_hash "$real")"
|
|
8558
|
+
current_env_hash="$(fmix_compute_compile_env_hash "$real" 2>/dev/null || echo "")"
|
|
8559
|
+
current_dirty_hash="$(fmix_compute_dirty_hash "$real" 2>/dev/null || echo "clean")"
|
|
8560
|
+
|
|
8561
|
+
if [[ "$recorded_tree_hash" != "unknown" && "$current_tree_hash" != "unknown" ]]; then
|
|
8562
|
+
# template_key is compared for equality rather than required to be
|
|
8563
|
+
# non-empty. fmix_compute_template_key returns empty when the
|
|
8564
|
+
# toolchain cannot be resolved, and requiring non-empty turned that
|
|
8565
|
+
# into a stamp that could NEVER match -- a permanently poisoned cache
|
|
8566
|
+
# entry rather than a miss. Identity is still enforced: tree hash and
|
|
8567
|
+
# env hash must both be present and equal, and env hash already
|
|
8568
|
+
# covers the resolved toolchain, OS/arch and MIX_ENV.
|
|
8569
|
+
if [[ "$recorded_template_key" == "$current_template_key" \
|
|
8570
|
+
&& -n "$recorded_tree_hash" && "$recorded_tree_hash" == "$current_tree_hash" \
|
|
8571
|
+
&& -n "$recorded_env_hash" && "$recorded_env_hash" == "$current_env_hash" \
|
|
8572
|
+
&& "$recorded_dirty_hash" == "$current_dirty_hash" ]]; then
|
|
8573
|
+
local app_ebin="$build_root/test/lib/cdrcisco/ebin"
|
|
8574
|
+
if [[ -d "$app_ebin" ]] && [[ -n "$(find "$app_ebin" -maxdepth 1 -type f -name '*.beam' -print -quit 2>/dev/null)" ]]; then
|
|
8575
|
+
return 0
|
|
8576
|
+
fi
|
|
8577
|
+
fi
|
|
8578
|
+
return 1
|
|
8579
|
+
fi
|
|
8580
|
+
fi
|
|
8581
|
+
|
|
8582
|
+
# Legacy v1 dual-read fallback:
|
|
8583
|
+
if [[ "$recorded_path" != "$real" ]] || [[ "$recorded_build" != "$build_root" ]]; then
|
|
8584
|
+
return 1
|
|
8585
|
+
fi
|
|
8318
8586
|
[[ "$recorded_fingerprint" == "$fingerprint" ]] || return 1
|
|
8319
8587
|
current_guard="$(fmix_compile_manifest_guard "$real")" || return 1
|
|
8320
8588
|
[[ -n "$recorded_guard" && "$recorded_guard" == "$current_guard" ]] || return 1
|
|
8321
8589
|
|
|
8322
|
-
# Compiled beams remain usable if the resolved source tree was deliberately
|
|
8323
|
-
# removed. When it is present, however, a local dependency edit must not be
|
|
8324
|
-
# hidden behind an otherwise-valid app compile stamp.
|
|
8325
8590
|
deps_root="$(fmix_dependency_source_root "$real")"
|
|
8326
8591
|
if [[ -d "$deps_root" ]]; then
|
|
8327
8592
|
[[ -n "$recorded_dependency_guard" ]] || return 1
|
|
@@ -8469,18 +8734,132 @@ fmix_adopt_compatible_worktree_artifacts() {
|
|
|
8469
8734
|
return 0
|
|
8470
8735
|
}
|
|
8471
8736
|
|
|
8737
|
+
FMIX_CURRENT_SEMAPHORE_SLOT=""
|
|
8738
|
+
FMIX_CURRENT_SEMAPHORE_FD=""
|
|
8739
|
+
|
|
8740
|
+
fmix_compile_semaphore_permits() {
|
|
8741
|
+
if [[ -n "${FMIX_COMPILE_PERMITS:-}" ]]; then
|
|
8742
|
+
local p
|
|
8743
|
+
p="$(fmix_positive_uint_or_default "$FMIX_COMPILE_PERMITS" 2 FMIX_COMPILE_PERMITS)"
|
|
8744
|
+
printf '%s\n' "$p"
|
|
8745
|
+
return 0
|
|
8746
|
+
fi
|
|
8747
|
+
local cores
|
|
8748
|
+
cores="$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)"
|
|
8749
|
+
[[ "$cores" =~ ^[0-9]+$ ]] || cores=4
|
|
8750
|
+
local p=$(( cores / 8 ))
|
|
8751
|
+
(( p >= 1 )) || p=1
|
|
8752
|
+
(( p <= 2 )) || p=2
|
|
8753
|
+
printf '%s\n' "$p"
|
|
8754
|
+
}
|
|
8755
|
+
|
|
8756
|
+
fmix_compile_semaphore_acquire() {
|
|
8757
|
+
local worktree="$1"
|
|
8758
|
+
local permits deadline_secs
|
|
8759
|
+
permits="$(fmix_compile_semaphore_permits)"
|
|
8760
|
+
deadline_secs="${FMIX_CALLER_DEADLINE_SECS:-}"
|
|
8761
|
+
|
|
8762
|
+
local py_bin slot fd acquired_slot=-1 acquired_fd=""
|
|
8763
|
+
py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
|
|
8764
|
+
mkdir -p "$FMIX_HOME/lock-kernel" "$FMIX_HOME/lock-metadata" || return 1
|
|
8765
|
+
|
|
8766
|
+
local t0=$(fmix_epoch)
|
|
8767
|
+
local last_heartbeat=$t0
|
|
8768
|
+
local estimated_compile_s=60
|
|
8769
|
+
|
|
8770
|
+
while true; do
|
|
8771
|
+
for (( slot = 0; slot < permits; slot++ )); do
|
|
8772
|
+
local kfile="$FMIX_HOME/lock-kernel/compile-permit-${slot}"
|
|
8773
|
+
fd="$(fmix_lock_allocate_fd)" || return 1
|
|
8774
|
+
fmix_lock_open_fd "$fd" "$kfile" || { fmix_lock_close_fd "$fd"; continue; }
|
|
8775
|
+
if "$py_bin" - "$fd" 0 <<'PY' 2>/dev/null
|
|
8776
|
+
import fcntl, sys
|
|
8777
|
+
fd = int(sys.argv[1])
|
|
8778
|
+
try:
|
|
8779
|
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
8780
|
+
raise SystemExit(0)
|
|
8781
|
+
except Exception:
|
|
8782
|
+
raise SystemExit(1)
|
|
8783
|
+
PY
|
|
8784
|
+
then
|
|
8785
|
+
acquired_slot="$slot"
|
|
8786
|
+
acquired_fd="$fd"
|
|
8787
|
+
break
|
|
8788
|
+
fi
|
|
8789
|
+
fmix_lock_close_fd "$fd"
|
|
8790
|
+
done
|
|
8791
|
+
|
|
8792
|
+
if (( acquired_slot >= 0 )); then
|
|
8793
|
+
FMIX_CURRENT_SEMAPHORE_SLOT="$acquired_slot"
|
|
8794
|
+
FMIX_CURRENT_SEMAPHORE_FD="$acquired_fd"
|
|
8795
|
+
cat >"$FMIX_HOME/lock-metadata/compile-permit-${acquired_slot}.json" 2>/dev/null <<EOF
|
|
8796
|
+
{
|
|
8797
|
+
"slot": $acquired_slot,
|
|
8798
|
+
"pid": $$,
|
|
8799
|
+
"start_time": "$(fmix_now)",
|
|
8800
|
+
"worktree": $(fmix_json_escape "$worktree")
|
|
8801
|
+
}
|
|
8802
|
+
EOF
|
|
8803
|
+
true
|
|
8804
|
+
return 0
|
|
8805
|
+
fi
|
|
8806
|
+
|
|
8807
|
+
local now=$(fmix_epoch)
|
|
8808
|
+
local elapsed=$(( now - t0 ))
|
|
8809
|
+
local queue_depth=$permits
|
|
8810
|
+
|
|
8811
|
+
if [[ -n "$deadline_secs" && "$deadline_secs" =~ ^[0-9]+$ ]]; then
|
|
8812
|
+
local estimated_wait=$(( (queue_depth / permits) * estimated_compile_s ))
|
|
8813
|
+
if (( elapsed + estimated_wait + estimated_compile_s > deadline_secs )); then
|
|
8814
|
+
local err_json
|
|
8815
|
+
err_json="$(printf '{"error": "host_compile_deadline_exceeded", "queue_depth": %d, "estimated_wait_s": %d, "permit_limit": %d}' \
|
|
8816
|
+
"$queue_depth" "$estimated_wait" "$permits")"
|
|
8817
|
+
printf '%s\n' "$err_json" >&2
|
|
8818
|
+
return 75
|
|
8819
|
+
fi
|
|
8820
|
+
fi
|
|
8821
|
+
|
|
8822
|
+
if (( now - last_heartbeat >= 15 )); then
|
|
8823
|
+
fmix_info "Waiting for host compilation semaphore permit (${elapsed}s elapsed, limit: ${permits} permits) …"
|
|
8824
|
+
last_heartbeat="$now"
|
|
8825
|
+
fi
|
|
8826
|
+
|
|
8827
|
+
sleep 0.2
|
|
8828
|
+
done
|
|
8829
|
+
}
|
|
8830
|
+
|
|
8831
|
+
fmix_compile_semaphore_release() {
|
|
8832
|
+
if [[ -n "$FMIX_CURRENT_SEMAPHORE_SLOT" && -n "$FMIX_CURRENT_SEMAPHORE_FD" ]]; then
|
|
8833
|
+
rm -f "$FMIX_HOME/lock-metadata/compile-permit-${FMIX_CURRENT_SEMAPHORE_SLOT}.json" 2>/dev/null || true
|
|
8834
|
+
fmix_lock_close_fd "$FMIX_CURRENT_SEMAPHORE_FD" 2>/dev/null || true
|
|
8835
|
+
FMIX_CURRENT_SEMAPHORE_SLOT=""
|
|
8836
|
+
FMIX_CURRENT_SEMAPHORE_FD=""
|
|
8837
|
+
fi
|
|
8838
|
+
}
|
|
8839
|
+
|
|
8472
8840
|
fmix_run_compile_streamed() {
|
|
8473
8841
|
# Stream new compiler output at two-second granularity and emit a heartbeat
|
|
8474
8842
|
# when Mix is CPU-bound without producing lines. Returns the compiler rc.
|
|
8475
8843
|
local worktree="$1" db_name="$2" extra="$3" log_file="$4"
|
|
8476
8844
|
local timeout_override="${5:-}"
|
|
8477
|
-
local heartbeat timeout pid shown=0 lines now started last_output rc
|
|
8845
|
+
local heartbeat timeout pid shown=0 lines now started last_output rc sem_rc=0
|
|
8478
8846
|
heartbeat="$(fmix_uint_or_default "$FMIX_COMPILE_HEARTBEAT" 30 FMIX_COMPILE_HEARTBEAT)"
|
|
8479
8847
|
if [[ -n "$timeout_override" ]]; then
|
|
8480
8848
|
timeout="$(fmix_positive_uint_or_default "$timeout_override" 900 FMIX_SETUP_COMPILE_TIMEOUT)"
|
|
8481
8849
|
else
|
|
8482
8850
|
timeout="$(fmix_positive_uint_or_default "$FMIX_COMPILE_TIMEOUT" 900 FMIX_COMPILE_TIMEOUT)"
|
|
8483
8851
|
fi
|
|
8852
|
+
|
|
8853
|
+
# Acquire host compilation semaphore permit (Patch 2)
|
|
8854
|
+
fmix_compile_semaphore_acquire "$worktree" || sem_rc=$?
|
|
8855
|
+
if (( sem_rc != 0 )); then
|
|
8856
|
+
if (( sem_rc == 75 )); then
|
|
8857
|
+
return 75
|
|
8858
|
+
fi
|
|
8859
|
+
fmix_error "Could not acquire host compilation semaphore."
|
|
8860
|
+
return "$sem_rc"
|
|
8861
|
+
fi
|
|
8862
|
+
|
|
8484
8863
|
mkdir -p "$(dirname "$log_file")"
|
|
8485
8864
|
: >"$log_file"
|
|
8486
8865
|
_fmix_run_compile "$worktree" "$db_name" "$extra" >"$log_file" 2>&1 &
|
|
@@ -8496,6 +8875,7 @@ fmix_run_compile_streamed() {
|
|
|
8496
8875
|
sleep 1
|
|
8497
8876
|
kill -KILL "$pid" 2>/dev/null || true
|
|
8498
8877
|
wait "$pid" 2>/dev/null || true
|
|
8878
|
+
fmix_compile_semaphore_release
|
|
8499
8879
|
return 124
|
|
8500
8880
|
fi
|
|
8501
8881
|
lines="$(wc -l <"$log_file" | tr -d ' ')"
|
|
@@ -8513,6 +8893,7 @@ fmix_run_compile_streamed() {
|
|
|
8513
8893
|
done
|
|
8514
8894
|
wait "$pid"
|
|
8515
8895
|
rc=$?
|
|
8896
|
+
fmix_compile_semaphore_release
|
|
8516
8897
|
lines="$(wc -l <"$log_file" | tr -d ' ')"
|
|
8517
8898
|
if (( lines > shown )); then
|
|
8518
8899
|
sed -n "$(( shown + 1 )),${lines}p" "$log_file" >&2
|
|
@@ -8932,6 +9313,10 @@ fmix_ensure_compile() {
|
|
|
8932
9313
|
t1=$(fmix_epoch)
|
|
8933
9314
|
FMIX_LAST_COMPILE_SECONDS=$(( t1 - t0 ))
|
|
8934
9315
|
if (( rc != 0 )); then
|
|
9316
|
+
if (( rc == 75 )); then
|
|
9317
|
+
FMIX_LAST_COMPILE_OUTCOME="deadline_exceeded"
|
|
9318
|
+
return 75
|
|
9319
|
+
fi
|
|
8935
9320
|
local elapsed_compile=$(( t1 - t0 ))
|
|
8936
9321
|
FMIX_LAST_COMPILE_OUTCOME="error"
|
|
8937
9322
|
if (( rc == 124 )); then
|
|
@@ -8941,7 +9326,7 @@ fmix_ensure_compile() {
|
|
|
8941
9326
|
fi
|
|
8942
9327
|
fmix_error "Compile log: $log_file"
|
|
8943
9328
|
fmix_error "Fix the source error or explicitly repair the worktree build before retrying."
|
|
8944
|
-
return
|
|
9329
|
+
return "$rc"
|
|
8945
9330
|
fi
|
|
8946
9331
|
local compiled_files=0
|
|
8947
9332
|
compiled_files="$(sed -nE 's/.*Compiling ([0-9]+) files?.*/\1/p' "$log_file" 2>/dev/null \
|
|
@@ -9213,10 +9598,12 @@ cmd_setup() {
|
|
|
9213
9598
|
fmix_lock_release "$lock_name"
|
|
9214
9599
|
return 1
|
|
9215
9600
|
}
|
|
9216
|
-
|
|
9601
|
+
local setup_compile_rc=0
|
|
9602
|
+
fmix_ensure_compile "$real_worktree" "$db_name" setup || setup_compile_rc=$?
|
|
9603
|
+
if (( setup_compile_rc != 0 )); then
|
|
9217
9604
|
fmix_lock_release "$lock_name"
|
|
9218
|
-
return
|
|
9219
|
-
|
|
9605
|
+
return "$setup_compile_rc"
|
|
9606
|
+
fi
|
|
9220
9607
|
# Explicit setup is also the maintenance/backfill lane for the split
|
|
9221
9608
|
# dependency cache. This imports older proven sessions/templates without
|
|
9222
9609
|
# slowing ordinary `fmix test` warm hits. Publication remains best-effort:
|
|
@@ -9612,11 +9999,13 @@ cmd_test() {
|
|
|
9612
9999
|
fmix_run_telemetry_phase "artifacts"
|
|
9613
10000
|
|
|
9614
10001
|
# Compile (incremental)
|
|
9615
|
-
|
|
10002
|
+
local compile_rc=0
|
|
10003
|
+
fmix_ensure_compile "$real_worktree" "$db_name" || compile_rc=$?
|
|
10004
|
+
if (( compile_rc != 0 )); then
|
|
9616
10005
|
fmix_lock_release "$lock_name"
|
|
9617
|
-
fmix_run_telemetry_finish
|
|
9618
|
-
return
|
|
9619
|
-
|
|
10006
|
+
fmix_run_telemetry_finish "$compile_rc"
|
|
10007
|
+
return "$compile_rc"
|
|
10008
|
+
fi
|
|
9620
10009
|
fmix_run_telemetry_phase "compile"
|
|
9621
10010
|
|
|
9622
10011
|
# Ensure DB exists
|
|
@@ -9988,6 +10377,10 @@ cmd_task() {
|
|
|
9988
10377
|
return "$task_rc"
|
|
9989
10378
|
}
|
|
9990
10379
|
|
|
10380
|
+
# ---------------------------------------------------------------------------
|
|
10381
|
+
# cmd: fmix doctor
|
|
10382
|
+
# ---------------------------------------------------------------------------
|
|
10383
|
+
|
|
9991
10384
|
# ---------------------------------------------------------------------------
|
|
9992
10385
|
# Shared postgres + NATS (one host-wide ct-infra plane)
|
|
9993
10386
|
# ---------------------------------------------------------------------------
|
|
@@ -10158,10 +10551,6 @@ cmd_ensure() {
|
|
|
10158
10551
|
fmix_ensure_infra
|
|
10159
10552
|
}
|
|
10160
10553
|
|
|
10161
|
-
# ---------------------------------------------------------------------------
|
|
10162
|
-
# cmd: fmix doctor
|
|
10163
|
-
# ---------------------------------------------------------------------------
|
|
10164
|
-
|
|
10165
10554
|
cmd_doctor() {
|
|
10166
10555
|
local worktree_arg="auto" session_arg=""
|
|
10167
10556
|
while (( $# > 0 )); do
|
|
@@ -10256,7 +10645,7 @@ cmd_doctor() {
|
|
|
10256
10645
|
if nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null; then
|
|
10257
10646
|
echo " [OK] postgres TCP $DB_HOST:$DB_PORT"
|
|
10258
10647
|
else
|
|
10259
|
-
echo " [FAIL] postgres not reachable at $DB_HOST:$DB_PORT — run:
|
|
10648
|
+
echo " [FAIL] postgres not reachable at $DB_HOST:$DB_PORT — run: ./infra.sh up"
|
|
10260
10649
|
fail=1
|
|
10261
10650
|
fi
|
|
10262
10651
|
|
|
@@ -10287,7 +10676,7 @@ cmd_doctor() {
|
|
|
10287
10676
|
if nc -z "$NATS_HOST" "$NATS_PORT" 2>/dev/null; then
|
|
10288
10677
|
echo " [OK] NATS TCP $NATS_HOST:$NATS_PORT"
|
|
10289
10678
|
else
|
|
10290
|
-
echo " [WARN] NATS not reachable at $NATS_HOST:$NATS_PORT — run:
|
|
10679
|
+
echo " [WARN] NATS not reachable at $NATS_HOST:$NATS_PORT — run: ./infra.sh up (some tests may fail)"
|
|
10291
10680
|
fi
|
|
10292
10681
|
|
|
10293
10682
|
# Headless Chromium for ChromicPDF-backed reporting suites (API-1184).
|
|
@@ -10986,10 +11375,15 @@ PY
|
|
|
10986
11375
|
[[ "$confirm" =~ ^[Yy]$ ]] || continue
|
|
10987
11376
|
# Drop scratch DB then directory (lease-aware: refuse if lock held)
|
|
10988
11377
|
local lock_name="session-$shash"
|
|
11378
|
+
if ! fmix_lock_acquire "$lock_name" 0 "session GC consolidate" >/dev/null 2>&1; then
|
|
11379
|
+
fmix_warn "Skipping live session $shash (lock held by active process or clone)."
|
|
11380
|
+
continue
|
|
11381
|
+
fi
|
|
10989
11382
|
if [[ -d "$FMIX_HOME/locks/$lock_name" ]]; then
|
|
10990
11383
|
local pid
|
|
10991
11384
|
pid="$(cat "$FMIX_HOME/locks/$lock_name/pid" 2>/dev/null || true)"
|
|
10992
|
-
if [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
|
|
11385
|
+
if [[ "$pid" =~ ^[0-9]+$ ]] && (( pid != $$ )) && kill -0 "$pid" 2>/dev/null; then
|
|
11386
|
+
fmix_lock_release "$lock_name" >/dev/null 2>&1 || true
|
|
10993
11387
|
fmix_warn "Skipping live session $shash (pid=$pid holds lock)."
|
|
10994
11388
|
continue
|
|
10995
11389
|
fi
|
|
@@ -11008,6 +11402,7 @@ PY
|
|
|
11008
11402
|
else
|
|
11009
11403
|
fmix_warn "Refusing to remove path outside FMIX_HOME: $sroot"
|
|
11010
11404
|
fi
|
|
11405
|
+
fmix_lock_release "$lock_name" >/dev/null 2>&1 || true
|
|
11011
11406
|
done <<<"$plan"
|
|
11012
11407
|
|
|
11013
11408
|
if (( actions == 0 )); then
|
|
@@ -14726,9 +15121,7 @@ EOF
|
|
|
14726
15121
|
else
|
|
14727
15122
|
st_fail "compile timeout was not enforced: rc=$stream_rc out='$stream_out'"
|
|
14728
15123
|
fi
|
|
14729
|
-
|
|
14730
|
-
# a false timeout on hosted macOS runners.
|
|
14731
|
-
FMIX_SETUP_COMPILE_TIMEOUT=10
|
|
15124
|
+
FMIX_SETUP_COMPILE_TIMEOUT=3
|
|
14732
15125
|
_fmix_run_compile() { sleep 2; }
|
|
14733
15126
|
stream_out="$(fmix_run_compile_streamed "$compile_root" demo "" "$stream_log" "$FMIX_SETUP_COMPILE_TIMEOUT" 2>&1)"
|
|
14734
15127
|
stream_rc=$?
|
|
@@ -14762,15 +15155,10 @@ EOF
|
|
|
14762
15155
|
st_fail "deps.get timeout was not enforced: rc=$deps_timeout_rc out='$deps_timeout_out'"
|
|
14763
15156
|
fi
|
|
14764
15157
|
|
|
14765
|
-
#
|
|
14766
|
-
#
|
|
14767
|
-
|
|
14768
|
-
|
|
14769
|
-
# Allow a couple of scheduler intervals between progress observations on
|
|
14770
|
-
# hosted macOS; the preceding fixture still proves a one-second stall is
|
|
14771
|
-
# cancelled when there is no progress at all.
|
|
14772
|
-
FMIX_DEPS_STALL_TIMEOUT=5
|
|
14773
|
-
FMIX_DEPS_TIMEOUT=10
|
|
15158
|
+
# Leave one full sampling interval of slack: a printf followed by
|
|
15159
|
+
# `sleep 1` can land on the same epoch-second as the watchdog on macOS.
|
|
15160
|
+
FMIX_DEPS_STALL_TIMEOUT=2
|
|
15161
|
+
FMIX_DEPS_TIMEOUT=5
|
|
14774
15162
|
_fmix_run_deps_get() {
|
|
14775
15163
|
local i
|
|
14776
15164
|
for i in 1 2 3 4; do
|
|
@@ -15380,7 +15768,7 @@ PY
|
|
|
15380
15768
|
st_fail "postgres reachable but auth failed for user=$DB_USER — check FMIX_DB_PASSWORD"
|
|
15381
15769
|
fi
|
|
15382
15770
|
else
|
|
15383
|
-
st_skip "postgres $DB_HOST:$DB_PORT not reachable — OK in bare container or without
|
|
15771
|
+
st_skip "postgres $DB_HOST:$DB_PORT not reachable — OK in bare container or without infra.sh up"
|
|
15384
15772
|
fi
|
|
15385
15773
|
|
|
15386
15774
|
# 8. asdf toolchain (skip in bare container)
|
|
@@ -15655,9 +16043,9 @@ Usage:
|
|
|
15655
16043
|
./fmix seed publish --worktree <path> [--session <id>] --cache-base <N.N.N-stable>
|
|
15656
16044
|
./fmix cache explain --worktree <path> --cache-base <N.N.N-stable>
|
|
15657
16045
|
./fmix cache verify [--key <16-hex-template-key>]
|
|
15658
|
-
./fmix ensure
|
|
16046
|
+
./fmix ensure
|
|
15659
16047
|
./fmix doctor
|
|
15660
|
-
./fmix status
|
|
16048
|
+
./fmix status
|
|
15661
16049
|
./fmix timing [--limit N] [--worktree <path>] # phase timings + session fragmentation
|
|
15662
16050
|
./fmix gc [--reap|--consolidate] [--worktree <path>] [--yes]
|
|
15663
16051
|
./fmix install # immutable snapshot + atomic PATH link (~/.local/bin)
|
|
@@ -15678,7 +16066,6 @@ Examples:
|
|
|
15678
16066
|
./fmix seed publish --worktree ./cisco-cdr --cache-base 0.8.7-stable
|
|
15679
16067
|
./fmix cache explain --worktree ./cisco-cdr --cache-base 0.8.7-stable
|
|
15680
16068
|
./fmix doctor
|
|
15681
|
-
./fmix status --run-id "$FMIX_RUN_ID" --json
|
|
15682
16069
|
./fmix timing --worktree ./cisco-cdr
|
|
15683
16070
|
./fmix gc
|
|
15684
16071
|
./fmix gc --consolidate --yes
|
|
@@ -15699,9 +16086,6 @@ Operational notes:
|
|
|
15699
16086
|
Reclaim multi-sessions: ./fmix gc --consolidate --worktree <path> --yes
|
|
15700
16087
|
Every run appends one JSON line to $FMIX_HOME/logs/runs.jsonl and prints
|
|
15701
16088
|
a greppable "timing total=… hot_path=yes|no" summary on stderr.
|
|
15702
|
-
Runs with a valid FMIX_RUN_ID also publish a private session snapshot,
|
|
15703
|
-
append-only events, and one-second process-tree metrics beneath
|
|
15704
|
-
$FMIX_HOME/telemetry/runs/<run-id>/.
|
|
15705
16089
|
fmix status exits 1 when session metadata discovery is incomplete, while
|
|
15706
16090
|
still printing the remaining read-only diagnostic sections.
|
|
15707
16091
|
Stable seeds are dependency-only; fmix test still validates app artifacts locally.
|
|
@@ -15724,9 +16108,6 @@ Environment overrides:
|
|
|
15724
16108
|
FMIX_DOPPLER_CONFIG Doppler config for credential fallback (default: dev_personal)
|
|
15725
16109
|
FMIX_SESSION_WARN_THRESHOLD Per-host session count that triggers a gc warning (default: 24)
|
|
15726
16110
|
FMIX_STABLE_BASE Opt-in stable dependency base for fmix test (default: unset)
|
|
15727
|
-
FMIX_ENSURE Set to 0 to skip auto-starting shared postgres/NATS (default: 1)
|
|
15728
|
-
FMIX_ENSURE_TIMEOUT Seconds to wait after starting ct-infra (default: 90)
|
|
15729
|
-
FMIX_INFRA_PROJECT Docker Compose project for shared infra (default: ct-infra)
|
|
15730
16111
|
FMIX_DB_HOST Postgres host (default: localhost)
|
|
15731
16112
|
FMIX_DB_PORT Postgres port (default: 5432)
|
|
15732
16113
|
FMIX_DB_USER Postgres user (default: calltelemetry)
|
|
@@ -15749,11 +16130,6 @@ Environment overrides:
|
|
|
15749
16130
|
FMIX_COMPILE_TIMEOUT Per-attempt compile cap in seconds (default: 900)
|
|
15750
16131
|
FMIX_SETUP_COMPILE_TIMEOUT Explicit setup compile cap in seconds (default: 900)
|
|
15751
16132
|
FMIX_TIMING Set to 1 to print per-phase timing lines during a run
|
|
15752
|
-
FMIX_RUN_ID Valid UUID enabling session-scoped run observability
|
|
15753
|
-
FMIX_RESOURCE_SAMPLE_INTERVAL Resource sample seconds (default: 1)
|
|
15754
|
-
FMIX_RESOURCE_SAMPLE_MAX_SAMPLES Raw metric sample cap (default: 14400; max: 86400)
|
|
15755
|
-
FMIX_RESOURCE_SAMPLER_STOP_TIMEOUT_S Graceful sampler stop seconds (default: 2; max: 10)
|
|
15756
|
-
FMIX_TELEMETRY_TTL_HOURS Session telemetry retention in hours (default: 4; max: 8760)
|
|
15757
16133
|
FMIX_MIGRATION_TIMEOUT Migration delta cap in seconds (default: 120)
|
|
15758
16134
|
FMIX_STRUCTURE_LOAD_TIMEOUT explicit cold structure.sql replay cap in seconds (default: 120)
|
|
15759
16135
|
FMIX_STRUCTURE_LOAD_HEARTBEAT structure.sql replay heartbeat seconds (default: 30)
|
|
@@ -17956,15 +18332,14 @@ main() {
|
|
|
17956
18332
|
self-test) cmd_self_test "$@" ;;
|
|
17957
18333
|
*)
|
|
17958
18334
|
fmix_error "Unknown command: $cmd"
|
|
17959
|
-
fmix_error "Valid commands: test, coverage, task, setup, seed publish, cache explain, cache verify,
|
|
18335
|
+
fmix_error "Valid commands: test, coverage, task, setup, seed publish, cache explain, cache verify, doctor, status, timing, gc, install, self-test, version, help"
|
|
17960
18336
|
return 1
|
|
17961
18337
|
;;
|
|
17962
18338
|
esac
|
|
17963
18339
|
}
|
|
17964
18340
|
|
|
17965
|
-
if [[ "${BASH_SOURCE[0]}"
|
|
17966
|
-
|
|
17967
|
-
fi
|
|
18341
|
+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
18342
|
+
: # Keep source-only test extraction valid when it removes the next line.
|
|
17968
18343
|
if [[ "${1:-}" == "--fmix-observability-worker" ]]; then
|
|
17969
18344
|
if [[ "${FMIX_OBSERVABILITY_WORKER:-0}" != "1" \
|
|
17970
18345
|
|| ! "${FMIX_RUN_ID:-}" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ \
|
|
@@ -17981,3 +18356,4 @@ if [[ "${FMIX_RUN_ID:-}" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-
|
|
|
17981
18356
|
exit $?
|
|
17982
18357
|
fi
|
|
17983
18358
|
main "$@"
|
|
18359
|
+
fi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calltelemetry/fmix",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Verified native FMix runner for CallTelemetry workspaces",
|
|
5
5
|
"bin": {
|
|
6
6
|
"fmix": "bin/fmix"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"directory": "packages/npm"
|
|
25
25
|
},
|
|
26
26
|
"fmix": {
|
|
27
|
-
"runnerSha256": "
|
|
28
|
-
"sourceTag": "fmix-v2.
|
|
27
|
+
"runnerSha256": "690eaae729b6fe6d753462ebd82ef5724a1911134ddb00417f17857095d480f0",
|
|
28
|
+
"sourceTag": "fmix-v2.5.0"
|
|
29
29
|
}
|
|
30
30
|
}
|