pub struct GoalCycle {
pub task_inactivity_timeout_secs: i64,
/* private fields */
}Expand description
The goal cycle and what it needs between passes.
Fields§
§task_inactivity_timeout_secs: i64Seconds of no task activity before detect_stuck_tasks interrupts a
running/claimed task. Defaults to 300.
Implementations§
Source§impl GoalCycle
impl GoalCycle
Sourcepub async fn check_due_mandates(&self)
pub async fn check_due_mandates(&self)
Claim and dispatch due mandate reviews from the mandate-owned wake clock.
This path is deliberately independent from goal_schedules: a mandate
review gets trigger_type = "mandate", no schedule id, and a distinct
root-task description. The mandate lease is the admission fence; the
task-attempt lease and per-goal run guard remain execution fences.
pub async fn dispatch_due_mandate_with_busy_retry( &self, mandate: Mandate, ) -> Result<()>
pub async fn dispatch_due_mandate(&self, mandate: Mandate) -> Result<()>
Source§impl GoalCycle
impl GoalCycle
Sourcepub async fn deliver_notifications(&self)
pub async fn deliver_notifications(&self)
Phase 5a: Scan goals that completed/failed and enqueue notifications. Phase 5b: Process notification queue — attempt delivery. Phase 5c: Cleanup expired status_update notifications.
Sourcepub async fn enqueue_goal_notifications(&self)
pub async fn enqueue_goal_notifications(&self)
Scan for goals needing notification and enqueue them.
Sourcepub async fn record_delivered_notification(
&self,
entry: &NotificationEntry,
delivered_text: &str,
)
pub async fn record_delivered_notification( &self, entry: &NotificationEntry, delivered_text: &str, )
Queue delivery bypasses deliver_parent_text_result, so persist every
delivered notice in owner history: a reply to it must reach an agent
that can see what it answers.
Sourcepub async fn bind_mandate_answer_context(
&self,
agent: &dyn TaskLeadHost,
entry: &NotificationEntry,
)
pub async fn bind_mandate_answer_context( &self, agent: &dyn TaskLeadHost, entry: &NotificationEntry, )
Bind the owner’s next reply to a delivered mandate question so a bare
“yes” reaches answer_question instead of an agent with no referent.
A timed-out ASK has already resumed, so any non-terminal mandate that
still carries the question qualifies; the answer lands as late guidance.
Sourcepub async fn process_notification_queue(&self)
pub async fn process_notification_queue(&self)
Process the notification queue: attempt delivery, track attempts.
Source§impl GoalCycle
impl GoalCycle
Sourcepub async fn check_due_goal_schedules(&self)
pub async fn check_due_goal_schedules(&self)
Check for due schedules across active orchestration goals and enqueue tasks.
Scheduling is per-schedule (goal_schedules) rather than a goal column.
pub async fn reconcile_open_scheduled_runs(&self)
pub async fn reconcile_open_scheduled_runs_for_goal( &self, goal_id: &str, ) -> Result<Vec<GoalRun>>
Sourcepub async fn launch_escalated_recoveries(&self)
pub async fn launch_escalated_recoveries(&self)
Launch one automatic recovery run per escalated objective once its
cool-down has elapsed, up to a fixed attempt cap. The recovery run is
the same typed recovery lineage the task lead creates inline
(terminal_recovery + recovery_for_run), so a verified success
resets the failure budget and resumes the paused schedules through
finish_goal_run, and a failure lands in the same budget accounting.
The paused schedules stay paused during recovery so the cron cannot
double-fire.
pub async fn fire_due_schedule(&self, schedule: GoalSchedule) -> Result<()>
Source§impl GoalCycle
impl GoalCycle
Sourcepub async fn detect_stuck_tasks(&self)
pub async fn detect_stuck_tasks(&self)
Detect tasks that have been running/claimed longer than the timeout and mark them interrupted.
pub async fn block_pending_tasks_with_terminal_failed_dependencies(&self)
Sourcepub async fn auto_retry_failed_tasks(&self)
pub async fn auto_retry_failed_tasks(&self)
Auto-retry failed idempotent tasks that haven’t exceeded their max retries. Resets them to “pending” so they get picked up by dispatch_pending_tasks.
Sourcepub async fn dispatch_pending_tasks(&self)
pub async fn dispatch_pending_tasks(&self)
Dispatch orphaned pending tasks by atomically claiming them and spawning task leads.
For each active goal with pending tasks but no running agent:
- Atomically claim a task via
claim_task(prevents duplicate dispatch) - Spawn a background task lead gated by the semaphore
- The task lead picks up all pending tasks for the goal
Falls back to notification if no agent reference is available.
Sourcepub async fn goal_run_mutating_success_tasks(&self, run_id: &str) -> Vec<String>
pub async fn goal_run_mutating_success_tasks(&self, run_id: &str) -> Vec<String>
Idempotency backstop for scheduled goals: returns the tasks in one
durable goal run that have a logged, successful, mutating (non-GET)
http_request activity.
This is a defense-in-depth check, not the primary fix — it exists so
that whatever caused a scheduled goal’s task to look unfinished
(timeout, tool cooldown, orchestrator misjudgment, a bug nobody’s hit
yet) can never turn into a repeated real-world side effect. It reads
task_activity rows that are already logged for every tool call
(src/agent/turn/tool_execution/run.rs), so it needs no schema change.
Fails closed toward “don’t block” on any parse/lookup miss — a false
negative here just falls back to prior behavior, never a false positive
that would wrongly skip real unfinished work. Scoping by goal_run_id
is what prevents a successful prior run from suppressing a new manual
trigger.
Source§impl GoalCycle
impl GoalCycle
pub fn new( state: Arc<dyn SchedulerStore>, presenter: Arc<dyn WorkPresenter>, goal_token_registry: Option<GoalTokenRegistry>, ) -> Self
Sourcepub fn set_booted_at(&mut self, booted_at: String)
pub fn set_booted_at(&mut self, booted_at: String)
This process’s boot instant (RFC 3339). Take it before anything in the process can claim a task attempt, and only while the process holds the database’s single-instance lock: startup recovery treats every attempt started before it as left by a stopped process.
Sourcepub fn needs_model_notices(&self) -> Arc<NeedsModelNotices> ⓘ
pub fn needs_model_notices(&self) -> Arc<NeedsModelNotices> ⓘ
The goals told they need a model, for clearing the moment a model
is connected (needs_model::clear_on_connect), not only at the
next pass.
Sourcepub fn set_task_inactivity_timeout(&mut self, secs: u64)
pub fn set_task_inactivity_timeout(&mut self, secs: u64)
Override the stuck-task inactivity timeout.
Sourcepub fn set_delivery(&mut self, delivery: Option<Arc<dyn NoticeDelivery>>)
pub fn set_delivery(&mut self, delivery: Option<Arc<dyn NoticeDelivery>>)
The channels notices go out through.
Sourcepub fn set_agent(&mut self, agent: Option<Arc<dyn TaskLeadHost>>)
pub fn set_agent(&mut self, agent: Option<Arc<dyn TaskLeadHost>>)
The agent runtime that runs task leads.
Sourcepub async fn startup_recovery(&self)
pub async fn startup_recovery(&self)
One-time recovery after startup: mark interrupted tasks, rebuild token registry.
Auto Trait Implementations§
impl !RefUnwindSafe for GoalCycle
impl !UnwindSafe for GoalCycle
impl Forget for GoalCycle
impl Freeze for GoalCyclewhere
*const ArcInner<dyn SchedulerStore> is !null: Freeze,
PhantomData<ArcInner<dyn SchedulerStore>>: Freeze,
*const ArcInner<dyn TaskLeadHost> is !null: Freeze,
PhantomData<ArcInner<dyn TaskLeadHost>>: Freeze,
*const ArcInner<dyn NoticeDelivery> is !null: Freeze,
PhantomData<ArcInner<dyn NoticeDelivery>>: Freeze,
*const ArcInner<dyn WorkPresenter> is !null: Freeze,
PhantomData<ArcInner<dyn WorkPresenter>>: Freeze,
*const ArcInner<RwLock<HashMap<String, CancellationToken>>> is !null: Freeze,
PhantomData<ArcInner<RwLock<HashMap<String, CancellationToken>>>>: Freeze,
*const ArcInner<RwLock<HashMap<String, GoalBudgetOverride>>> is !null: Freeze,
PhantomData<ArcInner<RwLock<HashMap<String, GoalBudgetOverride>>>>: Freeze,
*const ArcInner<RwLock<HashMap<String, GoalRunBudgetState>>> is !null: Freeze,
PhantomData<ArcInner<RwLock<HashMap<String, GoalRunBudgetState>>>>: Freeze,
*const ArcInner<Mutex<HashSet<String>>> is !null: Freeze,
PhantomData<ArcInner<Mutex<HashSet<String>>>>: Freeze,
*const ArcInner<Atomic<bool>> is !null: Freeze,
PhantomData<ArcInner<Atomic<bool>>>: Freeze,
*const ArcInner<Mutex<Vec<JoinHandle<()>>>> is !null: Freeze,
PhantomData<ArcInner<Mutex<Vec<JoinHandle<()>>>>>: Freeze,
*const ArcInner<NeedsModelNotices> is !null: Freeze,
PhantomData<ArcInner<NeedsModelNotices>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
impl Move for GoalCycle
impl Send for GoalCyclewhere
Arc<dyn SchedulerStore>: Send,
Arc<dyn TaskLeadHost>: Send,
Arc<dyn NoticeDelivery>: Send,
Arc<dyn WorkPresenter>: Send,
Arc<RwLock<HashMap<String, CancellationToken>>>: Send,
Arc<RwLock<HashMap<String, GoalBudgetOverride>>>: Send,
Arc<RwLock<HashMap<String, GoalRunBudgetState>>>: Send,
Arc<Mutex<HashSet<String>>>: Send,
Arc<Atomic<bool>>: Send,
Arc<Mutex<Vec<JoinHandle<()>>>>: Send,
Arc<NeedsModelNotices>: Send,
RawVecInner: Send,
impl Sync for GoalCyclewhere
Arc<dyn SchedulerStore>: Sync,
Arc<dyn TaskLeadHost>: Sync,
Arc<dyn NoticeDelivery>: Sync,
Arc<dyn WorkPresenter>: Sync,
Arc<RwLock<HashMap<String, CancellationToken>>>: Sync,
Arc<RwLock<HashMap<String, GoalBudgetOverride>>>: Sync,
Arc<RwLock<HashMap<String, GoalRunBudgetState>>>: Sync,
Arc<Mutex<HashSet<String>>>: Sync,
Arc<Atomic<bool>>: Sync,
Arc<Mutex<Vec<JoinHandle<()>>>>: Sync,
Arc<NeedsModelNotices>: Sync,
RawVecInner: Sync,
impl Unpin for GoalCyclewhere
Arc<dyn SchedulerStore>: Unpin,
Arc<dyn TaskLeadHost>: Unpin,
Arc<dyn NoticeDelivery>: Unpin,
Arc<dyn WorkPresenter>: Unpin,
Arc<RwLock<HashMap<String, CancellationToken>>>: Unpin,
Arc<RwLock<HashMap<String, GoalBudgetOverride>>>: Unpin,
Arc<RwLock<HashMap<String, GoalRunBudgetState>>>: Unpin,
Arc<Mutex<HashSet<String>>>: Unpin,
Arc<Atomic<bool>>: Unpin,
Arc<Mutex<Vec<JoinHandle<()>>>>: Unpin,
Arc<NeedsModelNotices>: Unpin,
*const u8 is !null: Unpin,
impl UnsafeUnpin for GoalCyclewhere
*const ArcInner<dyn SchedulerStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn SchedulerStore>>: UnsafeUnpin,
*const ArcInner<dyn TaskLeadHost> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn TaskLeadHost>>: UnsafeUnpin,
*const ArcInner<dyn NoticeDelivery> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn NoticeDelivery>>: UnsafeUnpin,
*const ArcInner<dyn WorkPresenter> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn WorkPresenter>>: UnsafeUnpin,
*const ArcInner<RwLock<HashMap<String, CancellationToken>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<HashMap<String, CancellationToken>>>>: UnsafeUnpin,
*const ArcInner<RwLock<HashMap<String, GoalBudgetOverride>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<HashMap<String, GoalBudgetOverride>>>>: UnsafeUnpin,
*const ArcInner<RwLock<HashMap<String, GoalRunBudgetState>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<HashMap<String, GoalRunBudgetState>>>>: UnsafeUnpin,
*const ArcInner<Mutex<HashSet<String>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<HashSet<String>>>>: UnsafeUnpin,
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
*const ArcInner<Mutex<Vec<JoinHandle<()>>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Vec<JoinHandle<()>>>>>: UnsafeUnpin,
*const ArcInner<NeedsModelNotices> is !null: UnsafeUnpin,
PhantomData<ArcInner<NeedsModelNotices>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more