fix(runner): v3 - 只清理 _diag/pages,不碰 RUNNER_TEMP

根因分析:
- RUNNER_TEMP 在同一 Runner 的所有 Jobs 之間共享
- 清理 RUNNER_TEMP 會刪除其他 Job 的 _runner_file_commands
- 導致 "Missing file at path: _runner_file_commands/set_output_xxx"

修正:
- 移除所有 RUNNER_TEMP 清理邏輯
- 只清理 _diag/pages (這是唯一需要清理的目錄)
- 簡化清理腳本,移除不必要的複雜度

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-29 02:08:50 +08:00
parent 02c38c3a9b
commit 08fb6c59c8

View File

@@ -57,51 +57,23 @@ jobs:
timeout-minutes: 1
steps:
# =======================================================================
# 2026-03-29: Runner _diag/pages 檔案衝突永久修復
# 問題: 並行 Job 寫入同一診斷檔案導致 "file already exists"
# 解法: 強制清理 + flock 鎖定 + 重建目錄
# 2026-03-29: Runner _diag/pages 檔案衝突修復 (v3)
# 重要: 只清理 _diag/pages不碰 RUNNER_TEMP
# 原因: RUNNER_TEMP 在所有 Jobs 之間共享,清理會破壞其他 Job
# =======================================================================
- name: "Clean Runner Diagnostics (Anti-Collision)"
- name: "Clean Runner Diagnostics"
run: |
set +e # 不因清理失敗而中斷
RUNNER_ROOT=$(dirname "$(dirname "$RUNNER_TEMP")")
DIAG_DIR="$RUNNER_ROOT/_diag"
PAGES_DIR="$DIAG_DIR/pages"
LOCK_FILE="/tmp/runner-diag-cleanup.lock"
PAGES_DIR="$RUNNER_ROOT/_diag/pages"
echo "🧹 Cleaning Runner diagnostics..."
echo " RUNNER_ROOT: $RUNNER_ROOT"
echo " PAGES_DIR: $PAGES_DIR"
# 只清理 _diag/pages (唯一需要清理的目錄)
rm -rf "$PAGES_DIR" 2>/dev/null || true
mkdir -p "$PAGES_DIR" 2>/dev/null || true
# 使用 flock 確保同一時間只有一個清理程序
(
flock -w 10 200 || { echo "⚠️ Lock timeout, proceeding anyway"; }
# 清理 Claude worktrees (本地專案目錄)
rm -rf .claude/worktrees 2>/dev/null || true
# 1. 清理 _diag/pages (最關鍵)
if [ -d "$PAGES_DIR" ]; then
# 刪除所有 .log 檔案
find "$PAGES_DIR" -name "*.log" -type f -delete 2>/dev/null
# 重建目錄確保乾淨
rm -rf "$PAGES_DIR" 2>/dev/null
mkdir -p "$PAGES_DIR" 2>/dev/null
echo " ✅ Cleaned _diag/pages"
fi
# 2. 清理 RUNNER_TEMP (排除 _runner_file_commands)
# 注意: 不能刪除整個目錄,否則會破壞 Runner 內部通訊
find "$RUNNER_TEMP" -mindepth 1 -maxdepth 1 ! -name "_runner_file_commands" -exec rm -rf {} \; 2>/dev/null || true
echo " ✅ Cleaned RUNNER_TEMP (preserved _runner_file_commands)"
# 3. 清理 Claude worktrees
rm -rf .claude/worktrees 2>/dev/null
# 4. 清理陳舊的 _work 暫存
find "$RUNNER_ROOT/_work" -name "*.tmp" -mmin +30 -delete 2>/dev/null || true
) 200>"$LOCK_FILE"
echo "✅ Runner cleanup completed"
echo "✅ Cleaned _diag/pages"
# =======================================================================
# ADR-035: Telegram 告警鏈路強制驗證