Skip to content

fix: keep activity group keys unique when Claude reuses tool call ids - #226

Merged
yuga-hashimoto merged 2 commits into
mainfrom
fix/activity-duplicate-key
Aug 8, 2026
Merged

fix: keep activity group keys unique when Claude reuses tool call ids#226
yuga-hashimoto merged 2 commits into
mainfrom
fix/activity-duplicate-key

Conversation

@yuga-hashimoto

Copy link
Copy Markdown
Owner

概要

Claude Code はリトライ時に tool_use の call id(toolu_...)を再利用するため、別々の activity グループが同じ先頭パーツ ID を持つことがあります。これが LazyColumn のキー(activity:${first part id})として衝突し、下記のクラッシュが発生していました。

java.lang.IllegalArgumentException: Key "activity:toolu_..." was already used.
If you are using LazyColumn/Row please make sure you provide a unique key for each item.

修正内容

groupConversationTimeline で、同じ先頭パーツ ID で始まるグループが何回目かをカウントし、2回目以降は activity:<id>:<n> というサフィックス付きキーにします。1回目は従来どおり bare id を維持するため、成長中のラン(ストリーミング中)の ID は安定したままです。

テスト

  • 同じ toolu_ ID で始まる複数グループでもキーが一意になることを検証
  • 1回目のグループが bare id を維持すること
  • ランの成長後も ID が安定すること

Claude Code reuses tool_use call ids (toolu_...) across retries, so two
distinct activity runs can both begin with a part of the same id. The
group key was 'activity:${first part id}' which then collided inside
LazyColumn, crashing with IllegalArgumentException. Tag repeat groups
with an occurrence suffix while keeping the bare id for the first run,
so a growing run's identity stays stable as its steps stream in.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment on lines 91 to 99
fun flush() {
if (pending.isEmpty()) return
entries += TimelineEntry.Activity("activity:${pending.first().id}", pending.toList())
val firstId = pending.first().id
val occurrence = firstIdOccurrences[firstId] ?: 0
firstIdOccurrences[firstId] = occurrence + 1
val id = if (occurrence == 0) "activity:$firstId" else "activity:$firstId:$occurrence"
entries += TimelineEntry.Activity(id, pending.toList())
pending.clear()
}

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.

[bug · high]
詳細シート(findActivityParts)の再解決が、この suffix schemeで壊れます。"activity:toolu_stream:1" は生成時のカウントで決まるため、messages が 1 つ進むたびにオフセットがずれて(1)既に開いているシートが別のグループの内容に置き換わる/(2)該当 id が見つからずシートが急に閉じる、という事象が起こります。これはコメントで主張している「growing run's identity stays stable」と矛盾します。

「連続で登場する index」ではなく「グループが満たす条件そのもの」で id を決める(例: 同一 firstId の連続出現をまとめ、suffix を覆居的な順序としない、または findActivityParts で suffix から n 番目の出現を解決する)方法に変えることを検討してください。少なくとも、_findActivityParts が開いている sheet の id を安定的に再解決できること_を保証する必要があります。

@yuga-hashimoto
yuga-hashimoto merged commit d6cb754 into main Aug 8, 2026
5 checks passed
@yuga-hashimoto
yuga-hashimoto deleted the fix/activity-duplicate-key branch August 8, 2026 13:42
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.

1 participant