Skip to content

fix(files): resolve chat uploads whose names are not in VFS form - #8566

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/chat-upload-name-normalize
Oct 2, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/chat-upload-name-normalize

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Chat uploads whose stored name isn't already in VFS display form could not be read through uploads/<name> — not by the path the upload notice prints, and not by the raw name. The agent gets "File not found" from files read, run_code input mounts, and every other uploads/ read, then gives up on the attachment
  • Every macOS screenshot hits this (Screenshot <date> at <time> AM.png — macOS puts U+202F before AM/PM), along with names that contain doubled spaces, decomposed (NFD) accents, or control characters. Over the last two weeks that was roughly one in five Chat uploads
  • Root cause: the upload notice prints encodeVfsSegment(name), which normalizes the name (NFC, trim, strip control characters, collapse every whitespace run to one space). parseChatUploadReference decodes back to that normalized form, but getChatUploadByName compared it to the raw stored display_name with =. Workspace files never hit this because the listing fallback compares normalized forms on both sides. Chat uploads are excluded from that listing on purpose, so their only path was the exact match. The bug has been there since the uploads/ namespace landed in feat(mothership): v1.0.0 #8208
  • Fix: getChatUploadByName now matches in the stored name's display form, entirely in SQL, and still returns one row (limit(1), newest first). The stored name is NFC-composed and its control characters are stripped. It is then matched against displaySegmentPattern(name), a new anchored regex in lib/vfs/path.ts. The pattern takes the requested words, regex-escaped, in order, separated by whitespace runs, and allows whitespace around them. Its whitespace class is the same constant VFS encoding uses to collapse whitespace, so the two cannot drift. Scope predicates are unchanged (workspace, context = 'mothership', chat, live)

Behavior changes

  • Before, an uploads/<name> reference resolved only when the stored name was already normalized. Now it resolves whenever the stored name normalizes to the same display name, which is the path the VFS shows the model
  • Scope, authorization, and newest-first ordering are unchanged. The chat-scoped miss still returns null without falling through, and non-uploads/ references are untouched
  • Two chat uploads whose names differ only in whitespace already shared one VFS path. As before, the newest one wins

Type of Change

  • Bug fix

Testing

  • file-names.integration.ts against real Postgres (bun run test:integration):
    • New: a U+202F screenshot name, a doubled-space name, an NFD name, and a control-character name each resolve by the notice path and by the raw name. This works with and without a chat scope, and another chat's scope still misses
    • New: matches are exact, never a pattern or a fragment (a_b does not match axb, notes.png does not match my notes.png.bak), and % and \ in names still resolve
    • Red on staging. Reverting each guard turns the suite red: regex escaping, anchoring, NFC in SQL, and control-character stripping in SQL. Also covered: a name with a trailing control character, whose printed path ends in an encoded space
  • workspace-file-reference.test.ts: dropped the assertions that pinned the old or(eq(displayName…)) query shape and limit(1). Behavior is now covered by the real-Postgres test
  • bun run lint, bun run type-check (apps/sim), bun run check:audits, docs-manifest:check, check-block-registry, root bun run test

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 2, 2026 8:51am UTC

Request Review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Changes file name matching logic in upload resolution.

The PR appears safe to merge; no new actionable issue or outstanding previous finding was identified.

Summary

The PR makes chat-upload lookups match the VFS display form of stored names in PostgreSQL, while retaining chat scope and newest-first selection. The follow-up change replaces an unbounded candidate load with an anchored SQL match and adds coverage for trailing controls and literal punctuation.

Reviews (2) · Last reviewed commit: "fix(files): match chat upload names exac..."

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts Outdated
Comment thread apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts Outdated
Comment thread apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 3/5

  • In apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts, distinct uploads can resolve to the same canonical VFS path, causing an older upload notice to point to the newest file. Use the same normalization when allocating chat display names and enforcing uniqueness.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts">

<violation number="1" location="apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts:1611">
P1: This normalized match can make two distinct uploads share one canonical VFS path and redirect an older upload notice to the newest file. Allocate chat display names and enforce uniqueness using the same normalized display key before resolving them here.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 1ebdccd into staging Oct 2, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/chat-upload-name-normalize branch October 2, 2026 15:33

This branch was previously deployed

1 inactive deployment
Preview — dd6ae556 Deployed Oct 2, 2026 by vercel[bot]
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.

1 participant