Skip to content

地下鉄・GPS精度劣化区間でETAを用いて接近/到着判定を補完・継続する機能を追加 - #6366

Merged
TinyKitten merged 9 commits into
devfrom
claude/eta-subway-support-v5jhtl
Jul 7, 2026
Merged

TinyKitten merged 9 commits into
devfrom
claude/eta-subway-support-v5jhtl

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

概要

地下鉄・地下区間などGPS精度が劣化・喪失する区間で、サーバー計算のETA(estimateArrivalTimes)をGPSの補完・代替に使い、接近/到着判定とヘッダー進行を安定化・継続させる。ETAはGPS非依存で地下でも取得できるが、これまでLineBoardの「あと◯分」バッジ表示にしか使われていなかった資産を位置推定へ転用する。既定はリモート設定でOFFのため、段階リリース前提で挙動は変わらない。

変更の種類

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

変更内容

  • GPS精度に応じた3レジームでETAを融合する仕組みを追加(リモート設定 eta_assist_enabled で制御、既定OFF)。
    • R0 健全(≤200m): 従来どおり。ETAは「最後にGPSで確定した駅イベント」をアンカーとして記録するのみ。
    • R1 劣化(200〜1500m): useRefreshStation の到着判定を、ETA仮想時計が最寄り停車駅の「停車」を示し、かつGPSの最寄り駅と一致するときに限りその駅の到着圏を広げる(確認的な緩和。精度が良い通常時は一切変わらない)。
    • R2 喪失(外れ値/受理測位の途絶/精度不良の継続): useEtaFallback がETA仮想時計を権威にして接近→到着→発車を前進駆動。useRefreshStation の書き込みはゲートで停止して2ライター競合を防ぎ、到着時は駅座標を locationAtom へ1回スナップして下流表示と整合させる。良好測位(≤200m)受理で即GPS優先へ復帰(200〜1500mの中途半端な測位では解除しないヒステリシス)。
  • 新規: estimateEtaPhase(走行フェーズ推定の純関数)/ useEtaAnchor(GPS確定駅イベントの記録)/ useEtaFallback(R2本体)/ etaFallback atom群。
  • useRefreshStation にR2ゲートとR1到着圏緩和を組み込み。
  • useEstimateArrivalTimes からクエリ変数組み立て・ルート抽出を useEstimateArrivalTimesRoute として切り出し(絶対累積分・全stopsを返す。クエリ変数が同一なのでReact QueryキャッシュをLineBoardと共有し追加通信は発生しない)。既存の表示挙動・テストは不変。
  • 遅延耐性として到着確定マージン(ARRIVING留め、既定30秒)とタイムキャップ(既定30分)を追加。リモート設定は既存の自前Cloudflare Worker配信(/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

  • 新機能
    • GPS精度低下時でもETA推定をフォールバックで継続し、走行フェーズ(接近/到着/停車)を自動更新します。
    • GPS確定イベントからETAアンカーを記録し、推定の基準に反映します。
    • 開発用診断画面でETAフォールバック/アンカーを確認できます。
  • 改善
    • リモート設定で有効/無効、確認マージン、最大継続時間を制御。
    • 低精度時の到着判定と更新抑制を最適化しました。

@github-actions github-actions Bot added the react label Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bef23fa6-4c79-4fe5-87db-c9a233b1cdc8

📥 Commits

Reviewing files that changed from the base of the PR and between e085ae2 and fbfc057.

📒 Files selected for processing (2)
  • src/components/DevOverlay.tsx
  • src/hooks/useEtaFallback.ts

📝 Walkthrough

Walkthrough

ETA到着時刻クエリを分離し、GPS劣化時のETAフェーズ推定とフォールバック状態を追加しました。あわせて、既存の到着判定、画面起動、副作用表示にETA関連の処理と診断表示を組み込みました。

Changes

ETAフォールバック機能

Layer / File(s) Summary
ETAルート取得の分離
src/hooks/index.ts, src/hooks/useEstimateArrivalTimesRoute.ts, src/hooks/useEstimateArrivalTimes.ts
GraphQLクエリの変数組み立て・実行・ルート抽出を新規フックへ分離し、既存フックは表示用の相対時間変換に限定、公開エクスポートを追加。
ETAフェーズ推定と状態
src/utils/etaFallback.ts, src/utils/etaFallback.test.ts, src/store/atoms/etaFallback.ts, src/store/atoms/location.ts, src/store/atoms/location.test.ts, src/lib/remoteConfig.ts, src/lib/remoteConfig.test.ts
ETA推定の型と関数、ETA関連アトム、最終受理測位の保持、remoteConfig の ETA 設定キーと取得API、各テストを追加。
useEtaAnchorの実装
src/hooks/useEtaAnchor.ts, src/hooks/useEtaAnchor.test.tsx
GPS到着・発車イベントを etaAnchorAtom に記録し、フォールバック活性時の抑止、定期更新、選択方位解除時のクリアを実装。
useEtaFallbackの実装
src/hooks/useEtaFallback.ts, src/hooks/useEtaFallback.test.tsx
GPS劣化時に ETA フェーズを推定してフォールバックを発動/解除し、駅状態と位置を更新する処理を実装。
既存フックと画面への統合
src/hooks/useRefreshStation.ts, src/hooks/useRefreshStation.test.tsx, src/screens/Main.tsx, src/components/DevOverlay.tsx, src/components/DevOverlay.test.tsx
到着判定半径の拡張、フォールバック中の更新抑止、MainScreen での新フック呼び出し、診断表示の追加を行う。

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6141: src/hooks/useRefreshStation.ts の到着判定と通知の経路が同じで、ETA フォールバック中の抑止ロジックと重なります。
  • TrainLCD/MobileApp#6151: remoteConfig.ts のキャッシュ破棄と ETA 設定追加が同じモジュールに入っています。
  • TrainLCD/MobileApp#6337: useEstimateArrivalTimesRoute の from/to/directionId 組み立てと直接関係します。

Poem

ぴょこんと耳を立てて、
ETA の風をくんくん🐇
ふらつく星でも道しるべ、
ぴたっと駅へ、ぽんと着地。
うさぎの時計は、
きょうもぴょんぴょん正確です。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRの主変更であるETAを使った接近/到着判定の補完・継続を簡潔に表しており、内容と一致しています。
Description check ✅ Passed 概要・変更の種類・変更内容・テストが揃っており、テンプレート要件をほぼ満たしています。
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.
✨ 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/eta-subway-support-v5jhtl

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

@TinyKitten TinyKitten self-assigned this Jul 7, 2026

@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: 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 win

baseMinutesが見つからない場合、他の停車駅の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

📥 Commits

Reviewing files that changed from the base of the PR and between f07e213 and 605ba93.

📒 Files selected for processing (17)
  • src/hooks/index.ts
  • src/hooks/useEstimateArrivalTimes.ts
  • src/hooks/useEstimateArrivalTimesRoute.ts
  • src/hooks/useEtaAnchor.test.tsx
  • src/hooks/useEtaAnchor.ts
  • src/hooks/useEtaFallback.test.tsx
  • src/hooks/useEtaFallback.ts
  • src/hooks/useRefreshStation.test.tsx
  • src/hooks/useRefreshStation.ts
  • src/lib/remoteConfig.test.ts
  • src/lib/remoteConfig.ts
  • src/screens/Main.tsx
  • src/store/atoms/etaFallback.ts
  • src/store/atoms/location.test.ts
  • src/store/atoms/location.ts
  • src/utils/etaFallback.test.ts
  • src/utils/etaFallback.ts

Comment thread src/hooks/useEtaAnchor.ts Resolved
Comment thread src/hooks/useEtaFallback.test.tsx Resolved
Comment thread src/hooks/useEtaFallback.ts Resolved
Comment thread src/hooks/useEtaFallback.ts Resolved
Comment thread src/hooks/useRefreshStation.ts Resolved

Copy link
Copy Markdown
Member Author

CodeRabbit のレビュー指摘に対応しました(コミット 0441ba3)。

対応済み(6件)

  • useEtaAnchor: 行き先未選択(selectedBound == null)の間はアンカーの定期更新も停止。クリア effect との競合で古いアンカーが復活するのを防止。
  • useEtaFallback: eta_assist_enabled が OFF のときは useEstimateArrivalTimesRoute({ skip: !isEtaAssistEnabled() }) で ETA ルート取得自体を停止。
  • useEtaFallback: DWELLING 駅が stationsAtom 上に見つからない場合は drive が false を返し、フォールバックを解除して状態凍結を防止(テスト追加)。
  • useRefreshStation: R2 活性中は逆方向通知も停止(接近/到着通知に加えてゲートを統一)。
  • remoteConfig: 「有限かつ正」の数値バリデーションを parsePositiveFiniteNumber に共通化。
  • useEtaFallback.test: タイムキャップのテストを短い上限モック+フェーズが残る時刻に変更し、!phase ではなく capExceeded 経路を確実に検証。

意図的に見送り(1件)

  • useEstimateArrivalTimes.ts の baseMinutes ?? 0 フォールバック(基準駅が allStops に見つからない場合に絶対値が相対時間として表示されうる件)は、本 PR で新規に導入したものではなく既存挙動です。本 PR の当該変更は「クエリ組み立て・ルート抽出を useEstimateArrivalTimesRoute へ切り出す挙動不変のリファクタ」であり、ここで表示挙動を変えると既存テストの前提も変わるため、別 PR での対応が適切と判断しました。

検証: npm run lint / npm test(188 suites / 2004 tests)/ npm run typecheck すべてグリーンです。


Generated by Claude Code

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 605ba93 and 3d425b5.

📒 Files selected for processing (7)
  • src/components/DevOverlay.test.tsx
  • src/components/DevOverlay.tsx
  • src/hooks/useEtaAnchor.ts
  • src/hooks/useEtaFallback.test.tsx
  • src/hooks/useEtaFallback.ts
  • src/hooks/useRefreshStation.ts
  • src/lib/remoteConfig.ts

Comment thread src/components/DevOverlay.test.tsx Resolved
Comment thread src/lib/remoteConfig.ts Resolved

@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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d425b5 and e085ae2.

📒 Files selected for processing (6)
  • src/components/DevOverlay.test.tsx
  • src/components/DevOverlay.tsx
  • src/hooks/useEtaFallback.test.tsx
  • src/hooks/useEtaFallback.ts
  • src/lib/remoteConfig.ts
  • src/store/atoms/location.ts

Comment thread src/components/DevOverlay.tsx Resolved
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