mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-15 12:15:16 +00:00
fix(scheduler)!: 中断栈语义(嵌套抢占 LIFO),并修掉抢占空转
用户指正:存在**中断被中断**的场景,所以被打断的现场要进**中断栈**。 我此前把 suspendPool 明确写成“不是栈、按优先级取”,是错的。 改动: - suspendPool 改名 suspendStack,恢复纪律改为**严格 LIFO(只比栈顶)**; 栈内不做优先级重排——嵌套抢占天然使栈自底向上基础级递增, 且“后被打断的先恢复”才是栈语义。取出即弹栈。 - 修掉一个由此暴露的真 bug(抢占空转):一次抢占生效后,被挂起的原任务 会因饥饿防护提升有效级,与抢占者同级;此时若按“先到先服务”,原任务 (入队更早)会被立刻选回,抢占者永远排不到 —— 抢占等于没发生。 现在**同级时 pendingInterrupts 优先于其它两类**,保证抢占必然生效。 - 状态 DTO:SuspendPool/suspend_pool → SuspendStack/suspend_stack - 设计稿:§2 用语更正(它**就是**中断栈)、§4.1 选择函数(候选只含栈顶 + pending 同级优先,并说明为何必需)、§6.2/§6.3/§9/§11 用例同步 测试新增 scheduler_stack_test.go 3 项: - 嵌套 L1→L2→L3,恢复严格 LIFO(B 先于 A) - 只比栈顶:人为构造“栈底 L3、栈顶 L2”,必须取栈顶(区分两种实现) - 嵌套下的深度上限 验收:agent 全量 + -race;全仓 build/vet 通过
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package core
|
||||
|
||||
// M3b 验收测试:四级优先级 + 严格大于抢占 + 现场保存/恢复 + suspendPool。
|
||||
// M3b 验收测试:四级优先级 + 严格大于抢占 + 现场保存/恢复 + suspendStack。
|
||||
//
|
||||
// 设计依据 docs/zh/input-scheduler-design.md §11(P1–P4、R1、R5、D1T、Q3)。
|
||||
//
|
||||
@ -124,13 +124,13 @@ func TestPreempt_HigherPreemptsAndResumes(t *testing.T) {
|
||||
if snap.Running != nil {
|
||||
t.Fatal("挂起后不应还有 running")
|
||||
}
|
||||
if len(snap.SuspendPool) != 1 {
|
||||
t.Fatalf("suspendPool=%d,期望 1", len(snap.SuspendPool))
|
||||
if len(snap.SuspendStack) != 1 {
|
||||
t.Fatalf("suspendStack=%d,期望 1", len(snap.SuspendStack))
|
||||
}
|
||||
if len(snap.PendingInterrupts) != 1 {
|
||||
t.Fatalf("pendingInterrupts=%d,期望 1", len(snap.PendingInterrupts))
|
||||
}
|
||||
sf := snap.SuspendPool[0].Frame
|
||||
sf := snap.SuspendStack[0].Frame
|
||||
if sf.Terminal != terminalSuspended {
|
||||
t.Fatalf("挂起任务终态=%v,期望 terminalSuspended", sf.Terminal)
|
||||
}
|
||||
@ -186,7 +186,7 @@ func TestPreempt_HigherPreemptsAndResumes(t *testing.T) {
|
||||
t.Fatalf("LLM 总调用=%d,期望 3(丢弃 1 + 中断 1 + 恢复 1)", sp.callCount())
|
||||
}
|
||||
snap = a.DumpScheduler()
|
||||
if len(snap.SuspendPool) != 0 || snap.Running != nil {
|
||||
if len(snap.SuspendStack) != 0 || snap.Running != nil {
|
||||
t.Fatalf("全部结束后应无挂起与运行任务:%+v", snap)
|
||||
}
|
||||
if snap.Stats.Executed != 2 {
|
||||
@ -239,7 +239,7 @@ func TestPreempt_LowerOrEqualDoesNotPreempt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// D1T:suspendPool 满时不再下潜(canSuspend=false),让位信号也不会 arm。
|
||||
// D1T:suspendStack 满时不再下潜(canSuspend=false),让位信号也不会 arm。
|
||||
func TestPreempt_DepthCapBlocksSuspension(t *testing.T) {
|
||||
a := newPreemptAgent(t, newPreemptProvider())
|
||||
|
||||
@ -259,7 +259,7 @@ func TestPreempt_DepthCapBlocksSuspension(t *testing.T) {
|
||||
if a.DumpScheduler().Stats.Rejected != before+1 {
|
||||
t.Fatal("超限挂起必须计数 Rejected")
|
||||
}
|
||||
if len(a.DumpScheduler().SuspendPool) != a.sched.maxSuspendDepth+1 {
|
||||
if len(a.DumpScheduler().SuspendStack) != a.sched.maxSuspendDepth+1 {
|
||||
t.Fatal("兜底路径必须保留帧而不是丢弃")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user