From f624feec75f08246dbc6fc2a86c1775db794fe7d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 10 Oct 2026 05:32:19 +0200 Subject: [PATCH] mind-body launch: dead runs closed in the opening batch, Busy from admission, breaker over the item's citations open_and_launch takes a Grant by value. Step 0 reads the in-force runs of hers of the request's turn on the instance (typed facts): a live unit or a run inside START_GRACE_S answers Busy; a dead one is closed Recorded in the same admission that opens the next run, so the in-force record is the one owner of liveness. Admission's AlreadyLive maps to Busy. The alias Busy query and the whole-mind breaker scan are deleted: the breaker counts the documents that cite the item, starting after the newest question raised in it, and a trip's question is keyed by the run label. SystemdLauncher holds no instance; unit names are validated before systemctl sees them. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/launch.rs | 557 +++++++++++++++++++++++++------- crates/mind-body/src/queue.rs | 205 +++++++----- crates/mind-body/src/testkit.rs | 40 ++- 3 files changed, 594 insertions(+), 208 deletions(-) diff --git a/crates/mind-body/src/launch.rs b/crates/mind-body/src/launch.rs index 922b9f4..cdd312a 100644 --- a/crates/mind-body/src/launch.rs +++ b/crates/mind-body/src/launch.rs @@ -1,29 +1,40 @@ //! The one way her organs open a run and start its unit. //! -//! `open_and_launch` is the whole path: Busy, queue membership and the -//! repetition breaker are checked in that order, the run is admitted into the -//! mind, and only after it commits is the unit started. The run is the grant -//! (target invariant run-is-the-grant), so there is no pressure file, lease or -//! breaker state beside it, and a unit never starts without a committed run. -//! The primitive owns no file and stops no unit: stopping her units is the -//! operator's brake hold, which is another cut's. +//! `open_and_launch` is the whole path, in this order: (0) the in-force runs of +//! hers of the request's turn are read, a live one (its unit active, or +//! admitted within `START_GRACE_S`) answers Busy and a dead one is to be closed +//! Recorded; (1) every cut-spec claim must be in the queue; (2) no claim may +//! trip the repetition breaker; (3) the run is admitted, in the one batch that +//! closes the dead holders, so liveness is decided by the in-force record alone +//! and the unit table is only the evidence for a close; (4) the unit is started, +//! only after that batch commits. The run is the grant (target invariant +//! run-is-the-grant), so there is no pressure file, lease or breaker state +//! beside it, and a unit never starts without a committed run. A run opens +//! only against a `Grant`, which `read_effective` alone makes. The primitive +//! owns no file and stops no unit: stopping her units is the operator's brake +//! hold, which is another cut's. use anyhow::{Result, anyhow}; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, Duration, Utc}; +use cultnet_rs::Selection; use eureka_pipeline::{ - Date, Label, PipelineDocument, PipelineKind, PipelineQuestion, PipelineRef, PipelineResolution, PipelineRun, QuestionOption, - ResolutionOutcome, RunOperator, RunTurn, Slug, + Date, Label, PipelineDocument, PipelineKind, PipelineQuestion, PipelineRef, PipelineResolution, PipelineRun, QuestionOption, ResolutionOutcome, + RunOperator, RunTurn, Slug, pipeline_key, }; -use huginn_mind::{MindRefusal, PipelineAdmissionOutcome}; -use rust_decimal::Decimal; +use huginn_mind::{MindRefusal, PipelineAdmissionOutcome, PipelineFacts}; -use crate::queue::{Breaker, MindPort, any_of, breaker, headers, in_force, of_kind, queue}; +use crate::control::Grant; +use crate::queue::{Breaker, MindPort, any_of, breaker, citing, headers, in_force, of_kind, queue}; + +/// How long a run just admitted may have no active unit before its slot is +/// treated as dead: `systemctl start --no-block` returns before the unit runs. +pub const START_GRACE_S: i64 = 120; /// Starts the unit that carries a run, and says whether it is still running. /// Nothing here stops a unit. pub trait Launcher { - fn start(&self, turn: RunTurn, label: &Label) -> Result<()>; - fn alive(&self, turn: RunTurn, label: &Label) -> bool; + fn start(&self, instance: &Slug, turn: RunTurn, label: &Label) -> Result<()>; + fn alive(&self, instance: &Slug, turn: RunTurn, label: &Label) -> bool; } /// The time the primitive reads: run labels, dates and receipts. @@ -61,42 +72,53 @@ impl Systemctl for RealSystemctl { /// Her units under systemd, templated by instance: /// `mind-persona@: