# STEP 1954 — orphan-gauge-v05-stability-fix

**Timestamp**: 2026-09-11T01:45 (JST)
**Tab worktree**: main (rei-aios-9b)
**Commit**: (this commit)

## 一行 summary

v0.5 = collect.ts readdirSync に .sort() 追加 + maxFiles 20k → 50k、2 runs 完全一致検証、v0.4 RUIN 389 は cap-artifact と判明 (真値 = 1,555)。

## 主要 finding / evidence

### 変更

- **`src/aios/orphan-gauge/collect.ts`**: `readdirSync(dir)` → `readdirSync(dir).sort()` (line 62)、determinism 確保
- **`src/aios/orphan-gauge/index.ts`** defaultConfig: `maxFiles: 20000` → `50000` (実 repo 全 tree を scanning、cap truncation 排除)
- Header comment に v0.5 説明追記 + 経緯

### Determinism verify (2 runs on same tree)

| Metric | Run 1 | Run 2 | Diff |
|---|---|---|---|
| in-scope total | 22,689 | 22,689 | 0 |
| scoped-out | 10,196 | 10,196 | 0 |
| LIVE | 682 | 682 | 0 |
| ORPHAN | 1,278 | 1,278 | 0 |
| **RUIN** | **1,555** | **1,555** | **0** |
| DEAD | 19,174 | 19,174 | 0 |
| **RUIN set membership diff** | — | — | **0 paths** |

**Only time-dependent fields differ** (`generatedAt`, `now`, `ageDays ±0.01`) — expected variance across separate runs, not scan artifact. Set-level determinism = achieved.

### ★★ Cap-based measurement artifact 判明 (honest re-reading)

**v0.4 (STEP 1952) reported RUIN=389 was 大幅 cap-truncated**:
- v0.4 measurement: in-scope 14,827 / scoped-out 5,173 / RUIN 389 (maxFiles=20k、cap hit)
- v0.5 measurement: in-scope 22,689 / scoped-out 10,196 / RUIN 1,555 (maxFiles=50k、full tree scanned)
- Delta: **+7,862 in-scope + 5,023 more scoped-out = 12,885 previously-unseen artifacts**
- Of those additional 12,885: 1,166 (9%) landed in RUIN (1,555 - 389)

**Implication**: v0.1 (1,136) → v0.2 (334) → v0.4 (389) の -70.6% RUIN reduction narrative は **部分的に cap-artifact**。 v0.1 も 20k cap 下 で 測っていた ため。 genuine archive-detection value は 存在する (scoped-out 5,118 → 10,196 は 実際に 2x archive files 検出増加)、しかし raw RUIN count で「-70.6% 減った」と 主張するのは overclaim。 v0.5 fair baseline: **RUIN 1,555 が 真の v0.5 状態、これを 出発点として v0.6 以降 の 改善を測る**。

## Honest scope

- **主張しないこと**:
  - v0.4 の 「70.6% 削減」 narrative は 完全 misclaim では ない = scoped-out 増加は 実 archive-detection 効果、しかし raw count 比較の 一部は cap artifact
  - v0.5 の maxFiles=50,000 も **依然 cap** — repo の 実 file count が 50k 超 の 場合 に同種 artifact 再発可能、v0.6 candidate = cap 撤廃 or lazy iteration
  - 「RUIN 1,555 = actionable count」 では ない、STEP 1947-1948 の calibration は v0.1/v0.2 cap 下 の RUIN で 実施、v0.5 remaining RUIN 1,555 の actionable rate は 未測 (STEP 1955 で 較正予定)
  - Runtime cost: 20k cap 14s → 50k cap 実測 ~15-20s (linear scaling 予想通り、cap 50k で truncation なし前提)
- **前提**:
  - `readdirSync().sort()` は ASCII bytewise sort (localeCompare は使わない)、意図的に単純 = 決定性 のみが 目的
  - test 49/49 PASS で v0.4 の 全 test 継承 + regressions なし

## Failure mode (機械学習用 dataset)

- **(bbb) cap-based sampling を「full tree scan」と誤伝**: v0.4 report で「RUIN 389」を 出したが cap=20k 制約下 の 部分測定、full tree では 1,555。 Prevention: cap hit を banner で **cap-hit flag** として 出力 + 「full tree scan は 未達成」 明示、count 単独で 装置精度を 主張しない。
- **(ccc) 「削減」narrative の cap-artifact**: v0.1→v0.4 -70.6% 削減 主張は 部分 artifact、 archive 検出の実効性 (scoped-out 増加) と 分けて 報告 すべき。 Prevention: 装置改善 の 効果指標は **scoped-out 増加量** or **archive-classified 増加率** で 提示、raw RUIN count 差 は misleading。
- **(ddd) readdir non-determinism の 見落とし**: 20 runs で 見つけていた measurement noise は 実は readdirSync + cap の 交互作用、 見過ごせば 全 v0.4 measurement が 「時刻依存 noisy」 と 誤解 されうる。 Prevention: 装置改善 arc の 初回 sanity test = **2 runs 完全一致 verify** を 必須 (STEP 1954 で 導入、v0.6 以降 も 継続)。

## 詳細参照

- Code: `src/aios/orphan-gauge/collect.ts` line 62 (sort) + `index.ts` defaultConfig line 66 (50k cap)
- Report: `data/orphan-gauge/step-1954/v05-report-summary.json`
- Test: 49/49 PASS unchanged
- 関連 STEP: 1926 → 1947 → 1948 → 1949 → 1950 → 1951 → 1952 → **1954 (this)** → 1955 (Phase B upcoming)

## 追加 section — v0.5 Tier 1 (ii) preparation

Phase B (STEP 1955) では、v0.5 の 真の RUIN 1,555 から **stratified sample 50** を re-review、STEP 1947 sample 50 (v0.1 の RUIN 1,136 から) と 直接比較可能な形で actionable rate を 測る。

**予測**: v0.5 RUIN 1,555 の 内訳 は v0.4 RUIN 389 (cap下) + 追加 1,166 (以前 見えなかった files) で、追加分 は 主に lean4-mathlib 深部 (stable proof) 想定。actionable rate 予測 = 10-20% (lean4-mathlib pilot 混入率 依存)。予測 CI 幅は STEP 1948 の 楽観予測 (40-70% → 実測 18%) の 教訓 で 広めに 提示。
