Repository navigation
地下鉄・GPS精度劣化区間でETAを用いて接近/到着判定を補完・継続する機能を追加 - #6366
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
…orを追加 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
…を組み込み Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughETA到着時刻クエリを分離し、GPS劣化時のETAフェーズ推定とフォールバック状態を追加しました。あわせて、既存の到着判定、画面起動、副作用表示にETA関連の処理と診断表示を組み込みました。 ChangesETAフォールバック機能
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related PRs
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: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/hooks/useEstimateArrivalTimes.ts (1)
36-60: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winbaseMinutesが見つからない場合、他の停車駅のETAが絶対値のまま表示される。
currentStationがallStops内に見つからずbaseMinutesが0にフォールバックした場合、現在駅自身のエントリは明示的に除外されますが(L46-52)、それ以外の停車駅は絶対値のcumulativeMinutesがそのまま相対時間として扱われてしまいます。このケースはコード内コメント(L42-45)でも認識されている既知のギャップです。結果として、実際のETAより大幅に大きい(あるいは無関係な)分数がユーザーに表示される可能性があります。基準値が取得できない場合は
stopsを空にするなど、誤った絶対値を相対時間として出さないようにするのが安全です。💡 修正案
- const baseMinutes = - allStops.find((s) => s.stationId === currentStation?.id) - ?.departureCumulativeMinutes ?? 0; + const baseStop = allStops.find((s) => s.stationId === currentStation?.id); + // 基準駅が見つからない場合、絶対値をそのまま相対時間として扱うと + // 誤ったETAを表示してしまうため stops を返さない。 + if (!baseStop) { + return { ...route, stops: [] }; + } + const baseMinutes = baseStop.departureCumulativeMinutes ?? 0;🤖 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/useEstimateArrivalTimes.ts` around lines 36 - 60, `useEstimateArrivalTimes` is falling back to `baseMinutes = 0` when `currentStation` is not found in `allStops`, which causes other stops to keep absolute `cumulativeMinutes` values and display incorrect ETAs. Update the logic around `baseMinutes`/`relativeStops` so that when the base station cannot be resolved, the hook does not emit ETA rows from `allStops` (for example, return an empty stop list or otherwise short-circuit before mapping). Keep the existing filtering in `useEstimateArrivalTimes` and make the failure mode explicit so `currentStation`, `allStops`, and `relativeStops` never produce misleading relative times.src/lib/remoteConfig.ts (1)
69-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win数値バリデーションの重複を共通化する余地あり。
Number.isFinite(x) && x > 0の判定パターンがmaxAccuracy・arrivalConfirmMarginSec・maxDurationMinの3箇所で重複しています。共通ヘルパーへ抽出すると、今後ETA関連の数値設定が増えた際の保守性が上がります。♻️ 提案リファクタ
+const parsePositiveFiniteNumber = (value: unknown): number | null => { + const n = Number(value); + return Number.isFinite(n) && n > 0 ? n : null; +}; + export const setupRemoteConfig = async (): Promise<void> => { resetRemoteConfigCache(); const res = await fetch(workerUrl('/config/remote')); if (!res.ok) { throw new Error(`remote config fetch failed: ${res.status}`); } const data = (await res.json()) as RemoteConfigResponse; - const maxAccuracy = Number(data.max_permit_accuracy); - if (Number.isFinite(maxAccuracy) && maxAccuracy > 0) { - cachedMaxPermitAccuracy = maxAccuracy; - } + const maxAccuracy = parsePositiveFiniteNumber(data.max_permit_accuracy); + if (maxAccuracy != null) { + cachedMaxPermitAccuracy = maxAccuracy; + } if (typeof data.force_not_arrived_on_low_accuracy === 'boolean') { cachedForceNotArrivedEnabled = data.force_not_arrived_on_low_accuracy; } if (typeof data.eta_assist_enabled === 'boolean') { cachedEtaAssistEnabled = data.eta_assist_enabled; } - const arrivalConfirmMarginSec = Number( - data.eta_fallback_arrival_confirm_margin_sec - ); - if (Number.isFinite(arrivalConfirmMarginSec) && arrivalConfirmMarginSec > 0) { - cachedEtaFallbackArrivalConfirmMarginSec = arrivalConfirmMarginSec; - } - const maxDurationMin = Number(data.eta_fallback_max_duration_min); - if (Number.isFinite(maxDurationMin) && maxDurationMin > 0) { - cachedEtaFallbackMaxDurationMin = maxDurationMin; - } + const arrivalConfirmMarginSec = parsePositiveFiniteNumber( + data.eta_fallback_arrival_confirm_margin_sec + ); + if (arrivalConfirmMarginSec != null) { + cachedEtaFallbackArrivalConfirmMarginSec = arrivalConfirmMarginSec; + } + const maxDurationMin = parsePositiveFiniteNumber( + data.eta_fallback_max_duration_min + ); + if (maxDurationMin != null) { + cachedEtaFallbackMaxDurationMin = maxDurationMin; + } };🤖 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/lib/remoteConfig.ts` around lines 69 - 88, The positive finite number validation is duplicated in the remote config parsing logic, so refactor the repeated Number.isFinite(x) && x > 0 checks into a shared helper and reuse it for maxAccuracy, arrivalConfirmMarginSec, and maxDurationMin in remoteConfig.ts. Update the parsing flow around the cache assignments in the same area so the helper centralizes the “finite and greater than zero” rule while preserving the existing cachedMaxPermitAccuracy, cachedEtaFallbackArrivalConfirmMarginSec, and cachedEtaFallbackMaxDurationMin behavior.
🤖 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/useEtaAnchor.ts`:
- Around line 38-79: The anchor refresh logic in useEtaAnchor is still
recreating an AT_STATION anchor even when selectedBound is null, so stop both
the useEffect path and the useInterval refresh path from calling setAnchor
unless a bound is selected. Update the guards around the arrived/station checks
in useEtaAnchor so they also require selectedBound to be present, and keep the
prevArrivedRef/prevStationRef bookkeeping intact to avoid stale transition
detection when the guard turns back on.
In `@src/hooks/useEtaFallback.test.tsx`:
- Around line 241-251: The test in useEtaFallback.test.tsx is passing for the
wrong reason because the chosen timestamp also makes the ETA route end, so it
can deactivate via !phase instead of the cap limit. Update the scenario in the
useEtaFallback test to mock a shorter max duration and advance time to a point
where the phase is still returned but the cap is exceeded, so the assertion
specifically exercises the capExceeded path in useEtaFallback and
etaFallbackActiveAtom.
In `@src/hooks/useEtaFallback.ts`:
- Around line 126-132: In useEtaFallback, the DWELLING branch currently exits
early when the station lookup fails, which leaves etaFallbackActiveAtom enabled
and keeps useRefreshStation updates blocked. Update the handling in the
phase.kind === 'DWELLING' path so that a missing station clears the fallback
state before returning, using the existing etaFallbackActiveAtom / store logic
in useEtaFallback to reset the flag instead of silently bailing out.
- Line 82: In useEtaFallback, the ETA route fetch is still being triggered even
when eta_assist_enabled is OFF because useEstimateArrivalTimesRoute() is always
invoked. Update useEtaFallback and the useEstimateArrivalTimesRoute hook so the
GraphQL query is disabled when isEtaAssistEnabled() is false, by passing skip:
!isEtaAssistEnabled() (or an equivalent enabled flag) and ensuring the route
retrieval only runs when ETA assist is enabled.
In `@src/hooks/useRefreshStation.ts`:
- Line 220: R2中は接近/到着通知だけでなく逆方向通知も止めるようにしてください。useRefreshStation の同じ effect
内で、canGoForward に加えて etaFallbackActive を reverse-direction 通知の判定にも適用し、ETA 駆動中は
Line 271 以降の通知ロジックが実行されないようにガードを統一してください。
---
Outside diff comments:
In `@src/hooks/useEstimateArrivalTimes.ts`:
- Around line 36-60: `useEstimateArrivalTimes` is falling back to `baseMinutes =
0` when `currentStation` is not found in `allStops`, which causes other stops to
keep absolute `cumulativeMinutes` values and display incorrect ETAs. Update the
logic around `baseMinutes`/`relativeStops` so that when the base station cannot
be resolved, the hook does not emit ETA rows from `allStops` (for example,
return an empty stop list or otherwise short-circuit before mapping). Keep the
existing filtering in `useEstimateArrivalTimes` and make the failure mode
explicit so `currentStation`, `allStops`, and `relativeStops` never produce
misleading relative times.
In `@src/lib/remoteConfig.ts`:
- Around line 69-88: The positive finite number validation is duplicated in the
remote config parsing logic, so refactor the repeated Number.isFinite(x) && x >
0 checks into a shared helper and reuse it for maxAccuracy,
arrivalConfirmMarginSec, and maxDurationMin in remoteConfig.ts. Update the
parsing flow around the cache assignments in the same area so the helper
centralizes the “finite and greater than zero” rule while preserving the
existing cachedMaxPermitAccuracy, cachedEtaFallbackArrivalConfirmMarginSec, and
cachedEtaFallbackMaxDurationMin behavior.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: ee442a92-c3a0-4cd2-bbdd-7bf5d829452c
📒 Files selected for processing (17)
src/hooks/index.tssrc/hooks/useEstimateArrivalTimes.tssrc/hooks/useEstimateArrivalTimesRoute.tssrc/hooks/useEtaAnchor.test.tsxsrc/hooks/useEtaAnchor.tssrc/hooks/useEtaFallback.test.tsxsrc/hooks/useEtaFallback.tssrc/hooks/useRefreshStation.test.tsxsrc/hooks/useRefreshStation.tssrc/lib/remoteConfig.test.tssrc/lib/remoteConfig.tssrc/screens/Main.tsxsrc/store/atoms/etaFallback.tssrc/store/atoms/location.test.tssrc/store/atoms/location.tssrc/utils/etaFallback.test.tssrc/utils/etaFallback.ts
…ションの共通化 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
|
CodeRabbit のレビュー指摘に対応しました(コミット 0441ba3)。 対応済み(6件)
意図的に見送り(1件)
検証: Generated by Claude Code |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/useEtaFallback.ts (1)
105-124: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
snapshotLocationの直書きでgoodFixが偽陽性になる
src/hooks/useEtaFallback.ts:105-124, 201-228
snapshotLocation()はlocationAtomをaccuracy: 0で上書きしますが、tick()のgoodFixは同じlocationAtomとlastAcceptedFixAtMsAtomを見ています。lastAcceptedFixAtMsAtomはsetLocation()でしか更新されないため、accuracySustainedBadで活性化したケースでは、次の tick で実測位が戻っていなくても解除条件を満たしてフォールバックが早期解除されます。スナップ値を判定対象から外すフラグ、または別 atom に分離してください。🤖 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/useEtaFallback.ts` around lines 105 - 124, `snapshotLocation` が `locationAtom` を直接書き換えることで `tick` の `goodFix` 判定に混入し、`lastAcceptedFixAtMsAtom` と不整合になっています。`snapshotLocation` で入れるスナップ値を `tick` の解除判定対象から除外するため、専用フラグを追加するか、`locationAtom` とは別の atom に分離してください。`snapshotLocation`、`tick`、`goodFix`、`lastAcceptedFixAtMsAtom` の関連を揃えて、スナップ更新がフォールバック解除条件に影響しないように修正してください。
🤖 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/components/DevOverlay.test.tsx`:
- Around line 211-227: The DevOverlay ETA fallback tests do not cover the
DWELLING branch that reads etaPhase.stationId, so add a dedicated test in
DevOverlay.test.tsx for the etaPhaseTargetId path when kind is DWELLING. Reuse
the existing DevOverlay render setup and remoteConfigModule.isEtaAssistEnabled
mocking, but set etaPhase to a DWELLING object with stationId and assert the
meta text reflects that station id, alongside the current phase label.
In `@src/lib/remoteConfig.ts`:
- Around line 40-44: parsePositiveFiniteNumber currently accepts booleans and
arrays because it coerces any unknown value with Number(), so tighten the
validation in this helper to only accept actual numeric inputs from
remoteConfig. Update parsePositiveFiniteNumber to reject non-number types before
the finite/positive check, and keep the existing fallback behavior for invalid
values; use the parsePositiveFiniteNumber symbol in src/lib/remoteConfig.ts as
the fix point.
---
Outside diff comments:
In `@src/hooks/useEtaFallback.ts`:
- Around line 105-124: `snapshotLocation` が `locationAtom` を直接書き換えることで `tick` の
`goodFix` 判定に混入し、`lastAcceptedFixAtMsAtom` と不整合になっています。`snapshotLocation`
で入れるスナップ値を `tick` の解除判定対象から除外するため、専用フラグを追加するか、`locationAtom` とは別の atom
に分離してください。`snapshotLocation`、`tick`、`goodFix`、`lastAcceptedFixAtMsAtom`
の関連を揃えて、スナップ更新がフォールバック解除条件に影響しないように修正してください。
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 57f38dd0-56b1-427f-8742-f27ba221cc1d
📒 Files selected for processing (7)
src/components/DevOverlay.test.tsxsrc/components/DevOverlay.tsxsrc/hooks/useEtaAnchor.tssrc/hooks/useEtaFallback.test.tsxsrc/hooks/useEtaFallback.tssrc/hooks/useRefreshStation.tssrc/lib/remoteConfig.ts
…rlayのDWELLING表示テストを追加 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/useEtaFallback.ts (1)
202-225: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
accuracyBadもlastAcceptedFixAccuracyAtomを使ってください
locationAtomのaccuracy: 0でbadSinceRefが毎 tick リセットされるため、accuracySustainedBadが実測位の劣化を追えません。goodFixと同じくlastFixAccuracyを基準にするのが一貫しています。🤖 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/useEtaFallback.ts` around lines 202 - 225, The accuracy-based bad state tracking in useEtaFallback should use the last accepted real fix instead of the current location snapshot, because locationAtom can be overwritten with accuracy:0 and reset badSinceRef every tick. Update the accuracyBad logic to base its threshold check on lastAcceptedFixAccuracyAtom (the same source used by goodFix) so sustained degradation is tracked consistently and gpsLost is not cleared prematurely.
🤖 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/components/DevOverlay.tsx`:
- Around line 426-439: `etaAnchorAgeSec` is computing elapsed time with
`Date.now()` directly during render in `DevOverlay`, which makes the value
depend on unrelated rerenders. Move “now” into React state in `DevOverlay` (or a
dedicated hook) updated by a `useEffect` with `setInterval`, and derive
`etaAnchorAgeSec` from that state instead of calling `Date.now()` inline; keep
`etaAnchorMeta` and the existing `etaAnchor`/`etaAnchorValue` logic wired to the
new state so the displayed age updates independently and predictably.
---
Outside diff comments:
In `@src/hooks/useEtaFallback.ts`:
- Around line 202-225: The accuracy-based bad state tracking in useEtaFallback
should use the last accepted real fix instead of the current location snapshot,
because locationAtom can be overwritten with accuracy:0 and reset badSinceRef
every tick. Update the accuracyBad logic to base its threshold check on
lastAcceptedFixAccuracyAtom (the same source used by goodFix) so sustained
degradation is tracked consistently and gpsLost is not cleared prematurely.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 8a5a15a1-4d6c-4437-8dde-d3a0d65dccb7
📒 Files selected for processing (6)
src/components/DevOverlay.test.tsxsrc/components/DevOverlay.tsxsrc/hooks/useEtaFallback.test.tsxsrc/hooks/useEtaFallback.tssrc/lib/remoteConfig.tssrc/store/atoms/location.ts
…tate化してレンダー中のDate.now呼び出しを解消 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
概要
地下鉄・地下区間などGPS精度が劣化・喪失する区間で、サーバー計算のETA(
estimateArrivalTimes)をGPSの補完・代替に使い、接近/到着判定とヘッダー進行を安定化・継続させる。ETAはGPS非依存で地下でも取得できるが、これまでLineBoardの「あと◯分」バッジ表示にしか使われていなかった資産を位置推定へ転用する。既定はリモート設定でOFFのため、段階リリース前提で挙動は変わらない。変更の種類
変更内容
eta_assist_enabledで制御、既定OFF)。useRefreshStationの到着判定を、ETA仮想時計が最寄り停車駅の「停車」を示し、かつGPSの最寄り駅と一致するときに限りその駅の到着圏を広げる(確認的な緩和。精度が良い通常時は一切変わらない)。useEtaFallbackがETA仮想時計を権威にして接近→到着→発車を前進駆動。useRefreshStationの書き込みはゲートで停止して2ライター競合を防ぎ、到着時は駅座標をlocationAtomへ1回スナップして下流表示と整合させる。良好測位(≤200m)受理で即GPS優先へ復帰(200〜1500mの中途半端な測位では解除しないヒステリシス)。estimateEtaPhase(走行フェーズ推定の純関数)/useEtaAnchor(GPS確定駅イベントの記録)/useEtaFallback(R2本体)/etaFallbackatom群。useRefreshStationにR2ゲートとR1到着圏緩和を組み込み。useEstimateArrivalTimesからクエリ変数組み立て・ルート抽出をuseEstimateArrivalTimesRouteとして切り出し(絶対累積分・全stopsを返す。クエリ変数が同一なのでReact QueryキャッシュをLineBoardと共有し追加通信は発生しない)。既存の表示挙動・テストは不変。/config/remote)にキーを足す方式(Firebase Remote Config不使用)。BFF側で配信するまではフォールバック値で動作する。本PRはフェーズ1(離散イベント駆動)。駅間の連続的な滑らかな進行表示、ETAイベントでの音声/通知発火、GPS再アンカー時の遅延学習は後続フェーズに送っている。
テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ること新規テスト:
estimateEtaPhase(純関数、仮想時計・接近リード・マージン留め・終端停止・異常データ耐性)、useEtaFallback(発動条件・到着スナップ・ヒステリシス・タイムキャップ)、useEtaAnchor、useRefreshStationのゲート。全体で 188 suites / 2003 tests がグリーン。関連Issue
スクリーンショット(任意)
Generated by Claude Code
Summary by CodeRabbit