Skip to content

feat: improve smart route recommendations and Android reminders - #118

Merged
AvianJay merged 5 commits into
mainfrom
feat/smart-recommendation-algorithm
Nov 21, 2026
Merged

AvianJay merged 5 commits into
mainfrom
feat/smart-recommendation-algorithm

Conversation

@AvianJay

Copy link
Copy Markdown
Collaborator

變更

  • 首頁智慧推薦改用有日期的造訪紀錄學習路線與常用站牌。同日多次開啟不會重複計算習慣,並區分平日、週末與星期幾,讓舊紀錄逐漸衰減。
  • Flutter 預先產生提醒時段表;Android 使用現行資料庫查找正確方向的站牌,只在有可能趕上的班次時通知。已學到常用站牌時不需要背景定位。
  • 將已發出的提醒納入學習,避免「看了通知就不開 App」被算成缺席,也避免提早點通知把習慣時間一再往前推。未再使用的時段約兩週後暫停;清除學習紀錄時一併清除 Android 提醒紀錄。
  • 承接 fix(android): detect boarding from the rider's own track #117:用原始站牌 ID 查即時到站,點通知時將完整 64-bit 站牌 ID 傳給 Flutter。

範圍

  • iOS 首頁推薦也使用新模型;背景智慧提醒仍僅支援 Android。Wear OS 離線備援計分未變更。
  • 開啟「同步路線紀錄」時,近 56 天內保存的造訪時間與站牌 ID 會隨路線紀錄同步;已發出的提醒紀錄只留在裝置上。

驗證

  • flutter analyze --no-pub:無問題。
  • flutter test --no-pub:646 個測試通過。
  • Android 本機 :app:testDebugUnitTest:387 個測試通過。另將通知點擊 ID 暫時改為折疊值,確認高雄站牌回歸測試失敗,還原後通過。
  • 尚未在 Android 實機驗證背景通知的送達時間。

Learn route habits from dated visits and share a reminder plan with Android. Look up arrivals at the actual stop, keep full-width stop IDs in notification launches, and cover the plan, database and launch contract with regression tests.

@Av1anJay Av1anJay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整合審查:請求修改

這次涵蓋完整 base...head diff、受影響的呼叫路徑、既有 #117 討論與三份獨立靜態審查。下方集中列出所有目前驗證的問題:清除/登出與收藏變動後的計畫狀態、排程競態、站牌學習與清除、資料庫恢復、跨 provider 配額、即時 ETA 時基、被封鎖頻道的回饋,以及首頁模型與舊資料遷移。#117 先前問題在各自原始情境的分類沿用 前次審查,沒有將其重複列為新問題。

驗證限制:exact-head CI 的 flutter analyze、646 個 Flutter 測試及 2 個 Chrome 測試通過;本機 JVM 編譯逾時,未獨立執行 Android/Robolectric 測試或裝置通知。以下競態與數值例子為原始碼推導/建模,並非聲稱已在裝置重現;PR 說明提及的 387 個 Android 單元測試沒有可供這次獨立核對的執行日誌。

await _resolveSmartRouteIds(now);
await storage.saveSmartRoutePlan(
SmartRoutePlanner.build(
profiles: _routeUsageProfiles,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 防止較舊的重建在清除學習紀錄後寫回舊計畫。這裡先捕獲舊的 _routeUsageProfiles,再等待 :2247 的平台呼叫;若清除全部紀錄期間另一個重建先寫入空計畫、取消排程並完成清除,原呼叫恢復後仍會用捕獲的清單覆寫計畫並重新排程,設定仍開啟時就可能再次提醒已清除的路線。請序列化重建或使用 generation 防止過期寫入/排程,並用可控制的延遲 log 回應測試 clear 完成後才釋放舊呼叫。這是依 async 順序推導,尚未在裝置重現。

await AndroidHomeIntegration.loadSmartRouteReminderLog(),
),
favoriteProfiles: _favoriteUsageProfiles,
favorites: _favoriteGroups.values

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 這份持久化快照需要在其輸入被替換時失效,否則即使沒有並行呼叫也會過期。登出/強制登出會用裝置本地資料取代合併後的路線紀錄(:740-767,833-849),但沒有重建計畫;原本只來自其他裝置的路線因此仍可能被提醒。另收藏的新增、刪除及遠端套用也不重建;若唯一收藏 A 被刪除,無定位時舊計畫仍可沿用 A 的到站資料。請對這兩種輸入變動都重新建置或清除計畫,測試登出及收藏變更後沒有其他重建觸發的情境。推導自資料流,未執行 Android 整合測試。

if (!SmartRouteReminderRules.hasLiveSlots(plan, now)) {
// Every habit in the plan has lapsed. Nothing can fire until
// the app is opened and writes a new one, which reschedules.
SmartRouteNotificationScheduler.cancel(applicationContext)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 不要讓基於舊快照的 worker 取消新計畫的週期工作。可能順序是 worker 讀到過期計畫後暫停,Flutter 儲存新計畫並完成 UPDATE,接著這裡依舊快照呼叫 cancelUniqueWork。本專案鎖定的 WorkManager 2.10.3 UPDATE 保留既有週期工作 ID、不中斷已在執行的 worker;稍後的按名稱取消會取消該已更新工作,因此新計畫雖有有效時段卻不再執行。請讓取消與計畫更新具備版本/排程同步,並測試此事件順序;這是根據鎖定版 WorkManager 原始碼建模,非 Android 實測。

Comment thread lib/core/models.dart Outdated
totalOpens: totalOpens,
lastOpenedAtMs: lastOpenedAtMs,
hourlyOpens: hourlyOpens,
visits: visits,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 清除路線選擇紀錄時也要去除訪問紀錄內的站牌 ID。設定說明承諾清除「站牌使用紀錄」並保留路線開啟次數,但 clearSelections 原樣保留含 stopId 的 visits;learnedStopId 仍可讀取這些站牌並繼續用於推薦及提醒,而且它們仍會保存/同步。可保留 visit 時間但移除其 stop ID;請測試清除後已學站牌不再留存或被選用。現有測試反而斷言該 ID 保留。

Comment thread lib/screens/route_detail_screen.dart Outdated
/// nearest stop to somebody reading the timetable from across town says
/// nothing about their habits.
int? _usageStopHint() {
final opened = _findStopById(_currentPathStops, widget.initialStopId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 明確選擇的上車站應優先於開頁站,也不能只靠 ID 判斷是否為定位猜測。從 A 站開啟頁面後,在 10 秒訪問紀錄計時前手動選 B,這裡仍回傳 A;如果手選 B 恰好也是候選最近站,:3158 又會把它當成猜測,距離太遠時直接捨棄。多次操作後會把錯站學成常用站,影響推薦與無定位提醒。請保留選擇來源、先處理使用者選擇,並測試這兩種情況;目前為靜態追蹤,沒有 widget 實測。

return null
}
return SmartLiveStop(
sec = stop["eta"].asInt(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 依 eta_reference_at 修正 ETA 後再判斷是否趕得上。此解析丟棄參考時間,:425-429 直接用原秒數與 180 秒/步行門檻比較;上游快取會保留舊參考時間而不重新減去快取年齡。依上游快取測試支持的 15 秒延遲建模,參考時 190 秒的班次實際剩 175 秒,這裡仍視為符合 180 秒下限。舊版倒數顯示也未處理參考時間;此處問題限於本 PR 新增的可趕車門檻判斷。請處理參考時間、抓取延遲及缺值相容,補快取/步行門檻測試;190 秒例子不是實際觀測到的通知。

),
timeoutMs = SmartRouteReminderRules.timeoutMs(decision),
)
SmartRouteNotificationSupport.saveReminder(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 頻道被封鎖時不要把提醒記成已顯示。canPostNotifications 只檢查 App 層級與權限;使用者可以只把智慧提醒頻道設成 IMPORTANCE_NONE,此時 notify 不顯示通知,但這裡仍保存已顯示紀錄和全域/每日/路線限額。新的習慣模型會把該紀錄當作已送達,跳過缺席證據,影響後續學習。請在可檢查的頻道封鎖情境下避免寫入此回饋並補測;舊版已有 App 層級檢查與部分冷卻問題,本次回報範圍是新加入的已顯示回饋與限額。平台行為為文件與原始碼推導,非裝置實測。

Comment thread lib/core/smart_route_service.dart Outdated
if (profile.pathId == null) {
return null;
}
final evidence = RouteHabitEvidence.of(profile, now);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 首頁排名也應取得與此路線對應的提醒回饋。這裡使用預設空 reminders,但計畫建置會傳入已顯示提醒,模型需要它把提醒後、習慣時間前的點擊歸回原時段,也需要它避免將已看提醒但未開 App 誤判為缺席。來源追蹤顯示首頁 loadSuggestions 路徑從未提供該 log;例如多週在 07:26 的提醒後 07:27 點擊、原本習慣 07:40,模型計算在 08:37 的支援天數可從有回饋的 35 降為無回饋的 0,使首頁推薦消失。這個數值例是模型運算而非 Flutter 實測;請補涵蓋首頁消費者的回饋測試。

Comment thread lib/core/smart_route_service.dart Outdated
: 0.0;
final legacyScore =
legacyWeight *
legacyStrength(profile, now, datedDays: evidence.dayCount);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 遷移舊小時計數時,勿讓其他時段的使用天數提前取代本時段的舊證據。evidence.dayCount 是所有時段合計;原本有大量 07:00 紀錄的舊使用者,遷移後只有一筆可定日期的早晨紀錄,即使接下來六天只在 18:00 使用,同樣會使早晨 legacy handover 歸零,而早晨新模型又不足兩天,原本可推薦的早晨路線消失。原版仍會以早晨小時計數推薦。請以相關時窗的日期證據交接,或採其他不讓無關時段立即抹除舊信號的策略,補跨時窗遷移測試;目前為原始碼構造案例,非應用程式實測。

Comment thread lib/core/app_controller.dart Outdated
await ensureRecommendationDataReady();
final now = DateTime.now();
await _resolveSmartRouteIds(now);
await storage.saveSmartRoutePlan(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 必要的清除工作不應被新增的提醒計畫寫入失敗中斷。clearRouteUsageProfiles 先透過 _persistSmartRouteProfiles 清除本機 profiles,再等待此新 saveSmartRoutePlan;若這個寫入拋錯,後續清除 destination/account device payload 與新加入的 forgetSmartRouteReminders 都不會執行。舊版 scheduler 失敗已有部分清除風險,這裡的回歸是新計畫寫入/建置故障也被放進必要清除流程之前,且會留下新提醒 log。請讓清除嘗試所有必要儲存/遺忘動作並明確回報錯誤,補注入計畫寫入失敗的測試;目前未注入重現。

- Serialize reminder plan rebuilds; an overtaken rebuild writes nothing,
  and a failed one leaves no plan rather than an outdated one.
- Rebuild the plan after logout, favourite changes and database downloads.
- Clearing learned history attempts every step, forgets the reminder log
  before the rebuild, and reports the first failure at the end.
- Clearing selection history also drops the stop of each visit.
- A boarding stop the rider picks takes precedence when recording a visit.
- Cap plan slots per provider.
- Home recommendations read the reminder log as the plan does.
- Legacy hourly counters hand over by dated use around the asked time.
- Count feed ETAs down from eta_reference_at and reject old references.
- Re-read the plan before posting; skip blocked channels and a foreground
  app without logging a reminder.
- Only cancel the periodic work under a lock, from the plan as it is now.
@AvianJay

Copy link
Copy Markdown
Collaborator Author

感謝這輪審查。12 項都已修正,每項都補了測試,並用變異確認測試守得住(把修正改回去,對應測試會轉紅)。

計畫狀態與排程

  • [P1] 舊的重建寫回已清除的計畫:重建改為一次只跑一個,並用「過期」旗標擋住。等待期間輸入改變的重建不寫入、也不排程,最後一次寫入的一定是排在後面、看得到新狀態的那次。測試讓一次重建卡在讀 log,清除完成後才放行,確認最終計畫為空,且只有新的那次重建寫了計畫。
  • [P2] 登出及收藏變更沒重建:_restoreDeviceLocalRouteHistory、_persistFavoriteGroups、資料庫下載完成時都會重建計畫。測試涵蓋三個情境:登出後只剩本機路線、刪掉唯一收藏後時段不再帶該站、缺 DB 時計畫為空,下載完成後恢復。
  • [P2] Worker 依舊快照取消新排程:排程的「讀計畫→排程或取消」改在同一把鎖裡做。Worker 不再直接取消,改呼叫 cancelIfNothingLive,在鎖內重讀當下計畫,確認確實沒有有效時段才取消。Flutter 一定先寫計畫再要求同步,WorkManager 也會依呼叫順序執行(2.10.3 的 cancel 與 enqueue 都走同一個 serial executor),所以依舊計畫做的決定後面一定接著依新計畫做的決定。
  • [P2] 清除流程被計畫寫入失敗中斷:clearRouteUsageProfiles 每一步都會嘗試,最後才拋出第一個錯誤;提醒 log 在重建計畫之前清除。重建失敗時會移除計畫並同步排程,不留下舊計畫。另外,因收藏、下載、登出、同步設定而觸發的重建失敗,不會讓原本那個操作失敗。

學習資料

  • [P2] 清除選擇紀錄時沒移除站牌:clearSelections 保留造訪時間,但移除站牌 ID,因此不會再學到該站、不會被選用,也不會再同步出去。
  • [P2] 手選上車站被開頁站或定位猜測覆蓋:新增 _riderPickedBoardingStopId,只在使用者自己選上車站時設定。優先順序改為「手選 > 開頁站(含 App 內重新導向的站)> 400 m 內的最近站」,手選站即使剛好是最近站也照樣採用。邏輯抽成 usageStopIdFor 測試,另有 widget 測試:從站 3 開啟、在 10 秒內改選站 5,記錄到的是 5。

提醒判斷

  • [P2] 未依 eta_reference_at 修正:解析時把秒數倒數到收到回應的時刻再判斷能不能趕上;參考時間超過 5 分鐘就視為過期。秒數、毫秒、字串與 ISO-8601 格式都能讀;缺值時視為當下,與 App 其他地方的做法一致;參考時間比裝置時鐘晚則不加秒數。通知上的到站時刻也從同一個時刻起算。
  • [P2] 頻道被封鎖仍記錄已顯示:canPostNotifications 會檢查本頻道是否為 IMPORTANCE_NONE。發送改由 remind() 負責:送出前重讀計畫(時段已被清除、路線剛被開過,或要看的站已更換,就不發),並重新確認 App 不在前景、頻道可用,之後才寫入限額與 log。
  • [P2] 64 個時段上限各 provider 共用:上限改為每個 provider 各自計算。測試中另一城市有 15 條信心較高的路線,目前城市的路線仍保有時段。

首頁模型

  • [P2] 首頁沒讀提醒回饋:SmartRouteReminder 移到 smart_route_habit.dart,rankProfile、rankProfilesForTime、loadSuggestions 都接收提醒;controller 的兩個首頁入口會讀 log 後傳入。用您舉的例子測試:07:26 的提醒、07:27 點開、原本習慣 07:40,08:37 時沒有回饋就不推薦,有回饋則仍推薦且支援天數為 10。controller 層另以推薦理由文字(07:25 vs 07:40)確認首頁確實讀到 log。
  • [P2] 舊計數被無關時段的使用天數取代:交接改用「目前時段附近」的支援天數(estimate.supportDays),而不是全天的 dayCount。測試確認早晨舊計數不會因為連續六天只在 18:00 使用而歸零,但若早晨累積滿六天,仍會交接給新模型。

驗證(皆為本機):flutter analyze 無問題;Flutter 全部 661 個測試通過;Android 本機 :app:testDebugUnitTest 398 個測試通過、無跳過(CI 不跑 Android 單元測試)。其中 #117 既有的 RouteTripMonitorServiceTest.aRemovedFamilyVariantsInFlightResponseCannotReachTheConfirmedRide 在首輪偶發失敗一次,之後單獨重跑 3 次、全套重跑 1 次皆通過;本次沒有動到該程式路徑。變異檢查:Dart 17 個、Kotlin 10 個,全數被抓到(Dart 首輪有 2 個存活,補測試後已抓到)。仍未在實機上等背景通知實際跳出。

@Av1anJay Av1anJay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整合複審:請求修改

已檢查完整 base...head 差異、受影響的呼叫路徑與前次 12 項意見。先前各項原始情境已有修正;其中「清除站牌使用紀錄」及「手選上車站來源」仍有下列相關狀態轉換未涵蓋,另有一項新加入的 worker 候選回退問題。原意見分別見 清除站牌紀錄 與 上車站來源。前次 #117 的歷史分類沿用其已核對的原始情境。

驗證:exact-head CI 實際執行 flutter analyze、661 個 Flutter 測試與 2 個 Chrome 測試,均通過;CI 未證實執行 Android 單元測試。作者回報本機 Android 單元測試 398 個通過,但這次沒有可獨立核對的執行日誌。本機 JVM 編譯曾逾時;Android/Robolectric 與實機通知未獨立執行。下列交錯順序皆為原始碼推導,並非裝置實測。

hourlyOpens[hour] = (hourlyOpens[hour] ?? 0) + count;
});
selections.addAll(profile.selectionTimestampsWithin());
visits.addAll(profile.visits);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 避免同步後重新匯入剛清除的站牌使用資料。原本 清除紀錄意見 的單裝置情境已由 clearSelections 去除 visit 的 stopId 修正;但開啟路線紀錄同步且另一裝置留有舊 visit 時,clearRouteSelectionHistory 只清目前合併結果及本裝置 payload。下一次同步套用其他裝置 payload 時,這裡會把舊 visit 加回來,normalizeVisits 甚至可能把站牌 ID 合併回剛清除的同一筆 visit;learnedStopId 之後又能選用該站,與設定畫面承諾的清除站牌使用紀錄不符。請讓本機清除在後續同步後仍有效,並補多裝置舊站牌 → 本機清除 → 再同步的測試;不要求逕自刪除其他裝置雲端紀錄。此為靜態資料流追蹤,未執行跨裝置測試。

Comment thread lib/screens/route_detail_screen.dart Outdated
_currentPathStops,
_riderPickedBoardingStopId,
)?.stopId,
openedStopId: _findStopById(_currentPathStops, _requestedStopId)?.stopId,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 上車站狀態變更後,不要把過期的選擇來源寫入 visit。前次意見 的開頁 A → 手選 B 已修正,但若 10 秒記錄前手選 B 後按「回到目前位置」C,實際上車站已回到定位候選,這裡卻仍優先使用原開頁站 A,反覆發生會學到錯站。相關另一種轉換:手選 B 後在同一路線頁接到帶站 A 與有效目的地的啟動動作,_applyRequestedDestinationIfPossible 已把上車站換成 A,舊的 _riderPickedBoardingStopId B 卻仍優先被記錄。請在明確回到定位或新動作實際替換上車站時更新來源,並測這兩種轉換,同時保留原有手選優先行為。此為原始碼狀態追蹤,非 widget 實測。


// Whether or not it went out, this run is done. The next one
// starts again from the plan as it is then.
SmartRouteNotificationSupport.remind(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 第一個候選在送出前失效時,仍應重新檢查其他有效候選。此呼叫的 remind 若因新計畫已不含 A、A 剛被查看或站牌變更而回傳 false,迴圈仍無條件 break;即使原本同時到期的 B 仍可提醒,本輪也不再檢查。具體例子:較高信心的 A 取即時資料期間,使用者點首頁的 A 推薦,recordRouteSelection 立即重建計畫,隨即退到背景;A 的最後重查失敗,但 B 仍在有效視窗。現有 smart_route_plan_test.dart:16-46 的 B 時段到 08:10,若該順序發生在 08:10 的最後幾秒,下一次不精確的週期工作可能已錯過 B 當日視窗。請在此類候選特定失效後重新讀取目前計畫及全域限額,再決定是否嘗試其他路線;前景或頻道封鎖等全域原因仍應停止。這是依原始碼建模的交錯順序,並非 Android 實測。

@AvianJay

Copy link
Copy Markdown
Collaborator Author

感謝複審,這次的 3 項意見都已修正,包含測試,並在 commit 046ea52 推送。

  • 清除站牌使用紀錄後的多裝置同步:本機裝置 payload 會保留 selectionHistoryClearedAtMs。後續合併其他裝置資料時,清除時間以前的選擇時間戳與 visit 站牌 ID 會在本機端移除,但仍保留 route-open 時間證據;其他裝置雲端 payload 不會被刪除。也補了「遠端舊站牌 → 本機清除 → 再同步」測試。
  • 上車站來源狀態:加入目前位置來源狀態。按「清除手動上車站」後,即使定位候選之後重新填入狀態,也不會回用開頁站;帶有效上車站與目的地的新啟動動作會清除舊的手選來源。補了兩個 widget 測試,並保留手選站優先行為。
  • Worker 候選回退:某候選在 remind() 最後重查失效時,會重新讀取目前 plan、全域提醒限額與 due candidates,繼續嘗試尚未嘗試的其他候選;App 回到前景或通知頻道被關閉等全域原因仍會停止整輪。

本機驗證

  • flutter analyze --no-pub:無問題。
  • Flutter:665 個測試全部通過。
  • Android :app:testDebugUnitTest:399 個測試通過、0 失敗、0 跳過(CI 不執行這組 Android JVM/Robolectric 測試)。
  • git diff --check:通過。

仍未在實機上等待背景通知實際跳出;前次 #117 的 flaky 測試本輪未再出現。

@Av1anJay Av1anJay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent Review

Verdict: Changes Requested

已完成 exact head 046ea520c0c6aaef022ab22c27a4342f3b5618ef 的完整 base...head diff、35 個 changed files、受影響呼叫路徑、前次兩份 review、作者回覆、獨立 cross-check 與 CI step metadata。前次 review 的原始情境已按本次修改重新核對,未重複列為新問題;以下是 fix interaction/state-transition pass 仍可觸發的 4 個問題。

Findings

  • P1 — app_controller.dart:4394:清除選擇紀錄後,目的地選擇仍可能被同步復原。 merge 只對 route-usage profiles 套用 selectionHistoryClearedAtMs,destination-choice profiles 沒有同樣的時間界線;另一裝置的舊目的地選擇可在清除後重新合併,並被自動目的地流程使用。
  • P2 — app_controller.dart:3282:尚未建立裝置歷史 payload 時,清除 tombstone 不會保存。 _updateRouteHistoryDevicePayload 在沒有既有 payload、且尚未開啟同步時直接 return;之後才開啟同步,清除時間戳不存在,舊同步資料仍可回來。
  • P2 — app_controller.dart:4438:登出恢復 own-device payload 時繞過清除 tombstone。 merge 雖把 marker 放回本機 payload,但 logout restore 直接讀 raw profiles,可能重新帶回 marker 以前的 stop IDs 與 destination choices。
  • P2 — route_detail_screen.dart:1487:只有 boarding stop 的新 launch 不會清掉舊手選來源。 _applyLaunchFocus 更新 requested stop,但只有含 destination 的路徑才會進入這段清理;訪問計時到期時仍可能記錄上一個手選站,而不是新 launch 指定的 boarding stop。

Verification

Exact-head CI 的 Verify job 實際完成 flutter analyze、flutter test 與 Chrome route-geometry test;Android APK、Wear OS、Web、Windows、Linux、macOS、unsigned iOS build jobs 均成功。git diff --check 通過。Flutter/Dart 未安裝於本機;先前相同 source/toolchain fingerprint 的 JVM 嘗試曾逾時,因此未盲目重跑。Android JVM/Robolectric、實機背景通知與上述 Dart state transitions 未由此次 review 在本機執行;findings 是可由 source trace 驗證的 reachable transitions,不宣稱裝置重現。

No claim is made that this review proves zero remaining bugs.

前次相關原意見:清除站牌紀錄、跨裝置清除、上車站來源。

Comment thread lib/core/app_controller.dart Outdated
final remoteSelectionHistoryClearedAtMs = _selectionHistoryClearedAtMs(
remoteOwnPayload,
);
int? selectionHistoryClearedAtMs = localSelectionHistoryClearedAtMs;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 P1 — selection-history clear 不會套用到 destination choices。 這個 marker 已被計算出來,但下面的 destinationChoiceParts 迴圈仍直接收集每個 device 的舊 DestinationChoiceProfile,沒有像 route profile 那樣以 marker 過濾 timestamps。另一裝置保留清除前的選擇時,後續 merge 仍可讓 learnedDestinationChoice 自動選回已清除的目的地。請對 destination-choice timestamps/records 套用同一個 tombstone,並補非空 remote destination-choice 的測試。

Comment thread lib/core/app_controller.dart Outdated
await _updateRouteHistoryDevicePayload(
profiles: deviceProfiles,
destinationChoices: const [],
selectionHistoryClearedAtMs: DateTime.now().millisecondsSinceEpoch,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2 — tombstone 可能根本沒有被保存。 clearRouteSelectionHistory 在這裡傳入清除時間,但 _updateRouteHistoryDevicePayload 的第一行會在 _tracksDeviceRouteHistory == false 時直接 return。對尚未啟用歷史同步、也沒有既有 device payload 的已登入使用者,清除後再啟用同步不會有 selectionHistoryClearedAtMs;之後的 remote merge 仍可復原清除前的 selections/stops。請讓本機 clear marker 在這個狀態也持久化,並補「未啟用同步 → 清除 → 啟用同步 → merge」測試。

if (selectionHistoryClearedAtMs != null) {
// A response may echo an older copy of this device's bucket. Keep the
// local clear marker so a later merge cannot resurrect old stop ids.
effectiveOwnPayload['selectionHistoryClearedAtMs'] =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2 — logout restore 會繞過清除界線。 merge 會把 selectionHistoryClearedAtMs 留在本機 payload,但 _restoreDeviceLocalRouteHistory 直接從 payload 讀 raw profiles/destination choices,沒有套用 marker;若 own-device bucket 仍含清除前的 visits,logout 即可把已清除的 stop IDs 或 destination choices 放回本機。請在 restore 時套用 marker,並補 merge/echo 舊 bucket → logout 的測試。

// A launch action with an explicit boarding stop replaces an earlier
// manual choice; do not let that stale choice win when the visit is
// recorded later.
if (requestedBoardingStop != null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2 — boarding-only launch 仍保留 stale manual provenance。 requestedBoardingStop 和清除 _riderPickedBoardingStopId 的邏輯只位於 _applyRequestedDestinationIfPossible();但 _applyLaunchFocus() 對沒有 destination stop 的 boarding-only action 會在呼叫該方法時立即 return。因此先手選 B、再收到只指定 A 的 launch 時,visit timer 仍會由 _usageStopHint() 優先回傳 B,而不是新 launch 的 A。請在 boarding-only launch 也更新來源狀態,並補不帶 destination 的 widget/state test。

@AvianJay

Copy link
Copy Markdown
Collaborator Author

自動審查回報的 4 項問題已修正,並在 commit 51d0101 推送:

  • destination choices tombstone:清除邊界現在同時套用到 route visits 與 destinationChoiceProfiles;清除前的目的地選擇不會在合併其他裝置資料後恢復。
  • 首次同步遺失 tombstone:新增本機持久化的清除邊界。即使使用者先清除紀錄、之後才第一次開啟路線紀錄同步,裝置 payload 仍會帶 selectionHistoryClearedAtMs。
  • 登出恢復未套用 tombstone:從裝置 payload 恢復本機資料時,也會過濾清除邊界以前的站牌 visits 與目的地選擇。
  • boarding-only launch 保留舊手選站:只有上車站、沒有目的地的新啟動動作,現在會清除舊的手選來源並以新啟動站牌記錄 visit。

本機驗證

  • flutter analyze --no-pub:無問題。
  • Flutter:668 個測試全部通過。
  • Android :app:testDebugUnitTest:399 個測試通過、0 失敗、0 跳過(CI 不執行這組 Android JVM/Robolectric 測試)。
  • git diff --check:通過。

新增測試涵蓋:首次同步的目的地選擇 tombstone、登出恢復、目的地選擇模型,以及 boarding-only launch 的 widget 狀態轉換。

@Av1anJay Av1anJay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent 綜合審查

結論:Request Changes。這次重新檢查 exact head 的完整 PR diff、51d0101 相對前一版的 7 檔修正,以及受影響的同步、推薦、啟動與背景乘車狀態。前一輪四項問題在原始情境已修正,這裡不重複既有 exact-head inline threads:目的地 tombstone、首次同步 tombstone、登出恢復 tombstone、boarding-only 的舊手選來源。

目前仍有 5 項可由原始碼資料流驗證的 P2 問題,詳見行內意見:

  • 清除界線以未帶 accountId 的全域 SharedPreferences key 儲存,會跨帳號套用。
  • cold/local load 讀回 route/destination profiles 時未套用已持久化的清除界線。
  • boarding-only launch 更換上車站時保留可能不相容的舊目的地。
  • boarding-only launch 更換上車站時未重置 iOS Live Activity 的舊 ride state。
  • path change 暫時清掉 active boarding 後,舊 manual source 仍可在路徑返回時重新被採用。

驗證範圍與限制:isolated checkout 的 exact head 為 51d0101,git diff --check 通過。GitHub Actions exact-head Verify 實際執行並通過 Analyze、Test、Chrome route geometry;Android APK/AAB、Wear OS、Web、Windows、Linux、macOS、unsigned iOS build jobs 也通過。Flutter/Dart 在本機不可用;Android JVM/Robolectric 未獨立執行,沿用先前相同 source/toolchain fingerprint timeout、未盲目重試;背景通知實機行為未執行。以上問題是 static source/dataflow evidence,不宣稱已在裝置重現。


Reviewed by Hermes Agent against commit 51d0101.

Comment thread lib/core/storage_service.dart Outdated
static const _favoriteUsageProfilesKey = 'favorite_usage_profiles';
static const _stopVisitProfilesKey = 'stop_visit_profiles';
static const _destinationChoiceProfilesKey = 'destination_choice_profiles';
static const _selectionHistoryClearedAtKey =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2:清除界線跨帳號共用。 這個 marker 以未帶 accountId 的單一 SharedPreferences key 儲存;AppController 在切換登入帳號時只重載 account-specific sync state,仍會把這個 marker 套到下一個帳號的 device payload。情境:A 清除路線紀錄→登出→B 在同機登入且雲端仍有較舊有效資料。預期清除界線只影響被清除的帳號/命名空間,實際上 B 的資料可能被過濾,且 B 新 payload 可能帶上 A 的 marker。請將 marker 綁定帳號或在帳號切換時明確重置/隔離。證據:storage_service.dart:20-21,397-409、app_controller.dart:424-432,849-881,4184-4197。

Comment thread lib/core/app_controller.dart Outdated
final history = await storage.loadHistory();
final routes = await storage.loadRouteUsageProfiles();
final destinations = await storage.loadDestinationChoiceProfiles();
_selectionHistoryClearedAtMs = await storage

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2:冷啟動讀取未套用持久化清除界線。 這裡載入 marker,但下一行仍把儲存中的 raw route/destination profiles 直接放入 controller;filter 只在 sync merge/logout restore 執行。若清除流程在 marker 寫入後、profiles 寫回前被中斷,或同步不可用而本機殘留舊資料,重啟後 learnedDestinationChoice 等 consumer 仍可讀到清除前資料。預期 local load 在暴露給推薦/目的地/提醒前套用 marker;請補一致的 load-time filtering 或交易式儲存。證據:app_controller.dart:424-432,3212-3236。

_didScrollToInitialStop = requestedStopId == null;
_autoScrolledPathId = null;
if (replacesBoardingSource) {
_boardingStopId = requestedStopId;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2:boarding-only launch 會保留可能不相容的舊目的地。 這裡只替換 _boardingStopId,沒有檢查或清除既有 _destinationStopId。情境:畫面先有目的地 D,接著收到只有上車站 A 的 launch,且 A 已在 D 之後;_applyRequestedDestinationIfPossible() 對沒有 requested destination 直接 return,舊 D 留下。後續 trip monitor 仍收到兩個 ID,可能監控與實際新上車站不一致的旅程。預期 boarding-only 更換起點時清除/重新驗證目的地。證據:route_detail_screen.dart:1382-1387,1449-1453 及 trip monitor 的雙 ID consumer。

if (replacesBoardingSource) {
_boardingStopId = requestedStopId;
_boardingStopName = requestedBoardingStop?.stopName;
_riderPickedBoardingStopId = null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2:boarding-only launch 未重置 iOS Live Activity ride state。 手動 _setBoardingStop() 會先呼叫 _resetLiveActivityRideState(),但這個 launch replacement 只清 manual source。情境:iOS 已確認上車/開啟 boarding window,接著 launch 改選另一個上車站;舊的 confirmed/window/vehicle/alert state 會沿用,Live Activity 可能把新旅程顯示成已上車或抑制提醒。預期起點改變時和手動變更走同一個 ride-state reset。證據:route_detail_screen.dart:2762-2771,3305-3315。

if (replacesBoardingSource) {
_boardingStopId = requestedStopId;
_boardingStopName = requestedBoardingStop?.stopName;
_riderPickedBoardingStopId = null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ P2:path change 後舊 manual source 可重新復活。 這次新增的 _riderPickedBoardingStopId 只在 launch/manual-clear 等路徑清除;tab listener 在目前路徑不再包含 destination 時清 _boardingStopId,卻沒有清 _riderPickedBoardingStopId。情境:手選 A→切到不含 A 的 path、active boarding 被清除→在 visit timer 前切回原 path;_usageStopHint() 又會把仍存在的 A 當 picked stop 記錄。預期已被 path change 淘汰的 provenance 不應只因路徑回來就重新採用;請綁定 path 或在清除 active boarding 時同步清除 manual source。證據:route_detail_screen.dart:1209-1218,3213-3226。

@AvianJay

Copy link
Copy Markdown
Collaborator Author

最新 Hermes review 的 5 項問題已修正,並在 commit a8f62c6 推送:

  • 清除邊界跨帳號共用:移除全域 SharedPreferences marker,改放入 account-specific AccountSyncLocalState,切換帳號時不會把 A 的清除時間帶給 B。
  • cold/local load 未套用清除邊界:route history 載入前先載入 account state,並在載入 raw route/destination profiles 後立即套用清除邊界;若帳號狀態稍後才載入,也會重新過濾已載入資料。
  • boarding-only launch 保留舊目的地:更換 boarding source 時清除舊 destination,新的 launch 若帶 destination,後續再套用新目的地。
  • boarding-only launch 未重置 Live Activity:boarding source 改變時重置 ride、destination 與相關 alert state。
  • path change 後 stale manual source 復活:目前路徑不再包含 active boarding stop 時,同步清除 manual provenance,避免切回原 path 後重新採用舊手選站。

本機驗證

  • flutter analyze --no-pub:無問題。
  • Flutter:668 個測試全部通過。
  • Android :app:testDebugUnitTest:399 個測試通過、0 失敗、0 跳過;本輪沒有修改 Android 檔案,沿用前一輪相同 Android source 的本機結果。
  • git diff --check:通過。

上一輪的 4 項問題與這次的 5 項都已在目前 head a8f62c6 覆蓋。

@Av1anJay Av1anJay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermes Agent consolidated review

Verdict: Approve.

Reviewed the complete diff at exact head a8f62c6 against base dfa3cd2, including affected callers, state transitions, previous reviews, author replies, and independent route-detail and smart-route cross-checks. The five findings from the previous head are fixed in the current source flow. The new account/storage, route-detail, and Android reminder candidates were rejected as contradicted, unproven product-contract assumptions, or lacking endpoint/runtime evidence; no blocking finding remains.

Verification: exact-head GitHub Verify passed 668 Flutter tests and 2 Chrome route-geometry tests. Android APK, Wear OS, Web, Linux, macOS, and unsigned iOS builds passed. The Windows executable built successfully; the packaging job failed later while installing NSIS through Chocolatey. Local Flutter/Dart was unavailable; Android JVM/Robolectric used the previously recorded identical-fingerprint timeout and was not retried; device/background-notification behavior was not independently executed.

Reviewed by Hermes Agent against the exact commit.

@AvianJay
AvianJay merged commit 02c0cdf into main Nov 21, 2026
17 of 18 checks passed
@AvianJay
AvianJay deleted the feat/smart-recommendation-algorithm branch November 21, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants