Skip to content

fix(post-merge-feedback): task labeling 規約導入で run dir 検索を決定論化#78

Merged
aloekun merged 2 commits into
masterfrom
fix/adr-030-task-labeling
Apr 25, 2026
Merged

fix(post-merge-feedback): task labeling 規約導入で run dir 検索を決定論化#78
aloekun merged 2 commits into
masterfrom
fix/adr-030-task-labeling

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented Apr 25, 2026

Summary

PR #77 の merge dogfood で発覚した copy_feedback_report のバグを Phase B 内で完結修正する。

Bug: takt の run dir 命名 <ts>-<sanitized-task-label> に対し、Rust 側が ends_with("-<workflow>") で suffix match していた。task に context (PR 番号等) が含まれると dir suffix が -post-merge-feedback-for-77 のようになり、-post-merge-feedback ends_with で fail。

Fix: 命名規約を導入することで曖昧な検索を排除する。task label は workflow 名を必ず prefix として含む "<workflow-name> [<context>]" 形式とし、Rust 側のマッチングを name.contains(&format!("-{}", workflow)) の 1 ルールに統一。context suffix の有無に関わらず一律にマッチする。

変更内容

コード

  • src/cli-merge-pipeline/src/feedback.rs:
    • find_latest_run_dir: 引数を suffixworkflow に、内部実装を ends_withcontains(&format!("-{}", workflow)) に変更
    • TAKT_TASK_PREFIX: "post-merge feedback for #""post-merge-feedback for #" (空白を除去し sanitization 後完全一致に)
    • 新規テスト 5 件: workflow 名のみ / context suffix 付き / 混在で lex max 選定 / 該当なし / dir 不在

設定 (post-pr-review の latent bug 予防)

ドキュメント

  • docs/adr/adr-030-deterministic-post-merge-feedback.md: 「§task labeling convention (Phase B dogfood で確立)」セクション追加
    • 規約: task label は workflow 名を prefix として含む形式
    • 制約: workflow 名同士は部分文字列関係になってはいけない (mergepost-merge-feedback は OK、post-mergepost-merge-feedback は NG)
    • 採用根拠: 同期実行 invariant に依存する代替案 (Option C: 「最新 run dir = 自分のもの」) より、命名規約による直接対応のほうが並行 takt 実行・将来の非同期化に対して頑健

設計判断

なぜ「最新 run dir を無条件で拾う」(Option C) ではなく命名規約 (Option A) か

観点 Option C (latest 無条件) Option A (命名規約 + contains match)
並行 takt 実行 別 workflow の run を誤検出 workflow 名で filter されるため誤検出なし
将来の非同期化 同期実行 invariant が壊れた瞬間に破綻 規約だけ守れば独立に動く
既存 (pre-push-review) との後方互換 関係なし task = pre-push-review で偶然一致するため変更不要
post-pr-review の latent bug 別 PR で対処が必要 同 PR で予防

バグの教訓 (PR #77 dogfood で抽出された Tier 1 #3 とも整合)

「ADR 移行時、旧機構の文言・参照・命名仮定が log メッセージや match ロジックに残留する」というパターンが ADR-015/018/030 と繰り返し発生している。本 PR では log 文言ではなくマッチング規約の側で問題を解決する (PR #77 で aggregate-feedback が提案した Tier 3 #1「ADR 移行チェックリストに grep ステップ追加」とも独立補完)。

Test plan

  • cargo test workspace 全 green (cli-merge-pipeline: 39 tests、新規 5 件)
  • cargo clippy --workspace -- -D warnings 通過
  • cargo fmt --check 通過
  • release build (cli-merge-pipeline + cli-pr-monitor): 成功
  • 既存テスト find_latest_prepush_picks_lexicographic_max (workflow 名のみ形式) が新実装でも pass
  • 新規テスト find_latest_run_dir_matches_workflow_with_context_suffix (PR 番号付き形式) が pass
  • 新規テスト find_latest_run_dir_picks_lex_max_across_mixed_forms (両形式混在) が pass

dogfood 検証は本 PR マージ後の post-merge-feedback workflow が .claude/feedback-reports/<pr>.md を正しく生成することで完了する (Phase B 内で bug 発見 → 修正 → 検証のサイクルを閉じる)。

References

Summary by CodeRabbit

  • Documentation

    • ワークフローとタスク命名規則を標準化するアーキテクチャ決定記録(ADR-030)を追加しました。
  • Bug Fixes

    • ランディレクトリ検索をワークフロー名ベースの部分一致に変更し、誤検出を防止して検索の信頼性を向上しました。
  • Chores

    • 設定テンプレートと実際の設定を新規命名規則に合わせて更新しました。
  • Tests

    • マッチングと選択ロジックを検証する単体テストを追加しました。

PR #77 の merge dogfood で発覚した `copy_feedback_report` の bug を修正する。
takt の run dir 命名は `<ts>-<sanitized-task-label>` 形式で workflow 名そのものは
含まないため、`ends_with("-<workflow>")` での suffix match が context suffix
(例: `-for-77`) 付きの dir に対して fail していた。

対策: 「task label は workflow 名を必ず prefix として含む」という命名規約を
ADR-030 に追記し、Rust 側のマッチングを `name.contains("-<workflow>")` の
1 ルールに統一。context suffix の有無に関わらず一律にマッチする。

主な変更:
- src/cli-merge-pipeline/src/feedback.rs: find_latest_run_dir を contains
  match に変更、TAKT_TASK_PREFIX を workflow 名と sanitization 後一致する形に
  修正、新規テスト 5 件追加
- src/cli-pr-monitor/src/config.rs + pr-monitor-config.toml +
  templates/pr-monitor-config.toml: post-pr-review の task を
  "analyze PR review comments" → "post-pr-review" に揃え、latent bug を予防
- docs/adr/adr-030-deterministic-post-merge-feedback.md: §task labeling
  convention セクション追加。規約・制約 (workflow 名同士の部分文字列禁止)・
  採用根拠を明記

Phase B 内の bugfix として完結し、Phase C には bug を持ち越さない。
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 89703d31-b914-437d-91a1-5a7502c2aaa7

📥 Commits

Reviewing files that changed from the base of the PR and between 52b70e1 and 423b36e.

📒 Files selected for processing (1)
  • docs/adr/adr-030-deterministic-post-merge-feedback.md

📝 Walkthrough

Walkthrough

ADRでタスクラベルとtakt実行ディレクトリ命名の一貫性を定め、Rust実装のランディレクトリ選択ロジックをサフィックス照合からワークフロー名の包含照合(contains("-<workflow>"))へ変更し、設定テンプレートとテストをそれに合わせて更新しました。

Changes

Cohort / File(s) Summary
ADR Documentation
docs/adr/adr-030-deterministic-post-merge-feedback.md
ADRを追加/更新し、タスクラベルがワークフロー名をプレフィックスとして含む命名規約と-<workflow>包含チェックによるマッチングルールを仕様化。
Configuration Files
pr-monitor-config.toml, templates/pr-monitor-config.toml
[takt].task"analyze PR review comments"から"post-pr-review"へ変更。コメントをADR-030準拠に更新。
Rust implementation & tests
src/cli-merge-pipeline/src/feedback.rs, src/cli-pr-monitor/src/config.rs
find_latest_run_dirのパラメータをsuffixworkflowへ変更し、ends_withからcontains("-<workflow>")への照合ロジックへ差し替え。呼び出し箇所を更新し、該当ユニットテストを追加/更新。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request title clearly describes the main change: deterministic run directory discovery through task label convention, matching the core fix across feedback.rs, config updates, and ADR documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/adr/adr-030-deterministic-post-merge-feedback.md`:
- Line 181: The ADR example is inconsistent with the implementation: the logic
in find_latest_run_dir using name.contains(&format!("-{}", workflow)) will match
internal substrings (e.g., "-merge" inside "post-merge-feedback"), so update the
ADR example to mark "merge" vs "post-merge-feedback" as invalid (NG) rather than
OK; reference the implementation detail (find_latest_run_dir and
name.contains(&format!("-{}", workflow))) in the ADR text and adjust the
wording/constraints so future readers see that any workflow name that is a
substring of another (including mid-string matches) is disallowed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96047c5b-ac59-4514-a199-24d5258953d8

📥 Commits

Reviewing files that changed from the base of the PR and between a1ee195 and 52b70e1.

📒 Files selected for processing (5)
  • docs/adr/adr-030-deterministic-post-merge-feedback.md
  • pr-monitor-config.toml
  • src/cli-merge-pipeline/src/feedback.rs
  • src/cli-pr-monitor/src/config.rs
  • templates/pr-monitor-config.toml

Comment thread docs/adr/adr-030-deterministic-post-merge-feedback.md Outdated
CodeRabbit (PR #78) が指摘した不整合を修正。

旧記述: "merge と post-merge-feedback は OK" は誤り。
- find_latest_run_dir は name.contains("-{workflow}") で照合
- workflow=merge の needle "-merge" は "<ts>-post-merge-feedback-..." に
  内部出現するため誤マッチが起きる
- したがって merge も post-merge と同様 NG

修正内容:
- 「部分文字列関係」の定義を実装メソッド (name.contains) と紐付けて明記
- NG 例を 2 件 (merge, post-merge) と OK 例 (build) を併記
- 実装ファイル feedback.rs へのリンクを追加
@aloekun aloekun merged commit 130790a into master Apr 25, 2026
1 check passed
@aloekun aloekun deleted the fix/adr-030-task-labeling branch April 25, 2026 17:59
aloekun added a commit that referenced this pull request Apr 26, 2026
)

Phase B dogfood で発見されたタイムアウト経路の残存不具合と、ボトルネック分析で
判明した sequential 構造を併せて修正する。

## 主な変更

### 1. workflow の並列化 (.takt/workflows/post-merge-feedback.yaml)
3 つの analyze facet (analyze-pr / analyze-session / analyze-prepush-reports) は
独立した情報源を扱うため parallel block で並列実行する。
PR #78 計測 (sequential 12m13s) → parallel 想定 ~7m30s に短縮。

### 2. TAKT_TIMEOUT_SECS: 600s → 1200s
PR #77 (14m21s)、#78 (12m13s) 観測実績を踏まえた暫定値。並列化後の想定 7m30s
に対し 2x の安全係数。docstring に「band-aid」と明記し、本質解は workflow 構造で
時間を抑えることだと残した。

### 3. caller-side reconciliation (run() 末尾)
Windows の child.kill() が takt の descendants を殺せず、Rust が timeout で kill
した後も takt が orphan として走り続けて report を完成させるケースを観測した
(PR #78 で kill 後 2m13s で feedback-report.md 完成)。

run_takt_workflow の戻り値に関わらず copy_feedback_report を必ず試行し、report が
存在すれば success 扱いとする。既存の .failed marker は cleanup_failed_marker で
除去する。

### 4. 並行起動 guard (CONCURRENT_RUN_GUARD_SECS = 1500s)
cross-invocation context overwrite race を発生源で予防。
.takt/post-merge-feedback-context.json が 1500s 以内に書かれていれば、orphan takt
が走行中の可能性が高いとみなして新規実行を refuse する。

### 5. テスト追加 (5 件)
concurrent_run_guard / context_age_secs の振る舞いを検証。

### 6. ADR-030 更新
- レイテンシモデル (parallel 想定 = max(analyze) + aggregate)
- Reconciliation 設計の根拠
- 並行起動 guard の意図と Phase B 外切り出し方針

## 残存リスク (Phase B 外)
- Windows の job object でプロセスツリー全体を kill する根本対策
- 完全な per-invocation isolation (takt context dir 連携)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant