Skip to content

deduct team credits for usage beyond monthly quota - #914

Open
zwfxxxxx wants to merge 1 commit into
masterfrom
team-ai-additional-credits
Open

zwfxxxxx wants to merge 1 commit into
masterfrom
team-ai-additional-credits

Conversation

@zwfxxxxx

Copy link
Copy Markdown
Contributor

No description provided.

@seafile-dev seafile-dev 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.

审查结论:请求修改

阻塞问题:

  • 用量统计写入失败后仍会继续扣减额外余额,可能在统计未落库时扣掉团队可购买额度;详见行内评论。

警告:

  • 未新增针对扣减流程、统计写入失败和余额不足的回归测试。
    建议修复:为 AIAdditionalCreditsManager 和 AIStatsWorker 补充单元测试,覆盖本次新增的统计与扣减边界。

org_cost_delta = defaultdict(float)
for data in team_data:
org_cost_delta[data['org_id']] += data['cost']
self.additional_credits_manager.deduct(org_cost_delta, month)

@seafile-dev seafile-dev Oct 8, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

【严重】统计失败仍会扣减余额

影响:
session.execute 或 commit 失败时,异常只被记录,随后仍无条件调用 deduct。本批用量没有写入 stats_ai_by_team,扣减逻辑却会用旧累计用量加上 cost_delta 计算超额,可能扣掉团队余额而没有对应的用量统计。

建议修复:仅在统计写入并成功提交后再构建 org_cost_delta 和调用 deduct;失败路径应跳过本批扣减并保留数据供后续重试。

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.

2 participants