fix(scheduler): 空闲时入队不再误报 "level insufficient"

现场:日志满屏
  [agent] interrupt queued: task#2 class=interrupt level=3 from qq (L3)
                          vs <nil> (?) — level insufficient
而实际成因是"当前没有运行任务可抢占",与级别毫无关系。这类假因会
把运维引到"是不是级别配低了"的错误方向(本仓反复吃亏的静默/误导同族)。

改成四种成因分开写:
  idle (no running task; queued for next pick) / running in critical section
  / preempt cooldown / level insufficient
This commit is contained in:
JianFeeeee
2026-10-27 15:58:55 +08:00
parent 9ffdebbb0b
commit 279b61198c

View File

@ -328,10 +328,16 @@ func (s *scheduler) registerInterrupt(t *Task) bool {
s.enqueueInterruptLocked(t)
// 入队而不是抢占:这也是要能看见的(否则「中断明明到了却没生效」无从解释)。
// 两种成因分开写:临界区 vs 级别不够/冷却期。
// 成因必须分开写,否则「中断明明到了却没生效」无从解释。
// 特别地:**空闲时没有受害者可抢**,不该报 "level insufficient"——
// 那会让运维以为级别配错了(实测日志里满屏 "vs <nil> (?) — level insufficient")。
reason := "level insufficient"
if critical {
switch {
case running == nil:
reason = "idle (no running task; queued for next pick)"
case critical:
reason = "running in critical section"
} else if canPreempt(t, running) && running != nil && !running.LastPreemptAt.IsZero() && time.Since(running.LastPreemptAt) < preemptCooldown {
case canPreempt(t, running) && !running.LastPreemptAt.IsZero() && time.Since(running.LastPreemptAt) < preemptCooldown:
reason = "preempt cooldown"
}
log.Printf("[agent] interrupt queued: %s from %s (L%d) vs %s (%s) — %s; queue=%d",