Skip to content

fix(desktop): resolve overlapping mention recipients by span#2939

Draft
yinkev wants to merge 1 commit into
block:mainfrom
yinkev:fix/mention-longest-match
Draft

fix(desktop): resolve overlapping mention recipients by span#2939
yinkev wants to merge 1 commit into
block:mainfrom
yinkev:fix/mention-longest-match

Conversation

@yinkev

@yinkev yinkev commented Jul 26, 2026

Copy link
Copy Markdown

Summary

  • resolve outgoing mentions by their concrete text spans instead of independently accepting every candidate whose name is a prefix of the visible mention
  • preserve an explicit autocomplete selection when its display name occurs once; when later edits create multiple occurrences, stop treating that name-only record as a global preference
  • for pasted/manual ambiguous text, choose the longest exact display name within each overlapping span
  • keep separate intentional short-name and long-name mentions independent, so both identities are emitted only when both spans are actually present
  • move recipient extraction into a focused helper, keeping useMentions.ts below the repository's file-size limit

Before this change, @OriginalName copy matched both OriginalName and OriginalName copy, so Desktop emitted two p tags and could start two distinct managed agents even though the composer visibly named only the copy.

Related issue

Fixes #2909

No competing implementation was found before opening this PR. Related historical mention work addresses autocomplete or other routing mechanisms, not outgoing overlapping-span tag extraction.

Testing

  • focused mention and outgoing-recipient regressions — 35 passed
  • pnpm typecheck
  • full Desktop test suite — passed
  • pnpm build
  • Biome format/check on all changed files
  • git diff --check

The repository-wide just ci frontend file-size step still reports the existing untouched desktop/src-tauri/src/managed_agents/runtime.rs upstream violation. PR #2930 restores that ratchet without changing runtime behavior and has a fully successful GitHub CI run. After extracting the new recipient helper, useMentions.ts remains below its 1,000-line limit.

@yinkev

yinkev commented Jul 26, 2026

Copy link
Copy Markdown
Author

@codex review

@yinkev
yinkev force-pushed the fix/mention-longest-match branch from 709ebbd to 97f3c3a Compare July 26, 2026 09:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97f3c3a2c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

candidate.displayName ? [candidate.displayName] : [],
),
],
selectedNames,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope selected-name preference to its original span

Passing every autocomplete-selected name as a global preference applies that preference to all matching spans, not only the selected occurrence. For example, after selecting @OriginalName and then manually pasting @OriginalName copy later in the same message, resolving @OriginalName then @OriginalName copy with the short name selected returns only OriginalName; the short prefix wins at both spans and the intended longer recipient is omitted. Preserve selection metadata per occurrence, or restrict preference so an earlier selected short mention cannot override an independent longer span.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the current head. A name-only autocomplete record is now preferred only while that display name has one occurrence in the current text. If later edits create another occurrence, each span returns to longest-match resolution, so an earlier selected short mention cannot suppress a later independent longer mention. Added the exact selected-short + pasted-long regression; all 35 focused mention tests pass.

Signed-off-by: Kevin Yin <182213728+yinkev@users.noreply.github.com>
@yinkev
yinkev force-pushed the fix/mention-longest-match branch from 97f3c3a to cc3fe80 Compare July 26, 2026 09:39
@yinkev

yinkev commented Jul 26, 2026

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc3fe80bae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +84 to +88
const displayNames = [...selectedPersonaMentions.keys()];
const resolvedDisplayNames = new Set(
resolveMentionedNames(text, displayNames, displayNames).map((name) =>
name.toLowerCase(),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve persona spans against competing pubkey mentions

When a shorter persona and a longer pubkey identity have both been selected, then the shorter mention is deleted so only the longer text remains (for example, persona OriginalName followed by managed agent OriginalName copy), this resolver considers only persona names and still interprets the prefix as the persona mention. createMentionedPersonaAgents consequently provisions the unintended persona, while the pubkey resolver—whose candidate set includes both names—correctly chooses only the longer identity. Resolve personas using the same competing selected/candidate names so both extraction paths agree on the visible span.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Mentioning a longer display name also tags its shorter prefix

1 participant