Repository navigation
AIチャットの提案から同一駅の重複を除外 - #6671
Merged
Merged
AIチャットの提案から同一駅の重複を除外#6671
Conversation
熱海駅のように 1 つの物理駅が路線ごとに別 stationId を持つケースで、 同じ駅のカードが並んで表示されていた。受信時に stationGroupId で、 再取得後に API 由来の groupId で重複を落とすようにした。 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gi8MssW9aV6doQAq3H8nxR
Contributor
📝 WalkthroughWalkthroughAIエージェントの駅候補を Changes駅候補の重複除去
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ChatResponse
participant useDestinationAgent
participant StationAPI
participant DestinationAgentState
ChatResponse->>useDestinationAgent: suggestions
useDestinationAgent->>useDestinationAgent: stationGroupIdで重複除去
useDestinationAgent->>StationAPI: 候補駅情報を再取得
StationAPI->>useDestinationAgent: Station[]
useDestinationAgent->>useDestinationAgent: groupIdで重複除去
useDestinationAgent->>DestinationAgentState: 順序を維持した駅一覧
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/hooks/useDestinationAgent.ts`:
- Around line 128-131: 取得前の候補処理で未検証の stationGroupId
によるグループ単位の除外を行わないよう、useDestinationAgent の dedupeAgentSuggestions
処理を更新し、グループ重複排除を API 取得後へ遅延するか、サーバー由来の検証済み契約に限定してください。architecture.md
の該当仕様も、stationGroupId を信頼済み契約として検証する方針または取得後に除外する方針へ更新し、異なる stationId に同じ不正な
stationGroupId が返っても候補を失わない Worker 契約テストを追加してください。
🪄 Autofix
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: 95ab3e58-9944-46d3-a74f-a363a6bd1381
📒 Files selected for processing (6)
docs/spec/ai-agent/architecture.mdsrc/hooks/useDestinationAgent.test.tssrc/hooks/useDestinationAgent.tssrc/screens/DestinationAgent/index.tsxsrc/utils/station.test.tssrc/utils/station.ts
提案の stationGroupId はサーバの実在性検証(stationId 突合)の対象外で untrusted なため、取得前にグループ単位で間引くと、誤った stationGroupId が 別々の駅に付いていた場合に GET_STATIONS_BY_IDS へ渡らず復元できなくなる。 受信時は同じ stationId の完全重複のみを落とし、同一物理駅の間引きは 再取得後の API 由来 groupId に一本化した。 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gi8MssW9aV6doQAq3H8nxR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
AIチャット(AIに行き先を相談)の提案カードで、同じ駅が繰り返し表示される問題を修正する。熱海のように 1 つの物理駅が路線ごとに別
stationIdを持つ駅では、サーバーのsuggestionsに同一駅が複数件(東海道線 / 東海道本線 / 伊東線)含まれ、そのまま 3 枚のカードとして並んでいた。変更の種類
変更内容
src/utils/station.ts:groupIdが同じStationを最初の 1 件だけ残すdedupeStationsByGroupIdを追加。DestinationAgentScreenのresolveSuggestions:GET_STATIONS_BY_IDSで駅を再取得した後にdedupeStationsByGroupIdを適用し、同一物理駅のカードが並ばないようにした。useDestinationAgent:dedupeAgentSuggestionsを追加し、同じstationIdを指す完全重複の提案だけを受信時に落とす(再取得 ID とスケルトンの React key の重複防止)。groupIdに一本化している。提案のstationGroupIdはサーバー側の実在性検証(ツール結果とのstationId突合)の対象外=untrusted で、誤った値が別々の駅に付いていると取得前に落とした駅をGET_STATIONS_BY_IDSに渡せず復元できなくなるため(CodeRabbit の指摘を受けて修正)。groupIdを持たない駅は同一判定できないためそのまま残す。docs/spec/ai-agent/architecture.md: 上記の方針を追記。useDestinationAgent.test.ts(同一stationIdの重複は 1 件に、stationGroupIdが同じでもstationIdが違う提案は落とさない)、station.test.ts(dedupeStationsByGroupIdの順序保持・groupIdなしの扱いなど 4 ケース)。会話ターンをまたいだ再提案(前のターンで出た駅が次の回答にも出る)は対象外。「その駅について詳しく」といった追問でカードが 0 件になる副作用があるため、必要ならサーバー側(BFF)のプロンプト・検証で扱うのが妥当と判断した。
リグレッションリスクと緩和
useDestinationSelection→SelectBoundModal)には変更なし。groupIdが無い駅を落とさないこと、untrusted なstationGroupIdで候補を失わないことをユニットテストで担保している。dedupeStationsByGroupIdは新規追加のため既存呼び出し元への影響なし。テスト
npm run lint/npm test/npm run typecheckをローカルで実行し、いずれも成功(218 suites / 2310 tests パス)。npm run lintが通ることnpm testが通ることnpm run typecheckが通ること関連Issue
スクリーンショット(任意)