Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

fix(engine): 种子意图任务误触发首轮 planner(Frontier 只数 open 与 worker claim 竞态)

Autumn-27de479b6c50ab
diff --git a/db/exploration.go b/db/exploration.go
index 8c66cdc..ee8c902 100644
--- a/db/exploration.go
+++ b/db/exploration.go
@@ -381,6 +381,18 @@ ORDER BY priority DESC, id ASC LIMIT $2`, s.expID, limit)
return scanNodes(rows)
}
+// HasActiveIntent reports whether this exploration has any intent still in play
+// (state open OR running). Used to decide whether to kick the FIRST planner round:
+// a seeded task's intent may already have been claimed (open→running) by a worker
+// before the check, so counting only 'open' (Frontier) races with worker claim and
+// wrongly kicks a redundant first round. Counting open+running is race-proof.
+func (s *ExplorationStore) HasActiveIntent() (bool, error) {
+ var exists bool
+ err := s.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM exploration_nodes
+WHERE exploration_id=$1 AND kind='intent' AND state IN ('open','running'))`, s.expID).Scan(&exists)
+ return exists, err
+}
+
// ClaimIntent atomically moves an open intent to running. Returns true if claimed.
func (s *ExplorationStore) ClaimIntent(id int64, owner string) (bool, error) {
res, err := s.db.Exec(`UPDATE exploration_nodes SET state='running', owner=$1
diff --git a/server/engine.go b/server/engine.go
index 3c5a5fa..c64c5d3 100644
--- a/server/engine.go
+++ b/server/engine.go
@@ -433,10 +433,12 @@ func (e *Engine) Run(ctx context.Context, t *Task) {
go e.workerLoop(ctx, t, fmt.Sprintf("work#%d", i+1))
}
e.startDeadlineCoordinator(ctx, t) // 任务级超时定时器(仅 timeout>0;去重)
- // 仅在 frontier 为空时才 kick 首轮规划:普通任务(空 frontier)照常触发;带种子意图的
- // 任务 frontier 已非空 → 跳过首轮 planner,worker 直接领种子意图开跑,跑完由 NotifyDone
- // 唤醒 planner。重启自动恢复时 frontier 通常也非空 → 顺带避免白烧一轮。
- if fr, _ := t.Store.Frontier(1); len(fr) == 0 {
+ // 仅在「完全没有活动意图(open+running)」时才 kick 首轮规划。带种子意图的任务:种子已
+ // 是 open,或已被上面刚起的 worker 抢先 claim 成 running——两种都算「有活干」,一律跳过
+ // 首轮 planner,worker 直接领种子意图开跑,跑完由 NotifyDone/心跳唤醒 planner。
+ // ⚠️ 不能用 Frontier(只数 open):worker 领取(open→running)与本检查存在竞态,会误 kick。
+ // 重启自动恢复时也可能只剩 running 意图,同样应跳过。
+ if has, _ := t.Store.HasActiveIntent(); !has {
t.Notify() // kick the first planning round (acted on once LLM is ready)
}
}