Skip to content

AIチャットの提案から同一駅の重複を除外 - #6671

Merged
TinyKitten merged 2 commits into
devfrom
claude/ai-chat-station-dedup-bdxaot
Aug 12, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/ai-chat-station-dedup-bdxaot

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

概要

AIチャット(AIに行き先を相談)の提案カードで、同じ駅が繰り返し表示される問題を修正する。熱海のように 1 つの物理駅が路線ごとに別 stationId を持つ駅では、サーバーの suggestions に同一駅が複数件(東海道線 / 東海道本線 / 伊東線)含まれ、そのまま 3 枚のカードとして並んでいた。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • src/utils/station.ts: groupId が同じ Station を最初の 1 件だけ残す dedupeStationsByGroupId を追加。
  • DestinationAgentScreen の resolveSuggestions: GET_STATIONS_BY_IDS で駅を再取得した後に dedupeStationsByGroupId を適用し、同一物理駅のカードが並ばないようにした。
  • useDestinationAgent: dedupeAgentSuggestions を追加し、同じ stationId を指す完全重複の提案だけを受信時に落とす(再取得 ID とスケルトンの React key の重複防止)。
  • グループ単位の間引きは再取得後の API 由来 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)のプロンプト・検証で扱うのが妥当と判断した。

リグレッションリスクと緩和

  • 影響範囲は AI チャット画面の提案カード表示のみ。提案タップ後のフロー(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

スクリーンショット(任意)

熱海駅のように 1 つの物理駅が路線ごとに別 stationId を持つケースで、
同じ駅のカードが並んで表示されていた。受信時に stationGroupId で、
再取得後に API 由来の groupId で重複を落とすようにした。

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gi8MssW9aV6doQAq3H8nxR
@github-actions github-actions Bot added the react label Aug 12, 2026
@TinyKitten TinyKitten self-assigned this Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

AIエージェントの駅候補をstationGroupIdで受信時に重複除去する。駅情報の再取得後はgroupIdでも重複除去する。各段階で最初の候補と提示順を維持する。仕様とテストを更新する。

Changes

駅候補の重複除去

Layer / File(s) Summary
チャット候補の重複除去
src/hooks/useDestinationAgent.ts, src/hooks/useDestinationAgent.test.ts, docs/spec/ai-agent/architecture.md
stationGroupId単位のdedupeAgentSuggestionsを追加した。形式検証後の候補に適用し、最初の候補と提示順を維持するテストと仕様を追加した。
駅情報取得後の重複除去
src/utils/station.ts, src/utils/station.test.ts, src/screens/DestinationAgent/index.tsx, docs/spec/ai-agent/architecture.md
groupId単位のdedupeStationsByGroupIdを追加した。駅情報取得後に適用し、重複除去後の駅一覧をloaded状態へ格納する。

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: 順序を維持した駅一覧
Loading

Possibly related PRs

Poem

うさぎが候補をひとつずつ数え
同じ駅なら先頭を残す
順番はそのまま跳ねてゆき
受信後も再取得後も整列
駅グループはすっきり、ぴょん!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed タイトルは、AIチャットの提案から同一駅の重複を除外する主要変更を明確に示しています。
Description check ✅ Passed 概要、変更内容、テスト結果、関連Issue、任意項目を含み、変更目的と検証内容を十分に説明しています。
✨ 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 claude/ai-chat-station-dedup-bdxaot

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1438fc9 and d2b56d9.

📒 Files selected for processing (6)
  • docs/spec/ai-agent/architecture.md
  • src/hooks/useDestinationAgent.test.ts
  • src/hooks/useDestinationAgent.ts
  • src/screens/DestinationAgent/index.tsx
  • src/utils/station.test.ts
  • src/utils/station.ts

Comment thread src/hooks/useDestinationAgent.ts Resolved
提案の 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
@TinyKitten
TinyKitten merged commit 4e81116 into dev Aug 12, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/ai-chat-station-dedup-bdxaot branch August 12, 2026 11:42
This was referenced Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants