@calltelemetry/fmix 2.7.9 → 2.7.11

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 +524 -51
  2. package/package.json +3 -3
package/bin/fmix CHANGED
@@ -24,7 +24,7 @@ set -uo pipefail
24
24
  # ---------------------------------------------------------------------------
25
25
  # Constants & config
26
26
  # ---------------------------------------------------------------------------
27
- FMIX_VERSION="2.7.9"
27
+ FMIX_VERSION="2.7.11"
28
28
  FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
29
29
  FMIX_OS="$(uname -s)"
30
30
  FMIX_ARCH="$(uname -m)"
@@ -554,18 +554,43 @@ fmix_resolved_toolchain_identity() {
554
554
  }
555
555
  done
556
556
 
557
- actual_otp_major="$(
558
- cd "$worktree" &&
559
- erl -noshell -eval 'io:format("~s", [erlang:system_info(otp_release)]), halt().' 2>/dev/null
560
- )" || actual_otp_major=""
561
- otp_root="$(
562
- cd "$worktree" &&
563
- erl -noshell -eval 'io:format("~s", [code:root_dir()]), halt().' 2>/dev/null
564
- )" || otp_root=""
565
- actual_erts="$(
557
+ # ONE erl spawn, not three. Each BEAM start is a full VM boot; measured on a
558
+ # loaded host at 1.5s / 1.8s / 0.7s here, and this function runs on every
559
+ # compile-fingerprint computation, i.e. every warm fmix invocation.
560
+ #
561
+ # Fields are NEWLINE-separated, one per line. `code:root_dir()` is an
562
+ # operator-controlled filesystem path, so any PRINTABLE delimiter could occur
563
+ # inside it: a path containing a literal `|` would truncate otp_root, make
564
+ # OTP_VERSION unreadable, and produce a spurious mismatch refusal. A newline
565
+ # cannot appear in a path, so the probe is read as a stream instead of split
566
+ # on a character.
567
+ local erl_probe
568
+ erl_probe="$(
566
569
  cd "$worktree" &&
567
- erl -noshell -eval 'io:format("~s", [erlang:system_info(version)]), halt().' 2>/dev/null
568
- )" || actual_erts=""
570
+ erl -noshell -eval 'io:format("~s~n~s~n~s~n", [erlang:system_info(otp_release), code:root_dir(), erlang:system_info(version)]), halt().' 2>/dev/null
571
+ )" || erl_probe=""
572
+ actual_otp_major=""
573
+ otp_root=""
574
+ actual_erts=""
575
+ if [[ -n "$erl_probe" ]]; then
576
+ local -a erl_fields=()
577
+ while IFS= read -r erl_field; do
578
+ erl_fields+=("$erl_field")
579
+ done <<< "$erl_probe"
580
+ if (( ${#erl_fields[@]} >= 3 )); then
581
+ actual_otp_major="${erl_fields[0]}"
582
+ otp_root="${erl_fields[1]}"
583
+ actual_erts="${erl_fields[2]}"
584
+ fi
585
+ fi
586
+ # A probe that did not yield three non-empty fields means the VM could not be
587
+ # queried; fail the identity rather than compiling against an unverified
588
+ # toolchain.
589
+ if [[ -z "$actual_otp_major" || -z "$otp_root" || -z "$actual_erts" ]]; then
590
+ actual_otp_major=""
591
+ otp_root=""
592
+ actual_erts=""
593
+ fi
569
594
  otp_version_file="$otp_root/releases/$actual_otp_major/OTP_VERSION"
570
595
  if [[ -r "$otp_version_file" ]]; then
571
596
  actual_otp="$(tr -d '[:space:]' <"$otp_version_file")"
@@ -1686,7 +1711,7 @@ fmix_run_telemetry_finish() {
1686
1711
  case "${FMIX_LAST_COMPILE_OUTCOME:-}" in
1687
1712
  stamp_hit|stamp_hit_repaired|stamp_hit_after_deps|stamp_hit_quick|noop_compile)
1688
1713
  case "${FMIX_LAST_ARTIFACTS_OUTCOME:-}" in
1689
- session_hit|adopt_stamps|adopt_compatible|dependency_reconcile|ready|stable_seed|donor_clone)
1714
+ session_hit|adopt_stamps|adopt_compatible|adopt_migration_delta|dependency_reconcile|ready|stable_seed|donor_clone)
1690
1715
  cache_hot="yes"
1691
1716
  ;;
1692
1717
  esac
@@ -1696,7 +1721,8 @@ fmix_run_telemetry_finish() {
1696
1721
  # proven application build and lets Mix compile only the affected
1697
1722
  # dependency/app delta. That is still a cache hit; a near-full
1698
1723
  # compile is classified separately as full_recompile.
1699
- [[ "${FMIX_LAST_ARTIFACTS_OUTCOME:-}" == "dependency_reconcile" ]] \
1724
+ [[ "${FMIX_LAST_ARTIFACTS_OUTCOME:-}" == "dependency_reconcile" \
1725
+ || "${FMIX_LAST_ARTIFACTS_OUTCOME:-}" == "adopt_migration_delta" ]] \
1700
1726
  && cache_hot="yes"
1701
1727
  ;;
1702
1728
  esac
@@ -2697,12 +2723,64 @@ fmix_guard_worktree_subdir() {
2697
2723
 
2698
2724
  # ---------------------------------------------------------------------------
2699
2725
  # Template key computation
2700
- # Template key (v4) = first 16 hex of sha256 over:
2726
+ # Template key (v5) = first 16 hex of sha256 over:
2701
2727
  # resolved BEAM ABI + dependency declarations/resolution + local dependency
2702
- # source inputs + uname -sm.
2728
+ # source inputs + a digest of priv/repo/migrations (names and contents) +
2729
+ # uname -sm.
2703
2730
  # ---------------------------------------------------------------------------
2704
2731
 
2732
+ fmix_migrations_digest() {
2733
+ # API-3576: a shared template that outlives a migration change is stale in
2734
+ # a way "0 pending migrations" can never reveal, because Ecto compares
2735
+ # versions, not contents. A migration edited in place (or a migration whose
2736
+ # body delegates to code that changed beside it) keeps its version while the
2737
+ # schema it produces moves on. Hashing every migration's relative name and
2738
+ # content makes any such change a new key, so the old template is simply
2739
+ # never selected. Emits a deterministic, path-relative manifest on stdout.
2740
+ local worktree="$1" dir listing file
2741
+ local -a files=()
2742
+ dir="$worktree/priv/repo/migrations"
2743
+ if [[ ! -d "$dir" ]]; then
2744
+ printf 'migrations:none\n'
2745
+ return 0
2746
+ fi
2747
+ listing="$(mktemp)" || return 1
2748
+ if ! find "$dir" -type f -print 2>/dev/null | LC_ALL=C sort >"$listing"; then
2749
+ rm -f "$listing"
2750
+ return 1
2751
+ fi
2752
+ while IFS= read -r file; do
2753
+ files+=("$file")
2754
+ done <"$listing"
2755
+ rm -f "$listing"
2756
+ printf 'migrations:v1\n'
2757
+ (( ${#files[@]} > 0 )) || return 0
2758
+ # Batched hashing keeps this to a handful of processes even for the
2759
+ # ~1000 migrations of a mature repository. Paths are made relative so the
2760
+ # digest does not depend on where the worktree lives.
2761
+ fmix_hash_file_batches "${files[@]}" | awk -v prefix="$dir/" '
2762
+ {
2763
+ digest = $1
2764
+ $1 = ""
2765
+ sub(/^ +/, "")
2766
+ if (index($0, prefix) == 1) $0 = substr($0, length(prefix) + 1)
2767
+ printf "migration:%s\t%s\n", $0, digest
2768
+ }' | LC_ALL=C sort
2769
+ [[ "${PIPESTATUS[0]}" == "0" && "${PIPESTATUS[1]}" == "0" ]]
2770
+ }
2771
+
2705
2772
  fmix_compute_template_key() {
2773
+ fmix_template_key_manifest_hash "$1" fmix-template-key-v5 1
2774
+ }
2775
+
2776
+ # FMix <= 2.7.9 addressed templates and stamped sessions with the v4 key, which
2777
+ # had no migrations digest. Kept only so artifact adoption can prove a session
2778
+ # stamped under v4 still describes the exact same non-migration inputs.
2779
+ fmix_compute_legacy_template_key_v4() {
2780
+ fmix_template_key_manifest_hash "$1" fmix-template-key-v4 0
2781
+ }
2782
+
2783
+ fmix_template_key_manifest_hash() {
2706
2784
  # The template caches compiled dependencies and an application baseline.
2707
2785
  # mix.lock alone is insufficient: path dependencies and dependency options
2708
2786
  # can change in mix.exs without producing a lockfile delta.
@@ -2716,7 +2794,7 @@ fmix_compute_template_key() {
2716
2794
  # and recompiles config-dependent APP modules after the post-clone
2717
2795
  # `mix compile`. Database selection uses the separate migration-content
2718
2796
  # manifest below and never includes wall-clock dates.
2719
- local worktree="$1"
2797
+ local worktree="$1" key_tag="$2" with_migrations="$3"
2720
2798
  local key toolchain_identity manifest rc
2721
2799
  toolchain_identity="${FMIX_TOOLCHAIN_IDENTITY:-}"
2722
2800
  if [[ -z "$toolchain_identity" ]]; then
@@ -2724,7 +2802,7 @@ fmix_compute_template_key() {
2724
2802
  fi
2725
2803
  manifest="$(mktemp)" || return 1
2726
2804
  (
2727
- printf 'fmix-template-key-v4\n'
2805
+ printf '%s\n' "$key_tag"
2728
2806
  printf 'os_arch=%s %s\n' "$FMIX_OS" "$FMIX_ARCH"
2729
2807
  printf '%s\n' "$toolchain_identity"
2730
2808
  for f in .tool-versions mix.exs mix.lock; do
@@ -2743,6 +2821,9 @@ fmix_compute_template_key() {
2743
2821
  fi
2744
2822
  done
2745
2823
  fmix_stable_seed_path_dependency_manifests "$worktree" || return 1
2824
+ if [[ "$with_migrations" == "1" ]]; then
2825
+ fmix_migrations_digest "$worktree" || return 1
2826
+ fi
2746
2827
  ) >"$manifest"
2747
2828
  rc=$?
2748
2829
  if (( rc != 0 )); then
@@ -3307,6 +3388,91 @@ fmix_stable_seed_source_tree_is_safe() {
3307
3388
  return 0
3308
3389
  }
3309
3390
 
3391
+ fmix_relativize_session_links() {
3392
+ # Rewrite ABSOLUTE symlinks that point back INSIDE this fmix session
3393
+ # directory into equivalent relative links. Usage:
3394
+ # fmix_relativize_session_links <session_root> <tree_root>...
3395
+ #
3396
+ # A dependency's own build can create an absolute link entirely inside the
3397
+ # session: rebar3 links deps/otel_http/_build/prod/plugins/rebar3_ex_doc to
3398
+ # the matching default/plugins directory using the session's absolute path.
3399
+ # That link is neither an escape nor host-bound state -- it is the session's
3400
+ # own content -- yet the absolute-link guards (template manifest, stable-seed
3401
+ # and dependency-artifact publication) rejected it, so `fmix setup` failed
3402
+ # and operators hand-edited the session to get past it.
3403
+ #
3404
+ # Relativizing preserves the link's exact meaning, so what the guards see is
3405
+ # what the absolute form already resolved to; nothing is weakened:
3406
+ # * only links whose normalized absolute target lies inside <session_root>
3407
+ # are rewritten; a link to anywhere else stays absolute and is still
3408
+ # rejected by the guards;
3409
+ # * a tree_root that is itself a symlink, or that resolves outside the
3410
+ # session, is never touched or traversed (a real symlinked _build/deps
3411
+ # ancestor is still rejected downstream);
3412
+ # * links are never followed while walking.
3413
+ local session_root="${1:-}"
3414
+ shift || true
3415
+ [[ -n "$session_root" && -d "$session_root" && ! -L "$session_root" ]] || return 0
3416
+ (( $# > 0 )) || return 0
3417
+ local py_bin
3418
+ py_bin="$(fmix_python_bin)" || return 1
3419
+ "$py_bin" - "$session_root" "$@" <<'PY'
3420
+ import os
3421
+ import sys
3422
+
3423
+ given = os.path.normpath(sys.argv[1])
3424
+ real = os.path.realpath(given)
3425
+ prefixes = {given, real}
3426
+
3427
+
3428
+ def inside(path):
3429
+ return any(path == p or path.startswith(p + os.sep) for p in prefixes)
3430
+
3431
+
3432
+ def to_real(path):
3433
+ for p in sorted(prefixes, key=len, reverse=True):
3434
+ if path == p or path.startswith(p + os.sep):
3435
+ return real + path[len(p):]
3436
+ return path
3437
+
3438
+
3439
+ for top in sys.argv[2:]:
3440
+ top = os.path.normpath(top)
3441
+ if os.path.islink(top) or not os.path.isdir(top):
3442
+ continue
3443
+ if not inside(os.path.realpath(top)):
3444
+ continue
3445
+ for current, dirs, files in os.walk(top, topdown=True, followlinks=False):
3446
+ for name in list(dirs) + files:
3447
+ path = os.path.join(current, name)
3448
+ if not os.path.islink(path):
3449
+ continue
3450
+ target = os.readlink(path)
3451
+ if not os.path.isabs(target):
3452
+ continue
3453
+ normalized = os.path.normpath(target)
3454
+ if not inside(normalized):
3455
+ continue
3456
+ relative = os.path.relpath(
3457
+ to_real(normalized), os.path.realpath(os.path.dirname(path))
3458
+ )
3459
+ staged = f"{path}.fmix-relink-{os.getpid()}"
3460
+ os.symlink(relative, staged)
3461
+ os.replace(staged, path)
3462
+ PY
3463
+ }
3464
+
3465
+ fmix_session_normalize_links() {
3466
+ # Relativize the session's own absolute links before any guard inspects it.
3467
+ # No-op outside an fmix session (an arbitrary worktree's deps/_build is
3468
+ # never rewritten).
3469
+ local worktree="${1:-}" deps_root build_root
3470
+ [[ -n "${FMIX_ACTIVE_SESSION_ROOT:-}" ]] || return 0
3471
+ deps_root="$(fmix_session_deps_root "$worktree")" || return 0
3472
+ build_root="$(fmix_compile_build_root "$worktree")" || return 0
3473
+ fmix_relativize_session_links "$FMIX_ACTIVE_SESSION_ROOT" "$deps_root" "$build_root"
3474
+ }
3475
+
3310
3476
  fmix_stable_seed_artifacts_are_safe() {
3311
3477
  # Validate the exact dependency transport roots without following links.
3312
3478
  # allow_app=1 is only for a publisher source, where the real cdrcisco build
@@ -3916,6 +4082,7 @@ _fmix_seed_publish_locked() {
3916
4082
  return 1
3917
4083
  fi
3918
4084
 
4085
+ fmix_session_normalize_links "$real" || return 1
3919
4086
  build_lib="$(fmix_compile_build_root "$real")/test/lib"
3920
4087
  if ! fmix_stable_seed_artifacts_are_safe \
3921
4088
  "$(fmix_session_deps_root "$real")" "$build_lib" 1 "$real" \
@@ -4114,6 +4281,10 @@ fmix_publish_dependency_artifact() {
4114
4281
  }
4115
4282
  fi
4116
4283
 
4284
+ fmix_session_normalize_links "$real" || {
4285
+ fmix_lock_release "$lock_name"
4286
+ return 1
4287
+ }
4117
4288
  deps_root="$(fmix_session_deps_root "$real")" || {
4118
4289
  fmix_lock_release "$lock_name"
4119
4290
  return 1
@@ -4573,16 +4744,24 @@ fmix_artifact_state_file() {
4573
4744
 
4574
4745
  fmix_write_artifact_state() {
4575
4746
  local worktree="$1" template_key="$2" real state tmp
4747
+ local base_key=""
4576
4748
  [[ "$template_key" =~ ^[0-9a-f]{16}$ ]] || return 1
4577
4749
  real="$(fmix_realpath "$worktree")" || return 1
4578
4750
  state="$(fmix_artifact_state_file "$real")" || return 1
4579
4751
  mkdir -p "$(dirname "$state")" || return 1
4580
4752
  tmp="$(mktemp "${state}.tmp.XXXXXX")" || return 1
4753
+ # The template key minus the migrations digest. A later migration-only key
4754
+ # change is recognised by this staying equal (see
4755
+ # fmix_adopt_migration_only_key_change); empty when it cannot be computed,
4756
+ # which simply disables that adoption.
4757
+ base_key="$(fmix_compute_legacy_template_key_v4 "$real" 2>/dev/null)" || base_key=""
4758
+ [[ "$base_key" =~ ^[0-9a-f]{16}$ ]] || base_key=""
4581
4759
  if ! cat >"$tmp" <<EOF
4582
4760
  {
4583
4761
  "schema": "fmix-artifacts-v1",
4584
4762
  "path": $(fmix_json_escape "$real"),
4585
4763
  "template_key": $(fmix_json_escape "$template_key"),
4764
+ "template_base_key": $(fmix_json_escape "$base_key"),
4586
4765
  "verified_at": $(fmix_json_escape "$(fmix_now)")
4587
4766
  }
4588
4767
  EOF
@@ -6278,6 +6457,16 @@ fmix_build_template() {
6278
6457
  fmix_warn "Exact dependency artifact publication failed; the full template remains authoritative."
6279
6458
  fi
6280
6459
 
6460
+ # The session's own absolute links (e.g. a dependency build's plugin link)
6461
+ # become relative before staging, so the manifest guard below judges them
6462
+ # as the contained links they are.
6463
+ if ! fmix_session_normalize_links "$worktree" >>"$log_file" 2>&1; then
6464
+ fmix_error "Could not normalize session-internal symlinks. See log: $log_file"
6465
+ fmix_template_quarantine "$tmp_dir" "session link normalization failed" >/dev/null 2>&1 || true
6466
+ fmix_lock_release "$lock_name"
6467
+ return 1
6468
+ fi
6469
+
6281
6470
  fmix_info "Cloning proven session artifacts into immutable staging …"
6282
6471
  if ! fmix_cow_clone "$deps_root" "$tmp_dir/deps" >>"$log_file" 2>&1 \
6283
6472
  || ! fmix_cow_clone "$build_root" "$tmp_dir/_build" >>"$log_file" 2>&1; then
@@ -6634,6 +6823,37 @@ fmix_clone_template_to_worktree() {
6634
6823
  # Ensure session artifacts (deps/ + _build/) are ready and template-matched
6635
6824
  # ---------------------------------------------------------------------------
6636
6825
 
6826
+ # REL-1244: is the application itself compiled into this session overlay?
6827
+ #
6828
+ # A matching template key proves deps and toolchain agree; it does NOT prove the
6829
+ # app was compiled. An overlay from a compile that was killed by
6830
+ # FMIX_COMPILE_TIMEOUT still has deps/ and _build/ and cdrcisco.app, but no .beam
6831
+ # files and no .mix/compile.elixir. Accepting that as a session hit makes every
6832
+ # later `mix compile` rebuild the whole DAG from nothing.
6833
+ #
6834
+ # Extracted as a function so a compatibility test can call the SHIPPED logic
6835
+ # rather than replaying a copy of it.
6836
+ fmix_session_has_app_manifest() {
6837
+ local worktree="$1" build_root="$2"
6838
+ local app_name="cdrcisco" found_app=""
6839
+ if [[ -f "$worktree/mix.exs" ]]; then
6840
+ found_app="$(grep -o 'app:[[:space:]]*:[a-zA-Z0-9_]*' "$worktree/mix.exs" 2>/dev/null | head -1 | sed 's/.*:\([a-zA-Z0-9_]*\)/\1/')"
6841
+ [[ -n "$found_app" ]] && app_name="$found_app"
6842
+ fi
6843
+ # fmix_compile_build_root returns the session's _build directory, while Mix
6844
+ # writes the app manifest under its MIX_ENV subdirectory (_build/test/lib).
6845
+ # Looking only at "$build_root/lib" never found it in a real session, so every
6846
+ # same-key session read as an interrupted overlay and was "repaired" from a
6847
+ # template that may not exist (API-3576: after the template key started to
6848
+ # include migrations that is the common case). Accept either layout.
6849
+ local layout
6850
+ for layout in "$build_root/lib" "$build_root/test/lib"; do
6851
+ [[ -f "$layout/$app_name/.mix/compile.elixir" ]] && return 0
6852
+ [[ -f "$layout/$app_name/.mix/compile.elixir_scm" ]] && return 0
6853
+ done
6854
+ return 1
6855
+ }
6856
+
6637
6857
  fmix_ensure_artifacts() {
6638
6858
  local worktree="$1" template_key="$2" allow_template_build="${3:-0}"
6639
6859
  local state_file artifact_state_file
@@ -6655,6 +6875,36 @@ fmix_ensure_artifacts() {
6655
6875
  [[ -d "$deps_root" ]] && has_deps=1
6656
6876
  [[ -d "$build_root" ]] && has_build=1
6657
6877
 
6878
+ # REL-1244: a matching template key is NOT proof that this session was ever
6879
+ # compiled. The key is derived from mix.lock plus the toolchain, so two
6880
+ # worktrees sharing a lockfile share a key -- and a session that inherited an
6881
+ # interrupted overlay still matches it.
6882
+ #
6883
+ # has_deps/has_build only tested that the DIRECTORIES exist. In the failure this
6884
+ # guards, the session had deps/ and _build/ present and cdrcisco.app present,
6885
+ # but ZERO .beam files and no .mix/compile.elixir for the app, because a prior
6886
+ # compile was killed by FMIX_COMPILE_TIMEOUT before it wrote a manifest. FMix
6887
+ # reported session_hit and returned success, so every subsequent `mix compile`
6888
+ # rebuilt the whole DAG from nothing (measured: 5252 files, 513s) and the
6889
+ # pre-push hook -- which runs that compile -- blew its own budget and reported
6890
+ # a compile failure that was really an unrecoverable cold rebuild.
6891
+ #
6892
+ # The clone path below touches every compile.* manifest after copying, and that
6893
+ # touch is precisely what makes a cloned session incremental. The early-return
6894
+ # path skipped that repair. Require the app compile manifest to be present
6895
+ # before accepting a session hit; otherwise fall through so the template is
6896
+ # re-cloned and the manifests are synchronized.
6897
+ #
6898
+ # Scoped deliberately to the SAME-KEY fast path. The other branches have their
6899
+ # own proofs (exact stamps, or fmix_adopt_compatible_worktree_artifacts) and a
6900
+ # key change must still be able to adopt a compatible overlay; gating the whole
6901
+ # block on the manifest broke "template storage-key changes adopt current
6902
+ # worktree stamps without cloning".
6903
+ local has_app_manifest=0
6904
+ if fmix_session_has_app_manifest "$worktree" "$build_root"; then
6905
+ has_app_manifest=1
6906
+ fi
6907
+
6658
6908
  if (( has_deps == 1 && has_build == 1 )); then
6659
6909
  if [[ -z "$recorded_key" ]]; then
6660
6910
  if [[ "$allow_template_build" != "1" ]]; then
@@ -6681,12 +6931,16 @@ fmix_ensure_artifacts() {
6681
6931
  fi
6682
6932
  fmix_info "Session artifact state is absent; exact stamps must prove it before publication."
6683
6933
  elif [[ "$recorded_key" == "$template_key" ]]; then
6684
- [[ -f "$artifact_state_file" ]] \
6685
- || fmix_write_artifact_state "$worktree" "$template_key" \
6686
- || return 1
6687
- fmix_info "Session artifacts match template key $template_key — skipping clone."
6688
- FMIX_LAST_ARTIFACTS_OUTCOME="session_hit"
6689
- return 0
6934
+ if (( has_app_manifest == 0 )); then
6935
+ fmix_warn "Session artifacts match template key $template_key but the app compile manifest is missing (interrupted or partial overlay); repairing from the template."
6936
+ else
6937
+ [[ -f "$artifact_state_file" ]] \
6938
+ || fmix_write_artifact_state "$worktree" "$template_key" \
6939
+ || return 1
6940
+ fmix_info "Session artifacts match template key $template_key — skipping clone."
6941
+ FMIX_LAST_ARTIFACTS_OUTCOME="session_hit"
6942
+ return 0
6943
+ fi
6690
6944
  else
6691
6945
  fmix_info "Template key mismatch (recorded=$recorded_key, current=$template_key)."
6692
6946
  if fmix_adopt_compatible_worktree_artifacts \
@@ -6696,6 +6950,14 @@ fmix_ensure_artifacts() {
6696
6950
  FMIX_LAST_ARTIFACTS_OUTCOME="adopt_compatible"
6697
6951
  return 0
6698
6952
  fi
6953
+ if (( has_app_manifest == 1 )) \
6954
+ && fmix_adopt_migration_only_key_change \
6955
+ "$worktree" "$recorded_key" "$template_key"; then
6956
+ fmix_write_artifact_state "$worktree" "$template_key" || return 1
6957
+ fmix_info "Only the migrations digest changed under template key $template_key — keeping the session build for incremental compile."
6958
+ FMIX_LAST_ARTIFACTS_OUTCOME="adopt_migration_delta"
6959
+ return 0
6960
+ fi
6699
6961
  if fmix_reconcile_same_toolchain_dependency_change \
6700
6962
  "$worktree" "$recorded_key" "$template_key"; then
6701
6963
  fmix_info "Dependency change adopted under template key $template_key — preserving the app cache for incremental compile."
@@ -7595,6 +7857,16 @@ fmix_publish_hot_base() {
7595
7857
  lock="db-publish-${key}"
7596
7858
  fmix_lock_acquire "$lock" "$FMIX_LOCK_TIMEOUT" || return 1
7597
7859
 
7860
+ if fmix_snapshot_ready "$target" && [[ "${FMIX_REPUBLISH_HOT_BASE:-0}" == "1" ]]; then
7861
+ # API-3576: an explicit cold rebuild just produced a verified-current
7862
+ # scratch. The base already published under this key is exactly the
7863
+ # artifact the operator is repairing, so replace it rather than keep
7864
+ # trusting it.
7865
+ fmix_warn "Replacing published hot base $target with the freshly rebuilt database."
7866
+ fmix_drop_db "$target" || { fmix_lock_release "$lock"; return 1; }
7867
+ rm -rf "$(fmix_db_index_dir "$key")" 2>/dev/null || true
7868
+ fi
7869
+
7598
7870
  if fmix_snapshot_ready "$target"; then
7599
7871
  if ! fmix_base_record_ready "$key"; then
7600
7872
  fmix_info "Hot base $target exists; publishing its missing metadata index."
@@ -7673,12 +7945,17 @@ fmix_migrate_from_zero() {
7673
7945
  # those objects) — but wherever the extension IS available, this lane is
7674
7946
  # unconditionally MORE faithful than the snapshot path can ever be by
7675
7947
  # construction, not just "no worse".
7676
- local worktree="$1" db_name="$2" key target lock timeout t0 t1
7948
+ #
7949
+ # API-3576: the optional third argument "1" (replace) skips both reuse
7950
+ # checks and replaces any published base for this key with the freshly
7951
+ # migrated result. Explicit --cold-db/--from-zero pass it: reusing a
7952
+ # published base is exactly what a rebuild is meant to avoid.
7953
+ local worktree="$1" db_name="$2" replace="${3:-0}" key target lock timeout t0 t1
7677
7954
  fmix_guard_db_name "$db_name" || return 1
7678
7955
  key="$(fmix_schema_key "$worktree")" || return 1
7679
7956
  target="$(fmix_hot_base_name "$key")" || return 1
7680
7957
 
7681
- if fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7958
+ if [[ "$replace" != "1" ]] && fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7682
7959
  fmix_info "Hot base $target already published for schema $key — cloning instead of migrating from zero."
7683
7960
  fmix_create_database "$db_name" "$target" || return 1
7684
7961
  return 0
@@ -7689,7 +7966,7 @@ fmix_migrate_from_zero() {
7689
7966
 
7690
7967
  # Double-checked: another host process may have published this exact
7691
7968
  # schema's hot base while we waited for the lock.
7692
- if fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7969
+ if [[ "$replace" != "1" ]] && fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7693
7970
  fmix_lock_release "$lock"
7694
7971
  fmix_info "Hot base $target was published while waiting on the lock — cloning."
7695
7972
  fmix_create_database "$db_name" "$target" || return 1
@@ -7725,7 +8002,7 @@ fmix_migrate_from_zero() {
7725
8002
 
7726
8003
  fmix_info "Publishing hot DB base $target from freshly from-zero-migrated $db_name …"
7727
8004
  if fmix_db_exists "$target"; then
7728
- fmix_warn "Removing incomplete hot base $target before a clean publication."
8005
+ fmix_warn "Removing incomplete or superseded hot base $target before a clean publication."
7729
8006
  fmix_drop_db "$target" || { fmix_lock_release "$lock"; return 1; }
7730
8007
  fi
7731
8008
  if ! fmix_create_database "$target" "$db_name" scratch-publish; then
@@ -7900,6 +8177,16 @@ fmix_ensure_db() {
7900
8177
  fmix_error "Scratch DB $db_name provenance is not a content-valid prefix of this branch."
7901
8178
  fi
7902
8179
  fi
8180
+ if (( valid == 1 )) && [[ "$rebuild_existing" == "1" ]]; then
8181
+ # API-3576: an explicit rebuild must rebuild. A scratch DB whose
8182
+ # recorded schema key still matches reports "0 pending migrations"
8183
+ # forever, even when the schema under that ledger is stale, so
8184
+ # reusing it here made --rebuild-db/--cold-db/--from-zero silent
8185
+ # no-ops. The operator asked for a fresh database: drop it.
8186
+ fmix_warn "Explicit rebuild requested; replacing otherwise-valid scratch DB $db_name."
8187
+ valid=0
8188
+ fmix_drop_db "$db_name" || return 1
8189
+ fi
7903
8190
  if (( valid == 1 )); then
7904
8191
  # The scratch will be asserted/migrated to the current manifest
7905
8192
  # before state publication. Preserve its source separately.
@@ -7908,18 +8195,29 @@ fmix_ensure_db() {
7908
8195
  FMIX_ACTIVE_DB_BASE_ID="$stored_base"
7909
8196
  return 0
7910
8197
  fi
7911
- if [[ "$rebuild_existing" != "1" ]]; then
7912
- fmix_error "Refusing to drop or reuse an unverified scratch DB in a normal lane."
7913
- fmix_error "After confirming no live owner: ./fmix setup --rebuild-db --worktree $worktree"
7914
- return 1
8198
+ if fmix_db_exists "$db_name"; then
8199
+ if [[ "$rebuild_existing" != "1" ]]; then
8200
+ fmix_error "Refusing to drop or reuse an unverified scratch DB in a normal lane."
8201
+ fmix_error "After confirming no live owner: ./fmix setup --rebuild-db --worktree $worktree"
8202
+ return 1
8203
+ fi
8204
+ fmix_warn "Explicit setup is replacing unverified scratch DB $db_name."
8205
+ fmix_drop_db "$db_name" || return 1
7915
8206
  fi
7916
- fmix_warn "Explicit setup is replacing unverified scratch DB $db_name."
7917
- fmix_drop_db "$db_name" || return 1
7918
8207
  fi
7919
8208
 
7920
- fmix_info "Selecting one content-indexed DB base for $db_name …"
7921
8209
  t0="$(fmix_epoch)"
7922
- selection="$(fmix_select_indexed_base "$worktree")" || selection=""
8210
+ selection=""
8211
+ if [[ "$allow_structure_build" == "1" ]]; then
8212
+ # API-3576: --cold-db and --from-zero exist to build the schema again.
8213
+ # Selecting a published hot base first re-cloned the very base that was
8214
+ # stale, so these lanes could never repair it. Skip selection; the
8215
+ # rebuilt scratch is republished over the stale base (see setup).
8216
+ fmix_info "Explicit cold rebuild: bypassing published hot bases for $db_name."
8217
+ else
8218
+ fmix_info "Selecting one content-indexed DB base for $db_name …"
8219
+ selection="$(fmix_select_indexed_base "$worktree")" || selection=""
8220
+ fi
7923
8221
  if [[ -n "$selection" ]]; then
7924
8222
  IFS=$'\t' read -r base base_key delta <<<"$selection"
7925
8223
  fmix_guard_template_db_name "$base" || return 1
@@ -7948,7 +8246,7 @@ fmix_ensure_db() {
7948
8246
  else
7949
8247
  fmix_warn "No indexed hot base exists and structure.sql is unusable for cold bootstrap; migrating from zero."
7950
8248
  fi
7951
- fmix_migrate_from_zero "$worktree" "$db_name" || return 1
8249
+ fmix_migrate_from_zero "$worktree" "$db_name" 1 || return 1
7952
8250
  FMIX_ACTIVE_DB_SCHEMA_KEY="$current_key"
7953
8251
  FMIX_ACTIVE_DB_SOURCE_KEY="$current_key"
7954
8252
  FMIX_ACTIVE_DB_BASE_ID="migrate-from-zero"
@@ -8056,6 +8354,8 @@ fmix_run_migration_bounded() {
8056
8354
  MEESEEKS_HTML5EVER_BUILD=0 \
8057
8355
  LOCAL_NATS="$NATS_HOST" \
8058
8356
  NATS_PORT="$NATS_PORT" \
8357
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
8358
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
8059
8359
  mix ecto.migrate --no-compile
8060
8360
  ) >"$log_file" 2>&1 &
8061
8361
  pid=$!
@@ -8278,6 +8578,8 @@ fmix_ensure_partitions() {
8278
8578
  MEESEEKS_HTML5EVER_BUILD=0 \
8279
8579
  LOCAL_NATS="$NATS_HOST" \
8280
8580
  NATS_PORT="$NATS_PORT" \
8581
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
8582
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
8281
8583
  env -u DB_HOST_IPV4 mix cdrcisco.bootstrap_partitions
8282
8584
  ) || {
8283
8585
  fmix_error "cdrcisco.bootstrap_partitions failed on $db_name."
@@ -9710,7 +10012,10 @@ fmix_compile_stamp_matches() {
9710
10012
  recorded_ignored_compile_hash="$(fmix_read_state "$stamp" ignored_compile_hash)"
9711
10013
 
9712
10014
  local current_template_key current_tree_hash current_env_hash current_dirty_hash
9713
- current_template_key="$(fmix_compute_template_key "$real" 2>/dev/null || echo "")"
10015
+ # The override lets artifact adoption prove a v4-stamped session against
10016
+ # the key it was actually stamped with (see
10017
+ # fmix_adopt_compatible_worktree_artifacts).
10018
+ current_template_key="${FMIX_COMPILE_STAMP_KEY_OVERRIDE:-$(fmix_compute_template_key "$real" 2>/dev/null || echo "")}"
9714
10019
  current_tree_hash="$(fmix_get_git_tree_hash "$real")" || return 1
9715
10020
  current_env_hash="$(fmix_compute_compile_env_hash "$real" 2>/dev/null || echo "")"
9716
10021
  current_dirty_hash="$(fmix_compute_dirty_hash "$real" 2>/dev/null)" \
@@ -9961,6 +10266,40 @@ fmix_reconcile_same_toolchain_dependency_change() {
9961
10266
  return 0
9962
10267
  }
9963
10268
 
10269
+ fmix_adopt_migration_only_key_change() {
10270
+ # API-3576: the template key now includes a migrations digest, so landing a
10271
+ # migration changes the key. Nothing the template caches (compiled deps and
10272
+ # the app baseline) depends on migrations, so a session whose recorded base
10273
+ # key (everything but the digest) still equals the current one keeps its
10274
+ # artifacts and only its storage key advances; Mix recompiles any changed
10275
+ # sources incrementally exactly as it did when migrations were not keyed.
10276
+ #
10277
+ # Deliberately does NOT adopt a v4-stamped session (see
10278
+ # fmix_adopt_compatible_worktree_artifacts, which also re-records stamps):
10279
+ # this path leaves stamps to the incremental compile that a changed tree
10280
+ # forces, so it requires proof that the tree actually changed.
10281
+ local worktree="$1" recorded_key="$2" template_key="$3"
10282
+ local real state_file artifact_state_file key_state_file recorded_base current_base
10283
+ local compile_stamp recorded_tree current_tree
10284
+ real="$(fmix_realpath "$worktree")" || return 1
10285
+ state_file="$(fmix_worktree_state_file "$real")"
10286
+ artifact_state_file="$(fmix_artifact_state_file "$real")"
10287
+ [[ -f "$artifact_state_file" ]] || return 1
10288
+ key_state_file="$artifact_state_file"
10289
+ [[ "$(fmix_read_state "$key_state_file" path)" == "$real" ]] || return 1
10290
+ recorded_base="$(fmix_read_state "$key_state_file" template_base_key)"
10291
+ [[ "$recorded_base" =~ ^[0-9a-f]{16}$ ]] || return 1
10292
+ current_base="$(fmix_compute_legacy_template_key_v4 "$real" 2>/dev/null)" || return 1
10293
+ [[ "$recorded_base" == "$current_base" ]] || return 1
10294
+ compile_stamp="$(fmix_compile_stamp_file "$real")"
10295
+ [[ -f "$compile_stamp" ]] || return 1
10296
+ recorded_tree="$(fmix_read_state "$compile_stamp" git_tree_hash)"
10297
+ current_tree="$(fmix_get_git_tree_hash "$real")" || return 1
10298
+ [[ -n "$recorded_tree" && "$recorded_tree" != "unknown" \
10299
+ && "$current_tree" != "unknown" && "$recorded_tree" != "$current_tree" ]] || return 1
10300
+ fmix_update_worktree_template_key "$real" "$recorded_key" "$template_key"
10301
+ }
10302
+
9964
10303
  fmix_adopt_compatible_worktree_artifacts() {
9965
10304
  local worktree="$1" recorded_key="$2" template_key="$3"
9966
10305
  local real state_file artifact_state_file key_state_file
@@ -9987,6 +10326,17 @@ fmix_adopt_compatible_worktree_artifacts() {
9987
10326
  if fmix_dependency_stamp_matches "$real" "$dependency_fingerprint" \
9988
10327
  && fmix_compile_stamp_matches "$real" "$compile_fingerprint"; then
9989
10328
  mode="current"
10329
+ elif legacy_key="$(fmix_compute_legacy_template_key_v4 "$real" 2>/dev/null)" \
10330
+ && [[ "$recorded_key" == "$legacy_key" ]] \
10331
+ && fmix_dependency_stamp_matches "$real" "$dependency_fingerprint" \
10332
+ && FMIX_COMPILE_STAMP_KEY_OVERRIDE="$legacy_key" \
10333
+ fmix_compile_stamp_matches "$real" "$compile_fingerprint"; then
10334
+ # API-3576: v5 added the migrations digest to the key, so every session
10335
+ # stamped by FMix <= 2.7.9 reads as a key mismatch even though nothing
10336
+ # it compiled changed. The recorded v4 key equals the v4 key of these
10337
+ # exact inputs and every stamp matches under it, so only the storage key
10338
+ # moves; stamps are re-recorded under v5 below.
10339
+ mode="v4"
9990
10340
  else
9991
10341
  legacy_key="$(fmix_compute_legacy_template_key_v2 "$real")" || return 1
9992
10342
  [[ "$recorded_key" == "$legacy_key" ]] || return 1
@@ -10003,7 +10353,7 @@ fmix_adopt_compatible_worktree_artifacts() {
10003
10353
  return 1
10004
10354
  fi
10005
10355
 
10006
- if [[ "$mode" == "legacy" ]]; then
10356
+ if [[ "$mode" == "legacy" || "$mode" == "v4" ]]; then
10007
10357
  if ! fmix_write_dependency_stamp "$real" "$dependency_fingerprint" \
10008
10358
  || ! fmix_write_compile_stamp "$real" "$compile_fingerprint"; then
10009
10359
  cp "$migration_dir/dependency.json" "$dependency_stamp" || true
@@ -10207,6 +10557,8 @@ _fmix_run_compile() {
10207
10557
  MEESEEKS_HTML5EVER_BUILD=0 \
10208
10558
  LOCAL_NATS="$NATS_HOST" \
10209
10559
  NATS_PORT="$NATS_PORT" \
10560
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
10561
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
10210
10562
  mix compile $extra 2>&1
10211
10563
  )
10212
10564
  }
@@ -10976,7 +11328,17 @@ cmd_setup() {
10976
11328
 
10977
11329
  local mig_stamp schema_key published_base
10978
11330
  schema_key="$FMIX_ACTIVE_DB_SCHEMA_KEY"
10979
- published_base="$(fmix_publish_hot_base "$real_worktree" "$db_name" "$schema_key")" || {
11331
+ # API-3576: --cold-db/--from-zero rebuilt the schema from scratch, so the
11332
+ # result must replace (not merely coexist with) any published base for this key.
11333
+ published_base="$(
11334
+ if [[ "$allow_structure_build" == "1" && "${FMIX_ACTIVE_DB_BASE_ID:-}" != "migrate-from-zero" ]]; then
11335
+ FMIX_REPUBLISH_HOT_BASE=1
11336
+ else
11337
+ FMIX_REPUBLISH_HOT_BASE=0
11338
+ fi
11339
+ export FMIX_REPUBLISH_HOT_BASE
11340
+ fmix_publish_hot_base "$real_worktree" "$db_name" "$schema_key"
11341
+ )" || {
10980
11342
  fmix_lock_release "$lock_name"
10981
11343
  return 1
10982
11344
  }
@@ -11643,6 +12005,8 @@ cmd_test() {
11643
12005
  SECRET_KEY_BASE="$SECRET_KEY_BASE"
11644
12006
  MEESEEKS_HTML5EVER_BUILD=0
11645
12007
  CT_SKIP_MIGRATION_TIMING=1
12008
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}"
12009
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}"
11646
12010
  )
11647
12011
  [[ -n "$event_fd" ]] && common_env+=("FMIX_EVENT_FD=$event_fd")
11648
12012
  # The child must observe the same run and session identity that
@@ -11888,6 +12252,8 @@ cmd_task() {
11888
12252
  ONPREM=TRUE \
11889
12253
  SECRET_KEY_BASE="$SECRET_KEY_BASE" \
11890
12254
  MEESEEKS_HTML5EVER_BUILD=0 \
12255
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
12256
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
11891
12257
  mix "${mix_args[@]}"
11892
12258
  ) || task_rc=$?
11893
12259
 
@@ -12548,8 +12914,105 @@ cmd_doctor() {
12548
12914
  # cmd: fmix status
12549
12915
  # ---------------------------------------------------------------------------
12550
12916
 
12917
+ # REL-1244: report a tree size WITHOUT stat()ing every file.
12918
+ #
12919
+ # fmix status and fmix doctor called `du -sh` on the artifact trees. On this host
12920
+ # the store is 1,682,684 files (753,820 templates + 928,864 dependency
12921
+ # artifacts, ~42 GB apparent). `du -sh` stats every one: measured at 40.9s for
12922
+ # templates and 63.5s for dependency-artifacts, i.e. ~104s of the 162s that
12923
+ # `fmix status` takes - all of it to print a size label nobody parses.
12924
+ #
12925
+ # Sizes are now read from a small cache beside each tree and refreshed at most
12926
+ # once per TTL. An uncached read returns "?" rather than blocking: a status
12927
+ # command must never be the slowest thing in a push.
12928
+ FMIX_TREE_SIZE_TTL="${FMIX_TREE_SIZE_TTL:-604800}" # 7 days
12929
+
12930
+ fmix_tree_size_cached() {
12931
+ local dir="$1" label="${2:-$(basename "$1")}"
12932
+ [[ -d "$dir" ]] || { printf '?\n'; return 0; }
12933
+ local cache="$FMIX_HOME/tree-sizes/${label}.json"
12934
+ local now recorded value
12935
+ now="$(date +%s)"
12936
+ if [[ -f "$cache" ]]; then
12937
+ recorded="$(fmix_read_state "$cache" recorded_at 2>/dev/null)"
12938
+ value="$(fmix_read_state "$cache" size 2>/dev/null)"
12939
+ # TTL is ENFORCED, not merely recorded. A cache entry without a usable
12940
+ # timestamp is treated as expired rather than trusted: an unenforced TTL
12941
+ # would report a size that a prune or a template rebuild has since
12942
+ # invalidated, and nothing would ever correct it.
12943
+ # A timestamp in the FUTURE is also invalid: `now - recorded` would be
12944
+ # negative and read as "very fresh". Clock skew or a hand-edited cache must
12945
+ # not be able to pin a stale size indefinitely.
12946
+ if [[ -n "$value" && "$recorded" =~ ^[0-9]+$ ]] \
12947
+ && (( recorded <= now )) \
12948
+ && (( now - recorded < FMIX_TREE_SIZE_TTL )); then
12949
+ printf '%s\n' "$value"
12950
+ return 0
12951
+ fi
12952
+ fi
12953
+ # No usable cached value: report unknown rather than walking 1.68M files here.
12954
+ # `fmix status --refresh-sizes` populates it explicitly.
12955
+ printf '?\n'
12956
+ return 0
12957
+ }
12958
+
12959
+ # Explicit, bounded refresh of the cached tree sizes.
12960
+ #
12961
+ # Labels MUST match what fmix_tree_size_cached is called with, or the cache is
12962
+ # written under keys nothing reads and every status stays "?". Templates are
12963
+ # cached per template key because the reader iterates per template.
12964
+ # Atomic: write beside the target and rename, so a concurrent reader never sees a
12965
+ # truncated file and two concurrent refreshes cannot interleave.
12966
+ fmix_tree_size_write() {
12967
+ local cache="$1" now="$2" size="$3" tmp
12968
+ tmp="${cache}.tmp-$$"
12969
+ if printf '{"recorded_at": %s, "size": "%s"}\n' "$now" "$size" > "$tmp" 2>/dev/null; then
12970
+ mv -f "$tmp" "$cache" 2>/dev/null || rm -f "$tmp" 2>/dev/null
12971
+ else
12972
+ rm -f "$tmp" 2>/dev/null
12973
+ fi
12974
+ }
12975
+
12976
+ fmix_tree_size_refresh() {
12977
+ local dirs_root="$FMIX_HOME/templates" key size now
12978
+ mkdir -p "$FMIX_HOME/tree-sizes" 2>/dev/null || true
12979
+ now="$(date +%s)"
12980
+ # Keys written this run; anything else in the cache refers to a tree that no
12981
+ # longer exists and is pruned below, so the cache cannot grow without bound
12982
+ # across prune/rebuild cycles.
12983
+ local -a live_keys=()
12984
+ if [[ -d "$dirs_root" ]]; then
12985
+ for dir in "$dirs_root"/*/; do
12986
+ [[ -d "$dir" ]] || continue
12987
+ key="$(basename "$dir")"
12988
+ size="$(du -sh "$dir" 2>/dev/null | awk '{print $1}')" || size="?"
12989
+ fmix_tree_size_write "$FMIX_HOME/tree-sizes/template_${key}.json" "$now" "$size"
12990
+ live_keys+=("template_${key}.json")
12991
+ printf '%s %s\n' "$size" "$dir"
12992
+ done
12993
+ fi
12994
+ local dep_root="$FMIX_HOME/dependency-artifacts/v1"
12995
+ if [[ -d "$dep_root" ]]; then
12996
+ size="$(du -sh "$dep_root" 2>/dev/null | awk '{print $1}')" || size="?"
12997
+ fmix_tree_size_write "$FMIX_HOME/tree-sizes/dependency_artifacts_v1.json" "$now" "$size"
12998
+ live_keys+=("dependency_artifacts_v1.json")
12999
+ printf '%s %s\n' "$size" "$dep_root"
13000
+ fi
13001
+ local existing base keep lk
13002
+ shopt -s nullglob
13003
+ for existing in "$FMIX_HOME/tree-sizes"/*.json; do
13004
+ base="$(basename "$existing")"
13005
+ keep=0
13006
+ for lk in "${live_keys[@]+"${live_keys[@]}"}"; do
13007
+ [[ "$base" == "$lk" ]] && { keep=1; break; }
13008
+ done
13009
+ (( keep == 0 )) && rm -f "$existing" 2>/dev/null
13010
+ done
13011
+ shopt -u nullglob
13012
+ }
13013
+
12551
13014
  cmd_status() {
12552
- local scoped_run_id="" scoped_json=0
13015
+ local scoped_run_id="" scoped_json=0 refresh_sizes=0
12553
13016
  while (( $# > 0 )); do
12554
13017
  case "$1" in
12555
13018
  --run-id)
@@ -12559,9 +13022,13 @@ cmd_status() {
12559
13022
  ;;
12560
13023
  --run-id=*) scoped_run_id="${1#--run-id=}"; shift ;;
12561
13024
  --json) scoped_json=1; shift ;;
12562
- *) fmix_error "Unknown status option: $1. Usage: fmix status [--run-id <uuid> --json]"; return 2 ;;
13025
+ --refresh-sizes) refresh_sizes=1; shift ;;
13026
+ *) fmix_error "Unknown status option: $1. Usage: fmix status [--run-id <uuid> --json] [--refresh-sizes]"; return 2 ;;
12563
13027
  esac
12564
13028
  done
13029
+ # NOTE: the refresh runs further down, AFTER --run-id validation. It walks every
13030
+ # artifact tree (~90s), so doing it before validation would spend that cost on an
13031
+ # invocation that is about to exit 2 with a usage error.
12565
13032
  if [[ -n "$scoped_run_id" ]]; then
12566
13033
  if ! fmix_run_id_is_valid "$scoped_run_id"; then
12567
13034
  fmix_error "Invalid FMix run ID: $scoped_run_id"
@@ -12644,6 +13111,13 @@ PY
12644
13111
  echo ""
12645
13112
 
12646
13113
  # Templates
13114
+ # Explicit, bounded: walks the artifact trees ONCE and records the result.
13115
+ # Normal status never does this; it reads the cached figure. Ordered after all
13116
+ # argument validation so a rejected invocation never pays for the walk.
13117
+ if (( refresh_sizes == 1 )); then
13118
+ fmix_tree_size_refresh >/dev/null
13119
+ fi
13120
+
12647
13121
  echo "--- Templates ($FMIX_HOME/templates/) ---"
12648
13122
  if [[ -d "$FMIX_HOME/templates" ]]; then
12649
13123
  local any_templates=0
@@ -12661,7 +13135,7 @@ PY
12661
13135
  built_at="$(fmix_read_template_meta "$key" "built_at")"
12662
13136
  last_used="$(fmix_read_template_last_used "$key")"
12663
13137
  local size=""
12664
- size="$(du -sh "$tdir" 2>/dev/null | awk '{print $1}')" || true
13138
+ size="$(fmix_tree_size_cached "$tdir" "template_${key}")"
12665
13139
  printf " %s status=%-10s built=%s last_used=%s size=%s\n" \
12666
13140
  "$key" "$status" "$built_at" "$last_used" "$size"
12667
13141
  done
@@ -12676,8 +13150,7 @@ PY
12676
13150
  if [[ -d "$FMIX_HOME/dependency-artifacts/v1" ]]; then
12677
13151
  dependency_artifact_count="$(find "$FMIX_HOME/dependency-artifacts/v1" \
12678
13152
  -mindepth 2 -maxdepth 2 -type d 2>/dev/null | wc -l | tr -d ' ')"
12679
- dependency_artifact_bytes="$(du -sh "$FMIX_HOME/dependency-artifacts/v1" \
12680
- 2>/dev/null | awk '{print $1}')" || dependency_artifact_bytes="?"
13153
+ dependency_artifact_bytes="$(fmix_tree_size_cached "$FMIX_HOME/dependency-artifacts/v1" "dependency_artifacts_v1")"
12681
13154
  printf ' generations=%s size=%s ttl=%sd\n' \
12682
13155
  "${dependency_artifact_count:-0}" "${dependency_artifact_bytes:-0}" \
12683
13156
  "$FMIX_DEPENDENCY_ARTIFACT_TTL_DAYS"
@@ -18060,9 +18533,9 @@ Usage:
18060
18533
  [--rebuild-db|--cold-db|--from-zero]
18061
18534
 
18062
18535
  Notes:
18063
- --rebuild-db reuse snapshots only; never replays structure.sql
18064
- --cold-db explicit one-time schema cache build
18065
- --from-zero full migration chain from an empty DB (structure.sql stale)
18536
+ --rebuild-db drop and re-clone the scratch DB from a published base; never replays structure.sql
18537
+ --cold-db rebuild from structure.sql, ignoring published bases, and replace the published base
18538
+ --from-zero full migration chain from an empty DB, replacing the published base (structure.sql stale)
18066
18539
 
18067
18540
  Example:
18068
18541
  fmix setup --worktree ./cisco-cdr
@@ -18196,9 +18669,9 @@ Examples:
18196
18669
  ./fmix task --worktree ./cisco-cdr -- openapi.gen --format all
18197
18670
  ./fmix task --worktree ./cisco-cdr --database ct_dev --mix-env dev -- ecto.migrate
18198
18671
  ./fmix setup --worktree ./cisco-cdr
18199
- ./fmix setup --rebuild-db --worktree ./cisco-cdr # reuse snapshots only; never replays structure.sql
18200
- ./fmix setup --cold-db --worktree ./cisco-cdr # explicit one-time schema cache build
18201
- ./fmix setup --from-zero --worktree ./cisco-cdr # full migration chain from an empty DB; structure.sql unusable/stale
18672
+ ./fmix setup --rebuild-db --worktree ./cisco-cdr # drop and re-clone the scratch DB from a published base; never replays structure.sql
18673
+ ./fmix setup --cold-db --worktree ./cisco-cdr # rebuild from structure.sql, ignoring and replacing the published base
18674
+ ./fmix setup --from-zero --worktree ./cisco-cdr # full migration chain from an empty DB, replacing the published base; structure.sql unusable/stale
18202
18675
  ./fmix seed publish --worktree ./cisco-cdr --cache-base 0.8.7-stable
18203
18676
  ./fmix cache explain --worktree ./cisco-cdr --cache-base 0.8.7-stable
18204
18677
  ./fmix doctor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calltelemetry/fmix",
3
- "version": "2.7.9",
3
+ "version": "2.7.11",
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": "67794255e5093d508bc36af1c8d3ad932d7f392624f44e96660d62379edfe9f5",
30
- "sourceTag": "fmix-v2.7.9"
29
+ "runnerSha256": "429e12afb8fed3cbfcea3f0e042a1c0ad53dd7554146e03f99677cf3958592c0",
30
+ "sourceTag": "fmix-v2.7.11"
31
31
  }
32
32
  }