Conversation
- 既存のAI解答機能(ai_answer)を完全に削除 - AiAnswerCreator, AiAnswerCreateJob, Ai::AnswerGenerator を削除 - ai_answer カラム削除マイグレーション追加 - show.html.slim, API jbuilder からai_answer表示を削除 - Q&A質問作成時にピヨルドが自動回答する機能を追加 - PjordQuestionAnswerer: question.create の通知でジョブをenqueue - PjordQuestionAnswerJob: Pjord.respondで回答生成しAnswerとして投稿 - メンション不要で自動的に回答 - 既存のメンション応答機能(PjordRespondJob)は変更なし
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughOpenAIベースの生成(Ai::AnswerGenerator、AiAnswerCreateJob、関連ビュー/テスト/VCR)を削除し、PJORDベースの自動応答(PjordQuestionAnswerJob、PjordQuestionAnswerer)へ移行。questionsテーブルから Changes
シーケンス図sequenceDiagram
participant User as 質問作成者
participant Notifier as ActiveSupport\n通知
participant Answerer as PjordQuestionAnswerer
participant Job as PjordQuestionAnswerJob
participant Pjord as Pjord(LLMクライアント)
participant DB as DB / Answer
User->>Notifier: question.create イベント発行
Notifier->>Answerer: call(event,..., question: question)
Answerer->>Job: PjordQuestionAnswerJob.perform_later(question_id: id)
Job->>Job: Question.find(id)
Job->>Pjord: Pjord.user / Pjord.respond(message, context)
Pjord-->>Job: 回答テキスト
Job->>DB: Answer.create!(user: pjord, question: question, description: response)
DB-->>Job: 作成完了
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
ウサギの詩
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🚀 Review AppURL: https://bootcamp-pr-9863-fvlfu45apq-an.a.run.app
|
- RuboCop: unused argument message → _message に修正 - テスト: retry_on を削除(inline adapter で enqueue_at が NotImplementedError) - テスト: Ai::AnswerGenerator テスト・VCRカセットの削除漏れ修正 - テスト: PjordQuestionAnswererTest を ActiveJob::TestCase に変更 - mock_helper: OpenAI レスポンスに RubyLLM 互換フィールド追加
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/jobs/pjord_question_answer_job_test.rb (1)
46-46: API エラー時のテストケース追加を検討してください。
Pjord.respondが API エラー時に例外を発生させる場合のテストがあると、リトライ動作の検証に役立ちます。📝 テストケースの例
test 'raises exception when Pjord.respond fails' do question = questions(:question1) Pjord.stub(:respond, ->(*) { raise StandardError, 'API error' }) do assert_raises(StandardError) do PjordQuestionAnswerJob.perform_now(question_id: question.id) end end end🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/jobs/pjord_question_answer_job_test.rb` at line 46, Add a test that simulates an API error from Pjord.respond and asserts the job raises so retry behavior can be validated: stub Pjord.respond to raise (e.g. StandardError 'API error') and call PjordQuestionAnswerJob.perform_now with a fixture question (e.g. questions(:question1)), then use assert_raises to confirm the exception is propagated; reference Pjord.respond and PjordQuestionAnswerJob.perform_now to locate where to add this test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/jobs/pjord_question_answer_job.rb`:
- Around line 3-5: The job PjordQuestionAnswerJob is missing the described
3-attempt retry behavior; add a retry_on for StandardError with attempts: 3 (and
optionally a wait/backoff) to ensure Pjord.respond failures are retried three
times; keep the existing discard_on ActiveJob::DeserializationError intact and
place the retry_on declaration inside the PjordQuestionAnswerJob class so
retries apply to perform invocations that call Pjord.respond.
- Around line 24-28: In build_context replace the conditional assignment that
uses respond_to?(:where_mention) with a direct call to question.where_mention;
remove the respond_to? check and set context[:location] = question.where_mention
(the Question model includes the Mentioner concern so where_mention is always
available).
---
Nitpick comments:
In `@test/jobs/pjord_question_answer_job_test.rb`:
- Line 46: Add a test that simulates an API error from Pjord.respond and asserts
the job raises so retry behavior can be validated: stub Pjord.respond to raise
(e.g. StandardError 'API error') and call PjordQuestionAnswerJob.perform_now
with a fixture question (e.g. questions(:question1)), then use assert_raises to
confirm the exception is propagated; reference Pjord.respond and
PjordQuestionAnswerJob.perform_now to locate where to add this test.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c978cf33-ba73-4c57-9ff9-e29ec88b7bee
📒 Files selected for processing (17)
app/jobs/ai_answer_create_job.rbapp/jobs/pjord_question_answer_job.rbapp/models/ai/answer_generator.rbapp/models/pjord_question_answerer.rbapp/views/api/questions/show.json.jbuilderapp/views/questions/_ai_answer.html.slimapp/views/questions/show.html.slimconfig/initializers/active_support_notifications.rbdb/fixtures/questions.ymldb/migrate/20260330072542_remove_ai_answer_from_questions.rbtest/cassettes/ai/answer_generator.ymltest/cassettes/question/ai_answer_create_job.ymltest/jobs/ai_answer_create_job_test.rbtest/jobs/pjord_question_answer_job_test.rbtest/models/ai/answer_generator_test.rbtest/models/pjord_question_answerer_test.rbtest/supports/mock_helper.rb
💤 Files with no reviewable changes (9)
- app/views/questions/_ai_answer.html.slim
- app/views/questions/show.html.slim
- test/cassettes/question/ai_answer_create_job.yml
- test/cassettes/ai/answer_generator.yml
- test/jobs/ai_answer_create_job_test.rb
- test/models/ai/answer_generator_test.rb
- app/jobs/ai_answer_create_job.rb
- app/models/ai/answer_generator.rb
- db/fixtures/questions.yml
- PjordQuestionAnswerJob: Pjord.respond の例外を rescue して return - CIではAPIキーが未設定のため RubyLLM::ConfigurationError が発生 - WebMockスタブはRubyLLMのAPIキー検証より後のため効かない - テスト: lambda の keyword argument 名を message: に戻す - _message: だと呼び出し側の message: とマッチしない
There was a problem hiding this comment.
♻️ Duplicate comments (1)
app/jobs/pjord_question_answer_job.rb (1)
5-5:⚠️ Potential issue | 🟠 Majorリトライ要件が未達で、例外握りつぶしにより再実行も発生しません。
Line 5 に
retry_onがなく、Line 19-21 でStandardErrorをreturnしているため、PR記載の「最大3回リトライ」が機能しません。Pjord.respond失敗時はジョブ失敗として再試行させてください。修正案
class PjordQuestionAnswerJob < ApplicationJob queue_as :default discard_on ActiveJob::DeserializationError + retry_on StandardError, wait: :polynomially_longer, attempts: 3 def perform(question_id:) @@ - begin - response = Pjord.respond(message: message, context: context) - rescue StandardError => e - Rails.logger.error("[PjordQuestionAnswerJob] #{e.class}: #{e.message}") - return - end + response = Pjord.respond(message: message, context: context)#!/bin/bash # retry設定と例外握りつぶしの有無を確認(read-only) rg -n 'retry_on|discard_on|rescue StandardError|Pjord.respond' app/jobs/pjord_question_answer_job.rb nl -ba app/jobs/pjord_question_answer_job.rb | sed -n '1,80p'Also applies to: 17-22
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/jobs/pjord_question_answer_job.rb` at line 5, 現在のジョブ(app/jobs/pjord_question_answer_job.rb)は discard_on ActiveJob::DeserializationError がある一方で retry_on が定義されておらず、また Pjord.respond 呼び出し失敗時に rescue 節で StandardError を return しているため「最大3回リトライ」が機能していません。fix: ジョブクラスに retry_on StandardError, attempts: 3(または指定された回数)を追加して再試行を有効化し、Pjord.respond を呼ぶ箇所(および該当する rescue 節)では例外を握りつぶさず raise するか、失敗時に raise するように変更してジョブを失敗させ再試行させてください;既存の discard_on ActiveJob::DeserializationError はそのまま残します。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@app/jobs/pjord_question_answer_job.rb`:
- Line 5: 現在のジョブ(app/jobs/pjord_question_answer_job.rb)は discard_on
ActiveJob::DeserializationError がある一方で retry_on が定義されておらず、また Pjord.respond
呼び出し失敗時に rescue 節で StandardError を return しているため「最大3回リトライ」が機能していません。fix: ジョブクラスに
retry_on StandardError, attempts: 3(または指定された回数)を追加して再試行を有効化し、Pjord.respond
を呼ぶ箇所(および該当する rescue 節)では例外を握りつぶさず raise するか、失敗時に raise
するように変更してジョブを失敗させ再試行させてください;既存の discard_on ActiveJob::DeserializationError
はそのまま残します。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 56349a6c-95c1-48ce-98e4-4852c29b4ba6
📒 Files selected for processing (2)
app/jobs/pjord_question_answer_job.rbtest/jobs/pjord_question_answer_job_test.rb
✅ Files skipped from review due to trivial changes (1)
- test/jobs/pjord_question_answer_job_test.rb
- build_context: respond_to?(:where_mention) チェックを削除(Question は常に Mentioner を include)
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/jobs/pjord_question_answer_job.rb (1)
7-27: 実装は適切です。ガードクローズによる早期リターン、エラーハンドリング、回答作成の流れが明確に構成されています。
Pjord.respondの例外をrescue StandardErrorで処理し、静かに終了する設計は意図的なものと理解しています。(任意)エラーログに question_id を追加すると、デバッグ時に追跡しやすくなります。
♻️ 提案(任意)
rescue StandardError => e - Rails.logger.error("[PjordQuestionAnswerJob] #{e.class}: #{e.message}") + Rails.logger.error("[PjordQuestionAnswerJob] question_id=#{question_id} #{e.class}: #{e.message}") return end🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/jobs/pjord_question_answer_job.rb` around lines 7 - 27, The error log in the rescue block should include the question identifier to aid debugging; update the rescue in perform to include question_id (and optionally question.title) in the Rails.logger.error message when rescuing Pjord.respond errors (referencing perform, Pjord.respond, and Rails.logger.error), so logs read something like "[PjordQuestionAnswerJob] question_id=... #{e.class}: #{e.message}" while leaving the existing early returns and Answer.create! behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/jobs/pjord_question_answer_job.rb`:
- Around line 7-27: The error log in the rescue block should include the
question identifier to aid debugging; update the rescue in perform to include
question_id (and optionally question.title) in the Rails.logger.error message
when rescuing Pjord.respond errors (referencing perform, Pjord.respond, and
Rails.logger.error), so logs read something like "[PjordQuestionAnswerJob]
question_id=... #{e.class}: #{e.message}" while leaving the existing early
returns and Answer.create! behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 24057a28-e38d-4ae4-85eb-bdfa47425073
📒 Files selected for processing (1)
app/jobs/pjord_question_answer_job.rb
- RubyLLMの設定をANTHROPIC_API_KEYを使用するように変更 - デフォルトモデルをclaude-sonnet-4-6に変更
AIがQ&Aの構造を理解しやすいように、タイトルと質問内容を 明確に区別したフォーマットに変更
概要
Q&Aに質問が投稿されたら、AIピヨルド(
@pjord)が自動的に回答(Answer)を投稿するようにしました。同時に、既存のAI解答機能(
ai_answerカラム)を削除しました。変更内容
削除: 既存のAI解答機能
AiAnswerCreator,AiAnswerCreateJob,Ai::AnswerGeneratorを削除questions.ai_answerカラム削除(マイグレーション追加)_ai_answer.html.slim)、API(jbuilder)から表示を削除追加: ピヨルド自動回答
PjordQuestionAnswerer:question.create通知のサブスクライバPjordQuestionAnswerJob:Pjord.respondで回答生成 →Answerとして投稿title+descriptionを送信practice情報をコンテキストに含むPjordRespondJob)は変更なしテスト
PjordQuestionAnswerJobTest: 回答作成、質問なし、pjordなし、応答blank、context確認PjordQuestionAnswererTest: ジョブenqueue確認Summary by CodeRabbit
新機能
削除
変更
テスト
その他