fix(sessions): keep attachment references a rewritten message still points at - #2236
fix(sessions): keep attachment references a rewritten message still points at#2236mattzcarey wants to merge 1 commit into
Conversation
…oints at Writers derived attachment references only from media extracted on that write, so a message written back in its stored pointer form lost its reference on update (and the payload was collected under a live pointer) or took none when appended under a new id. extractAttachments now reports every address the stored message points at, and append/update/import record those.
|
🟡 agents import sizesMeasured 336 runtime imports as minified bundles. The primary size is gzip; raw minified size is included for diagnosis. An existing import growing by more than 10% is marked red. This report is informational.
Compared Changed imports (1)
All 336 current runtime imports
Reported by agent-think[bot]. |
The bug
Sessions stores a message's media out of the row as a content-addressed pointer (
attachment:sha256:<hash>in the field that held the payload) and gives the payload its lifetime throughcf_agents_session_attachment_refs: when the last reference goes, the bytes are collected.The writers derived those references only from media extracted on that write (
extractAttachments(...).attachments). A part that already carries a pointer is not inline media, so it extracts to nothing. That gives two hazards for any message written back in its stored form — a read whose payload did not resolve, or host code that works on the row:updateMessagecollects the bytes under a live pointer.replaceRefs(id, [])drops every reference the message held and#collectdeletes the meta and chunk rows unless another message shares the hash. The row keeps its pointer, so the message is permanently unresolvable. The byte-identical no-op guard hides this only when nothing else in the message changed.appendMessage/importMessageof a pointer-form copy under a new id records no reference. The copy free-rides on the original's reference, and the bytes are collected as soon as the original is deleted or its session cleared.The fix
extractAttachmentsnow reportsreferences: every address the stored message points at — payloads extracted on this pass plus pointers it already carried.append,updateandimportrecord those instead of the extracted subset. References follow what the row says, not what one write happened to extract.No change to what is stored, read, or billed for messages that carry inline media or none. The new test fails on
mainand passes here.Tests
packages/agents:pnpm vitest --run --project workers src/tests/sessions— 75 passed (1 new: pointer-form update keeps its reference; pointer-form copy under a new id survives deleting the original).oxfmt --check .,oxlint,tsc --noEmit(packages/agents): clean.