Repository navigation
fix(input): stop placeholder ids from being recycled and clobbering live placeholders - #998
Merged
will-lamerton merged 3 commits intoAug 30, 2026
Conversation
Placeholder lookup was done with a hardcoded /\[Paste #(\d+): \d+ chars\]/ regex that parsed the map key back out of the rendered label. That tied three separate concerns to one value and broke in three ways: - @file mentions were invisible to it, so deleting a mention's text left its entry stranded in placeholderContent forever. - assemblePrompt replaced via String.replace(displayText, ...), which only substitutes the first match, so two placeholders rendering identically left one unexpanded and shipped a raw "[Paste Nano-Collective#2: 287 chars]" to the model. - deletePlaceholder interpolated the id into a RegExp, needing sanitization and a nosemgrep suppression to stay safe. Add findPlaceholderOccurrences, which scans the display value for each entry's own display text and gives every entry its own position. Deletion, assembly and cursor lookups all go through it, so they work for every placeholder type and never confuse duplicates. Dropping the constructed RegExp removes the injection concern outright, so the sanitizing and the suppression go too. Two deletePlaceholder specs were passing for the wrong reasons: they called a stale first-render snapshot of the hook, which blanked the input and made the assertions vacuously true, and one ended in a bare t.pass(). They now drive the live hook, keep the map key distinct from the display label, and assert the resulting string exactly.
Both handlers numbered placeholders from how many entries were currently alive: const pasteId = (existingPasteCount + 1).toString(); Count-based numbering frees an id the moment its placeholder is deleted, so the next allocation lands on a key that is still in use. Paste twice, delete the first, paste again: the third paste is handed id "2" and overwrites the second paste's content, leaving two chips both labelled "[Paste Nano-Collective#2: ...]". Allocate from the highest id ever used instead, and namespace by type (paste_1, file_1) so the two kinds can never share a key. Legacy bare-numeric paste keys are still recognised, because prompt-history persists InputState to disk and older sessions replay it. The visible "#N" is now a display counter carried in displayText rather than the map key, so chunked-paste continuation restates the existing label via resizePasteDisplayText instead of rebuilding it from the id. Note the collision in the original report - paste ids overwriting @file mentions - was never possible: file mentions have been keyed file_N since the feature shipped. The reported symptom came from this reuse instead.
semgrep's detect-non-literal-regexp flagged
new RegExp(`^${prefix}_(\\d+)$`)
as a possible ReDoS vector. The prefix only ever comes from a fixed record
keyed by PlaceholderType, so it was not reachable from user input, but the
regex was not needed either: a startsWith on the marker plus a hardcoded
/^\d+$/ on the remainder does the same job and is simpler to read.
No behaviour change; the allocator specs cover it.
arpan7sarkar
force-pushed
the
fix/placeholder-id-collision
branch
from
August 28, 2026 11:14
40d6f2f to
564ebb1
Compare
Member
|
Great work @arpan7sarkar :) |
will-lamerton
added a commit
that referenced
this pull request
Aug 30, 2026
Placeholder lookup matches on each entry's display text, so paste entries persisted to prompt history before placeholders carried a displayText were skipped: their label survived into the assembled prompt and reached the model as literal text instead of expanding to the pasted content. Rebuild the label for those entries from the ordinal in their key and the content they hold, restoring the legacy fallback that the display-text lookup replaced in #998.
2 of 8 tasks
Contributor
Author
|
Thanks @will-lamerton , It's really great to be part of building something meaningfull for the community :-) |
14 of 18 tasks
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.
Description
Closes #969
Paste placeholder ids were numbered from the count of live entries (
existingPasteCount + 1), so deleting one freed its id for reuse.Paste twice, delete the first, paste again: the third paste got id
2and overwrote the second paste, destroying its content and leaving two chips labelled#2- one of which reached the model as literal text.Ids are now namespaced by type (
paste_1,file_1) and allocated from the highest id ever used, so a deletion can never free one.Placeholder lookup matches on each entry's own display text instead of a paste-shaped regex, which also makes
@filementions delete atomically instead of leaving an orphan entry.Note: the reported paste/
@filecollision was never possible - mentions have been keyedfile_${n}since the feature shipped.The symptom was real but came from reuse within the paste keyspace.
Also included: a 9-line fix for 51 pre-existing failing specs in
source/vscode/, where the harness never loaded the newuri-utils.js/slash-command-utils.jswebview helpers.Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)pnpm test:ava- 6664 passed, 0 failed. Types, lint, format and knip clean;test:auditandtest:securityneed network and were left to CI.Manual Testing
No provider round-trip is involved - the defect lives in input state, before anything is sent.
To check in the TUI: paste a multi-line block twice, backspace once into the first chip, then paste again. Before, two chips read
#2; after,#2and#3.Checklist