Skip to content

fix(app): only attach comment @mentions that exist - #62242

Merged
Tarquinen merged 7 commits into
devfrom
mention-file-guard
Nov 6, 2026
Merged

Tarquinen merged 7 commits into
devfrom
mention-file-guard

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Closes #50393

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The app attaches every @word in a line comment as a file. A comment like Check @here and @src/app.ts attaches a file called here. The server can't read it, so it rejects the whole prompt with a 400 and the send fails.

Now the app checks which comment mentions exist before sending and only attaches those. It lists each mention's parent folder, the same check the files model uses. Mentions that don't exist stay as plain text in the comment.

#50526 and #52877 only attached mentions that looked like paths. This checks the file itself, so @Makefile and folders like @src/ still attach.

How did you verify your code works?

  • Ran the app against a dev server and sent a comment with Check @here, @Makefile and @src/app.ts please. On dev the send fails with a 400. With this PR it sends, attaching Makefile and src/app.ts and skipping here.
  • The quote test in submit.test.ts now includes @here. It fails without the fix.
  • The packages/app composer tests, bun typecheck and bun run check pass.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" font-family="ui-monospace,Menlo,monospace" font-size="11">
  <style>
    .ghost{animation:ghost 4s ease-in-out infinite}
    @keyframes ghost{0%,30%{opacity:.6}50%,90%{opacity:0}100%{opacity:.6}}
    @media (prefers-reduced-motion:reduce){.ghost{animation:none;opacity:0}}
  </style>
  <rect x="1" y="1" width="238" height="70" rx="10" stroke="currentColor" stroke-opacity=".2"/>
  <text x="14" y="24" fill="currentColor" fill-opacity=".6">Check @here, @Makefile, @src/app.ts</text>
  <rect x="14" y="36" width="68" height="22" rx="6" stroke="currentColor" stroke-opacity=".5"/>
  <text x="22" y="51" fill="currentColor">Makefile</text>
  <rect x="90" y="36" width="60" height="22" rx="6" stroke="currentColor" stroke-opacity=".5"/>
  <text x="98" y="51" fill="currentColor">app.ts</text>
  <g class="ghost">
    <rect x="158" y="36" width="46" height="22" rx="6" stroke="currentColor" stroke-dasharray="3 3"/>
    <text x="166" y="51" fill="currentColor">here</text>
  </g>
</svg>

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Fixes #62197

@opencodejr opencodejr 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.

Looks good. The bot's #50393 reproduction fails on dev (@here, @channel and @everyone are attached as file:///repo/<word>) and passes with this change. Path-like mentions (@src/shared.ts, @~/x, @foo#L3) are still attached. request.test.ts passes, and tsc -b in packages/app passes. I tested at the unit level; the change is in the app's prompt builder, so the TUI is unaffected.

Public API: unchanged. The files field of the prompt request just stops listing bare @words from comment text.

The same parser handles quote comments, so this also stops the 400 "Unable to read attachment" failure in #62197, where an unpicked @prototype blocked sending. As the description says, a root-level dotless file like Makefile or Dockerfile picked from the comment editor's @ menu is now inserted as @Makefile and no longer attached. If that matters later, the menu could insert @./Makefile for such paths.

Fixes #62197

@opencodejr opencodejr 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.

The new commit only merges dev; the fix itself is unchanged. I re-ran the #50393 reproduction: bare @here, @channel and @everyone are still attached as files on dev and are dropped with this branch, while path-like mentions are still attached. request.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.

@Tarquinen Tarquinen changed the title fix(app): ignore bare @words in comment mentions fix(app): only attach comment @mentions that exist Nov 6, 2026

@opencodejr opencodejr 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.

The existence check fixes the bare-@word case: an unpicked @here is no longer attached, and @Makefile attaches again, which addresses the trade-off I raised earlier. I checked it through the submitQuote path in submit.test.ts with an @here comment. request.test.ts, submit.test.ts and machine.test.ts pass, and tsc -b in packages/app passes. Public API: unchanged (existingMentions and commentMentions are internal to the app).

One regression, see the inline comment: directory mentions in comments are now always dropped, although dev attaches them and the server accepts them.

Comment thread packages/app/src/composer/submit.ts Outdated

await Promise.all(
[...new Set(mentions)].map(async (path) => {
const parent = /[\\/]/.test(path) ? getDirectory(path) : undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This drops directory mentions. The comment autocomplete offers folders (searchFilesAndDirectories), and the server accepts a directory file:// attachment (it sends the listing, see readAttachment in core/src/session/prompt.ts). On dev, @src/components/ in a comment is attached; here it is always treated as missing.

  • entry.type === "file" excludes directories.
  • fs.list returns directory entries with a trailing separator (src/components/), so getFilename doesn't match src/components either.
  • For @src/, getDirectory("src/") is /, so this lists the filesystem root.

Checking against a mock file.list shaped like the server's output: src/api.ts and Makefile are found, while src/components/, src/components and src/ are not. Accepting directory entries and comparing paths with any trailing separator removed would keep folder mentions working.

@opencodejr opencodejr 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.

The new commit fixes the directory-mention problem I raised: @src/components/, @src/components and @src/ are attached again, and @src/ now checks the project root rather than the filesystem root. I checked this against a mock file.list shaped like the server's output; bare @here is still not attached. request.test.ts, submit.test.ts and machine.test.ts pass, and tsc -b in packages/app passes. Public API: unchanged. Nothing new to raise.

@opencodejr opencodejr 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.

The new commit only adds a blank line for lint; behaviour is unchanged. The folder-mention fix from the previous push still applies, and request.test.ts, submit.test.ts, machine.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.

@Tarquinen
Tarquinen enabled auto-merge (squash) November 6, 2026 22:21

@opencodejr opencodejr 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.

The new commit only touches tests and narrows the file.list result type; the existence check is unchanged. The updated quote test in submit.test.ts fails on dev (an extra file:///C:/repo/here attachment) and passes here. request.test.ts, submit.test.ts, machine.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.

@Tarquinen
Tarquinen merged commit 91732f2 into dev Nov 6, 2026
22 checks passed
@Tarquinen
Tarquinen deleted the mention-file-guard branch November 6, 2026 22:27
@amrkmn amrkmn mentioned this pull request Nov 7, 2026
1 task
autonull pushed a commit to autonull/opencode_spacegraph that referenced this pull request Nov 7, 2026
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.

@ usage in quote comment prevents sending message Composer flags bare @words (e.g. Slack-style @here) as missing files

1 participant