Skip to content

fix(attachments): model egress attachments - #6312

Merged
icecrasher321 merged 1 commit into
stagingfrom
fix/attachments
Aug 6, 2026
Merged

fix(attachments): model egress attachments#6312
icecrasher321 merged 1 commit into
stagingfrom
fix/attachments

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Fix attachments to correctly work when model egress is involved.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • 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 Aug 6, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 6, 2026 5:13am

Request Review

@cursor

cursor Bot commented Aug 6, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes model egress gating for file attachments and fail-fast behavior on upload preparation—security-sensitive boundary logic, though provenance rules still fail closed on tainted/unknown content.

Overview
Fixes Copilot chat attachments being dropped or mishandled on model egress paths where attachment metadata does not carry a stable database file id.

Secret provenance filtering now classifies workspace attachments by canonical storage key and provenance state only—it no longer rejects attachments when the caller’s id does not match the workspace_files row. That matches older persisted workflows (no id), runtime-normalized ids, and wrong-but-key-correct references; tainted or unknown keys are still filtered out.

Chat payload building now surfaces prepared uploads in model context when tracking succeeds, and fails the request with a clear error (instead of silently skipping) when an authorized attachment cannot be prepared (e.g. provenance sidecar issues). Shared DB loading for model-safe row lookups is consolidated for attachment filtering and batch key checks.

Tests cover key-only attachments, successful upload context, and preparation failures.

Reviewed by Cursor Bugbot for commit e698b10. Configure here.

@icecrasher321
icecrasher321 merged commit e0a464d into staging Aug 6, 2026
24 checks passed
@icecrasher321
icecrasher321 deleted the fix/attachments branch August 6, 2026 05:15

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e698b10. Configure here.

throw new Error(
`Failed to prepare attached file "${filename}" for Copilot. Please try again.`,
{ cause }
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prepare failure leaves chat incomplete

Medium Severity

When trackChatUpload fails, the new rethrow aborts after persistUserMessage has already saved the user turn. For workspace chats that also publish started, the request returns 500 without terminal status or assistant finalization, so the chat can keep an attachment-bearing user message and no completed turn.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e698b10. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes model-egress attachment provenance checks to classify files by their canonical storage key rather than runtime attachment IDs, and makes Copilot attachment-preparation failures abort the request.

  • Extracts shared workspace-file provenance row loading.
  • Supports missing or synthesized attachment IDs while retaining workspace and provenance checks.
  • Adds tests for key-based classification, model context creation, and failed attachment preparation.
  • The new failure path can leave the submitted user message persisted despite returning an error.

Confidence Score: 4/5

The attachment failure path should be fixed before merging because it can return an error after leaving an incomplete user turn in chat history.

Attachment preparation now throws after user-message persistence has started, while the outer error handler returns a failure without reconciling that persisted message.

Files Needing Attention: apps/sim/lib/copilot/chat/payload.ts and apps/sim/app/api/copilot/chat/post.ts

Important Files Changed

Filename Overview
apps/sim/lib/copilot/chat/payload.ts Makes attachment tracking fail closed, but the exception occurs after message persistence has begun and can leave an incomplete chat turn.
apps/sim/lib/copilot/chat/payload.test.ts Adds model-context and attachment-preparation failure coverage, but does not exercise request-level persistence cleanup.
apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.ts Replaces attachment-ID matching with canonical, globally unique active storage-key classification and extracts the shared row query.
apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts Covers missing, synthesized, mismatched, and tainted attachment identities under key-based provenance classification.

Sequence Diagram

sequenceDiagram
  participant Client
  participant API as Copilot API
  participant DB
  participant Payload as Payload Builder
  participant Upload as Attachment Tracker
  Client->>API: Submit message with attachment
  API->>DB: Begin persisting user message
  API->>Payload: Build model payload
  Payload->>Upload: trackChatUpload
  Upload-->>Payload: Error
  Payload-->>API: Throw preparation error
  DB-->>API: User message persisted
  API-->>Client: HTTP 500
  Note over DB,Client: Persisted user turn has no assistant response
Loading

Reviews (1): Last reviewed commit: "fix(attachments): model egress attachmen..." | Re-trigger Greptile

Comment on lines 401 to +404
chatId,
error: toError(err).message,
error: cause.message,
})
throw new Error(

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.

P1 Attachment failure leaves persisted turn

When trackChatUpload rejects, this new exception aborts the request after persistence of the user message has already begun, causing the client to receive an HTTP 500 while the chat retains a user turn with no assistant response; retrying can then create duplicate user turns.

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