Skip to content

fix(id): uniquify colliding upload stored names - #1696

Merged
dezren39 merged 1 commit into
mainfrom
queue/1824-1549-upload-uniquify
Oct 28, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/1824-1549-upload-uniquify

Conversation

@dezren39

@dezren39 dezren39 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #1549.

Problem

upload_handler set the blob tag under the supplied filename unconditionally, so a second paste named image.png silently re-pointed the name at the new blob — the first image lost its name.

Fix (pkgs/id/src/web/routes.rs, per the triage ruling on #1549)

Archive-first was rejected in triage (it renames the FIRST image out from under existing name lookups). Instead, after the blob hash is known, the handler resolves the stored name:

  • Intended name free, or already naming this exact blob → kept unchanged (re-uploading identical bytes is idempotent, no -N suffix).
  • Intended name owned by a different blob → stored as stem-N.ext with the smallest free N ≥ 1.
  • The nameless paste-{secs} fallback passes through the same uniquifier, so two nameless uploads in the same second never share a stored name.

The tag, all filename-keyed metadata records, and the UploadResponse name/url all use the stored name. No change to document save semantics or the /blob/{hash} URL shape.

Tests

  • New: upload_same_name_different_bytes_uniquifies_second (both images listed and resolvable, first name still resolves to the first hash, second response carries image-1.png, identical re-upload idempotent) and upload_nameless_uploads_never_share_a_stored_name.
  • Laptop worktree: cargo test --features web --lib web::routes::upload_router_tests — 12 passed, 0 failed. CI is the verification of record for the full suite.

Queue task 1824 (repo-health-code-pilot), follow-up from triage task 1602.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

upload_handler set the blob tag under the supplied filename unconditionally, so a second paste named image.png silently re-pointed the name at the new blob and un-named the first image.

Per the triage ruling on #1549 (archive-first rejected: it renames the FIRST image), the handler now resolves the stored name after the blob hash is known: the intended name is kept when free or already naming the same blob (idempotent re-upload of identical bytes); when a different blob owns it, the upload is stored as stem-N.ext with the smallest free N >= 1. The paste-{secs} fallback passes through the same uniquifier. Tag, filename-keyed metadata, and UploadResponse name/url all use the stored name.

Regression tests: two same-name uploads with different bytes (both listed and resolvable, first name still resolves to the first hash, second response carries image-1.png, identical re-upload idempotent) and two nameless uploads never sharing a stored name.
@dezren39
dezren39 requested a review from a team as a code owner October 28, 2026 14:48
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a10da55c-ddb0-43bc-96a1-15db99d0547d
Commits

Reviewing files that changed from the base of the PR and between 211aa58 and 4d423fb.

Files selected for processing: 1
  • pkgs/id/src/web/routes.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T14:51:13.628372Z 4d423fb PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 4d423fbdff

ℹ️ 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 thread pkgs/id/src/web/routes.rs
Comment on lines +1489 to +1491
match upload_name_owner(store, &candidate).await? {
None => return Ok(candidate),
Some(owner) if owner == hash => return Ok(candidate),

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 Reserve the chosen upload name atomically

When two uploads with different bytes and the same intended filename overlap, both can observe the same candidate as free before either handler reaches tags().set(). Both then return that name successfully, but the last tag write silently removes the other image's name and listing—the data-loss scenario this change intends to prevent. This also affects suffix candidates when the original name is already occupied. The upload route has no serialization, and the web client's paste/drop handlers launch uploads concurrently. Make name selection and tag assignment atomic, or serialize the lookup-and-set sequence with a shared lock; the sequential tests do not cover this interleaving.

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.

id(web): image upload stores by filename with no collision handling — a second paste named 'image.png' silently un-names the first

1 participant