fix: performThink defer unlock改回立即unlock——LLM调用期间不能持锁
This commit is contained in:
@@ -1080,8 +1080,8 @@ func (t *Thinker) HasPendingThoughts() bool {
|
|||||||
// 强制执行最小间隔,防止并发调用或 bug 导致 LLM 配额被快速消耗。
|
// 强制执行最小间隔,防止并发调用或 bug 导致 LLM 配额被快速消耗。
|
||||||
func (t *Thinker) performThink(triggerReason string) {
|
func (t *Thinker) performThink(triggerReason string) {
|
||||||
t.muLock()
|
t.muLock()
|
||||||
defer t.muUnlock()
|
|
||||||
gapSinceLast := time.Since(t.lastThinkTimeAtomic())
|
gapSinceLast := time.Since(t.lastThinkTimeAtomic())
|
||||||
|
t.muUnlock()
|
||||||
minGap := t.minThinkGap
|
minGap := t.minThinkGap
|
||||||
if minGap <= 0 {
|
if minGap <= 0 {
|
||||||
minGap = 5 * time.Second // 默认最小间隔 5 秒
|
minGap = 5 * time.Second // 默认最小间隔 5 秒
|
||||||
@@ -1101,15 +1101,14 @@ func (t *Thinker) performThink(triggerReason string) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
t.muLock()
|
t.muLock()
|
||||||
defer t.muUnlock()
|
|
||||||
t.thinkCancel = cancel
|
t.thinkCancel = cancel
|
||||||
|
t.muUnlock()
|
||||||
|
|
||||||
// 0. 让步于前台——如果用户最近有活动(非post_chat),跳过本次思考。
|
// 0. 让步于前台——如果用户最近有活动(非post_chat),跳过本次思考。
|
||||||
if triggerReason != "post_chat" {
|
if triggerReason != "post_chat" {
|
||||||
t.muLock()
|
t.muLock()
|
||||||
defer t.muUnlock()
|
|
||||||
sinceLastUser := time.Since(t.lastUserTime())
|
sinceLastUser := time.Since(t.lastUserTime())
|
||||||
|
t.muUnlock()
|
||||||
|
|
||||||
if sinceLastUser < 10*time.Second {
|
if sinceLastUser < 10*time.Second {
|
||||||
log.Printf("[后台思考] 用户 %v 前有活动,让步于前台回复,跳过思考", sinceLastUser.Round(time.Second))
|
log.Printf("[后台思考] 用户 %v 前有活动,让步于前台回复,跳过思考", sinceLastUser.Round(time.Second))
|
||||||
@@ -1122,8 +1121,8 @@ func (t *Thinker) performThink(triggerReason string) {
|
|||||||
// 0. 让步于前台——如果用户最近有活动(非post_chat),跳过本次思考。
|
// 0. 让步于前台——如果用户最近有活动(非post_chat),跳过本次思考。
|
||||||
if triggerReason != "post_chat" {
|
if triggerReason != "post_chat" {
|
||||||
t.muLock()
|
t.muLock()
|
||||||
defer t.muUnlock()
|
|
||||||
sinceLastUser := time.Since(t.lastUserTime())
|
sinceLastUser := time.Since(t.lastUserTime())
|
||||||
|
t.muUnlock()
|
||||||
|
|
||||||
if sinceLastUser < 10*time.Second {
|
if sinceLastUser < 10*time.Second {
|
||||||
log.Printf("[后台思考] 用户 %v 前有活动,让步于前台回复,跳过思考", sinceLastUser.Round(time.Second))
|
log.Printf("[后台思考] 用户 %v 前有活动,让步于前台回复,跳过思考", sinceLastUser.Round(time.Second))
|
||||||
|
|||||||
Reference in New Issue
Block a user