fix(proxy): resolve CacheManager deadlocks and implement max quota logic - #3246
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets two areas in the Tauri proxy layer: (1) preventing CacheManager deadlocks by avoiding DashMap read-lock + mutation patterns, and (2) adjusting quota-protection aggregation to operate on per-standard-model groups using a group maximum to avoid premature protection when variants conflict.
Changes:
- Refactored CacheManager lookup paths to separate read access from mutation/removal to avoid DashMap lock contention.
- Updated quota protection to aggregate per “Standard ID” using group max percentage (instead of group min) and adjusted related logging.
- Updated
dist/index.htmlto reference a new hashed frontend bundle.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src-tauri/src/proxy/token_manager.rs |
Switches quota aggregation to per-standard-id max; updates trigger/migration behavior and logs. |
src-tauri/src/proxy/cache_manager.rs |
Reworks cache lookups to avoid holding read refs while mutating/removing entries (deadlock fix). |
src-tauri/src/modules/account.rs |
Mirrors quota aggregation changes in account quota update flow and updates logs. |
dist/index.html |
Updates hashed asset reference for the frontend entry bundle. |
Comments suppressed due to low confidence (1)
src-tauri/src/proxy/token_manager.rs:935
- If the protection condition is inclusive (
<= threshold), this log message should match the actual trigger rule; otherwise logs will be misleading at the boundary case.
tracing::info!(
"账号 {} 的模型 {} 因配额受限({}% < {}%)已被加入保护列表",
account_id,
model_name,
current_val,
threshold
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if min_pct <= threshold { | ||
| // 只要组内有一个不行,触发全组保护 | ||
| if max_pct < threshold { |
|
|
||
| for std_id in &config.monitored_models { | ||
| let max_pct = group_max_percentage.get(std_id).cloned().unwrap_or(100); | ||
| if max_pct < threshold { |
Comment on lines
635
to
+637
| // 5. [重构] 聚合判定逻辑:按 Standard ID 对账号所有型号进行分组 | ||
| // 解决如 Pro-Low (0%) 和 Pro-High (100%) 在同一账号内导致状态冲突的问题 | ||
| let mut group_min_percentage: HashMap<String, i32> = HashMap::new(); | ||
| let mut group_max_percentage: HashMap<String, i32> = HashMap::new(); |
| let max_pct = group_max_percentage.get(std_id).cloned().unwrap_or(100); | ||
|
|
||
| if min_pct <= threshold { | ||
| if max_pct < threshold { |
Comment on lines
1519
to
1522
| crate::modules::logger::log_info(&format!( | ||
| "[Quota] Triggering model protection: {} (Group: {} Min: {}% <= Thres: {}%)", | ||
| account.email, std_id, min_pct, threshold | ||
| "[Quota] Triggering model protection: {} (Group: {} Max: {}% < Thres: {}%)", | ||
| account.email, std_id, max_pct, threshold | ||
| )); |
Comment on lines
1527
to
1530
| crate::modules::logger::log_info(&format!( | ||
| "[Quota] Model protection recovered: {} (Group: {} Min: {}% > Thres: {}%)", | ||
| account.email, std_id, min_pct, threshold | ||
| "[Quota] Model protection recovered: {} (Group: {} Max: {}% >= Thres: {}%)", | ||
| account.email, std_id, max_pct, threshold | ||
| )); |
lbjlaq
added a commit
that referenced
this pull request
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a deadlock in CacheManager where lookup methods held read locks on the DashMap while attempting mutations. It also updates quota logic to use the maximum percentage in groups to prevent premature locks.