@calltelemetry/fmix 2.7.9 → 2.7.10

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 +514 -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.10"
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,27 @@ 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
+ [[ -f "$build_root/lib/$app_name/.mix/compile.elixir" ]] \
6844
+ || [[ -f "$build_root/lib/$app_name/.mix/compile.elixir_scm" ]]
6845
+ }
6846
+
6637
6847
  fmix_ensure_artifacts() {
6638
6848
  local worktree="$1" template_key="$2" allow_template_build="${3:-0}"
6639
6849
  local state_file artifact_state_file
@@ -6655,6 +6865,36 @@ fmix_ensure_artifacts() {
6655
6865
  [[ -d "$deps_root" ]] && has_deps=1
6656
6866
  [[ -d "$build_root" ]] && has_build=1
6657
6867
 
6868
+ # REL-1244: a matching template key is NOT proof that this session was ever
6869
+ # compiled. The key is derived from mix.lock plus the toolchain, so two
6870
+ # worktrees sharing a lockfile share a key -- and a session that inherited an
6871
+ # interrupted overlay still matches it.
6872
+ #
6873
+ # has_deps/has_build only tested that the DIRECTORIES exist. In the failure this
6874
+ # guards, the session had deps/ and _build/ present and cdrcisco.app present,
6875
+ # but ZERO .beam files and no .mix/compile.elixir for the app, because a prior
6876
+ # compile was killed by FMIX_COMPILE_TIMEOUT before it wrote a manifest. FMix
6877
+ # reported session_hit and returned success, so every subsequent `mix compile`
6878
+ # rebuilt the whole DAG from nothing (measured: 5252 files, 513s) and the
6879
+ # pre-push hook -- which runs that compile -- blew its own budget and reported
6880
+ # a compile failure that was really an unrecoverable cold rebuild.
6881
+ #
6882
+ # The clone path below touches every compile.* manifest after copying, and that
6883
+ # touch is precisely what makes a cloned session incremental. The early-return
6884
+ # path skipped that repair. Require the app compile manifest to be present
6885
+ # before accepting a session hit; otherwise fall through so the template is
6886
+ # re-cloned and the manifests are synchronized.
6887
+ #
6888
+ # Scoped deliberately to the SAME-KEY fast path. The other branches have their
6889
+ # own proofs (exact stamps, or fmix_adopt_compatible_worktree_artifacts) and a
6890
+ # key change must still be able to adopt a compatible overlay; gating the whole
6891
+ # block on the manifest broke "template storage-key changes adopt current
6892
+ # worktree stamps without cloning".
6893
+ local has_app_manifest=0
6894
+ if fmix_session_has_app_manifest "$worktree" "$build_root"; then
6895
+ has_app_manifest=1
6896
+ fi
6897
+
6658
6898
  if (( has_deps == 1 && has_build == 1 )); then
6659
6899
  if [[ -z "$recorded_key" ]]; then
6660
6900
  if [[ "$allow_template_build" != "1" ]]; then
@@ -6681,12 +6921,16 @@ fmix_ensure_artifacts() {
6681
6921
  fi
6682
6922
  fmix_info "Session artifact state is absent; exact stamps must prove it before publication."
6683
6923
  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
6924
+ if (( has_app_manifest == 0 )); then
6925
+ fmix_warn "Session artifacts match template key $template_key but the app compile manifest is missing (interrupted or partial overlay); repairing from the template."
6926
+ else
6927
+ [[ -f "$artifact_state_file" ]] \
6928
+ || fmix_write_artifact_state "$worktree" "$template_key" \
6929
+ || return 1
6930
+ fmix_info "Session artifacts match template key $template_key — skipping clone."
6931
+ FMIX_LAST_ARTIFACTS_OUTCOME="session_hit"
6932
+ return 0
6933
+ fi
6690
6934
  else
6691
6935
  fmix_info "Template key mismatch (recorded=$recorded_key, current=$template_key)."
6692
6936
  if fmix_adopt_compatible_worktree_artifacts \
@@ -6696,6 +6940,14 @@ fmix_ensure_artifacts() {
6696
6940
  FMIX_LAST_ARTIFACTS_OUTCOME="adopt_compatible"
6697
6941
  return 0
6698
6942
  fi
6943
+ if (( has_app_manifest == 1 )) \
6944
+ && fmix_adopt_migration_only_key_change \
6945
+ "$worktree" "$recorded_key" "$template_key"; then
6946
+ fmix_write_artifact_state "$worktree" "$template_key" || return 1
6947
+ fmix_info "Only the migrations digest changed under template key $template_key — keeping the session build for incremental compile."
6948
+ FMIX_LAST_ARTIFACTS_OUTCOME="adopt_migration_delta"
6949
+ return 0
6950
+ fi
6699
6951
  if fmix_reconcile_same_toolchain_dependency_change \
6700
6952
  "$worktree" "$recorded_key" "$template_key"; then
6701
6953
  fmix_info "Dependency change adopted under template key $template_key — preserving the app cache for incremental compile."
@@ -7595,6 +7847,16 @@ fmix_publish_hot_base() {
7595
7847
  lock="db-publish-${key}"
7596
7848
  fmix_lock_acquire "$lock" "$FMIX_LOCK_TIMEOUT" || return 1
7597
7849
 
7850
+ if fmix_snapshot_ready "$target" && [[ "${FMIX_REPUBLISH_HOT_BASE:-0}" == "1" ]]; then
7851
+ # API-3576: an explicit cold rebuild just produced a verified-current
7852
+ # scratch. The base already published under this key is exactly the
7853
+ # artifact the operator is repairing, so replace it rather than keep
7854
+ # trusting it.
7855
+ fmix_warn "Replacing published hot base $target with the freshly rebuilt database."
7856
+ fmix_drop_db "$target" || { fmix_lock_release "$lock"; return 1; }
7857
+ rm -rf "$(fmix_db_index_dir "$key")" 2>/dev/null || true
7858
+ fi
7859
+
7598
7860
  if fmix_snapshot_ready "$target"; then
7599
7861
  if ! fmix_base_record_ready "$key"; then
7600
7862
  fmix_info "Hot base $target exists; publishing its missing metadata index."
@@ -7673,12 +7935,17 @@ fmix_migrate_from_zero() {
7673
7935
  # those objects) — but wherever the extension IS available, this lane is
7674
7936
  # unconditionally MORE faithful than the snapshot path can ever be by
7675
7937
  # construction, not just "no worse".
7676
- local worktree="$1" db_name="$2" key target lock timeout t0 t1
7938
+ #
7939
+ # API-3576: the optional third argument "1" (replace) skips both reuse
7940
+ # checks and replaces any published base for this key with the freshly
7941
+ # migrated result. Explicit --cold-db/--from-zero pass it: reusing a
7942
+ # published base is exactly what a rebuild is meant to avoid.
7943
+ local worktree="$1" db_name="$2" replace="${3:-0}" key target lock timeout t0 t1
7677
7944
  fmix_guard_db_name "$db_name" || return 1
7678
7945
  key="$(fmix_schema_key "$worktree")" || return 1
7679
7946
  target="$(fmix_hot_base_name "$key")" || return 1
7680
7947
 
7681
- if fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7948
+ if [[ "$replace" != "1" ]] && fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7682
7949
  fmix_info "Hot base $target already published for schema $key — cloning instead of migrating from zero."
7683
7950
  fmix_create_database "$db_name" "$target" || return 1
7684
7951
  return 0
@@ -7689,7 +7956,7 @@ fmix_migrate_from_zero() {
7689
7956
 
7690
7957
  # Double-checked: another host process may have published this exact
7691
7958
  # schema's hot base while we waited for the lock.
7692
- if fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7959
+ if [[ "$replace" != "1" ]] && fmix_snapshot_ready "$target" && fmix_base_record_ready "$key"; then
7693
7960
  fmix_lock_release "$lock"
7694
7961
  fmix_info "Hot base $target was published while waiting on the lock — cloning."
7695
7962
  fmix_create_database "$db_name" "$target" || return 1
@@ -7725,7 +7992,7 @@ fmix_migrate_from_zero() {
7725
7992
 
7726
7993
  fmix_info "Publishing hot DB base $target from freshly from-zero-migrated $db_name …"
7727
7994
  if fmix_db_exists "$target"; then
7728
- fmix_warn "Removing incomplete hot base $target before a clean publication."
7995
+ fmix_warn "Removing incomplete or superseded hot base $target before a clean publication."
7729
7996
  fmix_drop_db "$target" || { fmix_lock_release "$lock"; return 1; }
7730
7997
  fi
7731
7998
  if ! fmix_create_database "$target" "$db_name" scratch-publish; then
@@ -7900,6 +8167,16 @@ fmix_ensure_db() {
7900
8167
  fmix_error "Scratch DB $db_name provenance is not a content-valid prefix of this branch."
7901
8168
  fi
7902
8169
  fi
8170
+ if (( valid == 1 )) && [[ "$rebuild_existing" == "1" ]]; then
8171
+ # API-3576: an explicit rebuild must rebuild. A scratch DB whose
8172
+ # recorded schema key still matches reports "0 pending migrations"
8173
+ # forever, even when the schema under that ledger is stale, so
8174
+ # reusing it here made --rebuild-db/--cold-db/--from-zero silent
8175
+ # no-ops. The operator asked for a fresh database: drop it.
8176
+ fmix_warn "Explicit rebuild requested; replacing otherwise-valid scratch DB $db_name."
8177
+ valid=0
8178
+ fmix_drop_db "$db_name" || return 1
8179
+ fi
7903
8180
  if (( valid == 1 )); then
7904
8181
  # The scratch will be asserted/migrated to the current manifest
7905
8182
  # before state publication. Preserve its source separately.
@@ -7908,18 +8185,29 @@ fmix_ensure_db() {
7908
8185
  FMIX_ACTIVE_DB_BASE_ID="$stored_base"
7909
8186
  return 0
7910
8187
  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
8188
+ if fmix_db_exists "$db_name"; then
8189
+ if [[ "$rebuild_existing" != "1" ]]; then
8190
+ fmix_error "Refusing to drop or reuse an unverified scratch DB in a normal lane."
8191
+ fmix_error "After confirming no live owner: ./fmix setup --rebuild-db --worktree $worktree"
8192
+ return 1
8193
+ fi
8194
+ fmix_warn "Explicit setup is replacing unverified scratch DB $db_name."
8195
+ fmix_drop_db "$db_name" || return 1
7915
8196
  fi
7916
- fmix_warn "Explicit setup is replacing unverified scratch DB $db_name."
7917
- fmix_drop_db "$db_name" || return 1
7918
8197
  fi
7919
8198
 
7920
- fmix_info "Selecting one content-indexed DB base for $db_name …"
7921
8199
  t0="$(fmix_epoch)"
7922
- selection="$(fmix_select_indexed_base "$worktree")" || selection=""
8200
+ selection=""
8201
+ if [[ "$allow_structure_build" == "1" ]]; then
8202
+ # API-3576: --cold-db and --from-zero exist to build the schema again.
8203
+ # Selecting a published hot base first re-cloned the very base that was
8204
+ # stale, so these lanes could never repair it. Skip selection; the
8205
+ # rebuilt scratch is republished over the stale base (see setup).
8206
+ fmix_info "Explicit cold rebuild: bypassing published hot bases for $db_name."
8207
+ else
8208
+ fmix_info "Selecting one content-indexed DB base for $db_name …"
8209
+ selection="$(fmix_select_indexed_base "$worktree")" || selection=""
8210
+ fi
7923
8211
  if [[ -n "$selection" ]]; then
7924
8212
  IFS=$'\t' read -r base base_key delta <<<"$selection"
7925
8213
  fmix_guard_template_db_name "$base" || return 1
@@ -7948,7 +8236,7 @@ fmix_ensure_db() {
7948
8236
  else
7949
8237
  fmix_warn "No indexed hot base exists and structure.sql is unusable for cold bootstrap; migrating from zero."
7950
8238
  fi
7951
- fmix_migrate_from_zero "$worktree" "$db_name" || return 1
8239
+ fmix_migrate_from_zero "$worktree" "$db_name" 1 || return 1
7952
8240
  FMIX_ACTIVE_DB_SCHEMA_KEY="$current_key"
7953
8241
  FMIX_ACTIVE_DB_SOURCE_KEY="$current_key"
7954
8242
  FMIX_ACTIVE_DB_BASE_ID="migrate-from-zero"
@@ -8056,6 +8344,8 @@ fmix_run_migration_bounded() {
8056
8344
  MEESEEKS_HTML5EVER_BUILD=0 \
8057
8345
  LOCAL_NATS="$NATS_HOST" \
8058
8346
  NATS_PORT="$NATS_PORT" \
8347
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
8348
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
8059
8349
  mix ecto.migrate --no-compile
8060
8350
  ) >"$log_file" 2>&1 &
8061
8351
  pid=$!
@@ -8278,6 +8568,8 @@ fmix_ensure_partitions() {
8278
8568
  MEESEEKS_HTML5EVER_BUILD=0 \
8279
8569
  LOCAL_NATS="$NATS_HOST" \
8280
8570
  NATS_PORT="$NATS_PORT" \
8571
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
8572
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
8281
8573
  env -u DB_HOST_IPV4 mix cdrcisco.bootstrap_partitions
8282
8574
  ) || {
8283
8575
  fmix_error "cdrcisco.bootstrap_partitions failed on $db_name."
@@ -9710,7 +10002,10 @@ fmix_compile_stamp_matches() {
9710
10002
  recorded_ignored_compile_hash="$(fmix_read_state "$stamp" ignored_compile_hash)"
9711
10003
 
9712
10004
  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 "")"
10005
+ # The override lets artifact adoption prove a v4-stamped session against
10006
+ # the key it was actually stamped with (see
10007
+ # fmix_adopt_compatible_worktree_artifacts).
10008
+ current_template_key="${FMIX_COMPILE_STAMP_KEY_OVERRIDE:-$(fmix_compute_template_key "$real" 2>/dev/null || echo "")}"
9714
10009
  current_tree_hash="$(fmix_get_git_tree_hash "$real")" || return 1
9715
10010
  current_env_hash="$(fmix_compute_compile_env_hash "$real" 2>/dev/null || echo "")"
9716
10011
  current_dirty_hash="$(fmix_compute_dirty_hash "$real" 2>/dev/null)" \
@@ -9961,6 +10256,40 @@ fmix_reconcile_same_toolchain_dependency_change() {
9961
10256
  return 0
9962
10257
  }
9963
10258
 
10259
+ fmix_adopt_migration_only_key_change() {
10260
+ # API-3576: the template key now includes a migrations digest, so landing a
10261
+ # migration changes the key. Nothing the template caches (compiled deps and
10262
+ # the app baseline) depends on migrations, so a session whose recorded base
10263
+ # key (everything but the digest) still equals the current one keeps its
10264
+ # artifacts and only its storage key advances; Mix recompiles any changed
10265
+ # sources incrementally exactly as it did when migrations were not keyed.
10266
+ #
10267
+ # Deliberately does NOT adopt a v4-stamped session (see
10268
+ # fmix_adopt_compatible_worktree_artifacts, which also re-records stamps):
10269
+ # this path leaves stamps to the incremental compile that a changed tree
10270
+ # forces, so it requires proof that the tree actually changed.
10271
+ local worktree="$1" recorded_key="$2" template_key="$3"
10272
+ local real state_file artifact_state_file key_state_file recorded_base current_base
10273
+ local compile_stamp recorded_tree current_tree
10274
+ real="$(fmix_realpath "$worktree")" || return 1
10275
+ state_file="$(fmix_worktree_state_file "$real")"
10276
+ artifact_state_file="$(fmix_artifact_state_file "$real")"
10277
+ [[ -f "$artifact_state_file" ]] || return 1
10278
+ key_state_file="$artifact_state_file"
10279
+ [[ "$(fmix_read_state "$key_state_file" path)" == "$real" ]] || return 1
10280
+ recorded_base="$(fmix_read_state "$key_state_file" template_base_key)"
10281
+ [[ "$recorded_base" =~ ^[0-9a-f]{16}$ ]] || return 1
10282
+ current_base="$(fmix_compute_legacy_template_key_v4 "$real" 2>/dev/null)" || return 1
10283
+ [[ "$recorded_base" == "$current_base" ]] || return 1
10284
+ compile_stamp="$(fmix_compile_stamp_file "$real")"
10285
+ [[ -f "$compile_stamp" ]] || return 1
10286
+ recorded_tree="$(fmix_read_state "$compile_stamp" git_tree_hash)"
10287
+ current_tree="$(fmix_get_git_tree_hash "$real")" || return 1
10288
+ [[ -n "$recorded_tree" && "$recorded_tree" != "unknown" \
10289
+ && "$current_tree" != "unknown" && "$recorded_tree" != "$current_tree" ]] || return 1
10290
+ fmix_update_worktree_template_key "$real" "$recorded_key" "$template_key"
10291
+ }
10292
+
9964
10293
  fmix_adopt_compatible_worktree_artifacts() {
9965
10294
  local worktree="$1" recorded_key="$2" template_key="$3"
9966
10295
  local real state_file artifact_state_file key_state_file
@@ -9987,6 +10316,17 @@ fmix_adopt_compatible_worktree_artifacts() {
9987
10316
  if fmix_dependency_stamp_matches "$real" "$dependency_fingerprint" \
9988
10317
  && fmix_compile_stamp_matches "$real" "$compile_fingerprint"; then
9989
10318
  mode="current"
10319
+ elif legacy_key="$(fmix_compute_legacy_template_key_v4 "$real" 2>/dev/null)" \
10320
+ && [[ "$recorded_key" == "$legacy_key" ]] \
10321
+ && fmix_dependency_stamp_matches "$real" "$dependency_fingerprint" \
10322
+ && FMIX_COMPILE_STAMP_KEY_OVERRIDE="$legacy_key" \
10323
+ fmix_compile_stamp_matches "$real" "$compile_fingerprint"; then
10324
+ # API-3576: v5 added the migrations digest to the key, so every session
10325
+ # stamped by FMix <= 2.7.9 reads as a key mismatch even though nothing
10326
+ # it compiled changed. The recorded v4 key equals the v4 key of these
10327
+ # exact inputs and every stamp matches under it, so only the storage key
10328
+ # moves; stamps are re-recorded under v5 below.
10329
+ mode="v4"
9990
10330
  else
9991
10331
  legacy_key="$(fmix_compute_legacy_template_key_v2 "$real")" || return 1
9992
10332
  [[ "$recorded_key" == "$legacy_key" ]] || return 1
@@ -10003,7 +10343,7 @@ fmix_adopt_compatible_worktree_artifacts() {
10003
10343
  return 1
10004
10344
  fi
10005
10345
 
10006
- if [[ "$mode" == "legacy" ]]; then
10346
+ if [[ "$mode" == "legacy" || "$mode" == "v4" ]]; then
10007
10347
  if ! fmix_write_dependency_stamp "$real" "$dependency_fingerprint" \
10008
10348
  || ! fmix_write_compile_stamp "$real" "$compile_fingerprint"; then
10009
10349
  cp "$migration_dir/dependency.json" "$dependency_stamp" || true
@@ -10207,6 +10547,8 @@ _fmix_run_compile() {
10207
10547
  MEESEEKS_HTML5EVER_BUILD=0 \
10208
10548
  LOCAL_NATS="$NATS_HOST" \
10209
10549
  NATS_PORT="$NATS_PORT" \
10550
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
10551
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
10210
10552
  mix compile $extra 2>&1
10211
10553
  )
10212
10554
  }
@@ -10976,7 +11318,17 @@ cmd_setup() {
10976
11318
 
10977
11319
  local mig_stamp schema_key published_base
10978
11320
  schema_key="$FMIX_ACTIVE_DB_SCHEMA_KEY"
10979
- published_base="$(fmix_publish_hot_base "$real_worktree" "$db_name" "$schema_key")" || {
11321
+ # API-3576: --cold-db/--from-zero rebuilt the schema from scratch, so the
11322
+ # result must replace (not merely coexist with) any published base for this key.
11323
+ published_base="$(
11324
+ if [[ "$allow_structure_build" == "1" && "${FMIX_ACTIVE_DB_BASE_ID:-}" != "migrate-from-zero" ]]; then
11325
+ FMIX_REPUBLISH_HOT_BASE=1
11326
+ else
11327
+ FMIX_REPUBLISH_HOT_BASE=0
11328
+ fi
11329
+ export FMIX_REPUBLISH_HOT_BASE
11330
+ fmix_publish_hot_base "$real_worktree" "$db_name" "$schema_key"
11331
+ )" || {
10980
11332
  fmix_lock_release "$lock_name"
10981
11333
  return 1
10982
11334
  }
@@ -11643,6 +11995,8 @@ cmd_test() {
11643
11995
  SECRET_KEY_BASE="$SECRET_KEY_BASE"
11644
11996
  MEESEEKS_HTML5EVER_BUILD=0
11645
11997
  CT_SKIP_MIGRATION_TIMING=1
11998
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}"
11999
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}"
11646
12000
  )
11647
12001
  [[ -n "$event_fd" ]] && common_env+=("FMIX_EVENT_FD=$event_fd")
11648
12002
  # The child must observe the same run and session identity that
@@ -11888,6 +12242,8 @@ cmd_task() {
11888
12242
  ONPREM=TRUE \
11889
12243
  SECRET_KEY_BASE="$SECRET_KEY_BASE" \
11890
12244
  MEESEEKS_HTML5EVER_BUILD=0 \
12245
+ POSTHOG_BACKEND_ENABLED="${POSTHOG_BACKEND_ENABLED:-false}" \
12246
+ POSTHOG_BROWSER_ENABLED="${POSTHOG_BROWSER_ENABLED:-false}" \
11891
12247
  mix "${mix_args[@]}"
11892
12248
  ) || task_rc=$?
11893
12249
 
@@ -12548,8 +12904,105 @@ cmd_doctor() {
12548
12904
  # cmd: fmix status
12549
12905
  # ---------------------------------------------------------------------------
12550
12906
 
12907
+ # REL-1244: report a tree size WITHOUT stat()ing every file.
12908
+ #
12909
+ # fmix status and fmix doctor called `du -sh` on the artifact trees. On this host
12910
+ # the store is 1,682,684 files (753,820 templates + 928,864 dependency
12911
+ # artifacts, ~42 GB apparent). `du -sh` stats every one: measured at 40.9s for
12912
+ # templates and 63.5s for dependency-artifacts, i.e. ~104s of the 162s that
12913
+ # `fmix status` takes - all of it to print a size label nobody parses.
12914
+ #
12915
+ # Sizes are now read from a small cache beside each tree and refreshed at most
12916
+ # once per TTL. An uncached read returns "?" rather than blocking: a status
12917
+ # command must never be the slowest thing in a push.
12918
+ FMIX_TREE_SIZE_TTL="${FMIX_TREE_SIZE_TTL:-604800}" # 7 days
12919
+
12920
+ fmix_tree_size_cached() {
12921
+ local dir="$1" label="${2:-$(basename "$1")}"
12922
+ [[ -d "$dir" ]] || { printf '?\n'; return 0; }
12923
+ local cache="$FMIX_HOME/tree-sizes/${label}.json"
12924
+ local now recorded value
12925
+ now="$(date +%s)"
12926
+ if [[ -f "$cache" ]]; then
12927
+ recorded="$(fmix_read_state "$cache" recorded_at 2>/dev/null)"
12928
+ value="$(fmix_read_state "$cache" size 2>/dev/null)"
12929
+ # TTL is ENFORCED, not merely recorded. A cache entry without a usable
12930
+ # timestamp is treated as expired rather than trusted: an unenforced TTL
12931
+ # would report a size that a prune or a template rebuild has since
12932
+ # invalidated, and nothing would ever correct it.
12933
+ # A timestamp in the FUTURE is also invalid: `now - recorded` would be
12934
+ # negative and read as "very fresh". Clock skew or a hand-edited cache must
12935
+ # not be able to pin a stale size indefinitely.
12936
+ if [[ -n "$value" && "$recorded" =~ ^[0-9]+$ ]] \
12937
+ && (( recorded <= now )) \
12938
+ && (( now - recorded < FMIX_TREE_SIZE_TTL )); then
12939
+ printf '%s\n' "$value"
12940
+ return 0
12941
+ fi
12942
+ fi
12943
+ # No usable cached value: report unknown rather than walking 1.68M files here.
12944
+ # `fmix status --refresh-sizes` populates it explicitly.
12945
+ printf '?\n'
12946
+ return 0
12947
+ }
12948
+
12949
+ # Explicit, bounded refresh of the cached tree sizes.
12950
+ #
12951
+ # Labels MUST match what fmix_tree_size_cached is called with, or the cache is
12952
+ # written under keys nothing reads and every status stays "?". Templates are
12953
+ # cached per template key because the reader iterates per template.
12954
+ # Atomic: write beside the target and rename, so a concurrent reader never sees a
12955
+ # truncated file and two concurrent refreshes cannot interleave.
12956
+ fmix_tree_size_write() {
12957
+ local cache="$1" now="$2" size="$3" tmp
12958
+ tmp="${cache}.tmp-$$"
12959
+ if printf '{"recorded_at": %s, "size": "%s"}\n' "$now" "$size" > "$tmp" 2>/dev/null; then
12960
+ mv -f "$tmp" "$cache" 2>/dev/null || rm -f "$tmp" 2>/dev/null
12961
+ else
12962
+ rm -f "$tmp" 2>/dev/null
12963
+ fi
12964
+ }
12965
+
12966
+ fmix_tree_size_refresh() {
12967
+ local dirs_root="$FMIX_HOME/templates" key size now
12968
+ mkdir -p "$FMIX_HOME/tree-sizes" 2>/dev/null || true
12969
+ now="$(date +%s)"
12970
+ # Keys written this run; anything else in the cache refers to a tree that no
12971
+ # longer exists and is pruned below, so the cache cannot grow without bound
12972
+ # across prune/rebuild cycles.
12973
+ local -a live_keys=()
12974
+ if [[ -d "$dirs_root" ]]; then
12975
+ for dir in "$dirs_root"/*/; do
12976
+ [[ -d "$dir" ]] || continue
12977
+ key="$(basename "$dir")"
12978
+ size="$(du -sh "$dir" 2>/dev/null | awk '{print $1}')" || size="?"
12979
+ fmix_tree_size_write "$FMIX_HOME/tree-sizes/template_${key}.json" "$now" "$size"
12980
+ live_keys+=("template_${key}.json")
12981
+ printf '%s %s\n' "$size" "$dir"
12982
+ done
12983
+ fi
12984
+ local dep_root="$FMIX_HOME/dependency-artifacts/v1"
12985
+ if [[ -d "$dep_root" ]]; then
12986
+ size="$(du -sh "$dep_root" 2>/dev/null | awk '{print $1}')" || size="?"
12987
+ fmix_tree_size_write "$FMIX_HOME/tree-sizes/dependency_artifacts_v1.json" "$now" "$size"
12988
+ live_keys+=("dependency_artifacts_v1.json")
12989
+ printf '%s %s\n' "$size" "$dep_root"
12990
+ fi
12991
+ local existing base keep lk
12992
+ shopt -s nullglob
12993
+ for existing in "$FMIX_HOME/tree-sizes"/*.json; do
12994
+ base="$(basename "$existing")"
12995
+ keep=0
12996
+ for lk in "${live_keys[@]+"${live_keys[@]}"}"; do
12997
+ [[ "$base" == "$lk" ]] && { keep=1; break; }
12998
+ done
12999
+ (( keep == 0 )) && rm -f "$existing" 2>/dev/null
13000
+ done
13001
+ shopt -u nullglob
13002
+ }
13003
+
12551
13004
  cmd_status() {
12552
- local scoped_run_id="" scoped_json=0
13005
+ local scoped_run_id="" scoped_json=0 refresh_sizes=0
12553
13006
  while (( $# > 0 )); do
12554
13007
  case "$1" in
12555
13008
  --run-id)
@@ -12559,9 +13012,13 @@ cmd_status() {
12559
13012
  ;;
12560
13013
  --run-id=*) scoped_run_id="${1#--run-id=}"; shift ;;
12561
13014
  --json) scoped_json=1; shift ;;
12562
- *) fmix_error "Unknown status option: $1. Usage: fmix status [--run-id <uuid> --json]"; return 2 ;;
13015
+ --refresh-sizes) refresh_sizes=1; shift ;;
13016
+ *) fmix_error "Unknown status option: $1. Usage: fmix status [--run-id <uuid> --json] [--refresh-sizes]"; return 2 ;;
12563
13017
  esac
12564
13018
  done
13019
+ # NOTE: the refresh runs further down, AFTER --run-id validation. It walks every
13020
+ # artifact tree (~90s), so doing it before validation would spend that cost on an
13021
+ # invocation that is about to exit 2 with a usage error.
12565
13022
  if [[ -n "$scoped_run_id" ]]; then
12566
13023
  if ! fmix_run_id_is_valid "$scoped_run_id"; then
12567
13024
  fmix_error "Invalid FMix run ID: $scoped_run_id"
@@ -12644,6 +13101,13 @@ PY
12644
13101
  echo ""
12645
13102
 
12646
13103
  # Templates
13104
+ # Explicit, bounded: walks the artifact trees ONCE and records the result.
13105
+ # Normal status never does this; it reads the cached figure. Ordered after all
13106
+ # argument validation so a rejected invocation never pays for the walk.
13107
+ if (( refresh_sizes == 1 )); then
13108
+ fmix_tree_size_refresh >/dev/null
13109
+ fi
13110
+
12647
13111
  echo "--- Templates ($FMIX_HOME/templates/) ---"
12648
13112
  if [[ -d "$FMIX_HOME/templates" ]]; then
12649
13113
  local any_templates=0
@@ -12661,7 +13125,7 @@ PY
12661
13125
  built_at="$(fmix_read_template_meta "$key" "built_at")"
12662
13126
  last_used="$(fmix_read_template_last_used "$key")"
12663
13127
  local size=""
12664
- size="$(du -sh "$tdir" 2>/dev/null | awk '{print $1}')" || true
13128
+ size="$(fmix_tree_size_cached "$tdir" "template_${key}")"
12665
13129
  printf " %s status=%-10s built=%s last_used=%s size=%s\n" \
12666
13130
  "$key" "$status" "$built_at" "$last_used" "$size"
12667
13131
  done
@@ -12676,8 +13140,7 @@ PY
12676
13140
  if [[ -d "$FMIX_HOME/dependency-artifacts/v1" ]]; then
12677
13141
  dependency_artifact_count="$(find "$FMIX_HOME/dependency-artifacts/v1" \
12678
13142
  -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="?"
13143
+ dependency_artifact_bytes="$(fmix_tree_size_cached "$FMIX_HOME/dependency-artifacts/v1" "dependency_artifacts_v1")"
12681
13144
  printf ' generations=%s size=%s ttl=%sd\n' \
12682
13145
  "${dependency_artifact_count:-0}" "${dependency_artifact_bytes:-0}" \
12683
13146
  "$FMIX_DEPENDENCY_ARTIFACT_TTL_DAYS"
@@ -18060,9 +18523,9 @@ Usage:
18060
18523
  [--rebuild-db|--cold-db|--from-zero]
18061
18524
 
18062
18525
  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)
18526
+ --rebuild-db drop and re-clone the scratch DB from a published base; never replays structure.sql
18527
+ --cold-db rebuild from structure.sql, ignoring published bases, and replace the published base
18528
+ --from-zero full migration chain from an empty DB, replacing the published base (structure.sql stale)
18066
18529
 
18067
18530
  Example:
18068
18531
  fmix setup --worktree ./cisco-cdr
@@ -18196,9 +18659,9 @@ Examples:
18196
18659
  ./fmix task --worktree ./cisco-cdr -- openapi.gen --format all
18197
18660
  ./fmix task --worktree ./cisco-cdr --database ct_dev --mix-env dev -- ecto.migrate
18198
18661
  ./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
18662
+ ./fmix setup --rebuild-db --worktree ./cisco-cdr # drop and re-clone the scratch DB from a published base; never replays structure.sql
18663
+ ./fmix setup --cold-db --worktree ./cisco-cdr # rebuild from structure.sql, ignoring and replacing the published base
18664
+ ./fmix setup --from-zero --worktree ./cisco-cdr # full migration chain from an empty DB, replacing the published base; structure.sql unusable/stale
18202
18665
  ./fmix seed publish --worktree ./cisco-cdr --cache-base 0.8.7-stable
18203
18666
  ./fmix cache explain --worktree ./cisco-cdr --cache-base 0.8.7-stable
18204
18667
  ./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.10",
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": "fc78800220663090467af95be18bb483f1ed60cffd9b1fb1f920153f3d29151d",
30
+ "sourceTag": "fmix-v2.7.10"
31
31
  }
32
32
  }