Skip to content

Use UUID as filename when passing to aichat backend#73451

Merged
bencodeorg merged 4 commits into
stagingfrom
ben/fix-aichat-image-upload
Jun 24, 2026
Merged

Use UUID as filename when passing to aichat backend#73451
bencodeorg merged 4 commits into
stagingfrom
ben/fix-aichat-image-upload

Conversation

@bencodeorg

@bencodeorg bencodeorg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #72980

We started uploading images in both AI Tutor and AI Chat Lab using UUIDs instead of human-readable filenames. Our AI Chat backend went looking for human-readable filenames and failed. This PR makes it so we pass UUID filenames instead fo the human-readable ones to the backend.

We could also do this on the backend, but made more sense to me to just pass the right filenames from the client. Open to other opinions, though. Switched to doing this check on the backend so we send human-readable filenames to the model to use in its response (thanks Molly!)

Links

Testing story

Tested manually that I repro'd the issue before the change, and no longer see it afterwards. Tested in both AI Chat Lab and AI Tutor.

@bencodeorg bencodeorg requested a review from a team June 24, 2026 17:56
: file.asset;
// Use bucketKey as filename so the backend retrieves the correct S3 object.
// bucketKey is a UUID-based key set at upload time to avoid collisions.
return asset.bucketKey ? {...asset, filename: asset.bucketKey} : asset;

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.

So we are moving from sending the filename to sending the bucketKey?

@bencodeorg bencodeorg Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! But to Molly's point below, we need both (UUID for getting the file from S3, human-readable name for usage in responses from AI). Updated to that, and added a test to your other point.

: file.asset;
// Use bucketKey as filename so the backend retrieves the correct S3 object.
// bucketKey is a UUID-based key set at upload time to avoid collisions.
return asset.bucketKey ? {...asset, filename: asset.bucketKey} : asset;

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.

Will this cause any confusion with the tutor when referring to these files in the future? Or are the filenames only used for backend lookup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm good q. I observed files still being appropriately added to the Web Lab project from tutor upload (ie, with human-readable names), so that seemed good. But maybe there's more complexity in tutor having the correct names...let me check.

@bencodeorg bencodeorg Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok yes that makes sense, we'd now be passing the wrong file names to AI Tutor for it to use in its response. I'll switch so we just sort this out on the back end and pass the human readable names to AI Tutor, and just use the UUID for the file lookup.

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

Left one question- also is there a way we can test for this?

@fisher-alice fisher-alice 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.

Thanks for taking care of this!


message['assets']&.each do |asset|
filename = asset["filename"]
# Newer assets are stored in S3 with a bucketKey (ie, a UUID), but older assets may only have the human-readable filename.

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.

Nice!

@molly-moen molly-moen 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.

Nice!

@bencodeorg bencodeorg merged commit 5cdf9dd into staging Jun 24, 2026
8 checks passed
@bencodeorg bencodeorg deleted the ben/fix-aichat-image-upload branch June 24, 2026 18:58
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.

4 participants