Skip to content

fix(ci): claude-review を OAuth 優先にし失効 API キーによる無言失敗を解消する - #1064

Merged
keito4 merged 1 commit into
mainfrom
fix/1063-claude-review-oauth-first
Aug 4, 2026
Merged

fix(ci): claude-review を OAuth 優先にし失効 API キーによる無言失敗を解消する#1064
keito4 merged 1 commit into
mainfrom
fix/1063-claude-review-oauth-first

Conversation

@keito4

@keito4 keito4 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Closes #1063

Why

claude-review ジョブがエラー本文なしで失敗し続けていた。

{ "type": "result", "subtype": "success", "is_error": true,
  "duration_ms": 182233, "num_turns": 1, "total_cost_usd": 0 }

調査の結果、これは #1061 で新たに発生した問題ではなく、2026-07-29 以降ずっと続いていた無言失敗だった。旧 action SHA (a92e7c70) が is_error:true をジョブ失敗として扱わなかったため success に見えていただけで、実際にはレビューが一度も実行されていない。

Run 日時 action SHA job conclusion
30806948161 08-03 10:47 be7b93b1 failure
30806071504 08-03 10:33 be7b93b1 failure
30794594290 08-03 07:41 be7b93b1 failure
30738576626 08-02 07:50 a92e7c70 success(偽グリーン)
30509563507 07-30 02:51 a92e7c70 success(偽グリーン)
30445646478 07-29 10:57 a92e7c70 success(偽グリーン)

原因

同日・同一シークレットで claude.yml は成功している。差分は資格情報の渡し方だけだった。

claude-code-review.yml claude.yml
anthropic_api_key の受け渡し あり なし
action ステップの ANTHROPIC_API_KEY セット済み
解決モデル claude-opus-5[1m] claude-sonnet-5
結果 is_error:true / 1 turn / $0 is_error:false / 22 turns / $0.89

Claude CLI は ANTHROPIC_API_KEYCLAUDE_CODE_OAUTH_TOKEN より優先する(ADR 0013 に既出)。レビューワークフローだけが失効済み API キーを無条件に action へ渡していたため、初回 API 呼び出しが 401 になり、約 180 秒リトライしたのちエラー本文なしで終了していた。PR #1061 が scheduled-maintenance で特定した「無効キーで 3 分走ってから落ちる」現象と同一。

What

変更 内容
.github/workflows/claude-code-review.yml CLAUDE_CODE_OAUTH_TOKEN が空のときだけ anthropic_api_key を渡す
test/claude-workflow-contract.test.js OAuth 優先の受け渡しを検証する契約テストを追加
docs/adr/0013-...md 資格情報優先順位が Claude Actions 全体に適用されることと、違反時の失敗シグネチャを明記

Check Claude authentication ガードは変更していないため、OAuth 未設定・API キーのみの下流リポジトリは従来どおり API キーで動作する。

How to test

  • Unit (Jest): 902 tests, 0 failures
  • Integration (BATS): 310 tests, 0 failures
  • actionlint .github/workflows/claude-code-review.yml: pass
  • 新規テストの Red → Green を確認済み(修正前は toContain が失敗)

Risk

  • 挙動変更は「OAuth があるとき API キーを渡さない」の一点のみ。OAuth のみ・API キーのみいずれの構成も引き続き動作する。
  • 失効していた ANTHROPIC_API_KEY シークレットは 08-03 12:00〜08-04 03:02 の間に既に削除済みで、現在のリポジトリシークレットは CLAUDE_CODE_OAUTH_TOKEN / CLAUDE_PAT のみ。本 PR はワークフロー側で再発を防ぐもの。
  • claude-review ジョブは continue-on-error: true のままなので、レビュー失敗がマージをブロックすることはない(偽グリーンの主因は旧 action の挙動であり、こちらは意図的な設定として維持)。
  • このワークフロー自身を変更する PR は review_gate_changed ガードでレビューがスキップされるため、修正の実効性は次回以降の PR で確認する。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved authentication handling for automated code reviews by prioritizing OAuth credentials and using API keys only when OAuth is unavailable.
    • Prevented authentication conflicts that could cause review workflows to fail.
  • Documentation

    • Documented credential precedence and related authentication failure scenarios.
  • Tests

    • Added coverage validating OAuth priority, API-key fallback, and existing federation settings.

Claude CLI は ANTHROPIC_API_KEY を CLAUDE_CODE_OAUTH_TOKEN より優先する。
claude-code-review.yml は両方を無条件に claude-code-action へ渡していたため、
失効した API キーが有効な OAuth トークンを握り潰し、初回 API 呼び出しの 401 を
約 180 秒リトライしたのちエラー本文なしで is_error:true / num_turns:1 /
total_cost_usd:0 で終了していた。

旧 action SHA は is_error:true をジョブ失敗として扱わなかったため、
2026-07-29 以降レビューが一度も実行されないまま success に見えていた。

OAuth トークンがある間は API キーを渡さないようにし、契約テストと ADR 0013 に
Claude Actions 全体の資格情報優先順位を明記する。

Closes #1063

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Claude Code Review workflow now prioritizes CLAUDE_CODE_OAUTH_TOKEN over ANTHROPIC_API_KEY. The ADR documents this rule, and the contract test verifies OAuth use, API-key fallback, and rejection of unconditional API-key forwarding.

Changes

Claude authentication precedence

Layer / File(s) Summary
Credential precedence implementation and validation
.github/workflows/claude-code-review.yml, docs/adr/0013-takt-repo-maintenance-orchestration.md, test/claude-workflow-contract.test.js
The workflow forwards ANTHROPIC_API_KEY only when no OAuth token is configured. The ADR documents credential precedence and the API-key shadowing failure mode. The contract test verifies OAuth precedence and API-key fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • keito4/config#1061: Both changes address Claude workflow credential precedence and OAuth/API-key authentication behavior.
  • keito4/config#870: This change extends the Claude workflow credential-precedence rules documented by that PR.
  • keito4/config#833: Both changes update the Claude Code Review workflow and its contract tests.

Suggested labels: size/S

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that claude-review now prioritizes OAuth and prevents failures caused by an expired API key.
Description check ✅ Passed The description explains the cause, changes, testing, risks, and related issue, but it omits the template's explicit Summary and Checklist sections.
Linked Issues check ✅ Passed The workflow change, OAuth-first contract test, and ADR update satisfy all coding objectives in issue #1063 while preserving API-key fallback support.
Out of Scope Changes check ✅ Passed All changes directly support issue #1063: credential precedence, regression coverage, and related ADR documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1063-claude-review-oauth-first

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/claude-workflow-contract.test.js

Oops! Something went wrong! :(

ESLint: 10.8.0

ReferenceError: describe is not defined
at Object. (/test/eslint-config.test.js:35:1)
at Module._compile (node:internal/modules/cjs/loader:1830:14)
at Object..js (node:internal/modules/cjs/loader:1961:10)
at Module.load (node:internal/modules/cjs/loader:1553:32)
at Module._load (node:internal/modules/cjs/loader:1355:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at loadCJSModuleWithModuleLoad (node:internal/modules/esm/translators:326:3)
at ModuleWrap. (node:internal/modules/esm/translators:231:7)
at ModuleJob.run (node:internal/modules/esm/module_job:437:25)
at async node:internal/modules/esm/loader:639:26


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.

@keito4 keito4 self-assigned this Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/claude-workflow-contract.test.js (1)

126-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that the OAuth input remains configured.

This test checks the conditional anthropic_api_key expression, but it does not check claude_code_oauth_token. A future edit could remove the OAuth input while this test still passes. Add an assertion for both credential inputs.

Proposed test addition
     const workflow = readWorkflow('.github/workflows/claude-code-review.yml');

+    expect(workflow).toContain(
+      "claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}",
+    );
     expect(workflow).toContain(
       "anthropic_api_key: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN == '' && secrets.ANTHROPIC_API_KEY || '' }}",
     );

The PR objective requires contract coverage for OAuth-first handling.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/claude-workflow-contract.test.js` around lines 126 - 133, Add a second
assertion to the test that verifies the OAuth token input itself is configured
in the workflow (checking for claude_code_oauth_token input definition), in
addition to the existing assertions that verify the anthropic_api_key
expression. This ensures both credential inputs are validated, preventing future
edits from removing the OAuth input while the test still passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/claude-workflow-contract.test.js`:
- Around line 126-133: Add a second assertion to the test that verifies the
OAuth token input itself is configured in the workflow (checking for
claude_code_oauth_token input definition), in addition to the existing
assertions that verify the anthropic_api_key expression. This ensures both
credential inputs are validated, preventing future edits from removing the OAuth
input while the test still passes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a1320e1-8568-4187-b937-83c264bc61eb

📥 Commits

Reviewing files that changed from the base of the PR and between 8e46fd7 and f2f8d7f.

📒 Files selected for processing (3)
  • .github/workflows/claude-code-review.yml
  • docs/adr/0013-takt-repo-maintenance-orchestration.md
  • test/claude-workflow-contract.test.js

@keito4
keito4 merged commit e6929df into main Aug 4, 2026
20 checks passed
@keito4
keito4 deleted the fix/1063-claude-review-oauth-first branch August 4, 2026 09:06
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.132.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-review が失効 ANTHROPIC_API_KEY を OAuth より優先し無言失敗する

1 participant