Repository navigation
iOSでAIエージェントのSSEが受信できない問題をXHR受信と非ストリーミングフォールバックで修正 - #6494
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012QJeVgNmJy26SCZvRntBbT
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012QJeVgNmJy26SCZvRntBbT
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthrough
ChangesAIエージェント通信
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant sendMessages
participant PlatformTransport
participant SSEParser
participant JSONFallback
sendMessages->>PlatformTransport: 共通リクエストボディでストリーミング送信
PlatformTransport->>SSEParser: SSEチャンクを逐次転送
SSEParser-->>sendMessages: 成功または分類済みエラー
alt networkエラー
sendMessages->>JSONFallback: 同じ本文でJSON POSTを1回実行
JSONFallback-->>sendMessages: 確定応答またはnetworkエラー
end
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/hooks/useDestinationAgent.test.ts (1)
830-839: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueフォールバック側の挙動も明示してください。
このテストは
getSessionTokenMockに 2 回だけnullを設定します。3 回目の呼び出しは既定のモックへ戻ります。そのためsendViaJsonはトークンを取得し、既定の失敗するglobalThis.fetchを呼びます。結果のnetworkはフォールバック失敗によるものであり、トークン取得失敗によるものではありません。
fallbackFetchMockの呼び出し回数を検証すると、テストの意図が明確になります。♻️ 提案する追加アサーション
expect(res).toEqual({ ok: false, error: 'network' }); expect(FakeXhr.instances).toHaveLength(0); + // ストリーミングが network で終わるためフォールバックは 1 回走る + expect(fallbackFetchMock).toHaveBeenCalledTimes(1);🤖 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 830 - 839, Update the test around renderSendMessages to explicitly assert the fallback fetch behavior by verifying fallbackFetchMock’s invocation count after the response. Keep the existing null token setup and network result assertions, while making clear that the third token attempt reaches sendViaJson and triggers the fallback fetch.
🤖 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 `@docs/spec/ai-agent/architecture.md`:
- Around line 684-685: フォールバック時の表示説明を、送信時のプレースホルダに限定しない内容へ更新してください。`delta` 後に
`done` なしで `network`
へ遷移する場合は既存の部分テキストが表示されたままフォールバックし、最終的に確定値へ置き換わる実装を、`onDelta` / `onToolStart`
の呼び出し制約と併せて記述してください。
In `@src/hooks/useDestinationAgent.test.ts`:
- Around line 812-828: Move fake-timer cleanup for the tests around sendMessages
into an afterEach hook, ensuring jest.useRealTimers() runs even when an
assertion fails. Remove the inline restoration from the timeout test while
preserving its existing timeout, abort, and fallback assertions.
---
Nitpick comments:
In `@src/hooks/useDestinationAgent.test.ts`:
- Around line 830-839: Update the test around renderSendMessages to explicitly
assert the fallback fetch behavior by verifying fallbackFetchMock’s invocation
count after the response. Keep the existing null token setup and network result
assertions, while making clear that the third token attempt reaches sendViaJson
and triggers the fallback fetch.
🪄 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: af2f60f5-0d07-423c-b670-a4afdea52463
📒 Files selected for processing (4)
docs/spec/ai-agent/architecture.mdpatches/expo+55.0.26.patchsrc/hooks/useDestinationAgent.test.tssrc/hooks/useDestinationAgent.ts
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012QJeVgNmJy26SCZvRntBbT
Fixes Applied SuccessfullyFixed 3 file(s) based on 2 CodeRabbit feedback item(s). Files modified:
Commit: The latest autofix changes are on the |
概要
EAS ビルドの iOS 実機で AI エージェントチャットが毎回「リクエストを正常に処理できませんでした」エラーになる問題の修正。原因は
expo/fetchの iOS ネイティブ実装の既知不具合(expo/expo#42161 のチャンク欠落・順序逆転の競合)で、SSE のdoneイベントが JS に届かないままストリームが閉じるため。サーバ側(/agent/chat/stream)は正常に完走していることをwrangler tailで確認済み。変更の種類
変更内容
expo/fetchからXMLHttpRequestの逐次テキスト受信(sendViaXhrStream)に切替。send()前にonreadystatechange/onprogressを登録して RN の逐次配送を有効化し、responseTextの未処理分を既存のparseSSEChunkで解釈する。Android / web は従来どおりexpo/fetchnetwork系の失敗に終わった場合のみ非ストリーミングのPOST /agent/chat(標準 fetch + JSON)へ 1 回フォールバックするsendViaJsonを追加(rateLimited/timeoutはフォールバックしない)patches/expo+55.0.26.patchを追加(patch-package)。expo/fetchのFetchResponseがreader.cancel()後のdidComplete/didFailWithErrorで二重クローズしTypeError: The stream is not in a state that permits closeを投げる競合([expo] fix expo/fetch fatal close race after stream cancel expo/expo#44909。Android 実機リリースビルドの logcat で観測)へのガードdocs/spec/ai-agent/architecture.md)に iOS の XHR 経路・フォールバック方針・expo パッチを反映useDestinationAgentのテストを拡張(XHR フェイクでの逐次配送・チャンク境界跨ぎ・429・フォールバック成否・タイムアウト等、計 37 件)公開 API(
sendMessages/AgentStreamHandlers/AgentErrorKind)は不変で、画面側は無改修。テスト
Android 実機(
assembleDevReleaseのリリースビルド)でストリーミングの逐次表示を回帰確認済み。iOS は TestFlight(EAS ビルド)で検証予定。npm run lintが通ることnpm testが通ることnpm run typecheckが通ること関連Issue
スクリーンショット(任意)
Summary by CodeRabbit
改善
バグ修正