mcp: intern element handles instead of minting one per mention
`element_to_handle` inserted a new arena slot on every call, so an element mentioned in two replies received two handles. Repeated queries therefore consumed the 10 000 slot budget for elements that were already tracked, and the LRU evicted handles the client was still holding. Driving an editor with a few hundred cards on screen minted roughly 8 000 handles for the same 400 elements. Look the element up first and reuse its slot. `ElementHandle` compares by pointer and doesn't hash, so the lookup buckets candidates by the item index and element index that equal elements share, then compares within the bucket. Entries whose slot was evicted, or whose element is gone, are dropped as they are encountered, so eviction and destruction need no extra bookkeeping. Handles now stay stable for as long as the element lives, which the server's instructions state so a client knows it can hold on to them. ChangeLog: The MCP server now returns the same handle for an element across queries, instead of a new one each time.
T
Till Adam committed
ad845df1833190b82c6d997d800109ea95011245
Parent: 80459a2
Committed by Simon Hausmann <hausmann@gmail.com>
on 9/9/2026, 12:22:06 PM