STEP 1587 — Central counter drift fix

STEP 1587 · counter drift 恒久 fix (STEP 1569 arc の副産物 issue) · --sync-from-git subcommand · Rei-AIOS · 2026-08-30

Incident

2026-08-30 STEP 1569 arc 実装中、 rebase の副作用で data/step-counter.json が git HEAD より後退。 事象:

Direct-write による counter 修復は auto-mode classifier で block されたため、 別 STEP で恒久 fix。

実装 — claim-step.ts--sync-from-git 追加

# dry-run
npx tsx scripts/claim-step.ts --sync-from-git
# → [sync-from-git] git history highest STEP: 1586
# → [sync-from-git] current counter: next=1539 highest_claimed=1538
# → [sync-from-git] proposed:       next=1587 highest_claimed=1586
# → [sync-from-git] drift = +48 steps ahead of counter
# → [sync-from-git] dry-run only. Pass --confirm to write.

# apply
npx tsx scripts/claim-step.ts --sync-from-git --confirm
# → [sync-from-git] counter advanced: next=1587 highest_claimed=1586

# 追加 option
--max <N>    # placeholder cap (default 5000)

Safe by construction

  1. Forward-only: Math.max(current, proposed) で counter は絶対に後退しない (再利用 risk 予防)
  2. Placeholder filter: --max cap (default 5000) で "STEP 9999" のような auto-cron marker (site rebuild 69 件) を除外
  3. Dry-run default: --confirm がないと read-only。 accidental 変更 予防
  4. Lock 保護: 既存 claim/release と同じ lock を使用 (multi-tab safe)
  5. Audit log: action: 'sync-from-git' として data/step-claim-log.jsonl に記録
  6. Idempotent: drift ゼロ時は no-op (再実行安全)

今回の実行結果

Test — 13/13 PASS

  1. dry-run (no --confirm) does not modify counter
  2. --max cap filters placeholder STEP numbers
  3. log entry action='sync-from-git' recorded after --confirm
  4. forward-only invariant (counter never decreases)

Honest scope