Skip to content

fix(proxy): resolve CacheManager deadlocks and implement max quota logic - #3246

Merged
lbjlaq merged 4 commits into
lbjlaq:mainfrom
CarlitoDon:fix/cache-deadlock-and-quota-max
Jul 13, 2026
Merged

fix(proxy): resolve CacheManager deadlocks and implement max quota logic#3246
lbjlaq merged 4 commits into
lbjlaq:mainfrom
CarlitoDon:fix/cache-deadlock-and-quota-max

Conversation

@CarlitoDon

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings July 13, 2026 10:22

Copilot AI 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.

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.html to 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
lbjlaq merged commit eac5b9a into lbjlaq:main Jul 13, 2026
7 checks passed
lbjlaq added a commit that referenced this pull request Jul 13, 2026
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.

3 participants