fix(goal): quiet waits and unify fleet NG ownership (#56, #57, #58)

This commit is contained in:
Dewey
2026-09-06 04:07:09 -05:00
parent 7345f330fc
commit 9a5fbdbda7
14 changed files with 892 additions and 26 deletions
+6 -1
View File
@@ -5,6 +5,11 @@ import { checkLimitReached, type GoalState } from "./state.ts";
export type SettleDecision = { action: "inject" } | { action: "wait" } | { action: "pause"; reason: string };
/** An untimed wait never spends model tokens on automatic reconciliation. */
export function hasUnresolvedWait(state: GoalState): boolean {
return !!state.activeWait && (!state.waitTimeoutSeconds || !state.activeWait.wakeSent);
}
/**
* Decide what the loop does when the agent settles while a goal is active.
* stopReason comes from the last assistant message ("stop", "toolUse",
@@ -17,7 +22,7 @@ export function decideSettle(state: GoalState, stopReason: string | undefined):
if (stopReason === "error") {
return { action: "pause", reason: "paused: run error" };
}
if (state.waitTimeoutSeconds && state.activeWait && !state.activeWait.wakeSent) {
if (hasUnresolvedWait(state)) {
return { action: "wait" };
}
if (checkLimitReached(state)) {
+4 -3
View File
@@ -77,7 +77,7 @@ export interface GoalState {
wakeDispatchedAt?: number;
wakeObserved?: boolean;
};
/** Operator opt-in: suspend waits, with one deadline wake per goal/resume. */
/** Operator opt-in: add one deadline wake to a suspended wait per goal/resume. */
waitTimeoutSeconds?: number;
waitWakeUsed?: boolean;
setAt: string;
@@ -144,7 +144,8 @@ export function blockGoal(state: GoalState, reason: string): GoalState {
}
export function resumeGoal(state: GoalState): GoalState {
if (state.status !== "paused" && state.status !== "blocked") return state;
if (state.status !== "paused" && state.status !== "blocked" &&
!(state.status === "active" && state.activeWait)) return state;
return {
...state,
status: "active",
@@ -152,7 +153,7 @@ export function resumeGoal(state: GoalState): GoalState {
noProgressReports: 0,
workEventSinceReport: false,
pausedReason: undefined,
activeWait: state.waitTimeoutSeconds ? undefined : state.activeWait,
activeWait: undefined,
waitWakeUsed: state.waitTimeoutSeconds ? false : state.waitWakeUsed,
};
}