fix(store): agent prompt の take で所有確認後にのみ削除し他 worktree の prompt 消失を防ぐ#258
Merged
Conversation
take はファイルを読み込んだ直後に所有権を確認せず無条件で remove_file して いたため、ハッシュ衝突や別マシンから同期された stale ファイルが自分の計算名に 存在すると、本来の所有 worktree の queued prompt を黙って削除していた(silent data loss)。 所有権を確認してから削除するように変更する。 - 自分のもの(worktree == key): prompt を返し、ファイルを削除(one-shot 配信)。 - 別 worktree のもの(parseable だが key 不一致): 削除せず None を返し、 本来の所有者が take できるよう残す。 - パース不能な壊れたファイル: 誰にも配信できないため削除して None。 - 存在しない: そのまま None。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📊 Test Coverage
🎉✨ パーフェクト!全ファイル Lines カバレッジ 100% を達成しました 🏆🐰 |
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.
目的
agent_prompt_store::takeが queued prompt を読み込んだ直後、所有権を確認する前に無条件でfs::remove_fileしていたため、別 worktree の prompt を黙って消す silent data loss の経路があった。これを塞ぐ。具体的な失敗モード:
DefaultHasherハッシュ。ハッシュ衝突で別 worktree のファイルが自分の計算名に居座ると、takeはそれを削除してしまう(呼び出し元にはNoneを返すが、本来の所有者の prompt は永久に失われる)。setが削除される(prompt の取りこぼし)。変更内容
src/infrastructure/agent_prompt_store.rsのみ変更。takeを「所有確認してから削除」に変更:worktree == key): prompt を返し、ファイルを削除(one-shot 配信は維持)。Noneを返し、本来の所有者が take できるよう残す。None。None。json_file::readのOk(Some)/Ok(None)/Errをmatchで分岐し、削除するのは「自分のもの」か「パース不能」のときだけにした。モジュール冒頭のドキュメントコメントも実態(衝突ファイルは所有者のために残す)に合わせて更新。テスト・確認方法
in-file テストで全分岐を網羅:
set_then_take_round_trips_and_is_one_shot— 正常な所有者一致パス(prompt 返却・ファイル削除)。a_file_queued_for_another_worktree_reads_as_absent_and_is_preserved— key B で take しても A 所有ファイルは 削除されず残ることを確認(本 PR の主眼)。a_corrupt_file_reads_as_absent_and_is_cleared— パース不能ファイルはNoneを返し削除される。distinct_worktrees_queue_independently/set_replaces_a_previously_queued_promptも維持。品質ゲート(worktree から実行):
cargo fmt— 通過cargo clippy --all-targets -- -D warnings— 通過cargo test— 1402 + 統合テスト全て通過(agent_prompt_store の 7 テスト含む)🤖 Generated with Claude Code