Skip to content

fix(models): publish the provider catalog through an atomic pointer and drop the dao-side cache so concurrent readers and publishers no longer race - #21749

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
flyingwhit:fix/model-provider-manager-race
Nov 2, 2026

Conversation

@flyingwhit

Copy link
Copy Markdown
Contributor

Fix

Publish the model provider catalog via an atomic pointer and drop the dao-side cache so concurrent reads, lazy init, and re-publishing no longer race.

@flyingwhit
flyingwhit requested a review from buua436 October 30, 2026 05:41
@flyingwhit flyingwhit added the ci Continue Integration label Oct 30, 2026
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f9d226b-cbe3-4447-a812-8370167aae28
Commits

Reviewing files that changed from the base of the PR and between 79bcebe and ec672ac.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a984cdc-7579-4b91-9b7a-3e1b78ba4015
Commits

Reviewing files that changed from the base of the PR and between 4c31b15 and 79bcebe.

Files selected for processing: 2
  • internal/dao/database.go
  • internal/entity/models/hostinger_router_test.go
Files with no reviewable changes: 1
  • internal/dao/database.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The models package now publishes the provider manager through an atomic pointer. The DAO getter checks the published manager before using a once-only initialization fallback. Tests cover concurrent publication and access, and use package accessors to manage test state.

Changes: Provider manager lifecycle

Layer / File(s) Summary
Atomic catalog publication
internal/entity/models/model.go, internal/entity/models/model_test.go, internal/entity/models/get_driver_test.go, internal/entity/models/nvidia_test.go, internal/entity/models/hostinger_router_test.go
The models package stores and loads the provider manager through an atomic pointer. Tests check concurrent publication and use the getter and setter to manage manager state.
DAO catalog access
internal/dao/model_provider.go, internal/dao/database.go, internal/dao/model_provider_test.go, internal/service/tenant_test.go
The DAO getter checks the published manager on each call and uses sync.Once for fallback lookup and initialization. The DAO-local cache and its assignment were removed. Tests check the getter’s result and concurrent callers; the tenant test no longer accesses the DAO-local variable through go:linkname.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: ricardasbitinas-jpg

Merge Risk: Minimal · previous review 79bce

No actionable merge-blocking risk was established in the reviewed changes.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive The description has only a short Fix section. It says the catalog is published through an atomic pointer and the DAO-side cache is removed, so concurrent reads, lazy init, and re-publishing no longer … Rename the section to "Summary" to match the repository template. Add background context: the race or failure that the DAO-side cache and mutex caused, why the atomic pointer fixes it, and how the sync.Once fallback in GetModelProviderManag…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title names the main change: the provider catalog is published through an atomic pointer and the DAO-side cache is removed to stop races between readers and publishers. The title is long, at 147 c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the provider catalog is published through an atomic pointer and the DAO-side cache is removed to stop races between readers and publishers. The title is long, at 147 characters and 22 words, but its scope matches the changeset. The title is accurate and specific, so it passes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 7 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description has only a short Fix section. It says the catalog is published through an atomic pointer and the DAO-side cache is removed, so concurrent reads, lazy init, and re-publishing no longer race. The repository template asks for a Summary section that explains what the PR solves and gives background context for reviewers. The description does not give that background, such as why the DAO cache caused races or how the lazy-init fallback behaves now. The description is brief but names the change, so it is mostly complete in scope but lacks the required Summary heading and background.

Resolution

Rename the section to "Summary" to match the repository template. Add background context: the race or failure that the DAO-side cache and mutex caused, why the atomic pointer fixes it, and how the sync.Once fallback in GetModelProviderManager now behaves. Mention the test coverage added for concurrent reads and publication.

  • 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

A rabbit checks the catalog bright,
And reads its pointer, safe and right.
Eight callers gather, none alone,
While fallback waits its once-known turn.
Test paws restore the state they knew,
Then hop away with work to do.

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

[P2] Avoid copying the atomic pointer in this test (internal/entity/models/hostinger_router_test.go:205-206)

providerManager is now an atomic.Pointer, which must not be copied after first use. This test still saves and restores it by direct assignment. Please use GetProviderManager() to save the current catalog and setProviderManager() to restore it, as the updated tests do.

@flyingwhit
flyingwhit force-pushed the fix/model-provider-manager-race branch from 79bcebe to ec672ac Compare November 2, 2026 02:31
@flyingwhit
flyingwhit requested a review from buua436 November 2, 2026 02:31

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

LGTM

@wangq8
wangq8 merged commit 527fd07 into infiniflow:main Nov 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants