Skip to content

fix(goal): bound goal-driven turns and map ESC to goal pause - #280

Merged
LeXwDeX merged 1 commit into
devfrom
fix/goal-turn-scope
Aug 15, 2026
Merged

fix(goal): bound goal-driven turns and map ESC to goal pause#280
LeXwDeX merged 1 commit into
devfrom
fix/goal-turn-scope

Conversation

@LeXwDeX

@LeXwDeX LeXwDeX commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Problem

Session ses_fe5ffaee337c9jD5JRqJyzB5fr 生产事故:/goal 完成TODO 后 goal_state 停留 active/turns_used=0/20 超 10 分钟,judge 从未运行。

根因(日志+DB+源码三方定位):GoalLoop 纯 idle 事件驱动,而 build agent 无 steps 配置 → 首轮 agent.steps ?? Infinity 无界执行(step 67+)→ idle 永不到来 → judge/budget/全部防御不可达。

reasoner 推演确认 3 个 Critical:

  • C1: kick/续派/resume-kick 三条派发路径全部无界,且无 goal 溯源标记
  • C2: 裸 ESC 后 shouldPreempt 恒 false(最后 user 消息即 /goal 命令本身)→ judge 自动复活用户刚中止的 goal(与 loop.ts F1 注释矛盾)
  • C3: 「idle 永不到来」是无守卫吸收态

Fix(GOAL-TURN-SCOPE)

  • GoalPrompts.GOAL_TURN_MAX_STEPS = 50:goal 驱动轮步数上限 min(agent.steps ?? ∞, 50)(用户更严格配置始终优先),保证每轮必达 idle 使 judge/budget 接管
  • Goal.Service 新增 turn 溯源:markTurnDriven/clearTurnDriven/isTurnDriven/goalTurnMaxSteps(对 durable row 二次校验、stale 自退役)/pauseForUserCancel;全部 terminal 转换(pause/clear/markDone/purgeSession)清 mark
  • ESC 语义:goal 轮被 cancel → durable pause + lease 释放(不再被 judge 复活)
  • 可观测性:statusLine 在 goal 轮执行中显示「执行中」;预算耗尽/resume 文案如实统一

Review

subagent review VERDICT: PASS(0 blocking / 4 info)。#1 purgeSession 对称性、#2 admit-mark 窗口(mark 提前到 admitIfIdle 前)已修;#3 记录为已知边界(dispatch 已有 busy guard);#4 集成测试部分补充。

Verification

  • bun typecheck (packages/opencode) 干净
  • bun test test/goal test/session/prompt.test.ts:175 pass / 0 fail / 1 skip(既有 skip)
  • 新增 turn-scope.test.ts 9 用例:ceiling 报告、stale mark 退役(clear/pause)、ESC durable pause、no-op、markDone/purgeSession 清理、执行中状态行

- GOAL-TURN-SCOPE: process-local turn provenance for kick/continuation/resume-kick
- cap goal turns at min(agent.steps, GOAL_TURN_MAX_STEPS=50) so every turn reaches idle where judge/budget engage
- ESC on a goal turn now pauses the goal instead of auto-resurrecting via judge continuation
- statusLine shows 执行中 while a goal turn runs; honest budget-exhaustion/resume texts
- tests: turn-scope.test.ts (9 cases)
@LeXwDeX
LeXwDeX merged commit ece0db5 into dev Aug 15, 2026
5 checks passed
@LeXwDeX
LeXwDeX deleted the fix/goal-turn-scope branch August 15, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant