Skip to main content

GoalCycle

Struct GoalCycle 

Source
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: i64

Seconds of no task activity before detect_stuck_tasks interrupts a running/claimed task. Defaults to 300.

Implementations§

Source§

impl GoalCycle

Source

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.

Source

pub async fn dispatch_due_mandate_with_busy_retry( &self, mandate: Mandate, ) -> Result<()>

Source

pub async fn dispatch_due_mandate(&self, mandate: Mandate) -> Result<()>

Source§

impl GoalCycle

Source

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.

Source

pub async fn enqueue_goal_notifications(&self)

Scan for goals needing notification and enqueue them.

Source

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.

Source

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.

Source

pub async fn process_notification_queue(&self)

Process the notification queue: attempt delivery, track attempts.

Source§

impl GoalCycle

Source

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.

Source

pub async fn reconcile_open_scheduled_runs(&self)

Source

pub async fn reconcile_open_scheduled_runs_for_goal( &self, goal_id: &str, ) -> Result<Vec<GoalRun>>

Source

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.

Source

pub async fn fire_due_schedule(&self, schedule: GoalSchedule) -> Result<()>

Source§

impl GoalCycle

Source

pub async fn detect_stuck_tasks(&self)

Detect tasks that have been running/claimed longer than the timeout and mark them interrupted.

Source

pub async fn block_pending_tasks_with_terminal_failed_dependencies(&self)

Source

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.

Source

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:

  1. Atomically claim a task via claim_task (prevents duplicate dispatch)
  2. Spawn a background task lead gated by the semaphore
  3. The task lead picks up all pending tasks for the goal

Falls back to notification if no agent reference is available.

Source

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

Source

pub fn new( state: Arc<dyn SchedulerStore>, presenter: Arc<dyn WorkPresenter>, goal_token_registry: Option<GoalTokenRegistry>, ) -> Self

Source

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.

Source

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.

Source

pub fn set_task_inactivity_timeout(&mut self, secs: u64)

Override the stuck-task inactivity timeout.

Source

pub fn set_delivery(&mut self, delivery: Option<Arc<dyn NoticeDelivery>>)

The channels notices go out through.

Source

pub fn set_agent(&mut self, agent: Option<Arc<dyn TaskLeadHost>>)

The agent runtime that runs task leads.

Source

pub async fn startup_recovery(&self)

One-time recovery after startup: mark interrupted tasks, rebuild token registry.

Source

pub async fn tick(&mut self) -> Result<()>

One pass of the goal cycle. Periodic jobs and the database check are the host’s.

Auto Trait Implementations§

§

impl !RefUnwindSafe for GoalCycle

§

impl !UnwindSafe for GoalCycle

§

impl Forget for GoalCycle

§

impl Freeze for GoalCycle
where *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 GoalCycle

§

impl Sync for GoalCycle

§

impl Unpin for GoalCycle

§

impl UnsafeUnpin for GoalCycle
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more