recordToTurn calls blocksOf(rec.Message.Content), and then toolIDs(&rec)
calls it again on the same bytes to collect tool-call identifiers. The largest
line in a local store is 4.3 MB, so that is a second multi-megabyte unmarshal
for a result already computed.
The duplication is also the only place where the two walks could be made to
diverge by a later edit — they agree today because both select tool_use blocks
from the same slice in the same order.
Fix
Have recordToTurn return the identifiers alongside the turn, and delete
toolIDs.
recordToTurncallsblocksOf(rec.Message.Content), and thentoolIDs(&rec)calls it again on the same bytes to collect tool-call identifiers. The largest
line in a local store is 4.3 MB, so that is a second multi-megabyte unmarshal
for a result already computed.
The duplication is also the only place where the two walks could be made to
diverge by a later edit — they agree today because both select
tool_useblocksfrom the same slice in the same order.
Fix
Have
recordToTurnreturn the identifiers alongside the turn, and deletetoolIDs.