fix(extension): stop fragmenting Included Memories that contain commas or newlines#1339
Open
abhay-codes07 wants to merge 1 commit into
Open
Conversation
…ines The Included Memories popup stores the memory list on a data-* attribute by joining it into a single string (String(response.data) / response.data), then reads it back by splitting on [,\n] in showMarkerPopover and in the T3 popup. Memory text is free-form and frequently contains commas and newlines, so a single memory was fragmented into several rows. In T3 that also desynced the per-item delete: the clicked index no longer mapped to a real memory, so removal spliced the wrong entry and rewrote the injected prompt from the mangled list. Store the list as JSON on the attribute and parse it back, so a memory with a comma or newline survives as one item. serializeMemoriesForDataset returns an empty string for an empty list so existing "memories present" truthiness checks on the attribute are unchanged, and parseMemoriesFromDataset falls back to the old delimiter split for any legacy value. This is confined to the popup's own display data: the GET_RELATED_MEMORIES response and the injected dataset.supermemories prompt text are left exactly as they were, so recall behaviour does not change. Applied consistently across ChatGPT, Claude, Gemini and T3, with unit tests for the round-trip.
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.
Follow-up to #1261, rebuilt to stay within the current architecture. That PR was closed because it changed the shared
GET_RELATED_MEMORIESresponse format and regressed auto-recall. This version does not touch that contract at all. It fixes only the one data-handling bug from #1257 that survived thememory-suggestion.tsrefactor, and it does so entirely inside the popup's own display data.The bug
The Included Memories popup stores the memory list on a
data-*attribute by joining it into one string, then reads it back by splitting on[,\n]:iconElement.dataset.memoriesData = String(response.data)(chatgpt.ts, claude.ts, gemini.ts) and= response.data(t3.ts)memories.split(/[,\n]/)inshowMarkerPopover(memory-suggestion.ts) and in T3's popup list and delete handlerMemory text is free-form and regularly contains commas and newlines, so one memory gets shredded into several rows. For example "Lives in Austin, Texas" shows as two entries. In T3 it is worse than cosmetic: the per-item delete indexes into that split list, so removing an entry splices the wrong item and then rewrites the injected prompt from the mangled result.
The fix
Store the list as JSON on the attribute and parse it back, so a memory with a comma or newline round-trips as a single item:
serializeMemoriesForDataset(memories)— JSON, returns""for an empty list so the existing "are there memories" truthiness checks on the attribute keep working unchanged.parseMemoriesFromDataset(raw)— parses the JSON, and falls back to the legacy[,\n]split for any value written by older code, so nothing breaks on upgrade.Applied consistently across all four consumers (ChatGPT, Claude, Gemini, T3).
Why this preserves the contract
The change is confined to
dataset.memoriesData, which only feeds the popup UI. TheGET_RELATED_MEMORIESmessage is untouched (still an array of raw strings), and the injecteddataset.supermemoriesprompt text is byte-for-byte the same as before (T3's initial injection still uses${response.data}, and its delete-path re-injection still uses the same joined form). So what the model sees, and therefore recall behaviour, does not change.Tests
memory-suggestion.test.ts(bun:test, followingsearch-request.test.ts) covers the round-trip: comma-bearing and newline-bearing memories stay single items, trimming/empty handling, empty-list serializes to"", and the legacy-split fallback. 7 tests pass. Extensiontscis clean for these files (the remainingnew_logo.pnggetURLoverload errors are pre-existing onmain). cc @ishaanxgupta