Skip to content

Reject duplicate store names in StoreManager#2533

Open
heyitsalec wants to merge 1 commit into
TraceMachina:mainfrom
heyitsalec:store-manager-reject-duplicate-names
Open

Reject duplicate store names in StoreManager#2533
heyitsalec wants to merge 1 commit into
TraceMachina:mainfrom
heyitsalec:store-manager-reject-duplicate-names

Conversation

@heyitsalec

@heyitsalec heyitsalec commented Jul 8, 2026

Copy link
Copy Markdown

Description

StoreManager::add_store registered stores with HashMap::insert, which
silently overwrites any existing entry. A config declaring two stores with the
same name dropped the first store with no error.

add_store now checks whether the name is already registered
and returns Err(Code::AlreadyExists) instead of overwriting. I opted for enforcing uniqueness on StoreManager (rather than only in the config loader) to protect every caller and composes with the existing parse-timecheck_store_conflict. The startup wiring loop propagates the error with err_tip, so a duplicate-name config now fails fast at startup with a clear message instead of silently discarding a store.

Fixes #1998

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added an inline unit test in store_manager.rs
(add_store_rejects_duplicate_name) that registers a store twice under the same
name and asserts the second call returns Code::AlreadyExists. All existing
add_store call sites were updated to the fallible signature.

relying on this PR's CI (bazel test //..., which also runs rustfmt) as the verification gate
rather than a local run. Happy to iterate quickly if CI flags anything.

Checklist

  • Updated documentation if needed
  • Tests added/amended
  • bazel test //... passes locally
  • PR is contained in a single commit, using git amend see some docs

This change is Reviewable

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
nativelink Ready Ready Preview, Comment Jul 8, 2026 9:31pm
nativelink-aidm Ready Ready Preview, Comment Jul 8, 2026 9:31pm

Request Review

@CLAassistant

CLAassistant commented Jul 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

StoreManager::add_store silently overwrote an existing store when a
duplicate name was inserted into its RwLock<HashMap>, so a config
with two stores sharing a name would drop the first without warning.

Make add_store fallible: it now guards on the name already being
present and returns Code::AlreadyExists instead of overwriting, and
returns Ok(()) on the happy path. The uniqueness invariant thus lives
on the type that owns the map, defending every caller rather than
just the config loader. The production wiring site err_tips the
failure with the offending store name, and all test call sites are
updated to the fallible signature. An inline unit test proves the
duplicate name is rejected.

Ref: TraceMachina#1998
store_manager.add_store("foo", memory_store.clone());
store_manager
.add_store("foo", memory_store.clone())
.unwrap();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be better to use expect with a reason here, but otherwise an awesome patch, thanks.

impl RootMetricsComponent for StoreManager {}

#[cfg(test)]
mod tests {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, the structure of the repo is to split tests out. Could this be moved to nativelink-store/tests/store_manager_test.rs please?

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.

Multiple stores with the same name allowed in config

3 participants