Skip to content

ローカルキャッシュ早期スキップ#70

Merged
HappyOnigiri merged 7 commits intomainfrom
cursor/-bc-cd6e9f52-7c6c-4663-a9a5-9911e814570d-763a
Mar 12, 2026
Merged

ローカルキャッシュ早期スキップ#70
HappyOnigiri merged 7 commits intomainfrom
cursor/-bc-cd6e9f52-7c6c-4663-a9a5-9911e814570d-763a

Conversation

@HappyOnigiri
Copy link
Owner

@HappyOnigiri HappyOnigiri commented Mar 12, 2026

概要 / Summary

GitHub API呼び出し削減と実行時間短縮のため、ローカルキャッシュによるPR早期スキップ機能を追加。

変更内容 / Changes

  • src/cache_manager.py を新規追加し、.refix_cache.json の読み書き、厳格なスキーマ検証、破損時の回復処理を実装。
  • src/auto_fixer.py にキャッシュのロード・保存ロジックを追加。
  • process_repo 内で、PRの updatedAt がキャッシュと一致する場合、詳細取得やレビュー処理をスキップする早期リターンを導入。
  • キャッシュはオプティマイザであり、GitHub上のState CommentがSource of Truthである原則を維持。

テスト / Testing

  • src/cache_manager.py の単体テストで、正常なI/O、ファイル未存在、JSON破損、スキーマ不一致時の挙動を確認。
  • src/auto_fixer.py のオーケストレーションテストで、updatedAt 一致時の早期スキップ、不一致時の詳細処理、処理後のキャッシュ更新が正しく行われることを確認。
  • make ci で全体的な回帰テストを実施。

関連 issues / Related issues

なし

Open in Web Open in Cursor 

Summary by CodeRabbit

  • 新機能
    • per-PRの更新時刻を記録するローカルキャッシュを導入し、前回と同じPRは自動でスキップして処理を短縮
  • 改善
    • 起動時にキャッシュを読み込み、終了時に保存して永続化。スキップやキャッシュ状態を示すメッセージを追加
    • 処理フローがキャッシュを受け渡して効率的に動作するようになった
  • テスト
    • キャッシュの入出力、スキップ挙動、更新時刻追跡を検証するテストを追加

Co-authored-by: HappyOnigiri <nodemeld+happy-onigiri@gmail.com>
@cursor
Copy link

cursor bot commented Mar 12, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22b8319c-fff6-44eb-920e-86dcedfb0228

📥 Commits

Reviewing files that changed from the base of the PR and between 4685651 and a11ffd2.

📒 Files selected for processing (1)
  • src/auto_fixer.py

📝 Walkthrough

Walkthrough

PRはPRのupdatedAtをローカルJSONでキャッシュするcache_manager.pyを追加し、auto_fixer.pyが起動時にキャッシュを読み込み、未変更のPRをスキップして処理後にキャッシュを更新・保存する流れを導入します。関連テストを追加・更新しています。

Changes

Cohort / File(s) Summary
キャッシュ管理
src/cache_manager.py
新規モジュール追加。CacheData型、DEFAULT_CACHE_PATHload_cache/save_cache/get_cached_updated_at/set_cached_updated_atを導入。JSON永続化、スキーマ検証、エラーハンドリングを実装。
自動修正ロジックの統合
src/auto_fixer.py
process_repoおよび_process_single_prのシグネチャを拡張してupdated_at_cachecacheableフラグを扱うよう変更。起動時にload_cacheを読み、PRごとにキャッシュ比較で未更新をスキップ、処理済PRはset_cached_updated_atで更新、終了時にsave_cacheを呼ぶ。メッセージ出力の追加。
キャッシュ関連テスト
tests/test_cache_manager.py
save_cache/load_cacheのラウンドトリップ、欠損ファイル・無効JSON・スキーマ不一致時の挙動検証、get/set_cached_updated_atのAPI挙動テストを追加。
テストの更新・インポート検証
tests/test_auto_fixer.py, tests/test_imports.py
process_repoupdated_at_cacheを渡すテストを追加・更新し、cache_managerがインポート可能であることを検証するテストを追加。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

refix:done

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed タイトル「ローカルキャッシュ早期スキップ」は、このPRの主要な変更内容(ローカルキャッシュを使用したPR早期スキップ機能の追加)を明確に説明しており、変更セットに完全に関連している。
Description check ✅ Passed PRの説明は概要、変更内容、テスト、関連issuesなど、テンプレートの全主要セクションをカバーしており、実装内容も詳細に記載されている。

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/-bc-cd6e9f52-7c6c-4663-a9a5-9911e814570d-763a

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

@HappyOnigiri HappyOnigiri marked this pull request as ready for review March 12, 2026 11:27
@HappyOnigiri HappyOnigiri added the refix:running Refix is currently processing review fixes. label Mar 12, 2026
Copy link
Contributor

@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 `@src/auto_fixer.py`:
- Around line 3133-3147: The current flow writes updatedAt for any PR added to
modified_prs, which allows incomplete/failed PR processing paths to mark a PR as
safe-to-skip; change _process_single_pr() to return a tuple (or object)
including a boolean cacheable flag (e.g., cacheable) alongside existing results,
then update the loop that handles modified_prs and the call site that currently
calls set_cached_updated_at() so that set_cached_updated_at(updated_at_cache,
repo, pr_number_raw, current_updated_at) is invoked only when cacheable is true
(and updated_at_cache is not None); also ensure
get_cached_updated_at(updated_at_cache, repo, pr_number_raw) and the early-skip
check using current_updated_at == cached_updated_at remain unchanged so only
truly cacheable successes are written to the cache.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 76f5e3ff-5fac-4165-99a3-1a1884566f03

📥 Commits

Reviewing files that changed from the base of the PR and between cf19a44 and 580ab07.

📒 Files selected for processing (5)
  • src/auto_fixer.py
  • src/cache_manager.py
  • tests/test_auto_fixer.py
  • tests/test_cache_manager.py
  • tests/test_imports.py

_process_single_pr now returns a cacheable flag (4th value). The caller
only calls set_cached_updated_at when cacheable=True, which is limited to
paths where processing fully completed (normal end or clean no-op). Paths
where processing was skipped or incomplete (CodeRabbit rate limit active,
review failed active, commit/claude limit reached, fetch/setup errors) all
return cacheable=False, preventing next-run early-skip on unprocessed PRs.
@HappyOnigiri
Copy link
Owner Author

HappyOnigiri commented Mar 12, 2026

🤖 Refix Status

対応済みレビュー一覧
Comment ID 処理日時
r3935847386 2026-03-12 20:55:15 JST
discussion_r2923993374 2026-03-12 20:55:15 JST
r3935996488 2026-03-12 21:10:03 JST
discussion_r2924127003 2026-03-12 21:10:04 JST
r3936118968 2026-03-12 21:26:39 JST
discussion_r2924230597 2026-03-12 21:26:39 JST

Copy link
Contributor

@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 `@src/auto_fixer.py`:
- Around line 2703-2706: The code currently sets _cacheable without considering
dry_run and also returns cacheable=True unconditionally on the review-fix path;
update both places so that when dry_run is True you never return cacheable=True.
Specifically, modify the _cacheable calculation (symbol: _cacheable) to include
a check for dry_run (e.g., _cacheable = not dry_run and not
bool(active_rate_limit) and not bool(active_review_failed)), and change the
return in the review-fix path (the unconditional return at lines around
3000–3002) to ensure it returns cacheable=False when dry_run is True.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 69b2851b-75a0-4fbe-b2ab-a7111fa7c3cc

📥 Commits

Reviewing files that changed from the base of the PR and between 580ab07 and 9940c56.

📒 Files selected for processing (1)
  • src/auto_fixer.py

Copy link
Contributor

@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

♻️ Duplicate comments (1)
src/auto_fixer.py (1)

3256-3260: ⚠️ Potential issue | 🔴 Critical

失敗・未完了の PR でも cacheable=True が返っています

Line 3257 は not dry_run しか見ていないため、subprocess.CalledProcessErrorreview_fix_failed=True になったケースや、state comment / thread resolve が完了せず state_saved=False のケースでも、Line 3455 で updatedAt が保存されます。次回同じ updatedAt のままだと未処理 PR を早期スキップしてしまいます。

🐛 修正案
-    _cacheable = not dry_run
+    _cacheable = (
+        not dry_run
+        and state_saved
+        and not review_fix_failed
+        and not bool(active_rate_limit)
+        and not bool(active_review_failed)
+    )
     if commits_by_phase:
         return False, True, (repo, pr_number, "\n".join(commits_by_phase)), _cacheable
     return False, True, None, _cacheable
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/auto_fixer.py` around lines 3256 - 3260, The code sets _cacheable = not
dry_run unconditionally which marks failed or incomplete fixes as cacheable;
change the logic so _cacheable is true only when not dry_run AND the fix
succeeded and state was persisted — i.e., compute _cacheable = (not dry_run) and
(not review_fix_failed) and (state_saved is True) and (commits_by_phase is empty
or indicates success), so update the branch that returns (False, True, ...) to
derive _cacheable from review_fix_failed and state_saved (and any
commits_by_phase success indicator) before returning to avoid saving updatedAt
for failed/incomplete PRs; adjust references to modified_prs.add, _cacheable,
commits_by_phase, review_fix_failed, state_saved and updatedAt accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/auto_fixer.py`:
- Around line 3631-3635: In the finally block around
save_cache(updated_at_cache) only persist the cache when the run is actually
allowed to change state: check the dry-run and summarize-only flags (e.g.
args.dry_run or summarize_only) and also verify updated_at_cache is non-empty
and different from the cache returned by load_cache() (capture the original
loaded cache into a variable when calling load_cache()). Replace the
unconditional save_cache call with a guard that returns early for
dry-run/summarize-only or when there is no meaningful change to avoid
overwriting a valid existing cache.

---

Duplicate comments:
In `@src/auto_fixer.py`:
- Around line 3256-3260: The code sets _cacheable = not dry_run unconditionally
which marks failed or incomplete fixes as cacheable; change the logic so
_cacheable is true only when not dry_run AND the fix succeeded and state was
persisted — i.e., compute _cacheable = (not dry_run) and (not review_fix_failed)
and (state_saved is True) and (commits_by_phase is empty or indicates success),
so update the branch that returns (False, True, ...) to derive _cacheable from
review_fix_failed and state_saved (and any commits_by_phase success indicator)
before returning to avoid saving updatedAt for failed/incomplete PRs; adjust
references to modified_prs.add, _cacheable, commits_by_phase, review_fix_failed,
state_saved and updatedAt accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fb70c923-203a-4c75-bf43-8683b38e8de4

📥 Commits

Reviewing files that changed from the base of the PR and between 9940c56 and 4685651.

📒 Files selected for processing (2)
  • src/auto_fixer.py
  • tests/test_auto_fixer.py

…acheable in review-fix path

failure/incomplete PR でも cacheable=True が返っていた問題を修正。
review_fix_failed や state_saved=False のケースで次回実行時に未処理 PR を
早期スキップしてしまうのを防ぐ。
finally ブロックの save_cache を dry_run / summarize_only 時にスキップし、
非破壊モードの実行で既存キャッシュを上書きしないようにする。
@HappyOnigiri HappyOnigiri added the refix:done Refix finished review checks/fixes for now. label Mar 12, 2026
@HappyOnigiri HappyOnigiri merged commit c26d9f3 into main Mar 12, 2026
2 checks passed
@HappyOnigiri HappyOnigiri added the refix:auto-merge-requested Refix has requested auto-merge for this PR. label Mar 12, 2026
@HappyOnigiri HappyOnigiri deleted the cursor/-bc-cd6e9f52-7c6c-4663-a9a5-9911e814570d-763a branch March 12, 2026 12:30
@HappyOnigiri HappyOnigiri added refix:merged PR has been merged after Refix auto-merge. and removed refix:running Refix is currently processing review fixes. refix:auto-merge-requested Refix has requested auto-merge for this PR. labels Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refix:done Refix finished review checks/fixes for now. refix:merged PR has been merged after Refix auto-merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants