Repository navigation
AIエージェント送信時のトークン先読みと検索中表示でストリーミング開始までの体感遅延を改善 - #6493
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017RfgmFqn92SHMdeRPUXgEP
📝 WalkthroughWalkthrough目的地検索AIに検索中ラベル、検索状態、アクセシビリティ通知を追加しました。 Changes目的地エージェントの読み込み状態
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant DestinationAgentScreen
participant AgentTypingIndicator
participant AccessibilityNotification
DestinationAgentScreen->>DestinationAgentScreen: tool 開始イベントを受信する
DestinationAgentScreen->>AgentTypingIndicator: destinationAgentSearching を渡す
AgentTypingIndicator-->>DestinationAgentScreen: 検索中ラベルを表示する
DestinationAgentScreen->>AccessibilityNotification: 検索中メッセージを1回通知する
DestinationAgentScreen->>DestinationAgentScreen: 最初の delta、完了、失敗時に状態を解除する
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017RfgmFqn92SHMdeRPUXgEP
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/hooks/useDestinationAgent.test.ts (1)
111-127: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winキャッシュ再利用を検証するテストを追加してください。
このテストは
getSessionTokenMockの呼び出しだけを確認しています。モックがキャッシュ処理を置き換えるため、先読み完了後のsendMessagesが同じトークンを再利用し、/auth/tokenを再取得しないことは検証できません。実際のキャッシュ動作、または取得中のPromiseの共有を検証するテストを追加してください。🤖 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 `@src/hooks/useDestinationAgent.test.ts` around lines 111 - 127, useDestinationAgent の先読みだけでなく、取得済みトークンのキャッシュ再利用を検証するテストを追加してください。先読み完了後に sendMessages を実行し、同じトークンが送信に使われることと、getSessionTokenMock および /auth/token(fetchMock)が追加取得されないことを確認してください。必要に応じて、取得中の Promise が共有されるケースも検証してください。
🤖 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 152-161: Update getSessionToken in src/lib/session.ts to share the
in-flight token-fetch Promise, so concurrent preload and sendMessages calls
reuse one /auth/token POST before caching the completed token. Clear the shared
Promise after resolution or rejection while preserving existing cache and error
behavior, and add a test covering concurrent calls and ensuring only one request
is made.
---
Nitpick comments:
In `@src/hooks/useDestinationAgent.test.ts`:
- Around line 111-127: useDestinationAgent
の先読みだけでなく、取得済みトークンのキャッシュ再利用を検証するテストを追加してください。先読み完了後に sendMessages
を実行し、同じトークンが送信に使われることと、getSessionTokenMock および
/auth/token(fetchMock)が追加取得されないことを確認してください。必要に応じて、取得中の Promise
が共有されるケースも検証してください。
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a662fb1-1cd1-4544-9143-3836192d74ae
📒 Files selected for processing (7)
assets/translations/en.jsonassets/translations/ja.jsondocs/spec/ai-agent/ui.mdsrc/hooks/useDestinationAgent.test.tssrc/hooks/useDestinationAgent.tssrc/screens/DestinationAgent/AgentTypingIndicator.tsxsrc/screens/DestinationAgent/index.tsx
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017RfgmFqn92SHMdeRPUXgEP
Fixes Applied SuccessfullyFixed 2 file(s) based on 1 CodeRabbit feedback item(s). Files modified:
Commit: The latest autofix changes are on the |
概要
AI エージェントのストリーミング対応(#6492)のフォローアップとして、送信からストリーミング開始(最初の
delta受信)までの体感遅延を改善しました。クライアント側で対処できる 2 点です:/auth/tokenへの往復が送信の直列経路に入っていたため、チャット画面マウント時に先読みしてキャッシュに載せ、送信時の待ちを解消toolイベントを受けてタイピングインジケータに「駅を検索しています…」を添えて進捗が見えるように変更BFF 側の直列レイテンシ削減(前段処理の並列化・レート制限カウンタ書き込みのクリティカルパス除去・OpenAI 系モデルの reasoning 抑制、毎ターン約 150〜450ms + reasoning 分の削減見込み)は TrainLCD/BFF リポジトリ側で実装済みで、別途 PR を作成します。本 PR には対応する設計書の追随を含みます。
変更の種類
変更内容
src/hooks/useDestinationAgent.ts: マウント時にgetSessionToken()を先読みするuseEffectを追加(キャッシュ付き・冪等のため StrictMode 再実行にも安全)src/lib/session.ts: 取得中(in-flight)の Promise を共有し、先読みと初回送信が競合しても/auth/tokenへの POST が 1 回になるよう変更(CodeRabbit 指摘対応)src/screens/DestinationAgent/index.tsx:searchingstate を追加し、onToolStart(世代ガード通過時のみ)で検索中表示を点灯、最初のdeltaまたは応答確定で消灯。読み上げは 1 送信 1 回src/screens/DestinationAgent/AgentTypingIndicator.tsx: optional なlabelprop を追加し、ドットの右に補助文言を表示(LED テーマ対応)assets/translations/ja.json/en.json:destinationAgentSearchingキーを追加docs/spec/ai-agent/ui.md: 検索中表示の仕様を追記docs/spec/ai-agent/architecture.md: BFF 側レイテンシ改善(前段処理の並列化・レート制限カウンタのチェック / 消費分離)を設計書に反映src/hooks/useDestinationAgent.test.ts: トークン先読みのテスト 2 件を追加(計 24 件)src/lib/session.test.ts(新規): 並行呼び出しの POST 共有・失敗後の再取得のテスト 3 件テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ることnpm testは全体で 199 suites / 2143 tests パス。dev への rebase 後にもnpm run typecheckと対象テストの通過を確認済みです。設計書はmarkdownlint-cli20 件。関連Issue
スクリーンショット(任意)