@calltelemetry/fmix 2.7.13 → 2.7.15

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.
Files changed (2) hide show
  1. package/bin/fmix +720 -96
  2. package/package.json +3 -3
package/bin/fmix CHANGED
@@ -25,7 +25,7 @@ set -uo pipefail
25
25
  # ---------------------------------------------------------------------------
26
26
  # Constants & config
27
27
  # ---------------------------------------------------------------------------
28
- FMIX_VERSION="2.7.13"
28
+ FMIX_VERSION="2.7.15"
29
29
  FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
30
30
  FMIX_OS="$(uname -s)"
31
31
  FMIX_ARCH="$(uname -m)"
@@ -5670,13 +5670,15 @@ fmix_lock_keeper_start() {
5670
5670
  fi
5671
5671
  mkdir -p "$FMIX_HOME/lock-keeper-state" || {
5672
5672
  printf '{"error":"lock_keeper_bootstrap_failed","reason":"state preparation failed"}\n' >&2
5673
+ fmix_error "Check filesystem permissions and agent sandbox write access to FMIX_HOME: $FMIX_HOME"
5673
5674
  return 70
5674
5675
  }
5675
5676
  state="$FMIX_HOME/lock-keeper-state/${lock_name}.${owner_pid}.${RANDOM}.state"
5676
5677
  # Keep the program in argv, not a background heredoc pipe that Bash must
5677
5678
  # fill before exec. A quoted literal also avoids a heredoc-backed command
5678
5679
  # substitution while retaining the single-file Bash 3.2 runner contract.
5679
- keeper_source='import fcntl
5680
+ keeper_source='import errno
5681
+ import fcntl
5680
5682
  import json
5681
5683
  import os
5682
5684
  import signal
@@ -5704,12 +5706,31 @@ def request_stop(_signum, _frame):
5704
5706
  stop_requested = True
5705
5707
 
5706
5708
 
5709
+ def io_failure(operation, target, error):
5710
+ hint = "Check available disk space and filesystem health for FMIX_HOME."
5711
+ if error.errno in (errno.EACCES, errno.EPERM, errno.EROFS):
5712
+ hint = (
5713
+ "Check filesystem permissions and agent sandbox write access to the configured "
5714
+ "FMIX_HOME. Retry only after access is authorized; do not bypass locks or "
5715
+ "relocate only lock state away from the shared cache."
5716
+ )
5717
+ sys.stderr.write(json.dumps({
5718
+ "error": "lock_keeper_io_failed", "operation": operation,
5719
+ "path": str(target), "errno": error.errno, "hint": hint,
5720
+ }) + "\n")
5721
+ sys.stderr.flush()
5722
+ raise SystemExit(70)
5723
+
5724
+
5707
5725
  def publish_state(value):
5708
5726
  temporary = state_path.with_name(
5709
5727
  state_path.name + f".tmp-{os.getpid()}"
5710
5728
  )
5711
- temporary.write_text(value + "\n", encoding="utf-8")
5712
- os.replace(temporary, state_path)
5729
+ try:
5730
+ temporary.write_text(value + "\n", encoding="utf-8")
5731
+ os.replace(temporary, state_path)
5732
+ except OSError as error:
5733
+ io_failure("publish_state", state_path, error)
5713
5734
 
5714
5735
 
5715
5736
  def owner_alive():
@@ -5745,7 +5766,10 @@ def get_holder_info(lock_name, fmix_home):
5745
5766
  signal.signal(signal.SIGTERM, request_stop)
5746
5767
  signal.signal(signal.SIGINT, request_stop)
5747
5768
  publish_state("started")
5748
- fd = os.open(path, os.O_RDWR | os.O_CREAT, 0o600)
5769
+ try:
5770
+ fd = os.open(path, os.O_RDWR | os.O_CREAT, 0o600)
5771
+ except OSError as error:
5772
+ io_failure("open_kernel_lock", path, error)
5749
5773
  os.set_inheritable(fd, False)
5750
5774
  operation = fcntl.LOCK_SH if mode == "shared" else fcntl.LOCK_EX
5751
5775
  try:
@@ -5769,6 +5793,8 @@ try:
5769
5793
  sys.stderr.flush()
5770
5794
  last_heartbeat = now
5771
5795
  time.sleep(0.05)
5796
+ except OSError as error:
5797
+ io_failure("acquire_kernel_lock", path, error)
5772
5798
  else:
5773
5799
  publish_state("stopped")
5774
5800
  raise SystemExit(1)
@@ -7743,6 +7769,7 @@ fmix_ensure_template() {
7743
7769
  fmix_find_warm_donor_session() {
7744
7770
  local worktree="$1" template_key="$2"
7745
7771
  local real py_bin donor
7772
+ shift 2
7746
7773
  real="$(fmix_realpath "$worktree")" || return 1
7747
7774
  [[ -n "$FMIX_ACTIVE_SESSION_ROOT" ]] || return 1
7748
7775
  py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
@@ -7751,21 +7778,22 @@ fmix_find_warm_donor_session() {
7751
7778
  DONOR_WORKTREE="$real" \
7752
7779
  DONOR_TEMPLATE_KEY="$template_key" \
7753
7780
  DONOR_EXCLUDE="$FMIX_ACTIVE_SESSION_ROOT" \
7754
- "$py_bin" - <<'PY'
7755
- import json, os
7781
+ "$py_bin" - "$@" <<'PY'
7782
+ import json, os, sys
7756
7783
  from pathlib import Path
7757
7784
 
7758
7785
  home = Path(os.environ["FMIX_HOME_FOR_DONOR"])
7759
7786
  wt = os.environ["DONOR_WORKTREE"]
7760
7787
  key = os.environ["DONOR_TEMPLATE_KEY"]
7761
- exclude = os.environ["DONOR_EXCLUDE"]
7788
+ excluded = {os.environ["DONOR_EXCLUDE"]}
7789
+ excluded.update(sys.argv[1:])
7762
7790
  root = home / "sessions" / "v1"
7763
7791
  best = None # (is_same_wt, last, path)
7764
7792
  if not root.is_dir():
7765
7793
  raise SystemExit(0)
7766
7794
  for meta in root.glob("*/*/*/meta.json"):
7767
7795
  session_root = meta.parent
7768
- if str(session_root) == exclude:
7796
+ if str(session_root) in excluded:
7769
7797
  continue
7770
7798
  try:
7771
7799
  d = json.loads(meta.read_text(encoding="utf-8"))
@@ -7808,15 +7836,327 @@ PY
7808
7836
  printf '%s\n' "$donor"
7809
7837
  }
7810
7838
 
7839
+ fmix_donor_session_roots_are_owned() {
7840
+ local donor="$1" py_bin
7841
+ py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
7842
+ FMIX_HOME_FOR_DONOR="$FMIX_HOME" \
7843
+ DONOR_ROOT="$donor" \
7844
+ "$py_bin" - <<'PY'
7845
+ import os
7846
+ import re
7847
+ import stat
7848
+ import sys
7849
+
7850
+ configured_home = os.environ["FMIX_HOME_FOR_DONOR"].rstrip(os.sep)
7851
+ home = os.path.realpath(configured_home)
7852
+ donor = os.path.abspath(os.environ["DONOR_ROOT"])
7853
+ fd = None
7854
+ try:
7855
+ if not os.path.isabs(configured_home) or not os.path.isdir(home):
7856
+ raise ValueError("home path")
7857
+ prefix = os.path.join(configured_home, "sessions", "v1") + os.sep
7858
+ if not donor.startswith(prefix) or os.path.normpath(donor) != donor:
7859
+ raise ValueError("session path")
7860
+ components = donor[len(prefix):].split(os.sep)
7861
+ if (len(components) != 3
7862
+ or any(part in ("", ".", "..") for part in components)
7863
+ or not re.fullmatch(r"[0-9a-f]{16}", components[1])):
7864
+ raise ValueError("session components")
7865
+
7866
+ if not hasattr(os, "O_NOFOLLOW") or not hasattr(os, "O_DIRECTORY"):
7867
+ raise ValueError("no-follow directory opens unavailable")
7868
+ flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
7869
+ fd = os.open(home, flags)
7870
+ home_stat = os.fstat(fd)
7871
+ device = home_stat.st_dev
7872
+ owner = os.getuid()
7873
+ if home_stat.st_uid != owner or not stat.S_ISDIR(home_stat.st_mode):
7874
+ raise ValueError("home ownership")
7875
+ for component in ("sessions", "v1", *components):
7876
+ child = os.open(component, flags, dir_fd=fd)
7877
+ os.close(fd)
7878
+ fd = child
7879
+ current = os.fstat(fd)
7880
+ if (current.st_uid != owner or current.st_dev != device
7881
+ or not stat.S_ISDIR(current.st_mode)):
7882
+ raise ValueError("session root ownership")
7883
+ for component in ("deps", "_build"):
7884
+ child = os.open(component, flags, dir_fd=fd)
7885
+ current = os.fstat(child)
7886
+ os.close(child)
7887
+ if (current.st_uid != owner or current.st_dev != device
7888
+ or not stat.S_ISDIR(current.st_mode)):
7889
+ raise ValueError("artifact root ownership")
7890
+ except (OSError, ValueError):
7891
+ raise SystemExit(1)
7892
+ finally:
7893
+ if fd is not None:
7894
+ os.close(fd)
7895
+ PY
7896
+ }
7897
+
7898
+ fmix_donor_session_revalidate() {
7899
+ local donor="$1" target_worktree="$2" template_key="$3" expected_session_hash="$4"
7900
+ local donor_meta="$donor/meta.json" current_session_hash py_bin
7901
+ fmix_donor_session_roots_are_owned "$donor" || return $?
7902
+ [[ -d "$donor/deps" && ! -L "$donor/deps" \
7903
+ && -d "$donor/_build" && ! -L "$donor/_build" \
7904
+ && -f "$donor/artifact-state.json" && -f "$donor/compile-stamp.json" ]] || return 1
7905
+ current_session_hash="$(fmix_session_hash_from_metadata_path "$donor_meta")" || return $?
7906
+ [[ "$current_session_hash" == "$expected_session_hash" ]] || return 1
7907
+ fmix_session_metadata_identity_matches_path "$donor_meta" || return $?
7908
+ py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
7909
+ DONOR_ROOT="$donor" \
7910
+ DONOR_TARGET_WORKTREE="$target_worktree" \
7911
+ DONOR_TEMPLATE_KEY="$template_key" \
7912
+ DONOR_SESSION_HASH="$expected_session_hash" \
7913
+ "$py_bin" - <<'PY'
7914
+ import json
7915
+ import os
7916
+ from pathlib import Path
7917
+
7918
+ root = Path(os.path.abspath(os.environ["DONOR_ROOT"]))
7919
+ target_worktree = os.path.realpath(os.environ["DONOR_TARGET_WORKTREE"])
7920
+ template_key = os.environ["DONOR_TEMPLATE_KEY"]
7921
+ session_hash = os.environ["DONOR_SESSION_HASH"]
7922
+
7923
+ def read_object(name):
7924
+ path = root / name
7925
+ if path.is_symlink() or not path.is_file():
7926
+ raise ValueError(name)
7927
+ value = json.loads(path.read_text(encoding="utf-8"))
7928
+ if not isinstance(value, dict):
7929
+ raise ValueError(name)
7930
+ return value
7931
+
7932
+ def canonical_path(value):
7933
+ if not isinstance(value, str) or not value or not os.path.isabs(value):
7934
+ raise ValueError("path")
7935
+ return os.path.realpath(value)
7936
+
7937
+ try:
7938
+ meta = read_object("meta.json")
7939
+ if meta.get("session_hash") not in (None, session_hash):
7940
+ raise ValueError("session hash")
7941
+ if meta.get("session_id") not in (None, session_hash):
7942
+ raise ValueError("session id")
7943
+ source_worktree = canonical_path(meta.get("worktree"))
7944
+ if ("deps_path" in meta
7945
+ and canonical_path(meta["deps_path"]) != os.path.realpath(root / "deps")):
7946
+ raise ValueError("metadata deps path")
7947
+ if "build_path" in meta:
7948
+ recorded_build_path = canonical_path(meta["build_path"])
7949
+ allowed_build_paths = {
7950
+ os.path.realpath(root / "_build"),
7951
+ os.path.realpath(root / "_build" / "test"),
7952
+ }
7953
+ if recorded_build_path not in allowed_build_paths:
7954
+ raise ValueError("metadata build path")
7955
+
7956
+ artifact_state = read_object("artifact-state.json")
7957
+ if artifact_state.get("template_key") != template_key:
7958
+ raise ValueError("template key")
7959
+
7960
+ compile_stamp = read_object("compile-stamp.json")
7961
+ if ("template_key" in compile_stamp
7962
+ and compile_stamp.get("template_key") != template_key):
7963
+ raise ValueError("compile template key")
7964
+ if ("path" in compile_stamp
7965
+ and canonical_path(compile_stamp["path"]) != source_worktree):
7966
+ raise ValueError("compile path")
7967
+ if ("build_root" in compile_stamp
7968
+ and canonical_path(compile_stamp["build_root"]) != os.path.realpath(root / "_build")):
7969
+ raise ValueError("compile build root")
7970
+
7971
+ dependency_stamp_path = root / "dependency-stamp.json"
7972
+ if dependency_stamp_path.exists() or dependency_stamp_path.is_symlink():
7973
+ dependency_stamp = read_object("dependency-stamp.json")
7974
+ if ("path" in dependency_stamp
7975
+ and canonical_path(dependency_stamp["path"]) != source_worktree):
7976
+ raise ValueError("dependency path")
7977
+ if ("build_root" in dependency_stamp
7978
+ and canonical_path(dependency_stamp["build_root"]) != os.path.realpath(root / "_build")):
7979
+ raise ValueError("dependency build root")
7980
+
7981
+ if source_worktree != target_worktree and compile_stamp.get("schema_version") == 2:
7982
+ if compile_stamp.get("dirty_hash", "clean") != "clean":
7983
+ raise ValueError("dirty cross-worktree donor")
7984
+ except (OSError, TypeError, ValueError, json.JSONDecodeError):
7985
+ raise SystemExit(1)
7986
+ PY
7987
+ }
7988
+
7989
+ fmix_donor_make_stage_writable() {
7990
+ (( $# == 2 )) || return 1
7991
+ chmod -R u+w "$1" "$2"
7992
+ }
7993
+
7994
+ fmix_donor_copy_stamps() {
7995
+ (( $# == 2 )) || return 1
7996
+ local donor="$1" stage_root="$2"
7997
+ cp -f "$donor/compile-stamp.json" "$stage_root/compile-stamp.json" || return 1
7998
+ if [[ -f "$donor/dependency-stamp.json" ]]; then
7999
+ cp -f "$donor/dependency-stamp.json" "$stage_root/dependency-stamp.json" || return 1
8000
+ fi
8001
+ }
8002
+
8003
+ fmix_donor_rebind_staged_stamps() {
8004
+ local stage_root="$1" real="$2" build_root="$3" py_bin="$4"
8005
+ "$py_bin" - "$stage_root" "$real" "$build_root" <<'PY'
8006
+ import json
8007
+ import os
8008
+ import sys
8009
+ from pathlib import Path
8010
+
8011
+ root = Path(sys.argv[1])
8012
+ real = sys.argv[2]
8013
+ build_root = sys.argv[3]
8014
+ for name in ("compile-stamp.json", "dependency-stamp.json"):
8015
+ path = root / name
8016
+ if not path.exists() and not path.is_symlink():
8017
+ if name == "compile-stamp.json":
8018
+ raise SystemExit(1)
8019
+ continue
8020
+ if path.is_symlink() or not path.is_file():
8021
+ raise SystemExit(1)
8022
+ try:
8023
+ value = json.loads(path.read_text(encoding="utf-8"))
8024
+ if not isinstance(value, dict):
8025
+ raise ValueError(name)
8026
+ value["path"] = real
8027
+ value["build_root"] = build_root
8028
+ temporary = path.with_name(path.name + f".tmp-{os.getpid()}")
8029
+ temporary.write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8")
8030
+ os.replace(temporary, path)
8031
+ except (OSError, TypeError, ValueError, json.JSONDecodeError):
8032
+ raise SystemExit(1)
8033
+ PY
8034
+ }
8035
+
8036
+ fmix_donor_stage_artifact_state() {
8037
+ (( $# == 3 )) || return 1
8038
+ local staged_root="$1" worktree="$2" template_key="$3"
8039
+ local original_session_root="$FMIX_ACTIVE_SESSION_ROOT" rc=0
8040
+ FMIX_ACTIVE_SESSION_ROOT="$staged_root"
8041
+ fmix_write_artifact_state "$worktree" "$template_key" || rc=$?
8042
+ FMIX_ACTIVE_SESSION_ROOT="$original_session_root"
8043
+ return "$rc"
8044
+ }
8045
+
8046
+ fmix_donor_transaction_move() {
8047
+ (( $# == 3 )) || return 1
8048
+ mv "$1" "$2"
8049
+ }
8050
+
8051
+ fmix_donor_transaction_stage_cleanup() {
8052
+ (( $# == 1 )) || return 1
8053
+ local stage="$1"
8054
+ fmix_guard_path "$stage" || return 1
8055
+ rm -rf "$stage" || return 1
8056
+ [[ ! -e "$stage" && ! -L "$stage" ]]
8057
+ }
8058
+
8059
+ _fmix_donor_install_interrupt() {
8060
+ if (( ${donor_install_interrupted:-0} == 0 )); then
8061
+ donor_install_interrupted=1
8062
+ donor_install_interrupt_rc="${1:-130}"
8063
+ fi
8064
+ }
8065
+
8066
+ fmix_donor_restore_interrupt_traps() {
8067
+ (( $# == 3 )) || return 1
8068
+ local saved_int="$1" saved_term="$2" saved_hup="$3"
8069
+ if [[ -n "$saved_int" ]]; then eval "$saved_int"; else trap - INT; fi
8070
+ if [[ -n "$saved_term" ]]; then eval "$saved_term"; else trap - TERM; fi
8071
+ if [[ -n "$saved_hup" ]]; then eval "$saved_hup"; else trap - HUP; fi
8072
+ }
8073
+
8074
+ fmix_donor_session_lease_release() {
8075
+ local lock_name="${1:-}" operation_rc="${2:-0}" release_rc=0
8076
+ fmix_lock_release "$lock_name" || release_rc=$?
8077
+ if [[ -n "$FMIX_PENDING_LOCK_KEEPER_PID" ]] && (( release_rc == 0 )); then
8078
+ release_rc=70
8079
+ fi
8080
+ if (( release_rc != 0 )); then
8081
+ FMIX_ARTIFACT_LEASE_RELEASE_FAILED=1
8082
+ printf '{"error":"donor_session_lock_cleanup_failed","operation_exit_code":%d,"cleanup_exit_code":%d}\n' \
8083
+ "$operation_rc" "$release_rc" >&2
8084
+ fmix_error "Donor session lease cleanup failed (operation rc=$operation_rc, release rc=$release_rc)."
8085
+ return 70
8086
+ fi
8087
+ return 0
8088
+ }
8089
+
8090
+ _fmix_donor_abort_staging() {
8091
+ (( $# == 4 )) || return 70
8092
+ local lock_name="$1" stage="${2:-}" operation_rc="$3"
8093
+ local lease_held="$4" release_rc=0 cleanup_rc=0 restore_rc=0
8094
+
8095
+ if (( donor_install_interrupted != 0 )); then
8096
+ operation_rc="$donor_install_interrupt_rc"
8097
+ fi
8098
+ # The scoped signal handler only records cancellation while cleanup runs;
8099
+ # keep it installed through lease retirement and stage removal.
8100
+ if (( lease_held != 0 )); then
8101
+ fmix_donor_session_lease_release "$lock_name" "$operation_rc" \
8102
+ || release_rc=$?
8103
+ fi
8104
+ # Keep staging inputs when lease release is not confirmed. Cleanup failure
8105
+ # also remains fatal, with whatever recovery data is left kept in place.
8106
+ if (( release_rc == 0 )) && [[ -n "$stage" ]]; then
8107
+ fmix_donor_transaction_stage_cleanup "$stage" || cleanup_rc=$?
8108
+ fi
8109
+ if (( cleanup_rc != 0 )); then
8110
+ fmix_error "Could not clean failed donor staging; preserving recovery inputs: $stage"
8111
+ fi
8112
+ fmix_donor_restore_interrupt_traps \
8113
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" || restore_rc=$?
8114
+ # A signal delivered while the previous handlers are being restored must
8115
+ # still become the caller-visible result instead of an ordinary cache miss.
8116
+ if (( donor_install_interrupted != 0 )); then
8117
+ operation_rc="$donor_install_interrupt_rc"
8118
+ fi
8119
+ if (( release_rc != 0 )); then
8120
+ return 70
8121
+ fi
8122
+ if (( cleanup_rc != 0 )); then
8123
+ return 70
8124
+ fi
8125
+ if (( restore_rc != 0 )); then
8126
+ fmix_error "Could not restore caller signal traps after donor staging cleanup."
8127
+ return 70
8128
+ fi
8129
+ return "$operation_rc"
8130
+ }
8131
+
7811
8132
  fmix_clone_donor_to_session() {
7812
- local worktree="$1" donor="$2" deps_root build_root retired retired_used=0 real py_bin
8133
+ local worktree="$1" donor="$2" template_key="${3:-}"
8134
+ local deps_root build_root real py_bin
8135
+ local donor_meta donor_session_hash donor_lock_name
8136
+ local target_session_root dependency_stamp compile_stamp artifact_state
8137
+ local donor_lease_rc=0 donor_lease_held=0 donor_restore_rc=0
8138
+ local donor_signal_after_restore=0
8139
+ local stage="" stage_new stage_old stage_rc=0 stage_cleanup_rc=0
8140
+ local transaction_rc=0 rollback_failed=0 index item_name item_source item_target move_rc
8141
+ local revalidate_rc=0
8142
+ local donor_install_interrupted=0 donor_install_interrupt_rc=0
8143
+ local saved_trap_int saved_trap_term saved_trap_hup
8144
+ (( $# == 3 )) && [[ "$template_key" =~ ^[0-9a-f]{16}$ ]] || return 1
7813
8145
  real="$(fmix_realpath "$worktree")" || return 1
7814
8146
  deps_root="$(fmix_session_deps_root "$worktree")" || return 1
7815
8147
  build_root="$(fmix_compile_build_root "$worktree")" || return 1
7816
8148
 
7817
8149
  [[ -n "$FMIX_ACTIVE_SESSION_ROOT" ]] || return 1
8150
+ target_session_root="$FMIX_ACTIVE_SESSION_ROOT"
8151
+ [[ -d "$target_session_root" && ! -L "$target_session_root" ]] || return 1
7818
8152
  [[ "$deps_root" == "$FMIX_ACTIVE_SESSION_ROOT/deps" \
7819
8153
  && "$build_root" == "$FMIX_ACTIVE_SESSION_ROOT/_build" ]] || return 1
8154
+ dependency_stamp="$(fmix_dependency_stamp_file "$worktree")" || return 1
8155
+ compile_stamp="$(fmix_compile_stamp_file "$worktree")" || return 1
8156
+ artifact_state="$(fmix_artifact_state_file "$worktree")" || return 1
8157
+ [[ "$dependency_stamp" == "$target_session_root/dependency-stamp.json" \
8158
+ && "$compile_stamp" == "$target_session_root/compile-stamp.json" \
8159
+ && "$artifact_state" == "$target_session_root/artifact-state.json" ]] || return 1
7820
8160
  fmix_guard_path "$donor" || {
7821
8161
  fmix_error "Donor path is outside FMIX_HOME: $donor"
7822
8162
  return 1
@@ -7827,99 +8167,357 @@ fmix_clone_donor_to_session() {
7827
8167
 
7828
8168
  py_bin="$(fmix_python_bin 2>/dev/null || echo python3)"
7829
8169
 
7830
- # Lock-Then-Revalidate (LOCK_SH): a dedicated keeper owns the descriptor,
7831
- # so copy helpers cannot inherit and extend donor-lock lifetime.
7832
- local donor_keeper_pid donor_keeper_rc=0
7833
- [[ -f "$donor/meta.json" ]] || return 1
7834
- fmix_lock_keeper_start "$donor/meta.json" shared 0 \
7835
- "donor session clone" "donor-$(fmix_hash_string "$donor" | cut -c1-16)" || donor_keeper_rc=$?
7836
- if (( donor_keeper_rc != 0 )); then
7837
- fmix_warn "Could not acquire shared lock on donor session $donor."
7838
- return "$donor_keeper_rc"
7839
- fi
7840
- donor_keeper_pid="$FMIX_LAST_LOCK_KEEPER_PID"
7841
-
7842
- # Revalidate donor artifacts under active LOCK_SH
7843
- if [[ ! -d "$donor/deps" || ! -d "$donor/_build" || ! -f "$donor/compile-stamp.json" ]]; then
7844
- fmix_lock_keeper_retire "$donor_keeper_pid" || return 70
7845
- fmix_warn "Donor session $donor missing required artifacts during revalidation."
7846
- return 1
8170
+ # Donor sessions share the same persistent session kernel lock used by
8171
+ # execution and GC. Never derive this lock from a metadata field: metadata
8172
+ # is replaceable, so derive and validate the identity from its canonical
8173
+ # session path before acquiring the lease.
8174
+ donor_meta="$donor/meta.json"
8175
+ [[ -f "$donor_meta" && ! -L "$donor_meta" ]] || return 1
8176
+ donor_session_hash="$(fmix_session_hash_from_metadata_path "$donor_meta")" || return 1
8177
+ fmix_session_metadata_identity_matches_path "$donor_meta" || return 1
8178
+ donor_lock_name="session-$donor_session_hash"
8179
+ # Guard the entire leased read, including revalidation and staging copies.
8180
+ # The saved caller handlers are restored on every exit after admission.
8181
+ saved_trap_int="$(trap -p INT)"
8182
+ saved_trap_term="$(trap -p TERM)"
8183
+ saved_trap_hup="$(trap -p HUP)"
8184
+ trap '_fmix_donor_install_interrupt 130' INT
8185
+ trap '_fmix_donor_install_interrupt 143' TERM
8186
+ trap '_fmix_donor_install_interrupt 129' HUP
8187
+ # Use the canonical session lease so new and legacy FMix binaries arbitrate
8188
+ # on the same mkdir record as execution and GC. This intentionally takes an
8189
+ # exclusive, zero-wait lease only for the duration of copying one donor.
8190
+ # Passive mode refuses preexisting legacy metadata without stale cleanup.
8191
+ fmix_lock_acquire "$donor_lock_name" 0 "donor session clone" 1 || donor_lease_rc=$?
8192
+ if (( donor_lease_rc != 0 )); then
8193
+ fmix_donor_restore_interrupt_traps \
8194
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" \
8195
+ || donor_restore_rc=$?
8196
+ if (( donor_install_interrupted != 0 )); then
8197
+ donor_signal_after_restore=1
8198
+ fi
8199
+ if (( donor_restore_rc != 0 )); then return 70; fi
8200
+ fmix_lock_failure_is_fatal "$donor_lease_rc" && return 70
8201
+ if (( donor_signal_after_restore != 0 )); then
8202
+ donor_lease_rc="$donor_install_interrupt_rc"
8203
+ fi
8204
+ fmix_warn "Could not acquire exclusive donor session lease for $donor."
8205
+ return "$donor_lease_rc"
8206
+ fi
8207
+ donor_lease_held=1
8208
+ if (( donor_install_interrupted != 0 )); then
8209
+ _fmix_donor_abort_staging \
8210
+ "$donor_lock_name" "" "$donor_install_interrupt_rc" "$donor_lease_held"
8211
+ return $?
7847
8212
  fi
7848
8213
 
7849
- retired="$FMIX_ACTIVE_SESSION_ROOT/retired/$(date +%Y%m%dT%H%M%S)-$$-${RANDOM}"
7850
- if [[ -e "$deps_root" || -L "$deps_root" \
7851
- || -e "$build_root" || -L "$build_root" ]]; then
7852
- mkdir -p "$retired" || { fmix_lock_keeper_retire "$donor_keeper_pid" || return 70; return 1; }
7853
- retired_used=1
7854
- [[ -e "$deps_root" || -L "$deps_root" ]] && mv "$deps_root" "$retired/deps"
7855
- [[ -e "$build_root" || -L "$build_root" ]] && mv "$build_root" "$retired/_build"
8214
+ # Atomic metadata replacement does not release this path-derived canonical
8215
+ # session lease. Re-read identity, paths, key, and existing stamps while held.
8216
+ fmix_donor_session_revalidate \
8217
+ "$donor" "$real" "$template_key" "$donor_session_hash" || revalidate_rc=$?
8218
+ if (( donor_install_interrupted != 0 )); then
8219
+ revalidate_rc="$donor_install_interrupt_rc"
8220
+ fi
8221
+ if (( revalidate_rc != 0 )); then
8222
+ if (( donor_install_interrupted == 0 )); then
8223
+ fmix_warn "Donor session $donor failed identity or artifact revalidation."
8224
+ fi
8225
+ _fmix_donor_abort_staging \
8226
+ "$donor_lock_name" "" "$revalidate_rc" "$donor_lease_held"
8227
+ return $?
7856
8228
  fi
7857
8229
 
7858
- if ! fmix_cow_clone "$donor/deps" "$deps_root"; then
7859
- fmix_lock_keeper_retire "$donor_keeper_pid" || return 70
7860
- return 1
8230
+ stage="$(mktemp -d "$target_session_root/.donor-install.XXXXXX")" || stage_rc=$?
8231
+ if (( donor_install_interrupted != 0 )); then
8232
+ stage_rc="$donor_install_interrupt_rc"
7861
8233
  fi
7862
- if ! fmix_cow_clone "$donor/_build" "$build_root"; then
7863
- mkdir -p "$retired" || true
7864
- mv "$deps_root" "$retired/failed-deps" 2>/dev/null || true
7865
- fmix_lock_keeper_retire "$donor_keeper_pid" || return 70
7866
- return 1
8234
+ if (( stage_rc != 0 )); then
8235
+ _fmix_donor_abort_staging \
8236
+ "$donor_lock_name" "$stage" "$stage_rc" "$donor_lease_held"
8237
+ return $?
7867
8238
  fi
7868
- chmod -R u+w "$deps_root" "$build_root" || {
7869
- fmix_error "Could not make donor clone writable."
7870
- fmix_lock_keeper_retire "$donor_keeper_pid" || return 70
7871
- return 1
7872
- }
7873
-
7874
- # Import proven stamps so fmix_ensure_compile can stamp-hit when content matches.
7875
- local f
7876
- for f in dependency-stamp.json compile-stamp.json; do
7877
- if [[ -f "$donor/$f" ]]; then
7878
- cp -f "$donor/$f" "$FMIX_ACTIVE_SESSION_ROOT/$f" || true
8239
+ stage_new="$stage/new"
8240
+ stage_old="$stage/old"
8241
+ mkdir -p "$stage_new" "$stage_old" || stage_rc=$?
8242
+ if (( donor_install_interrupted != 0 )); then
8243
+ stage_rc="$donor_install_interrupt_rc"
8244
+ fi
8245
+ if (( stage_rc == 0 )); then
8246
+ fmix_cow_clone "$donor/deps" "$stage_new/deps" || stage_rc=$?
8247
+ if (( donor_install_interrupted != 0 )); then
8248
+ stage_rc="$donor_install_interrupt_rc"
7879
8249
  fi
7880
- done
8250
+ fi
8251
+ if (( stage_rc == 0 )); then
8252
+ fmix_cow_clone "$donor/_build" "$stage_new/_build" || stage_rc=$?
8253
+ if (( donor_install_interrupted != 0 )); then
8254
+ stage_rc="$donor_install_interrupt_rc"
8255
+ fi
8256
+ fi
8257
+ if (( stage_rc == 0 )); then
8258
+ fmix_donor_make_stage_writable \
8259
+ "$stage_new/deps" "$stage_new/_build" || stage_rc=$?
8260
+ if (( donor_install_interrupted != 0 )); then
8261
+ stage_rc="$donor_install_interrupt_rc"
8262
+ fi
8263
+ fi
8264
+ if (( stage_rc == 0 )); then
8265
+ fmix_donor_copy_stamps "$donor" "$stage_new" || stage_rc=$?
8266
+ if (( donor_install_interrupted != 0 )); then
8267
+ stage_rc="$donor_install_interrupt_rc"
8268
+ fi
8269
+ fi
8270
+ if (( stage_rc == 0 )); then
8271
+ fmix_donor_rebind_staged_stamps \
8272
+ "$stage_new" "$real" "$build_root" "$py_bin" || stage_rc=$?
8273
+ if (( donor_install_interrupted != 0 )); then
8274
+ stage_rc="$donor_install_interrupt_rc"
8275
+ fi
8276
+ fi
8277
+ if (( stage_rc == 0 )); then
8278
+ find "$stage_new/_build" -type f -name 'compile.*' -exec touch {} + \
8279
+ 2>/dev/null || stage_rc=$?
8280
+ if (( donor_install_interrupted != 0 )); then
8281
+ stage_rc="$donor_install_interrupt_rc"
8282
+ fi
8283
+ if (( stage_rc == 0 )); then
8284
+ find "$stage_new/deps" -type f -name 'CMakeCache.txt' -delete \
8285
+ 2>/dev/null || stage_rc=$?
8286
+ fi
8287
+ if (( donor_install_interrupted != 0 )); then
8288
+ stage_rc="$donor_install_interrupt_rc"
8289
+ fi
8290
+ if (( stage_rc == 0 )); then
8291
+ find "$stage_new/deps" -type d -name 'c_build' -exec rm -rf {} + \
8292
+ 2>/dev/null || stage_rc=$?
8293
+ fi
8294
+ if (( donor_install_interrupted != 0 )); then
8295
+ stage_rc="$donor_install_interrupt_rc"
8296
+ fi
8297
+ if (( stage_rc == 0 )); then
8298
+ find "$stage_new/deps" -type d -name 'CMakeFiles' -exec rm -rf {} + \
8299
+ 2>/dev/null || stage_rc=$?
8300
+ fi
8301
+ if (( donor_install_interrupted != 0 )); then
8302
+ stage_rc="$donor_install_interrupt_rc"
8303
+ fi
8304
+ fi
8305
+ if (( stage_rc != 0 )); then
8306
+ _fmix_donor_abort_staging \
8307
+ "$donor_lock_name" "$stage" "$stage_rc" "$donor_lease_held"
8308
+ return $?
8309
+ fi
8310
+ # No donor bytes or stamps are read after this point; release the source
8311
+ # session lease before publishing the target's artifact-state marker.
8312
+ if ! fmix_donor_session_lease_release "$donor_lock_name" 0; then
8313
+ donor_lease_held=0
8314
+ donor_restore_rc=0
8315
+ fmix_donor_restore_interrupt_traps \
8316
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" \
8317
+ || donor_restore_rc=$?
8318
+ if (( donor_install_interrupted != 0 )); then
8319
+ donor_lease_rc="$donor_install_interrupt_rc"
8320
+ fi
8321
+ (( donor_restore_rc == 0 )) || return 70
8322
+ return 70
8323
+ fi
8324
+ donor_lease_held=0
8325
+ if (( donor_install_interrupted != 0 )); then
8326
+ _fmix_donor_abort_staging \
8327
+ "$donor_lock_name" "$stage" "$donor_install_interrupt_rc" "$donor_lease_held"
8328
+ return $?
8329
+ fi
7881
8330
 
7882
- # Rebind path and build_root in cloned stamps to target session's bound realpath
7883
- "$py_bin" - "$FMIX_ACTIVE_SESSION_ROOT" "$real" "$build_root" <<'PY' 2>/dev/null
7884
- import json, sys
7885
- from pathlib import Path
7886
- sroot = Path(sys.argv[1])
7887
- r_path = sys.argv[2]
7888
- b_root = sys.argv[3]
7889
- for name in ("compile-stamp.json", "dependency-stamp.json"):
7890
- p = sroot / name
7891
- if p.is_file():
7892
- try:
7893
- d = json.loads(p.read_text(encoding="utf-8"))
7894
- d["path"] = r_path
7895
- d["build_root"] = b_root
7896
- p.write_text(json.dumps(d, indent=2) + "\n", encoding="utf-8")
7897
- except Exception:
7898
- pass
7899
- PY
7900
- true
8331
+ stage_rc=0
8332
+ fmix_donor_stage_artifact_state \
8333
+ "$stage_new" "$worktree" "$template_key" || stage_rc=$?
8334
+ if (( donor_install_interrupted != 0 )); then
8335
+ stage_rc="$donor_install_interrupt_rc"
8336
+ fi
8337
+ if (( stage_rc != 0 )); then
8338
+ _fmix_donor_abort_staging \
8339
+ "$donor_lock_name" "$stage" "$stage_rc" "$donor_lease_held"
8340
+ return $?
8341
+ fi
7901
8342
 
7902
- # Release LOCK_SH on donor.
7903
- fmix_lock_keeper_retire "$donor_keeper_pid" || return 70
8343
+ local -a donor_item_names=(deps _build dependency-stamp.json compile-stamp.json artifact-state.json)
8344
+ local -a donor_item_targets=("$deps_root" "$build_root" "$dependency_stamp" "$compile_stamp" "$artifact_state")
8345
+ local -a donor_item_backed=()
8346
+ local -a donor_item_installed=()
8347
+ for (( index = 0; index < ${#donor_item_names[@]}; index++ )); do
8348
+ donor_item_backed[$index]=0
8349
+ donor_item_installed[$index]=0
8350
+ done
7904
8351
 
7905
- # Post-clone manifest synchronization: touch compile manifests to prevent full DAG recompiles
7906
- find "$build_root" -type f -name 'compile.*' -exec touch {} + 2>/dev/null || true
8352
+ # Stage every donor byte and provenance file before moving any active path.
8353
+ # Keep old state beside the transaction until artifact-state is installed last.
8354
+ for (( index = 0; index < ${#donor_item_names[@]}; index++ )); do
8355
+ if (( donor_install_interrupted != 0 )); then
8356
+ transaction_rc="$donor_install_interrupt_rc"
8357
+ break
8358
+ fi
8359
+ item_name="${donor_item_names[$index]}"
8360
+ item_target="${donor_item_targets[$index]}"
8361
+ if [[ -e "$item_target" || -L "$item_target" ]]; then
8362
+ move_rc=0
8363
+ fmix_donor_transaction_move \
8364
+ "$item_target" "$stage_old/$item_name" "backup:$item_name" \
8365
+ || move_rc=$?
8366
+ if [[ ! -e "$item_target" && ! -L "$item_target" \
8367
+ && ( -e "$stage_old/$item_name" || -L "$stage_old/$item_name" ) ]]; then
8368
+ donor_item_backed[$index]=1
8369
+ fi
8370
+ if (( move_rc != 0 || donor_item_backed[$index] == 0 )); then
8371
+ transaction_rc="$move_rc"
8372
+ (( transaction_rc != 0 )) || transaction_rc=1
8373
+ break
8374
+ fi
8375
+ fi
8376
+ done
8377
+ if (( donor_install_interrupted != 0 )); then
8378
+ transaction_rc="$donor_install_interrupt_rc"
8379
+ fi
8380
+ if (( transaction_rc == 0 )); then
8381
+ for (( index = 0; index < ${#donor_item_names[@]}; index++ )); do
8382
+ if (( donor_install_interrupted != 0 )); then
8383
+ transaction_rc="$donor_install_interrupt_rc"
8384
+ break
8385
+ fi
8386
+ item_name="${donor_item_names[$index]}"
8387
+ item_source="$stage_new/$item_name"
8388
+ item_target="${donor_item_targets[$index]}"
8389
+ if [[ ! -e "$item_source" && ! -L "$item_source" ]]; then
8390
+ [[ "$item_name" == "dependency-stamp.json" ]] && continue
8391
+ transaction_rc=1
8392
+ break
8393
+ fi
8394
+ move_rc=0
8395
+ fmix_donor_transaction_move \
8396
+ "$item_source" "$item_target" "install:$item_name" \
8397
+ || move_rc=$?
8398
+ if [[ ! -e "$item_source" && ! -L "$item_source" \
8399
+ && ( -e "$item_target" || -L "$item_target" ) ]]; then
8400
+ donor_item_installed[$index]=1
8401
+ fi
8402
+ if (( move_rc != 0 || donor_item_installed[$index] == 0 )); then
8403
+ transaction_rc="$move_rc"
8404
+ (( transaction_rc != 0 )) || transaction_rc=1
8405
+ break
8406
+ fi
8407
+ if (( donor_install_interrupted != 0 )); then
8408
+ transaction_rc="$donor_install_interrupt_rc"
8409
+ break
8410
+ fi
8411
+ done
8412
+ fi
8413
+ if (( donor_install_interrupted != 0 )); then
8414
+ transaction_rc="$donor_install_interrupt_rc"
8415
+ fi
8416
+
8417
+ if (( transaction_rc == 0 && donor_install_interrupted != 0 )); then
8418
+ transaction_rc="$donor_install_interrupt_rc"
8419
+ fi
8420
+ if (( transaction_rc != 0 )); then
8421
+ for (( index = ${#donor_item_names[@]} - 1; index >= 0; index-- )); do
8422
+ if (( donor_item_installed[$index] == 1 )); then
8423
+ item_name="${donor_item_names[$index]}"
8424
+ item_source="${donor_item_targets[$index]}"
8425
+ item_target="$stage_new/$item_name"
8426
+ if [[ ( -e "$item_source" || -L "$item_source" ) \
8427
+ && ! -e "$item_target" && ! -L "$item_target" ]]; then
8428
+ move_rc=0
8429
+ fmix_donor_transaction_move \
8430
+ "$item_source" "$item_target" "rollback-new:$item_name" \
8431
+ || move_rc=$?
8432
+ if [[ -e "$item_source" || -L "$item_source" \
8433
+ || ! -e "$item_target" && ! -L "$item_target" ]]; then
8434
+ rollback_failed=1
8435
+ fi
8436
+ else
8437
+ rollback_failed=1
8438
+ fi
8439
+ fi
8440
+ done
8441
+ for (( index = ${#donor_item_names[@]} - 1; index >= 0; index-- )); do
8442
+ if (( donor_item_backed[$index] == 1 )); then
8443
+ item_name="${donor_item_names[$index]}"
8444
+ item_source="$stage_old/$item_name"
8445
+ item_target="${donor_item_targets[$index]}"
8446
+ if [[ ( -e "$item_source" || -L "$item_source" ) \
8447
+ && ! -e "$item_target" && ! -L "$item_target" ]]; then
8448
+ move_rc=0
8449
+ fmix_donor_transaction_move \
8450
+ "$item_source" "$item_target" "rollback-old:$item_name" \
8451
+ || move_rc=$?
8452
+ if [[ -e "$item_source" || -L "$item_source" \
8453
+ || ! -e "$item_target" && ! -L "$item_target" ]]; then
8454
+ rollback_failed=1
8455
+ fi
8456
+ else
8457
+ rollback_failed=1
8458
+ fi
8459
+ fi
8460
+ done
8461
+ if (( donor_install_interrupted != 0 )); then
8462
+ transaction_rc="$donor_install_interrupt_rc"
8463
+ fi
8464
+ if (( rollback_failed != 0 )); then
8465
+ fmix_error "Donor clone rollback incomplete; preserving recovery inputs: $stage"
8466
+ donor_restore_rc=0
8467
+ fmix_donor_restore_interrupt_traps \
8468
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" \
8469
+ || donor_restore_rc=$?
8470
+ if (( donor_install_interrupted != 0 )); then
8471
+ transaction_rc="$donor_install_interrupt_rc"
8472
+ fi
8473
+ (( donor_restore_rc == 0 )) || return 70
8474
+ return 2
8475
+ fi
8476
+ stage_cleanup_rc=0
8477
+ fmix_donor_transaction_stage_cleanup "$stage" || stage_cleanup_rc=$?
8478
+ if (( donor_install_interrupted != 0 )); then
8479
+ transaction_rc="$donor_install_interrupt_rc"
8480
+ fi
8481
+ if (( stage_cleanup_rc != 0 )); then
8482
+ fmix_error "Could not clean rolled-back donor staging: $stage"
8483
+ fi
8484
+ donor_restore_rc=0
8485
+ fmix_donor_restore_interrupt_traps \
8486
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" \
8487
+ || donor_restore_rc=$?
8488
+ if (( donor_install_interrupted != 0 )); then
8489
+ transaction_rc="$donor_install_interrupt_rc"
8490
+ fi
8491
+ (( donor_restore_rc == 0 )) || return 70
8492
+ if (( stage_cleanup_rc != 0 )); then
8493
+ return 70
8494
+ fi
8495
+ return "$transaction_rc"
8496
+ fi
7907
8497
 
7908
- # Sanitize CMake / NIF artifacts
7909
- find "$deps_root" -type f -name 'CMakeCache.txt' -delete 2>/dev/null || true
7910
- find "$deps_root" -type d -name 'c_build' -exec rm -rf {} + 2>/dev/null || true
7911
- find "$deps_root" -type d -name 'CMakeFiles' -exec rm -rf {} + 2>/dev/null || true
8498
+ # The source lease has been released after copy and stamp rebinding. Old
8499
+ # target state remains in the transaction until final staging cleanup.
8500
+ stage_cleanup_rc=0
8501
+ fmix_donor_transaction_stage_cleanup "$stage" || stage_cleanup_rc=$?
8502
+ if (( stage_cleanup_rc != 0 )); then
8503
+ fmix_error "Donor clone committed but old transaction data remains: $stage"
8504
+ fi
8505
+ donor_restore_rc=0
8506
+ fmix_donor_restore_interrupt_traps \
8507
+ "$saved_trap_int" "$saved_trap_term" "$saved_trap_hup" \
8508
+ || donor_restore_rc=$?
8509
+ if (( donor_install_interrupted != 0 )); then
8510
+ transaction_rc="$donor_install_interrupt_rc"
8511
+ fi
8512
+ (( donor_restore_rc == 0 )) || return 70
8513
+ if (( stage_cleanup_rc != 0 )); then
8514
+ return 70
8515
+ fi
8516
+ if (( donor_install_interrupted != 0 )); then
8517
+ return "$donor_install_interrupt_rc"
8518
+ fi
7912
8519
 
7913
- # NIF path-drift heal after CoW into a new session path.
7914
8520
  fmix_check_known_nif_caches "$worktree" 2>/dev/null || true
7915
-
7916
- if (( retired_used == 1 )); then
7917
- if fmix_guard_path "$retired" && rm -rf "$retired"; then
7918
- rmdir "$(dirname "$retired")" 2>/dev/null || true
7919
- else
7920
- fmix_warn "Donor clone succeeded, but retired artifacts remain: $retired"
7921
- fi
7922
- fi
7923
8521
  fmix_info "Warm donor cloned into session."
7924
8522
  return 0
7925
8523
  }
@@ -8233,10 +8831,32 @@ _fmix_ensure_artifacts_impl() {
8233
8831
  fi
8234
8832
  # Prefer a warm peer session for the same worktree+template over a cold
8235
8833
  # template clone (avoids ~4700-file recompile when isolate/new session).
8236
- local donor=""
8237
- if donor="$(fmix_find_warm_donor_session "$worktree" "$template_key")"; then
8238
- if fmix_clone_donor_to_session "$worktree" "$donor"; then
8239
- fmix_write_artifact_state "$worktree" "$template_key" || return 1
8834
+ # A contended donor can be skipped, but the retry window is deliberately
8835
+ # small so donor discovery never becomes an unbounded session scan/clone.
8836
+ local donor="" donor_attempt donor_seen tried_donor
8837
+ local donor_attempt_limit=3 donor_attempted=0
8838
+ local -a attempted_donors=()
8839
+ for (( donor_attempt = 0; donor_attempt < donor_attempt_limit; donor_attempt++ )); do
8840
+ donor=""
8841
+ if ! donor="$(fmix_find_warm_donor_session \
8842
+ "$worktree" "$template_key" ${attempted_donors[@]+"${attempted_donors[@]}"})"; then
8843
+ break
8844
+ fi
8845
+ [[ -n "$donor" ]] || break
8846
+ donor_seen=0
8847
+ for tried_donor in ${attempted_donors[@]+"${attempted_donors[@]}"}; do
8848
+ if [[ "$tried_donor" == "$donor" ]]; then
8849
+ donor_seen=1
8850
+ break
8851
+ fi
8852
+ done
8853
+ # Be defensive against older wrappers or test doubles that do not
8854
+ # implement optional exclusions: never try the same donor twice.
8855
+ (( donor_seen == 0 )) || break
8856
+ attempted_donors+=("$donor")
8857
+ donor_attempted=$(( donor_attempted + 1 ))
8858
+
8859
+ if fmix_clone_donor_to_session "$worktree" "$donor" "$template_key"; then
8240
8860
  FMIX_LAST_ARTIFACTS_OUTCOME="donor_clone"
8241
8861
  return 0
8242
8862
  else
@@ -8246,9 +8866,13 @@ _fmix_ensure_artifacts_impl() {
8246
8866
  fmix_lock_failure_is_fatal "$donor_rc" && return 70
8247
8867
  fi
8248
8868
  # Only an ordinary donor miss permits fallback. A keeper bootstrap or
8249
- # retirement failure must not admit artifacts while recovery is pending.
8869
+ # retirement failure must not admit artifacts or attempt another donor
8870
+ # while recovery is pending.
8250
8871
  (( donor_rc == 1 )) || return "$donor_rc"
8251
- fmix_warn "Warm donor clone failed; falling back to immutable template."
8872
+ fmix_warn "Warm donor clone failed; trying another eligible donor if available."
8873
+ done
8874
+ if (( donor_attempted > 0 )); then
8875
+ fmix_warn "Warm donor attempts exhausted or unavailable; falling back to immutable template."
8252
8876
  fi
8253
8877
 
8254
8878
  FMIX_TEMPLATE_BUILT_FROM_ACTIVE_SESSION=0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calltelemetry/fmix",
3
- "version": "2.7.13",
3
+ "version": "2.7.15",
4
4
  "description": "Verified native FMix runner for CallTelemetry workspaces",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -26,7 +26,7 @@
26
26
  "directory": "packages/npm"
27
27
  },
28
28
  "fmix": {
29
- "runnerSha256": "2438b033c93d8b1b99e4d484edad68fd74a511048316fc30d57fda780c846222",
30
- "sourceTag": "fmix-v2.7.13"
29
+ "runnerSha256": "35b7561e56fc748e13e4eaf3e3df25f0cb060352f6cf8fb6d0d3edce34eba733",
30
+ "sourceTag": "fmix-v2.7.15"
31
31
  }
32
32
  }