fix(resident): 子的「轮次」一直显示 0 —— info() 根本没填 Rounds

现象(用户线上联调实录 + 我复验):父侧 `resident_agents` 列出 `输入ch=[timer] 轮次=0
处理表=2` —— **处理表已有两条记录,轮次却是 0**,自相矛盾,容易被读成"子没干活"。

根因:`residentChild.info()` 构造 `ResidentInfo` 时**从来没有填过 Rounds 字段**
(结构体里有这个字段,于是永远输出零值),不是计数漏加。

改法:`Rounds = 已执行轮次数`(调度器执行计数,单调不减)。新增 `Agent.roundsExecuted()`
并写明为什么**不能**用 inputch 处理表条数当轮次:那张表记的是"当前上下文窗口内"的轮次,
压缩会清空(设计 §8.3)—— 用它会让父看到轮次倒退。

判据:inputch 路由测试里补一条断言 —— 子处理完输入后 `info().Rounds > 0`。
This commit is contained in:
JianFeeeee
2026-09-13 15:41:02 +08:00
parent 1d46c6c0f6
commit cd88b2dfe5
3 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,11 @@ func TestResident_InputchRoutingIsExclusive(t *testing.T) {
if got := parent.DumpScheduler().Stats.Enqueued; got != before {
t.Fatalf("划给子的 inputch父不应再入队before=%d after=%d", before, got)
}
// 轮次必须真的涨:此前 info() 根本没填 Rounds ⇒ 父永远读到 0
// (现场:子处理表已有 2 条,轮次却显示 0被误判成"子没干活")。
if got := parent.residents["r-route"].info().Rounds; got <= 0 {
t.Fatalf("子处理的轮次应 > 0实际 %d", got)
}
}
// 归属到一个不存在(或已销毁)的 agent 时**不吞输入**:父兜底处理。

View File

@ -504,6 +504,13 @@ func (rc *residentChild) info() ResidentInfo {
ID: rc.id, State: state, InputChs: append([]string(nil), rc.inputChs...),
AllowedOutputs: append([]string(nil), rc.allowed...),
ContextFull: full, CreatedAt: rc.createdAt, TableSize: len(table),
// Rounds = 子**已执行的轮次数**(调度器的执行计数,单调不减)。
//
// 此前这里根本没填这个字段 ⇒ 父看到的永远是 `轮次=0`,与"处理表已有 N 条"
// 自相矛盾(现场:子明明处理了两轮,父读到 rounds=0误判成"子没干活")。
// 注意它**不等于** len(table):处理表记的是"当前上下文窗口内"的轮次,
// 压缩会清空§8.3),所以窗口内的条数会被重置,而轮次总数不会。
Rounds: rc.agent.roundsExecuted(),
}
if len(table) > 0 {
info.Table = table

View File

@ -745,6 +745,18 @@ func newKernelInterruptTask(evt *agentIO.InputEvent) *Task {
}
// DumpScheduler 返回调度器的原子快照(供状态页/测试断言)。
// roundsExecuted 返回本 agent 已执行的轮次数(供驻留子状态面展示)。
//
// 一轮 = 一次被执行的输入(排队与中断都算)。为什么不用 inputch 处理表的条数:
// 那张表记的是"当前上下文窗口内"的轮次,压缩会清空(设计 §8.3)——
// 拿它当轮次会让父看到轮次倒退。
func (a *Agent) roundsExecuted() int {
if a.sched == nil {
return 0
}
return int(a.DumpScheduler().Stats.Executed)
}
func (a *Agent) DumpScheduler() SchedulerSnapshot {
if a.sched == nil {
return SchedulerSnapshot{}