Repository navigation
地下でETAが現在地を独占駆動して勝手に動くデグレを解消しETAをGPSの到着判定補助(R1)に限定、設定に手動A/Bトグルを追加 - #6369
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
📝 WalkthroughWalkthroughETAフォールバックの状態駆動(駅状態を前進させるロジック)を撤去し、 ChangesETA補助の再構成
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ExperimentalSettings
participant etaAssistManualEnabledAtom
participant storage
participant remoteConfig
participant DevOverlay
ExperimentalSettings->>remoteConfig: isEtaAssistRemoteEnabled()
remoteConfig-->>ExperimentalSettings: 許可状態
ExperimentalSettings->>etaAssistManualEnabledAtom: 手動トグルをset
ExperimentalSettings->>storage: ETA_ASSIST_MANUAL_ENABLEDを保存
remoteConfig->>remoteConfig: isEtaAssistEnabled = remote && manual
DevOverlay->>remoteConfig: isEtaAssistEnabled参照
DevOverlay->>DevOverlay: etaPhaseAtom/etaAnchorAtomを表示
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: 4
🤖 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.test.tsx`:
- Around line 115-136: `useEtaAnchor` のテストに `MOVING_RECENCY_MS`
の境界ケースを追加してください。現在は `lastMovingAtMsAtom` が null
の場合しか見ていないため、`lastMovingAtMsAtom` に値はあるが `MOVING_RECENCY_MS` を超えて古いときに
`arrivedAtom` が false へ倒れても `DEPARTED` を記録しないことを、`etaAnchorAtom` と `arrivedAtom`
の振る舞いで検証してください。既存の `renderWithStore` と `createStore` を使い、`useEtaAnchor` の motion
gate が時間しきい値を正しく判定することを確認できる形にしてください。
In `@src/hooks/useEtaAnchor.ts`:
- Around line 61-76: The motion-gate check for “recently moving” is duplicated
between useEtaAnchor and useEtaFallback’s tick logic. Extract the shared
`lastMovingAtMs != null && now - lastMovingAtMs < MOVING_RECENCY_MS` condition
into a common helper in `src/utils/etaFallback.ts` (for example,
`isRecentlyMoving(lastMovingAtMs, nowMs)`), then replace both local checks with
that helper so the behavior stays consistent when the threshold or rule changes.
In `@src/store/atoms/location.test.ts`:
- Around line 288-296: The current location tests cover coarse-to-coarse
behavior, but they miss the low-precision to high-precision transition where
recordMotion may wrongly treat a resumed accurate fix as real movement after a
degraded sample. Add a test in location.test.ts around setLocation and
lastMovingAtMsAtom that first establishes a coarse baseline, then feeds a
high-precision update with distance over the normal threshold but still
representing a stationary case, and assert that the motion state is not
incorrectly updated. Use the existing recordMotion behavior and the same helpers
like makeLocation, setLocation, and store.get(lastMovingAtMsAtom) to keep the
scenario aligned with the implementation.
In `@src/store/atoms/location.ts`:
- Around line 93-125: `recordMotion` の移動判定を強化してください。`lastMotionSampleAtom`
には位置だけでなく前回の `accuracy` も保存し、現在の `accuracy` と前回の `accuracy` の両方を使って `threshold`
を決めるようにしてください。あわせて、`recordMotion` 内で `dtSec <= 0` の場合は `speed` を 0
にせずその場で判定を中断し、同一時刻や時刻逆行時に `lastMovingAtMsAtom` が誤打刻されないようにしてください。
🪄 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: 21022d64-5ca8-4088-8e32-144b288a2d11
📒 Files selected for processing (7)
src/hooks/useEtaAnchor.test.tsxsrc/hooks/useEtaAnchor.tssrc/hooks/useEtaFallback.test.tsxsrc/hooks/useEtaFallback.tssrc/store/atoms/location.test.tssrc/store/atoms/location.tssrc/utils/etaFallback.ts
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/store/atoms/location.ts (1)
96-141: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
src/store/atoms/location.ts:96-141の速度判定は長時間停車後に過小評価されます
lastMotionSampleAtomが移動確定時しか更新されないため、停車が長いほどdtSecが肥大化し、単発の劣化フィックスでもspeed = dist / dtSecがMAX_PLAUSIBLE_SPEEDを下回ってlastMovingAtMsAtomを誤更新できます。直近 fix 基準の判定にするか、複数回連続で閾値超過した場合のみ打刻してください。🤖 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/store/atoms/location.ts` around lines 96 - 141, `recordMotion` の速度判定が `lastMotionSampleAtom` を移動確定時にしか更新しないため、長時間停車後に `dtSec` が大きくなって単発の劣化フィックスを見逃す問題があります。`recordMotion` と `lastMotionSampleAtom` の扱いを見直し、直近の受理 fix を基準に速度を計算するか、`lastMovingAtMsAtom` を更新する前に複数回連続で `dist` と `speed` の閾値超過を確認するようにしてください。
🤖 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.
Outside diff comments:
In `@src/store/atoms/location.ts`:
- Around line 96-141: `recordMotion` の速度判定が `lastMotionSampleAtom`
を移動確定時にしか更新しないため、長時間停車後に `dtSec` が大きくなって単発の劣化フィックスを見逃す問題があります。`recordMotion` と
`lastMotionSampleAtom` の扱いを見直し、直近の受理 fix を基準に速度を計算するか、`lastMovingAtMsAtom`
を更新する前に複数回連続で `dist` と `speed` の閾値超過を確認するようにしてください。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 445a17db-fd27-468d-95e5-47b03c95875a
📒 Files selected for processing (7)
src/hooks/useEtaAnchor.test.tsxsrc/hooks/useEtaAnchor.tssrc/hooks/useEtaFallback.test.tsxsrc/hooks/useEtaFallback.tssrc/store/atoms/location.test.tssrc/store/atoms/location.tssrc/utils/etaFallback.ts
…)のみに限定 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
…aleness用のlastAcceptedFix系atom・DevOverlayの稼働フラグ)を撤去 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
…作不可にして手動でも有効化できないようにする Co-Authored-By: Claude Opus 4.8 <[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 (2)
src/store/atoms/location.ts (1)
90-141: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift発車判定の基準サンプルを停車中にも前進させてください
lastMotionSampleAtomが「移動と判定できた時」しか更新されないため、長時間停車後はdtSecが膨らんだままになり、最初の発車サンプルがMOTION_MIN_SPEED_MPSを満たすまでlastMovingAtMsAtomが立ちません。useEtaAnchorはarrived true -> falseの瞬間にしかlastMovingAtMsAtomを見ないので、この遅延でDEPARTEDを取りこぼす可能性があります。ジッタ抑制用の基準と、最近の実移動判定用の基準は分けるのが安全です。🤖 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/store/atoms/location.ts` around lines 90 - 141, `recordMotion` only advances `lastMotionSampleAtom` when motion is already detected, which leaves the baseline stale during long stops and can delay or miss the first departure transition. Update the sampling logic so the reference sample is advanced on each accepted location fix (or split it into separate atoms for jitter suppression vs. motion detection), while keeping `lastMovingAtMsAtom` gated on the existing distance/speed checks. Use the existing `recordMotion`, `lastMotionSampleAtom`, and `lastMovingAtMsAtom` flow so `useEtaAnchor` can observe the departure promptly.src/hooks/useEtaFallback.test.tsx (1)
33-52: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
stationは共通ファクトリへ寄せてくださいsrc/utils/test/factories.tsのcreateStationで置き換えられます。routeStopとBASE_LOCATIONは共通ヘルパーが見当たらないので、そのままで問題ありません。🤖 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.test.tsx` around lines 33 - 52, The local station helper in useEtaFallback.test.tsx should be removed and replaced with the shared createStation factory from src/utils/test/factories so the test uses the common Station setup instead of duplicating it. Keep routeStop and BASE_LOCATION as-is, and update the test setup to call createStation wherever station is currently used.Source: Path instructions
🤖 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 413-414: The ETA FALLBACK warning state is being driven by
etaPhase presence, which makes the card look urgent during normal assisted
operation instead of only when fallback is actually active. Update the warning
condition in DevOverlay.tsx so the card uses the real fallback/assist-active
signal (the previous isEtaFallbackActive-style logic) rather than etaPhase !=
null, and apply the same fix to the other ETA fallback display blocks referenced
by the ETA card rendering.
In `@src/screens/ExperimentalSettings.tsx`:
- Around line 122-137: `handleToggleEtaAssist` repeats the same
toggle/persist/rollback pattern used by `handleTogglePortraitMode` and
`handleToggleTelemetry`, so extract this boolean preference flow into a shared
hook/helper and have these handlers call it with their specific atom setter,
storage key, and alert message. Keep the existing behavior intact: flip the
current value, update the atom, persist via `storage.set`, and on failure roll
back the atom and show the error alert.
---
Outside diff comments:
In `@src/hooks/useEtaFallback.test.tsx`:
- Around line 33-52: The local station helper in useEtaFallback.test.tsx should
be removed and replaced with the shared createStation factory from
src/utils/test/factories so the test uses the common Station setup instead of
duplicating it. Keep routeStop and BASE_LOCATION as-is, and update the test
setup to call createStation wherever station is currently used.
In `@src/store/atoms/location.ts`:
- Around line 90-141: `recordMotion` only advances `lastMotionSampleAtom` when
motion is already detected, which leaves the baseline stale during long stops
and can delay or miss the first departure transition. Update the sampling logic
so the reference sample is advanced on each accepted location fix (or split it
into separate atoms for jitter suppression vs. motion detection), while keeping
`lastMovingAtMsAtom` gated on the existing distance/speed checks. Use the
existing `recordMotion`, `lastMotionSampleAtom`, and `lastMovingAtMsAtom` flow
so `useEtaAnchor` can observe the departure promptly.
🪄 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: af4eade9-a0e9-4b1a-956c-f816d7a0e508
📒 Files selected for processing (20)
assets/translations/en.jsonassets/translations/ja.jsonsrc/components/DevOverlay.test.tsxsrc/components/DevOverlay.tsxsrc/components/Permitted.tsxsrc/constants/storage.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/ExperimentalSettings.test.tsxsrc/screens/ExperimentalSettings.tsxsrc/store/atoms/etaFallback.tssrc/store/atoms/experimental.tssrc/store/atoms/location.test.tssrc/store/atoms/location.ts
…oving)を撤去しDEPARTEDを無条件記録へ戻す Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NEhSCr8uZ4drhiUxKcRFRU
There was a problem hiding this comment.
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/lib/remoteConfig.ts`:
- Around line 135-140: The ETA assist gate logic is duplicated between
isEtaAssistEnabled() and the JSX in ExperimentalSettings.tsx, so move the shared
Remote AND manual check into a reusable hook such as useEtaAssistEnabled() that
reads etaAssistRemoteEnabled and etaAssistManualEnabledAtom reactively. Update
ExperimentalSettings.tsx to use the new hook for rendering, and keep
isEtaAssistEnabled() as the synchronous helper for non-React callers like
DevOverlay by delegating to the same underlying gate logic.
🪄 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: 6a80d59d-e371-4057-8024-6f38d554f2f4
📒 Files selected for processing (11)
src/components/DevOverlay.test.tsxsrc/components/DevOverlay.tsxsrc/hooks/useEtaAnchor.test.tsxsrc/hooks/useEtaAnchor.tssrc/hooks/useEtaFallback.test.tsxsrc/lib/remoteConfig.test.tssrc/lib/remoteConfig.tssrc/screens/ExperimentalSettings.test.tsxsrc/screens/ExperimentalSettings.tsxsrc/store/atoms/location.test.tssrc/store/atoms/location.ts
💤 Files with no reviewable changes (2)
- src/store/atoms/location.test.ts
- src/store/atoms/location.ts
| // ETA補助機能の実効的な有効/無効を同期的に取得する。Remote Config が許可(マスターON)し、 | ||
| // かつ設定画面の手動トグルもONのときだけ有効。Remote が false のときは手動トグルの値に | ||
| // 関わらず無効。 | ||
| export const isEtaAssistEnabled = (): boolean => | ||
| isEtaAssistRemoteEnabled() && store.get(etaAssistManualEnabledAtom); | ||
|
|
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Remote AND 手動の判定ロジックが2箇所に分散している。
isEtaAssistEnabled()のAND条件と、src/screens/ExperimentalSettings.tsxのJSX(etaAssistRemoteEnabled && etaAssistManualEnabled)が同じ業務ロジックを別々に実装しています。将来ゲート条件が増えた際に片方だけ更新され挙動がズレるリスクがあります。useAtomValue(etaAssistManualEnabledAtom) && isEtaAssistRemoteEnabled()をまとめた再利用可能なフック(例: useEtaAssistEnabled())に切り出すと、UI側(ExperimentalSettings.tsx)でもリアクティブに購読でき、非リアクティブなisEtaAssistEnabled()(DevOverlay等)とロジックを一元化できます。
♻️ 提案: 共通フックへの切り出し
+export const useEtaAssistEnabled = (): boolean => {
+ const manualEnabled = useAtomValue(etaAssistManualEnabledAtom);
+ return isEtaAssistRemoteEnabled() && manualEnabled;
+};
+
export const isEtaAssistEnabled = (): boolean =>
isEtaAssistRemoteEnabled() && store.get(etaAssistManualEnabledAtom);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // ETA補助機能の実効的な有効/無効を同期的に取得する。Remote Config が許可(マスターON)し、 | |
| // かつ設定画面の手動トグルもONのときだけ有効。Remote が false のときは手動トグルの値に | |
| // 関わらず無効。 | |
| export const isEtaAssistEnabled = (): boolean => | |
| isEtaAssistRemoteEnabled() && store.get(etaAssistManualEnabledAtom); | |
| // ETA補助機能の実効的な有効/無効を同期的に取得する。Remote Config が許可(マスターON)し、 | |
| // かつ設定画面の手動トグルもONのときだけ有効。Remote が false のときは手動トグルの値に | |
| // 関わらず無効。 | |
| export const useEtaAssistEnabled = (): boolean => { | |
| const manualEnabled = useAtomValue(etaAssistManualEnabledAtom); | |
| return isEtaAssistRemoteEnabled() && manualEnabled; | |
| }; | |
| export const isEtaAssistEnabled = (): boolean => | |
| isEtaAssistRemoteEnabled() && store.get(etaAssistManualEnabledAtom); |
🤖 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 135 - 140, The ETA assist gate logic is
duplicated between isEtaAssistEnabled() and the JSX in ExperimentalSettings.tsx,
so move the shared Remote AND manual check into a reusable hook such as
useEtaAssistEnabled() that reads etaAssistRemoteEnabled and
etaAssistManualEnabledAtom reactively. Update ExperimentalSettings.tsx to use
the new hook for rendering, and keep isEtaAssistEnabled() as the synchronous
helper for non-React callers like DevOverlay by delegating to the same
underlying gate logic.
概要
先行PR #6366 で入れた ETA フォールバックのうち、GPSが喪失した区間で ETA が現在地・到着を単独駆動する部分(R2) が、地下鉄で重大なデグレを起こすことが実機で判明したため撤去する。具体的には、駅に到着後も ETA の時刻進行にしたがって現在地が勝手に動き、GPSの実測と喧嘩していた(クレームになりうるレベル)。
GPSが完全凍結した区間では「待機/走行/遅延」を位置から区別できず、ETA単独で位置を進めるのは原理的に安全に行えない。そこで ETA は「GPSの補助」に役割を限定する:
useRefreshStation)が権威。ETA はこれらを一切駆動しない。etaPhaseAtom)の公開に徹し、精度劣化時に 「ETAが同じ駅で停車を示すときだけ、その駅の到着しきい値を緩和する」補助(R1、既存) にのみ使う。到着判定自体はGPSが行う。あわせて、この ETA 補助を切り替えられるよう、設定画面の試験的機能にトグルを追加する。Remote Config
eta_assist_enabledをマスタースイッチとし、それが false のときは手動トグルも操作不可にする。変更の種類
変更内容
src/hooks/useEtaFallback.ts): 発動/解除/drive/座標スナップ/etaFallbackActiveAtomの駆動をすべて削除し、useEtaFallbackは毎tickestimateEtaPhaseを評価してetaPhaseAtomを公開するだけにした。位置・到着・接近・現在駅は書き換えない(GPSを唯一の権威に保つ)。src/hooks/useRefreshStation.ts): 精度劣化時にetaPhaseAtomが最寄り駅で DWELLING を示すときだけ到着しきい値を緩和する既存ロジックはそのまま。到着はGPSが確定する。src/hooks/useEtaAnchor.ts): 到着中/発車(arrivedtrue→false)をetaAnchorAtomへ記録し、etaPhaseAtomの仮想時計の起点にする。ETAは位置を駆動しないため、仮に静止中の強制未到着でDEPARTEDが記録されても、R1は最寄り駅とETA停車駅が一致する時だけ効き、GPS復帰で自己修復する。src/screens/ExperimentalSettings.tsxほか):etaAssistManualEnabledAtom+ETA_ASSIST_MANUAL_ENABLEDで永続化し、起動時にPermitted.tsxで復元。実効有効 = Remote Config(マスター)AND 手動トグル。Remote が false のときはトグルを disabled にして手動でも有効化できない(isEtaAssistRemoteEnabledを切り出し)。翻訳キーetaAssistTitle/etaAssistDescriptionを ja/en に追加。etaFallbackActiveAtom(+useRefreshStationの2ライターゲート)、staleness用のlastAcceptedFix*atom を削除。ETAが位置を駆動しなくなったことで役割を失った実移動検知(recordMotion/lastMovingAtMsAtom/isRecentlyMoving)も撤去。useEtaFallbackはフェーズ公開のみ&状態非駆動、remoteConfig/ExperimentalSettingsのマスタースイッチ挙動、DevOverlayの無効時非表示ほか)。テスト
npm run lintが通ることnpm testが通ること(2005件パス)npm run typecheckが通ること関連Issue
スクリーンショット(任意)
🤖 Generated with Claude Code
Summary by CodeRabbit
新機能
変更