Repository navigation
fix(drawer): show pull request badges for chats not yet opened - #450
Merged
Merged
Conversation
The drawer's pull request marker only appeared after a chat had been opened: the session-to-pull-request association was recorded by the open chat's view model and merely persisted for later runs. Every chat the user had not visited since the feature shipped showed no badge. Scan the transcripts of the chats the drawer is about to show and record the pull requests they link, so the badge is there on the first look. Reads run one at a time, only when a session's updated time differs from the last scan, and never for the chat that is open (its view model already tracks it live). Also serialize the session-store read-modify-write now that the drawer's scan can record a chat while the open chat records its own.
Contributor
|
Debug APK built successfully Download APK artifact Commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
ドロワーの各チャット行に出る PR 状態アイコンが「そのセッションを一度開くまで表示されない」問題を修正します。
従来は、開いたチャットの
ChatViewModelがセッション→PR の紐付けをPullRequestStatusRepositoryに記録し、永続化するだけでした。そのため、機能追加後に一度も開いていないチャット(他クライアントで作られた PR を含む)は、開くまでバッジが出ませんでした。SessionPullRequestDiscoveryを追加core/apiにOpenCodeMessage用の PR 抽出(pullRequestRefsIn)を追加し、チャット側の「1パートが1つの PR を名指すときだけ」ルールを共通ヘルパー化time.updatedが変わったセッションのみ、オープン中のセッションとサブエージェントは除外。失敗時は60秒クールダウンPullRequestStatusRepositoryのセッション保存をプロセス共有ロックで read-modify-write 排他化(アプリ生成インスタンスと Koin インスタンスが同じストアを書き込むため)refreshTrackedSessions()をドロワーオープン時の effect(ジェスチャー開閉を含む)へ移動テスト
OpenCodePullRequestRefsTest: テキスト/ツール出力・エラーからの抽出、複数リンクの一覧除外、最新5件の順序SessionPullRequestDiscoveryTest: 走査と記録、未変更の再走査抑止、更新後の再走査、オープン中/サブエージェントの除外、失敗クールダウンPullRequestLinksTest/PullRequestStatusRepositoryTest/ChatViewModelPullRequestTestと論理等価Pre-PR review
判定: APPROVE
ブロッカー
提案(非ブロッキング)
app/src/main/java/com/yugahashimoto/andcode/data/repository/SessionPullRequestDiscovery.kt:32—scannedRevision/retryAfterは削除済みセッションの id を保持し続けるため、長寿命プロセスで無視できる程度ですが単調増加します。気になるなら prune を検討してください(現状は実害なし)。app/src/main/java/com/yugahashimoto/andcode/ui/AndCodeApp.kt:1035— 初回ドロワーオープン時は可視チャット(最大25件)の未走査トランスクリプトを逐次listMessagesします。ローカルは安価ですがリモートでは 25 回の HTTP になり得ます。必要なら同時実行上限や初回バッチの方針を検討してください(現状のスコープでは許容範囲)。app/src/main/java/com/yugahashimoto/andcode/data/repository/SessionPullRequestDiscovery.kt:41—discoverのジョブはapplicationScope上で走り、ドロワーを閉じても最後まで継続します。閉じたら即座に止めたい場合は effect 側onDispose/DisposableEffectでキャンセルする手もあります(軽微)。app/src/main/java/com/yugahashimoto/andcode/ui/AndCodeApp.kt:1035—refreshTrackedSessions()がdiscoveryKey変化ごとにも走るようになりました(従来は開いた瞬間のみ)。StateFlow の equals で無駄な emit は抑えられますが、厳密に「開いた時だけ」にしたいならisOpen遷移専用の別 effect に分けてもよいです。app/src/test/java/com/yugahashimoto/andcode/data/repository/SessionPullRequestDiscoveryTest.kt— discovery 単体は良好にカバーされていますが、「discovery の結果がPullRequestStatusRepositoryのsessionStatusesに反映される」結合は未テストです。余力があれば 1 本追加すると退行検知が強くなります。チェック済み項目
git diff origin/main...HEADの全 8 ファイル・全ハンクを精読し、追加/削除/改名の整合を確認。rg -Uとrg '[ \t]+$'で確認)。max_line_length=140超え行なし(detekt 設定と照合)。import 順は既存ファイルのkotlinx → java順と一致し、ktlint 1.2.1 の既存パターン(state =\n mapOf(、key to\n Value()とも一致することを確認。SessionPullRequestDiscovery: サブエージェント除外、オープン中セッション除外、time.updated ?: createdの revision ゲート、失敗時の 60s クールダウン、CancellationExceptionの再送出、ConcurrentHashMap利用をテストと突き合わせて確認。pullRequestRefsIn(OpenCodeMessage)の newest-first /takeLast(5)をOpenCodePullRequestRefsTestと照合([8,7,6,5,4] 期待と一致)。singlePullRequestIn(Tool)の output+error 重複除去も確認。feature/chat/PullRequestLinks.ktの抽出共通化が既存ChatViewModelPullRequestTestと論理等価(Text=単一リンク、Tool=output/error の distinct→singleOrNull)であることを確認。PullRequestStatusRepository: プロセス共有private companion objectロックが、AndCodeApplication生成インスタンスと Koin 生成インスタンス(AppModule.kt:203)双方の read-modify-write を直列化することを確認。sessionStoreは同一EncryptedPreferencesを読み書きし、refreshTrackedSessionsの再読込も同ロック内で安全。track()はロック外で呼ばれデッドロックなし。AndCodeApplicationの初期化順(pullRequestStatusRepository→runtimeRegistry→sessionPullRequestDiscovery)と、AndCodeAppの手組み factory が同じ app インスタンスを使うことを確認。app.sessionPullRequestDiscoveryのprivate setアクセスも問題なし。discoverySessions/discoveryKeyの Compose 挙動:LaunchedEffectはList<String>の構造的 equals で再起動せず、バッジ到着でスキャンが再走しないこと、allSessionsはメッセージイベント毎ではなくカタログ更新時のみ変化するため starvation しないことを確認。AppDrawerContent.ktの並べ替え + strings 削除)が本ブランチのファイルと競合せず、browsableSessions(recentSessions)の前提(既定上限25)も維持されていることをgit show origin/main:.../AppDrawerContent.ktで確認。scripts/new-worktree.sh由来の worktree(.worktree/fix/recent-chat-preview-not-loaded)上にあり、origin/mainを base としていることを確認。