Merge origin/main (fb19703, held-questions successor cut) into eureka-body/persona-session
The one conflict was the public-surface snapshot: the branch's new
launch::StopScope line beside main's LaunchOutcome::Tripped { run } line;
both kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
153678a321
12 changed files with 1605 additions and 174 deletions
|
|
@ -22,13 +22,17 @@ mod render;
|
|||
mod schema;
|
||||
mod trouble;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::io::Write;
|
||||
use std::process::ExitCode;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
|
||||
use cultnet_rs::{PROJECTION_DOCUMENT, Selection};
|
||||
use huginn_mind::eureka_pipeline::{Line, PipelineDocument, PipelineRef, Short, Slug, pipeline_key};
|
||||
use eureka_state::hold;
|
||||
use huginn_mind::eureka_pipeline::{
|
||||
Line, PipelineDocument, PipelineRef, Short, Slug, pipeline_key,
|
||||
};
|
||||
use huginn_mind::{
|
||||
BATCH_MAX, Faculty, HuginnMindRequest, HuginnMindResponse, MindRefusal, PipelineAdmissionBatch, PipelineAdmissionOutcome,
|
||||
PipelinePageItems, PipelineProvenance, PipelineSelectionPage, SemanticQuery, SourceQuery,
|
||||
|
|
@ -182,7 +186,15 @@ fn run(settings: &Settings, command: Command) -> Result<u8, Trouble> {
|
|||
let semantic = near.map(|text| SemanticQuery { text: Line(text), top_k: top_k.unwrap_or(DEFAULT_TOP_K) });
|
||||
query(settings, selection, semantic, None, documents)
|
||||
}
|
||||
Command::Sources { text, repo, top_k, json } => sources(settings, text, repo, top_k, json),
|
||||
Command::Sources {
|
||||
text,
|
||||
repo,
|
||||
top_k,
|
||||
json,
|
||||
} => sources(settings, text, repo, top_k, json),
|
||||
Command::Recipe(Recipe::Blocked { spec_id, page }) => {
|
||||
blocked(settings, &spec_id, page.cursor, page.documents)
|
||||
}
|
||||
Command::Recipe(recipe) => {
|
||||
let ask = recipe.ask()?;
|
||||
query(settings, door::selection_value(&ask.selection)?, ask.semantic, ask.page.cursor, ask.page.documents)
|
||||
|
|
@ -264,9 +276,81 @@ fn query(
|
|||
}
|
||||
}
|
||||
|
||||
fn sources(settings: &Settings, text: String, repo: Option<String>, top_k: Option<u32>, json: bool) -> Result<u8, Trouble> {
|
||||
let query = SourceQuery { text: Line(text), top_k: top_k.unwrap_or(DEFAULT_TOP_K), repo: repo.map(Short) };
|
||||
match settings.ask(|instance| HuginnMindRequest::SearchSources { instance: instance.clone(), query })? {
|
||||
/// The open questions that hold a spec, and the answered-`retire` ones whose
|
||||
/// claims are not yet resolved: `eureka_state::hold`'s answer, the one the
|
||||
/// heartbeat's gate reads, printed as a selection of those questions.
|
||||
fn blocked(
|
||||
settings: &Settings,
|
||||
spec_id: &str,
|
||||
cursor: Option<String>,
|
||||
documents: bool,
|
||||
) -> Result<u8, Trouble> {
|
||||
let spec = PipelineRef {
|
||||
kind: door::kind_of(spec_id)?,
|
||||
id: Short(spec_id.to_string()),
|
||||
};
|
||||
let failure: RefCell<Option<Trouble>> = RefCell::new(None);
|
||||
let as_of = Cell::new(0);
|
||||
let ask = |selection: &Selection| -> anyhow::Result<PipelineSelectionPage> {
|
||||
let selection = selection.clone();
|
||||
match settings.ask(|instance| HuginnMindRequest::Query {
|
||||
instance: instance.clone(),
|
||||
selection,
|
||||
semantic: None,
|
||||
}) {
|
||||
Ok(HuginnMindResponse::Query(page)) => {
|
||||
as_of.set(page.as_of);
|
||||
Ok(page)
|
||||
}
|
||||
Ok(_) => Err(anyhow::anyhow!(
|
||||
"the mind answered a query with something else"
|
||||
)),
|
||||
Err(trouble) => {
|
||||
*failure.borrow_mut() = Some(trouble);
|
||||
Err(anyhow::anyhow!("the mind could not be asked"))
|
||||
}
|
||||
}
|
||||
};
|
||||
let holding = match hold::holds(&ask) {
|
||||
Ok(holds) => holds,
|
||||
Err(error) => {
|
||||
return Err(failure
|
||||
.take()
|
||||
.unwrap_or_else(|| Trouble::Internal(error.to_string())));
|
||||
}
|
||||
};
|
||||
let keys: Vec<String> = holding
|
||||
.iter()
|
||||
.filter(|held| held.items.contains(&spec))
|
||||
.map(|held| held.question.id.id.0.clone())
|
||||
.collect();
|
||||
if keys.is_empty() {
|
||||
say(format_args!("matched 0 as_of {} next -", as_of.get()));
|
||||
return Ok(0);
|
||||
}
|
||||
let selection = Selection {
|
||||
keys: Some(keys),
|
||||
..Selection::default()
|
||||
};
|
||||
query(settings, selection, None, cursor, documents)
|
||||
}
|
||||
|
||||
fn sources(
|
||||
settings: &Settings,
|
||||
text: String,
|
||||
repo: Option<String>,
|
||||
top_k: Option<u32>,
|
||||
json: bool,
|
||||
) -> Result<u8, Trouble> {
|
||||
let query = SourceQuery {
|
||||
text: Line(text),
|
||||
top_k: top_k.unwrap_or(DEFAULT_TOP_K),
|
||||
repo: repo.map(Short),
|
||||
};
|
||||
match settings.ask(|instance| HuginnMindRequest::SearchSources {
|
||||
instance: instance.clone(),
|
||||
query,
|
||||
})? {
|
||||
HuginnMindResponse::Sources(found) => {
|
||||
if json {
|
||||
say(serde_json::to_string_pretty(&found).map_err(|error| Trouble::Internal(error.to_string()))?);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
//! The campaign progress view as named subcommands. Each recipe is exactly the
|
||||
//! selection `references/campaign-state.md` gives (Eureka 278b881, "Recipes"),
|
||||
//! built per call and never cached. Each one's `--help` prints its selection.
|
||||
//! The one exception is `blocked`, which asks what a question holds and so
|
||||
//! reads through `eureka_state::hold`, the decider the heartbeat's gate reads.
|
||||
|
||||
use clap::{Args, Subcommand};
|
||||
use huginn_mind::SemanticQuery;
|
||||
|
|
@ -66,7 +68,7 @@ pub enum Recipe {
|
|||
#[command(flatten)]
|
||||
page: Paging,
|
||||
},
|
||||
/// Open questions raised in a spec: the spec waits on the operator.
|
||||
/// Questions that hold a spec, answered-retire ones included: the spec waits on the operator.
|
||||
Blocked {
|
||||
spec_id: String,
|
||||
#[command(flatten)]
|
||||
|
|
@ -125,7 +127,12 @@ impl Recipe {
|
|||
Self::Open { campaigns, page } => (open(&campaigns), None, page),
|
||||
Self::Findings { campaign, blocking, page } => (findings(&campaign, blocking), None, page),
|
||||
Self::Unreported { campaign, page } => (unreported(&campaign), None, page),
|
||||
Self::Blocked { spec_id, page } => (blocked(&spec_id), None, page),
|
||||
// Several selections, not one: `main` answers it through `eureka_state::hold`.
|
||||
Self::Blocked { .. } => {
|
||||
return Err(Trouble::Internal(
|
||||
"blocked is answered by the hold, not by one selection".into(),
|
||||
));
|
||||
}
|
||||
Self::Unjudged { campaign, page } => (unjudged(&campaign), None, page),
|
||||
Self::History { id, page } => (history(door::kind_of(&id)?.type_id(), &id), None, page),
|
||||
Self::Cut { campaign, label, page } => (cut(&campaign, &label), None, page),
|
||||
|
|
@ -198,14 +205,6 @@ fn unreported(campaign: &str) -> Value {
|
|||
})
|
||||
}
|
||||
|
||||
fn blocked(spec_id: &str) -> Value {
|
||||
json!({
|
||||
"schemas": [schema(PipelineKind::Question)],
|
||||
"fields": [in_force()],
|
||||
"cites": { "target": { "schemaId": schema(PipelineKind::CutSpec), "recordKey": spec_id }, "role": "raised_in" },
|
||||
})
|
||||
}
|
||||
|
||||
fn unjudged(campaign: &str) -> Value {
|
||||
json!({
|
||||
"schemas": [schema(PipelineKind::CutReport)],
|
||||
|
|
@ -257,6 +256,18 @@ fn gaps() -> Value {
|
|||
})
|
||||
}
|
||||
|
||||
/// `blocked` is not one selection: it reads the in-force questions and, for each,
|
||||
/// what it holds, by `eureka_state::hold`, the decider the heartbeat's gate reads.
|
||||
fn blocked_help() -> String {
|
||||
let questions = json!({ "schemas": [schema(PipelineKind::Question)], "fields": [in_force()] });
|
||||
format!(
|
||||
"selection (first of several):
|
||||
{}
|
||||
A question holds the item it is raised in, or every claim of the run it is raised in; one answered `retire` keeps holding the claims still in force. The recipe prints the questions that hold <id>.",
|
||||
serde_json::to_string_pretty(&questions).unwrap_or_default()
|
||||
)
|
||||
}
|
||||
|
||||
/// Each recipe's `--help` addendum: its selection with placeholders in the
|
||||
/// arguments' places. The same builders as execution, so help cannot drift
|
||||
/// from what runs.
|
||||
|
|
@ -276,7 +287,7 @@ pub fn help() -> Vec<(&'static str, String)> {
|
|||
("open", selection(open(&[c()]))),
|
||||
("findings", findings_help),
|
||||
("unreported", selection(unreported(&c()))),
|
||||
("blocked", selection(blocked("<id>"))),
|
||||
("blocked", blocked_help()),
|
||||
("unjudged", selection(unjudged(&c()))),
|
||||
("history", selection(history("epiphany.pipeline.<kind>.v2", "<id>"))),
|
||||
("cut", selection(cut(&c(), "<label>"))),
|
||||
|
|
|
|||
173
crates/eureka-state/src/hold.rs
Normal file
173
crates/eureka-state/src/hold.rs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
//! What an open question holds: the one decider, read by the heartbeat's gate
|
||||
//! and by `huginn blocked`, so the two cannot disagree.
|
||||
//!
|
||||
//! A question raised in a run holds every claim of that run, the set that
|
||||
//! failed together; a question raised in anything else holds that item. A
|
||||
//! question answered with the option `retire` keeps holding the claims of the
|
||||
//! run it was raised in for as long as they are in force: the answer has said
|
||||
//! they are not to be worked, and whoever resolves them is the one writer of
|
||||
//! that. Answering or withdrawing a question with any other choice lifts its
|
||||
//! hold. The question's text is display only.
|
||||
//!
|
||||
//! Nothing here keeps state. Every answer is read through `ask`, one typed
|
||||
//! selection at a time, so a caller with a daemon and a caller with a
|
||||
//! temporary mind read the same way.
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use cultnet_rs::{Citation, FieldPredicate, Incoming, RecordRef, Selection};
|
||||
use huginn_mind::eureka_pipeline::{PipelineKind, PipelineRef};
|
||||
use huginn_mind::{
|
||||
PipelineDocumentSummary, PipelineFacts, PipelinePageItems, PipelineSelectionPage,
|
||||
PipelineStatusSummary,
|
||||
};
|
||||
|
||||
/// The option label of a breaker question whose answer retires the claims it holds.
|
||||
pub const RETIRE: &str = "retire";
|
||||
|
||||
/// One page of a selection, from whoever reads the mind.
|
||||
pub type Ask<'a> = dyn Fn(&Selection) -> Result<PipelineSelectionPage> + 'a;
|
||||
|
||||
/// A question and the items it holds.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Hold {
|
||||
pub question: PipelineDocumentSummary,
|
||||
pub items: Vec<PipelineRef>,
|
||||
/// The question is answered `retire`: the items are held until they are resolved.
|
||||
pub retired: bool,
|
||||
}
|
||||
|
||||
/// The documents that cite `target`, under `role` or any.
|
||||
pub fn citing(target: &PipelineRef, role: Option<&str>) -> Citation {
|
||||
Citation {
|
||||
target: RecordRef::new(target.kind.type_id(), target.id.0.clone()),
|
||||
role: role.map(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn of_kind(kind: PipelineKind) -> Selection {
|
||||
Selection {
|
||||
schemas: Some(vec![kind.type_id().to_string()]),
|
||||
..Selection::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn any_of(mut selection: Selection, index: &str, values: &[&str]) -> Selection {
|
||||
selection
|
||||
.fields
|
||||
.get_or_insert_with(Vec::new)
|
||||
.push(FieldPredicate {
|
||||
index: index.into(),
|
||||
op: "any_of".into(),
|
||||
values: Some(values.iter().map(|value| value.to_string()).collect()),
|
||||
number: None,
|
||||
});
|
||||
selection
|
||||
}
|
||||
|
||||
pub fn in_force(selection: Selection) -> Selection {
|
||||
any_of(selection, "in_force", &["true"])
|
||||
}
|
||||
|
||||
/// Every page of a selection, in the mind's order. The one paging loop.
|
||||
pub fn headers(ask: &Ask, selection: &Selection) -> Result<Vec<PipelineDocumentSummary>> {
|
||||
let mut all = Vec::new();
|
||||
let mut asking = selection.clone();
|
||||
loop {
|
||||
let page = ask(&asking)?;
|
||||
let PipelinePageItems::Headers(items) = page.items else {
|
||||
bail!("the mind answered documents to a header selection")
|
||||
};
|
||||
all.extend(items);
|
||||
match page.next {
|
||||
Some(cursor) => asking.cursor = Some(cursor),
|
||||
None => return Ok(all),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The claims of the run `run`, resolved or not (a citation outlives its
|
||||
/// resolution). Empty when the mind has no such run.
|
||||
pub fn claims_of(ask: &Ask, run: &PipelineRef) -> Result<Vec<PipelineRef>> {
|
||||
let one = Selection {
|
||||
keys: Some(vec![run.id.0.clone()]),
|
||||
..of_kind(PipelineKind::Run)
|
||||
};
|
||||
Ok(headers(ask, &one)?
|
||||
.into_iter()
|
||||
.flat_map(|header| match header.facts {
|
||||
PipelineFacts::Run { claims, .. } => claims,
|
||||
_ => Vec::new(),
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Every question holding anything: the open ones, each with what it holds,
|
||||
/// then the answered-`retire` ones whose claims are still in force.
|
||||
pub fn holds(ask: &Ask) -> Result<Vec<Hold>> {
|
||||
let mut found = Vec::new();
|
||||
for question in headers(ask, &in_force(of_kind(PipelineKind::Question)))? {
|
||||
if let PipelineFacts::Question {
|
||||
raised_in: Some(at),
|
||||
..
|
||||
} = &question.facts
|
||||
{
|
||||
let items = if at.kind == PipelineKind::Run {
|
||||
claims_of(ask, at)?
|
||||
} else {
|
||||
vec![at.clone()]
|
||||
};
|
||||
found.push(Hold {
|
||||
question,
|
||||
items,
|
||||
retired: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
let asked_in = Selection {
|
||||
cited: Some(Incoming {
|
||||
role: "raised_in".into(),
|
||||
exists: true,
|
||||
}),
|
||||
..of_kind(PipelineKind::Run)
|
||||
};
|
||||
for run in headers(ask, &asked_in)? {
|
||||
let questions = Selection {
|
||||
cites: Some(citing(&run.id, Some("raised_in"))),
|
||||
..of_kind(PipelineKind::Question)
|
||||
};
|
||||
for question in headers(ask, &questions)? {
|
||||
if matches!(question.status, PipelineStatusSummary::InForce)
|
||||
|| !answered_retire(ask, &question.id)?
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let mut items = Vec::new();
|
||||
for claim in claims_of(ask, &run.id)? {
|
||||
let live = Selection {
|
||||
keys: Some(vec![claim.id.0.clone()]),
|
||||
..in_force(of_kind(claim.kind))
|
||||
};
|
||||
if !headers(ask, &live)?.is_empty() {
|
||||
items.push(claim);
|
||||
}
|
||||
}
|
||||
if !items.is_empty() {
|
||||
found.push(Hold {
|
||||
question,
|
||||
items,
|
||||
retired: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
/// Whether a ruling answers `question` with the option `retire`.
|
||||
fn answered_retire(ask: &Ask, question: &PipelineRef) -> Result<bool> {
|
||||
let answers = Selection {
|
||||
cites: Some(citing(question, Some("answers"))),
|
||||
..of_kind(PipelineKind::Ruling)
|
||||
};
|
||||
Ok(headers(ask, &answers)?.iter().any(|ruling| matches!(&ruling.facts, PipelineFacts::Ruling { choice: Some(choice), .. } if choice.0 == RETIRE)))
|
||||
}
|
||||
|
|
@ -30,6 +30,8 @@ use huginn_mind::eureka_pipeline::Slug;
|
|||
use huginn_mind::{HuginnMindRequest, HuginnMindResponse, MAX_DEFERRED_BODY_BYTES, PipelineProvenance};
|
||||
use serde_json::Value;
|
||||
|
||||
pub mod hold;
|
||||
|
||||
/// The correlation key of the one request a session carries.
|
||||
const MESSAGE_ID: &str = "eureka-state-call";
|
||||
const POLL: Duration = Duration::from_millis(2);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ use std::sync::{Arc, Mutex};
|
|||
use cultnet_rs::Selection;
|
||||
use huginn_mind::envelope::{OperationFailure, decode_request, encode_failure, encode_response};
|
||||
use huginn_mind::eureka_pipeline::{
|
||||
CodeLocation, CommitRange, CutVerification, Date, Evidence, EvidenceKind, MutationRecord, OrgRepo, PipelineCutReport,
|
||||
PipelineCutSpec, PipelineDocument, PipelineKind, PipelineRef, PipelineRuling, Promise, ReportCommit, RulingAuthority, Short,
|
||||
StructuralDelta, pipeline_key,
|
||||
CodeLocation, CommitRange, CutVerification, Date, Evidence, EvidenceKind, MutationRecord,
|
||||
OrgRepo, PipelineCutReport, PipelineCutSpec, PipelineDocument, PipelineKind, PipelineQuestion,
|
||||
PipelineRef, PipelineResolution, PipelineRuling, PipelineRun, Promise, QuestionOption,
|
||||
ReportCommit, ResolutionOutcome, RulingAuthority, RunOperator, RunTurn, Short, StructuralDelta,
|
||||
pipeline_key,
|
||||
};
|
||||
use huginn_mind::{
|
||||
AdmissionFacts, HuginnMindRequest, HuginnMindResponse, IndexStatus, MindRefusal, MindStatus, PersonaStatus, PipelineAdmissionOutcome, PipelineDocumentView,
|
||||
|
|
@ -747,17 +749,6 @@ fn the_recipes_send_exactly_the_pages_selections() {
|
|||
"cited": { "role": "cut_spec", "exists": false },
|
||||
}),
|
||||
),
|
||||
(
|
||||
vec!["blocked", "eureka-substrate:cut_spec:cut-x.r1"],
|
||||
json!({
|
||||
"schemas": [schema("question")],
|
||||
"fields": [in_force],
|
||||
"cites": {
|
||||
"target": { "schemaId": schema("cut_spec"), "recordKey": "eureka-substrate:cut_spec:cut-x.r1" },
|
||||
"role": "raised_in",
|
||||
},
|
||||
}),
|
||||
),
|
||||
(
|
||||
vec!["unjudged", c],
|
||||
json!({
|
||||
|
|
@ -802,6 +793,150 @@ fn the_recipes_send_exactly_the_pages_selections() {
|
|||
}
|
||||
}
|
||||
|
||||
/// `huginn blocked` answers with the hold the heartbeat's gate reads: a question
|
||||
/// raised in a run holds every claim of that run, and an answer of `retire`
|
||||
/// keeps holding the claims until they are resolved.
|
||||
#[test]
|
||||
fn blocked_names_the_questions_that_hold_a_spec_as_the_gate_reads_them() {
|
||||
let server = live();
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let admit = |name: &str, documents: Value| {
|
||||
let file = write(&dir, name, &documents);
|
||||
let ran = at(server.addr, &admit_args(&file), None);
|
||||
assert_eq!(ran.code, 0, "{name}: {}", ran.err);
|
||||
};
|
||||
let value = |document: PipelineDocument| serde_json::to_value(document).unwrap();
|
||||
let spec_id = |cut: &str| format!("{CAMPAIGN}:cut_spec:cut-{cut}.r1");
|
||||
let held = |cut: &str| at(server.addr, &["blocked", &spec_id(cut)], None);
|
||||
admit("campaign.json", json!([campaign_json()]));
|
||||
admit("specs.json", json!([spec("A"), spec("B")]));
|
||||
let claim = PipelineRef {
|
||||
kind: PipelineKind::CutSpec,
|
||||
id: Short(spec_id("A")),
|
||||
};
|
||||
admit(
|
||||
"run.json",
|
||||
json!([value(PipelineDocument::Run(PipelineRun {
|
||||
instance: slug(INSTANCE),
|
||||
label: "failed".into(),
|
||||
operated_by: RunOperator::Mind,
|
||||
turn: RunTurn::SelfRun,
|
||||
host: "test".into(),
|
||||
started_on: Date("2026-10-10".into()),
|
||||
budget_usd: "0".into(),
|
||||
claims: vec![claim.clone()],
|
||||
campaigns: vec![slug(CAMPAIGN)],
|
||||
}))]),
|
||||
);
|
||||
let run = PipelineRef {
|
||||
kind: PipelineKind::Run,
|
||||
id: Short(format!("{INSTANCE}:run:failed")),
|
||||
};
|
||||
let resolution = |subject: &PipelineRef, outcome: ResolutionOutcome| {
|
||||
value(PipelineDocument::Resolution(PipelineResolution {
|
||||
subject: subject.clone(),
|
||||
sequence: 1,
|
||||
outcome,
|
||||
rationale: "So.".into(),
|
||||
resolved_on: Date("2026-10-10".into()),
|
||||
}))
|
||||
};
|
||||
admit(
|
||||
"ended.json",
|
||||
json!([resolution(
|
||||
&run,
|
||||
ResolutionOutcome::Recorded {
|
||||
reason: "unit not active".into()
|
||||
}
|
||||
)]),
|
||||
);
|
||||
assert!(
|
||||
held("A").out.starts_with("matched 0 "),
|
||||
"no question yet: {}",
|
||||
held("A").out
|
||||
);
|
||||
|
||||
// A second run claims B, and a second question is raised in it: it holds B and never A.
|
||||
let other_claim = PipelineRef { kind: PipelineKind::CutSpec, id: Short(spec_id("B")) };
|
||||
admit(
|
||||
"other.json",
|
||||
json!([value(PipelineDocument::Run(PipelineRun {
|
||||
instance: slug(INSTANCE),
|
||||
label: "other".into(),
|
||||
operated_by: RunOperator::Mind,
|
||||
turn: RunTurn::SelfRun,
|
||||
host: "test".into(),
|
||||
started_on: Date("2026-10-10".into()),
|
||||
budget_usd: "0".into(),
|
||||
claims: vec![other_claim],
|
||||
campaigns: vec![slug(CAMPAIGN)],
|
||||
}))]),
|
||||
);
|
||||
let other = PipelineRef { kind: PipelineKind::Run, id: Short(format!("{INSTANCE}:run:other")) };
|
||||
admit("other-ended.json", json!([resolution(&other, ResolutionOutcome::Recorded { reason: "unit not active".into() })]));
|
||||
let ask = |label: &str, raised_in: PipelineRef| {
|
||||
value(PipelineDocument::Question(PipelineQuestion {
|
||||
campaign: slug(CAMPAIGN),
|
||||
label: label.into(),
|
||||
title: "A fork".into(),
|
||||
question: "Which?".into(),
|
||||
options: ["reopen", "retire"].iter().map(|name| QuestionOption { label: (*name).into(), text: "an option".into() }).collect(),
|
||||
recommended: "reopen".into(),
|
||||
depends: vec![],
|
||||
raised_in: Some(raised_in),
|
||||
asked_on: Date("2026-10-10".into()),
|
||||
}))
|
||||
};
|
||||
admit("other-question.json", json!([ask("fork2", other)]));
|
||||
let other_question = format!("{CAMPAIGN}:question:fork2");
|
||||
let question = format!("{CAMPAIGN}:question:fork");
|
||||
admit("question.json", json!([ask("fork", run)]));
|
||||
let shown = held("A");
|
||||
assert_eq!(shown.code, 0, "{}", shown.err);
|
||||
assert!(
|
||||
shown.out.starts_with(&format!("{question} InForce ")) && shown.out.contains("matched 1 "),
|
||||
"a question raised in the run holds its claim: {}",
|
||||
shown.out
|
||||
);
|
||||
assert!(!shown.out.contains(&other_question), "a question raised in another run does not hold A: {}", shown.out);
|
||||
let shown = held("B");
|
||||
assert!(
|
||||
shown.out.starts_with(&format!("{other_question} InForce ")) && !shown.out.contains(&format!("{question} ")) && shown.out.contains("matched 1 "),
|
||||
"B is held by its own run's question only: {}",
|
||||
shown.out
|
||||
);
|
||||
|
||||
let PipelineDocument::Ruling(mut answer) = ruling(None) else {
|
||||
unreachable!()
|
||||
};
|
||||
(answer.answers, answer.choice) = (Some(Short(question.clone())), Some("retire".into()));
|
||||
admit(
|
||||
"answer.json",
|
||||
json!([value(PipelineDocument::Ruling(answer))]),
|
||||
);
|
||||
let shown = held("A");
|
||||
assert!(
|
||||
shown.out.starts_with(&format!("{question} Resolved")) && shown.out.contains("matched 1 "),
|
||||
"retired and not yet resolved, it still holds: {}",
|
||||
shown.out
|
||||
);
|
||||
|
||||
admit(
|
||||
"withdrawn.json",
|
||||
json!([resolution(
|
||||
&claim,
|
||||
ResolutionOutcome::Withdrawn {
|
||||
reason: "retired".into()
|
||||
}
|
||||
)]),
|
||||
);
|
||||
assert!(
|
||||
held("A").out.starts_with("matched 0 "),
|
||||
"the claim resolved, nothing holds it: {}",
|
||||
held("A").out
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paging_and_query_flags_shape_the_selection() {
|
||||
let (selection, semantic) = sent(&["gaps", "--cursor", "abc", "--documents"]);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,15 @@
|
|||
//! waited, bent by the urgency she declared for herself, a member addressing her
|
||||
//! and (a later cut) topics she subscribed to. Two things launch a Persona off
|
||||
//! the beat: the operator tagging or naming her, once per message, and her own
|
||||
//! Self run having ended since her last turn. Nothing is metered here: no
|
||||
//! meter and no model call.
|
||||
//! Self run having ended since her last turn. A beat's launch for a Mind whose
|
||||
//! Self holds briefs (`inbox::derive`) is a Self run claiming them, in place of
|
||||
//! her Persona turn: a session that ended with a brief open, or a brief admitted
|
||||
//! after its flush, is never an orphan, and a Self start takes the beat like any
|
||||
//! launch. A brief an open question holds (raised in it, or in a run that claims it:
|
||||
//! the repetition breaker's trip holds the claims of the run it belongs to) is
|
||||
//! neither claimed nor told until that question is answered or withdrawn; other
|
||||
//! briefs are. Nothing is metered here:
|
||||
//! no meter and no model call.
|
||||
//!
|
||||
//! The heartbeat owns `heartbeat.cc` and is its only writer; Persona units read
|
||||
//! it. The brakes stay the operator's and are read on every poll. Busy and idle
|
||||
|
|
@ -21,6 +28,7 @@
|
|||
//! A held swarm brake ends the poll before the mind or the mouth is touched.
|
||||
|
||||
use std::fmt;
|
||||
use std::collections::HashSet;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -33,8 +41,9 @@ use huginn_mind::{PipelineDocumentSummary, PipelineFacts, PipelinePageItems};
|
|||
|
||||
use crate::chat_client::{Chat, ChatDelivery};
|
||||
use crate::control::{ControlSource, Effective, FileSource, HeldReason, SwarmEffective, read_effective, read_envelope, set_mode_world_readable};
|
||||
use crate::launch::{Clock, LaunchOutcome, LaunchRequest, Launcher, Ports, holders, open_and_launch};
|
||||
use crate::queue::{MindPort, any_of, citing, headers, of_kind};
|
||||
use crate::launch::{Clock, LaunchOutcome, LaunchRequest, Launcher, Ports, holders, open_and_launch, slot};
|
||||
use crate::queue::{MindPort, any_of, citing, claims_of, headers, of_kind, on_hold};
|
||||
use crate::self_run::inbox;
|
||||
use crate::tempo::{self, Standing};
|
||||
|
||||
/// The admitting agent's name on every run the heartbeat opens.
|
||||
|
|
@ -548,20 +557,96 @@ enum Launched {
|
|||
Refused(String),
|
||||
}
|
||||
|
||||
/// The one way the heartbeat starts a Persona turn: the same brake read and the
|
||||
/// same opener for a beat, an operator mention and a Self run that ended.
|
||||
fn launch(organs: &Organs, row: &Row) -> Result<Launched> {
|
||||
let Effective::Released(grant) = organs.control.effective(row.slug()) else { return Ok(Launched::Refused("the brake is held".into())) };
|
||||
let ports = Ports { mind: row.seat.mind, launcher: organs.launcher, clock: organs.clock, host: organs.host };
|
||||
let request = LaunchRequest { turn: RunTurn::PersonaTurn, claims: vec![], agent: AGENT.into(), grant };
|
||||
fn ports<'a>(organs: &Organs<'a>, mind: &'a dyn MindPort) -> Ports<'a> {
|
||||
Ports {
|
||||
mind,
|
||||
launcher: organs.launcher,
|
||||
clock: organs.clock,
|
||||
host: organs.host,
|
||||
}
|
||||
}
|
||||
|
||||
/// The one way the heartbeat starts a run: the same brake read and the same
|
||||
/// opener for a Persona turn (a beat, an operator mention, a Self run that ended)
|
||||
/// and for the Self run a beat gives to the briefs her Self holds.
|
||||
fn launch(
|
||||
organs: &Organs,
|
||||
row: &Row,
|
||||
turn: RunTurn,
|
||||
claims: Vec<PipelineRef>,
|
||||
) -> Result<Launched> {
|
||||
let Effective::Released(grant) = organs.control.effective(row.slug()) else {
|
||||
return Ok(Launched::Refused("the brake is held".into()));
|
||||
};
|
||||
let request = LaunchRequest {
|
||||
turn,
|
||||
claims,
|
||||
agent: AGENT.into(),
|
||||
grant,
|
||||
};
|
||||
let ports = ports(organs, row.seat.mind);
|
||||
Ok(match open_and_launch(&ports, request) {
|
||||
Ok(LaunchOutcome::Launched { run }) => Launched::Run(label_of(&run)),
|
||||
Ok(LaunchOutcome::Busy { .. }) => Launched::Busy,
|
||||
Ok(LaunchOutcome::Tripped { run, question }) => {
|
||||
let held = claims_of(row.seat.mind, &run).map_or(0, |claims| claims.len());
|
||||
Launched::Refused(format!("tripped: {} holds the {held} claims of {}", question.id.0, run.id.0))
|
||||
}
|
||||
Ok(_) => Launched::Refused("launch refused".into()),
|
||||
Err(error) => Launched::Refused(format!("launch failed: {error}")),
|
||||
})
|
||||
}
|
||||
|
||||
/// The most briefs one Self run claims.
|
||||
const BRIEFS_PER_SELF_RUN: usize = 64;
|
||||
|
||||
/// What a Self run would claim for this Mind, read at one instant.
|
||||
struct Claimable {
|
||||
/// The briefs in force that no live Self run holds and no open question holds.
|
||||
claims: Vec<PipelineRef>,
|
||||
/// How many briefs an open question holds.
|
||||
held: usize,
|
||||
/// Self runs in force whose unit is gone: the launch closes them.
|
||||
dead: Vec<PipelineRef>,
|
||||
}
|
||||
|
||||
/// The briefs a Self run would claim for this Mind: those in force that no live
|
||||
/// Self run holds and no open question holds. A Self run claims up to
|
||||
/// `BRIEFS_PER_SELF_RUN` briefs and every run it ends empty counts against all
|
||||
/// of them, so one cause trips them together; a trip holds the claims of its
|
||||
/// run, not the Mind, until the operator answers or withdraws its question, and
|
||||
/// the count starts afresh. Whether a holder lives is `launch::slot`'s answer
|
||||
/// (a dead one is closed by the launch, so it does not stop the successor), and
|
||||
/// what is held is `queue::on_hold`'s. The read here only chooses the claims;
|
||||
/// the launch's gate reads the hold again at admission and decides.
|
||||
fn claimable(organs: &Organs, row: &Row) -> Result<Claimable> {
|
||||
let mind = row.seat.mind;
|
||||
let found = slot(
|
||||
&ports(organs, mind),
|
||||
row.slug(),
|
||||
RunTurn::SelfRun,
|
||||
organs.clock.now(),
|
||||
)?;
|
||||
if found.live.is_some() {
|
||||
return Ok(Claimable {
|
||||
claims: Vec::new(),
|
||||
held: 0,
|
||||
dead: Vec::new(),
|
||||
});
|
||||
}
|
||||
let (free, held) = inbox::derive_counting_held(mind, &on_hold(mind)?, &HashSet::new())?;
|
||||
let claims = free
|
||||
.into_iter()
|
||||
.map(|brief| PipelineRef { kind: PipelineKind::FollowUp, id: brief.id.as_str().into() })
|
||||
.take(BRIEFS_PER_SELF_RUN)
|
||||
.collect();
|
||||
Ok(Claimable {
|
||||
claims,
|
||||
held,
|
||||
dead: found.dead,
|
||||
})
|
||||
}
|
||||
|
||||
/// One poll.
|
||||
pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
||||
if let SwarmEffective::Held(reason) = organs.control.envelope() {
|
||||
|
|
@ -626,7 +711,7 @@ pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
|||
if mentioned.is_none() && !self_ended {
|
||||
continue;
|
||||
}
|
||||
match launch(organs, row)? {
|
||||
match launch(organs, row, RunTurn::PersonaTurn, vec![])? {
|
||||
Launched::Run(label) => {
|
||||
if let Some(key) = mentioned {
|
||||
state.handled_mentions.push(key);
|
||||
|
|
@ -664,10 +749,42 @@ pub fn poll(organs: &Organs, config: &Config) -> Result<Outcome> {
|
|||
// one failing Mind never starves the others; a launch ends the beat.
|
||||
let mut passed: Vec<Standing> = standings.clone();
|
||||
while due && let Some(winner) = tempo::pick(&passed, beat_s) {
|
||||
match launch(organs, &rows[winner])? {
|
||||
// Her Self holds briefs: the beat is a Self run for them; otherwise a Persona turn.
|
||||
let Claimable {
|
||||
claims,
|
||||
held,
|
||||
dead,
|
||||
} = claimable(organs, &rows[winner]).unwrap_or_else(|error| {
|
||||
rows[winner].note = format!("briefs: {error}");
|
||||
Claimable {
|
||||
claims: Vec::new(),
|
||||
held: 0,
|
||||
dead: Vec::new(),
|
||||
}
|
||||
});
|
||||
let mut notes: Vec<String> = Vec::new();
|
||||
if held > 0 {
|
||||
notes.push(format!("{held} briefs held by open questions"));
|
||||
}
|
||||
if !claims.is_empty() && !dead.is_empty() {
|
||||
let ids: Vec<&str> = dead.iter().map(|run| run.id.0.as_str()).collect();
|
||||
notes.push(format!(
|
||||
"closing the Self run whose unit is gone: {}",
|
||||
ids.join(", ")
|
||||
));
|
||||
}
|
||||
if !notes.is_empty() {
|
||||
rows[winner].note = notes.join("; ");
|
||||
}
|
||||
let turn = if claims.is_empty() {
|
||||
RunTurn::PersonaTurn
|
||||
} else {
|
||||
RunTurn::SelfRun
|
||||
};
|
||||
match launch(organs, &rows[winner], turn, claims)? {
|
||||
Launched::Run(label) => {
|
||||
state.last_beat_at = now;
|
||||
rows[winner].busy = true;
|
||||
rows[winner].busy = turn == RunTurn::PersonaTurn;
|
||||
launches.push(label);
|
||||
launched.push(rows[winner].slug().clone());
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -780,3 +780,448 @@ fn every_newest_read_asks_for_exactly_one_header() {
|
|||
let queries = rig.calls[ANN].get();
|
||||
assert!(queries >= 3, "the poll did read her mind ({queries} queries)");
|
||||
}
|
||||
|
||||
// ---- the beat gives a Self run to a Mind whose Self holds briefs ----------------------
|
||||
|
||||
use eureka_pipeline::PipelineDocument;
|
||||
|
||||
/// A self-run follow-up for `who`, admitted under `agent`'s receipt.
|
||||
fn brief_by(rig: &Rig, who: usize, agent: &str, label: &str, source: &PipelineRef) {
|
||||
let PipelineDocument::FollowUp(mut document) = crate::testkit::follow_up(label, source) else { unreachable!() };
|
||||
document.owner = "self-run".into();
|
||||
let outcome = rig.minds[who].admit(agent, "session-a", vec![PipelineDocument::FollowUp(document)]).unwrap();
|
||||
assert!(matches!(outcome, huginn_mind::PipelineAdmissionOutcome::Committed { .. }), "{outcome:?}");
|
||||
}
|
||||
|
||||
/// Two Minds that have both acted, ann longest ago, and a Persona turn of hers to cite.
|
||||
fn rig_with_a_persona_turn() -> (Box<Rig>, PipelineRef) {
|
||||
let rig = Rig::new();
|
||||
let label = rig.turn(ANN, 3000);
|
||||
rig.turn(BOB, 1000);
|
||||
let source = reference(K::Run, &format!("ann:run:{label}"));
|
||||
(rig, source)
|
||||
}
|
||||
|
||||
fn self_runs(rig: &Rig, who: usize) -> Vec<eureka_pipeline::PipelineRun> {
|
||||
rig.minds[who]
|
||||
.ids(K::Run)
|
||||
.iter()
|
||||
.filter_map(|id| match rig.minds[who].view(K::Run, id)?.document {
|
||||
PipelineDocument::Run(run) if run.turn == RunTurn::SelfRun => Some(run),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_beat_won_by_a_mind_whose_self_holds_briefs_is_one_self_run_claiming_them_and_the_outcome_says_so() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "first", &source);
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "second", &source);
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("ann".into())] }, "the launch is in the outcome, not only the trace");
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), 1, "one Self run for both briefs");
|
||||
let claimed: Vec<String> = runs[0].claims.iter().map(|claim| claim.id.0.clone()).collect();
|
||||
assert_eq!(claimed, vec!["eureka-body:follow_up:first".to_string(), "eureka-body:follow_up:second".to_string()]);
|
||||
assert_eq!(rig.launcher.started.borrow().iter().filter(|(_, turn)| *turn == RunTurn::SelfRun).count(), 1);
|
||||
assert!(self_runs(&rig, BOB).is_empty(), "bob holds no brief");
|
||||
let trace = rig.store.traces.borrow().last().cloned().unwrap();
|
||||
assert_eq!(trace.launches.len(), 1);
|
||||
assert!(!trace.instances[ANN].busy, "a Self run is not her Persona's turn: she is not busy");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_beat_won_by_a_mind_with_no_brief_is_a_persona_turn_and_marks_her_busy() {
|
||||
let (rig, _source) = rig_with_a_persona_turn();
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![Slug("ann".into())] });
|
||||
assert!(self_runs(&rig, ANN).is_empty());
|
||||
assert!(rig.store.traces.borrow().last().unwrap().instances[ANN].busy);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_self_run_waits_for_the_beat_like_any_launch() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
rig.poll();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "waiting", &source);
|
||||
rig.end_run(ANN);
|
||||
rig.advance(60);
|
||||
assert_eq!(rig.poll(), Outcome::Polled { launched: vec![] }, "the beat has not passed: no Self run starts");
|
||||
assert!(self_runs(&rig, ANN).is_empty());
|
||||
rig.advance(900);
|
||||
let Outcome::Polled { launched } = rig.poll() else { panic!("held") };
|
||||
assert_eq!(launched.len(), 1, "one launch for the beat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_live_self_run_holds_the_briefs_and_the_beat_is_a_persona_turn() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "taken", &source);
|
||||
rig.poll();
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 1);
|
||||
rig.advance(1000);
|
||||
rig.poll();
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 1, "a live Self run is never given a second");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_follow_up_her_persona_did_not_admit_launches_no_self_run_whatever_source_it_names() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::self_run::AGENT, "hers", &source);
|
||||
brief_by(&rig, ANN, "test", "by-hand", &source);
|
||||
rig.poll();
|
||||
assert!(self_runs(&rig, ANN).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_braked_mind_launches_no_self_run() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "waiting", &source);
|
||||
rig.control.braked.borrow_mut().push("ann".into());
|
||||
rig.poll();
|
||||
assert!(self_runs(&rig, ANN).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_brief_that_keeps_failing_trips_once_and_a_trip_is_a_stop_until_the_question_is_answered() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "stuck", &source);
|
||||
let item = reference(K::FollowUp, "eureka-body:follow_up:stuck");
|
||||
// Three Self runs have ended on it, each leaving nothing.
|
||||
for n in 0..3 {
|
||||
let label = format!("failed-{n}");
|
||||
rig.minds[ANN].committed(vec![run_in("ann", &label, RunTurn::SelfRun, RunOperator::Mind, std::slice::from_ref(&item))]);
|
||||
rig.minds[ANN].committed(vec![close(reference(K::Run, &format!("ann:run:{label}")), recorded())]);
|
||||
}
|
||||
let before = self_runs(&rig, ANN).len();
|
||||
// Beat after beat, whoever launches: no new Self run on the brief, and the breaker asks once.
|
||||
for _ in 0..8 {
|
||||
rig.advance(1000);
|
||||
rig.poll();
|
||||
for who in [ANN, BOB] {
|
||||
if rig.minds[who].ids(K::Run).last().is_some_and(|id| rig.minds[who].view(K::Run, id).is_some_and(|view| matches!(view.status, huginn_mind::PipelineStatus::InForce))) {
|
||||
rig.end_run(who);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(self_runs(&rig, ANN).len(), before, "no Self run after the trip");
|
||||
assert_eq!(rig.minds[ANN].ids(K::Question).len(), 1, "the breaker asked once; an open question is not asked again nor a fresh count");
|
||||
}
|
||||
|
||||
/// Three Self runs that each claimed every one of `items` and ended leaving nothing.
|
||||
fn fail_bundle(rig: &Rig, items: &[PipelineRef]) {
|
||||
for n in 0..3 {
|
||||
let label = format!("failed-{n}");
|
||||
rig.minds[ANN].committed(vec![run_in("ann", &label, RunTurn::SelfRun, RunOperator::Mind, items)]);
|
||||
rig.minds[ANN].committed(vec![close(reference(K::Run, &format!("ann:run:{label}")), recorded())]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Beats on which every live run ends at once; the Self runs and questions the Mind has after them.
|
||||
fn beats(rig: &Rig, count: usize) {
|
||||
for _ in 0..count {
|
||||
rig.advance(1000);
|
||||
rig.poll();
|
||||
for who in [ANN, BOB] {
|
||||
if rig.minds[who].ids(K::Run).last().is_some_and(|id| rig.minds[who].view(K::Run, id).is_some_and(|view| matches!(view.status, huginn_mind::PipelineStatus::InForce))) {
|
||||
rig.end_run(who);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_cause_failing_a_bundle_of_briefs_is_one_question_not_one_per_brief() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
let labels = ["a", "b", "c", "d", "e"];
|
||||
let items: Vec<PipelineRef> = labels.iter().map(|label| reference(K::FollowUp, &format!("eureka-body:follow_up:{label}"))).collect();
|
||||
for label in labels {
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, label, &source);
|
||||
}
|
||||
fail_bundle(&rig, &items);
|
||||
let before = self_runs(&rig, ANN).len();
|
||||
beats(&rig, 10);
|
||||
assert_eq!(rig.minds[ANN].ids(K::Question).len(), 1, "five briefs, one cause, one question on the desk");
|
||||
assert_eq!(self_runs(&rig, ANN).len(), before, "and no Self run launches while it is open");
|
||||
assert!(rig.minds[BOB].ids(K::Question).is_empty(), "another Mind is not stopped");
|
||||
let question = rig.minds[ANN].ids(K::Question).pop().unwrap();
|
||||
assert_eq!(question_raised_in(&rig, &question), Some(reference(K::Run, "ann:run:failed-2")), "raised in the run whose end tripped it, not in a brief");
|
||||
}
|
||||
|
||||
/// Five briefs a..e of ann's Self, and the three Self runs that each claimed all of them and ended empty.
|
||||
fn failed_bundle(rig: &Rig, source: &PipelineRef) -> Vec<PipelineRef> {
|
||||
let items: Vec<PipelineRef> = ["a", "b", "c", "d", "e"].iter().map(|label| brief_ref(label)).collect();
|
||||
for label in ["a", "b", "c", "d", "e"] {
|
||||
brief_by(rig, ANN, crate::persona::AGENT, label, source);
|
||||
}
|
||||
fail_bundle(rig, &items);
|
||||
items
|
||||
}
|
||||
|
||||
fn brief_ref(label: &str) -> PipelineRef {
|
||||
reference(K::FollowUp, &format!("eureka-body:follow_up:{label}"))
|
||||
}
|
||||
|
||||
fn question_raised_in(rig: &Rig, question: &str) -> Option<PipelineRef> {
|
||||
let PipelineDocument::Question(asked) = rig.minds[ANN].view(K::Question, question)?.document else { return None };
|
||||
asked.raised_in
|
||||
}
|
||||
|
||||
fn claims_of_run(run: &eureka_pipeline::PipelineRun) -> Vec<String> {
|
||||
run.claims.iter().map(|claim| claim.id.0.clone()).collect()
|
||||
}
|
||||
|
||||
/// Beats until `done`, at most `limit`; which beat a Mind wins is not the test's business.
|
||||
fn beats_until(rig: &Rig, limit: usize, done: impl Fn() -> bool) {
|
||||
for _ in 0..limit {
|
||||
if done() {
|
||||
return;
|
||||
}
|
||||
beats(rig, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Answers a breaker question of ann by a ruling, or closes it Withdrawn.
|
||||
fn lift(rig: &Rig, question: &str, withdraw: bool) {
|
||||
let outcome = if withdraw {
|
||||
close(reference(K::Question, question), crate::testkit::withdrawn())
|
||||
} else {
|
||||
crate::testkit::ruling("answer", Some((question, "reopen")))
|
||||
};
|
||||
rig.minds[ANN].committed(vec![outcome]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_answer_or_a_withdrawal_reopens_the_whole_bundle_with_a_fresh_count() {
|
||||
for withdraw in [false, true] {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
let items = failed_bundle(&rig, &source);
|
||||
beats(&rig, 3);
|
||||
let question = rig.minds[ANN].ids(K::Question).pop().expect("the trip asked");
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 3, "the trip launched nothing");
|
||||
lift(&rig, &question, withdraw);
|
||||
// The next Self run claims all five; three empty ones after the boundary trip once more, never before.
|
||||
beats_until(&rig, 12, || self_runs(&rig, ANN).len() == 4);
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), 4, "one Self run after the answer (withdrawn: {withdraw})");
|
||||
assert_eq!(claims_of_run(&runs[3]), items.iter().map(|item| item.id.0.clone()).collect::<Vec<_>>(), "all five in one run");
|
||||
beats_until(&rig, 24, || self_runs(&rig, ANN).len() == 6);
|
||||
assert_eq!((self_runs(&rig, ANN).len(), rig.minds[ANN].ids(K::Question).len()), (6, 1), "three empty runs since the answer, and no second question yet");
|
||||
beats_until(&rig, 24, || rig.minds[ANN].ids(K::Question).len() == 2);
|
||||
beats(&rig, 6);
|
||||
assert_eq!((self_runs(&rig, ANN).len(), rig.minds[ANN].ids(K::Question).len()), (6, 2), "the fourth launch trips once more, once, and launches nothing");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_open_question_raised_elsewhere_stops_no_brief() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "b1", &source);
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "b2", &source);
|
||||
// A follow-up that is no brief, a cut spec, and a run that claimed only other items.
|
||||
rig.minds[ANN].committed(vec![crate::testkit::follow_up("plain", &source), crate::testkit::spec("c1")]);
|
||||
rig.minds[ANN].committed(vec![run_in("ann", "other", RunTurn::SelfRun, RunOperator::Mind, &[crate::testkit::spec_ref("c1")])]);
|
||||
rig.minds[ANN].committed(vec![close(reference(K::Run, "ann:run:other"), recorded())]);
|
||||
for (label, place) in [("q1", reference(K::FollowUp, "eureka-body:follow_up:plain")), ("q2", crate::testkit::spec_ref("c1")), ("q3", reference(K::Run, "ann:run:other"))] {
|
||||
rig.minds[ANN].committed(vec![crate::testkit::question_in(label, &place)]);
|
||||
}
|
||||
let before = self_runs(&rig, ANN).len();
|
||||
beats_until(&rig, 6, || self_runs(&rig, ANN).len() > before);
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), before + 1, "the successor launches as usual");
|
||||
assert_eq!(claims_of_run(runs.last().unwrap()), vec![brief_ref("b1").id.0, brief_ref("b2").id.0], "both briefs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_raised_in_one_brief_holds_only_that_brief() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
for label in ["b1", "b2", "b3"] {
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, label, &source);
|
||||
}
|
||||
rig.minds[ANN].committed(vec![crate::testkit::question_in("fork", &brief_ref("b2"))]);
|
||||
let told: Vec<String> = inbox::derive(&rig.minds[ANN], &HashSet::new()).unwrap().into_iter().map(|brief| brief.id).collect();
|
||||
assert_eq!(told, vec![brief_ref("b1").id.0, brief_ref("b3").id.0], "derive omits b2");
|
||||
beats_until(&rig, 6, || !self_runs(&rig, ANN).is_empty());
|
||||
assert_eq!(claims_of_run(&self_runs(&rig, ANN)[0]), vec![brief_ref("b1").id.0, brief_ref("b3").id.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_resolved_tripped_brief_drops_out_and_the_question_holds_the_rest_and_nothing_new() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
let items = failed_bundle(&rig, &source);
|
||||
beats(&rig, 3);
|
||||
assert_eq!(rig.minds[ANN].ids(K::Question).len(), 1);
|
||||
rig.minds[ANN].committed(vec![close(items[0].clone(), recorded())]);
|
||||
assert!(inbox::derive(&rig.minds[ANN], &HashSet::new()).unwrap().is_empty(), "the rest stay held and untold");
|
||||
for item in &items[1..] {
|
||||
rig.minds[ANN].committed(vec![close(item.clone(), recorded())]);
|
||||
}
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "new", &source);
|
||||
beats_until(&rig, 6, || self_runs(&rig, ANN).len() > 3);
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), 4, "a new brief launched");
|
||||
assert_eq!(claims_of_run(&runs[3]), vec![brief_ref("new").id.0], "no Self run claims any of the five");
|
||||
beats(&rig, 2);
|
||||
assert_eq!(rig.minds[ANN].ids(K::Question).len(), 1, "the question stays in force and no second is asked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_brief_admitted_while_a_question_is_open_is_claimed_and_told_alone() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
failed_bundle(&rig, &source);
|
||||
beats(&rig, 3);
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "fresh", &source);
|
||||
let told: Vec<String> = inbox::derive(&rig.minds[ANN], &HashSet::new()).unwrap().into_iter().map(|brief| brief.id).collect();
|
||||
assert_eq!(told, vec![brief_ref("fresh").id.0], "the start tell and the mid-session tells read this: none of the held briefs");
|
||||
beats_until(&rig, 6, || self_runs(&rig, ANN).len() > 3);
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), 4);
|
||||
assert_eq!(claims_of_run(&runs[3]), vec![brief_ref("fresh").id.0], "claimed alone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_trip_and_a_wait_say_so_in_the_trace() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
failed_bundle(&rig, &source);
|
||||
let notes = || rig.store.traces.borrow().iter().flat_map(|trace| trace.instances.iter().map(|instance| instance.note.clone())).collect::<Vec<_>>();
|
||||
beats_until(&rig, 6, || !rig.minds[ANN].ids(K::Question).is_empty());
|
||||
let question = rig.minds[ANN].ids(K::Question).pop().unwrap();
|
||||
let expected = format!("tripped: {question} holds the 5 claims of ann:run:failed-2");
|
||||
assert!(notes().contains(&expected), "{:?}", notes());
|
||||
let waiting = "5 briefs held by open questions".to_string();
|
||||
beats_until(&rig, 12, || notes().contains(&waiting));
|
||||
assert!(notes().contains(&waiting), "{:?}", notes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_beat_with_no_held_brief_writes_no_held_note() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "free", &source);
|
||||
rig.poll();
|
||||
let notes: Vec<String> = rig.store.traces.borrow().iter().flat_map(|trace| trace.instances.iter().map(|instance| instance.note.clone())).collect();
|
||||
assert!(notes.iter().all(|note| !note.contains("held") && !note.contains("closing")), "{notes:?}: a free brief and no dead holder write no note");
|
||||
}
|
||||
|
||||
/// Her Self run in force whose unit is gone, claiming `claims`, admitted `ago` seconds before now.
|
||||
fn crashed_self_run(rig: &Rig, claims: &[PipelineRef], ago: i64) {
|
||||
rig.minds[ANN].admit_at(rig.now() - Duration::seconds(ago));
|
||||
rig.minds[ANN].committed(vec![run_in(
|
||||
"ann",
|
||||
"crashed",
|
||||
RunTurn::SelfRun,
|
||||
RunOperator::Mind,
|
||||
claims,
|
||||
)]);
|
||||
}
|
||||
|
||||
/// Polls on, a beat apart, leaving every run to its unit: nothing here ends one.
|
||||
fn polls(rig: &Rig, count: usize) {
|
||||
for _ in 0..count {
|
||||
rig.advance(1000);
|
||||
rig.poll();
|
||||
}
|
||||
}
|
||||
|
||||
fn notes_of(rig: &Rig) -> Vec<String> {
|
||||
rig.store
|
||||
.traces
|
||||
.borrow()
|
||||
.iter()
|
||||
.flat_map(|trace| trace.instances.iter().map(|instance| instance.note.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_self_run_left_in_force_by_a_crash_is_closed_by_the_next_beat_and_the_successor_launches() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "orphan", &source);
|
||||
crashed_self_run(&rig, &[brief_ref("orphan")], 3600);
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 1);
|
||||
polls(&rig, 8);
|
||||
let runs = self_runs(&rig, ANN);
|
||||
assert_eq!(runs.len(), 2, "one successor, once");
|
||||
assert!(
|
||||
matches!(
|
||||
rig.minds[ANN]
|
||||
.view(K::Run, "ann:run:crashed")
|
||||
.unwrap()
|
||||
.status,
|
||||
huginn_mind::PipelineStatus::Resolved { .. }
|
||||
),
|
||||
"the dead holder was closed by the launch"
|
||||
);
|
||||
assert_eq!(
|
||||
claims_of_run(&runs[1]),
|
||||
vec![brief_ref("orphan").id.0],
|
||||
"claiming the brief the dead run left"
|
||||
);
|
||||
assert!(
|
||||
notes_of(&rig)
|
||||
.contains(&"closing the Self run whose unit is gone: ann:run:crashed".to_string()),
|
||||
"{:?}",
|
||||
notes_of(&rig)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_self_run_whose_unit_may_still_be_starting_or_is_running_gets_no_successor() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "orphan", &source);
|
||||
crashed_self_run(&rig, &[brief_ref("orphan")], 30);
|
||||
rig.advance(10);
|
||||
rig.poll();
|
||||
assert_eq!(
|
||||
self_runs(&rig, ANN).len(),
|
||||
1,
|
||||
"inside the start grace the unit may still be starting"
|
||||
);
|
||||
rig.launcher
|
||||
.revive_as(&Slug("ann".into()), RunTurn::SelfRun);
|
||||
rig.advance(3600);
|
||||
rig.poll();
|
||||
polls(&rig, 4);
|
||||
assert_eq!(
|
||||
self_runs(&rig, ANN).len(),
|
||||
1,
|
||||
"a run whose unit is active holds the briefs however old it is"
|
||||
);
|
||||
assert!(matches!(
|
||||
rig.minds[ANN]
|
||||
.view(K::Run, "ann:run:crashed")
|
||||
.unwrap()
|
||||
.status,
|
||||
huginn_mind::PipelineStatus::InForce
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_held_brief_says_so_in_the_trace() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
brief_by(&rig, ANN, crate::persona::AGENT, "solo", &source);
|
||||
fail_bundle(&rig, &[brief_ref("solo")]);
|
||||
beats_until(&rig, 12, || {
|
||||
notes_of(&rig).contains(&"1 briefs held by open questions".to_string())
|
||||
});
|
||||
assert!(
|
||||
notes_of(&rig).contains(&"1 briefs held by open questions".to_string()),
|
||||
"{:?}",
|
||||
notes_of(&rig)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_answer_of_retire_resolves_nothing_and_the_hold_stays_until_the_answerer_resolves() {
|
||||
let (rig, source) = rig_with_a_persona_turn();
|
||||
let items = failed_bundle(&rig, &source);
|
||||
beats(&rig, 3);
|
||||
let question = rig.minds[ANN].ids(K::Question).pop().expect("the trip asked");
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 3);
|
||||
rig.minds[ANN].committed(vec![crate::testkit::ruling("answer", Some((&question, "retire")))]);
|
||||
beats(&rig, 6);
|
||||
assert_eq!(self_runs(&rig, ANN).len(), 3, "no Self run after the answer: retire does not relaunch");
|
||||
for item in &items {
|
||||
let view = rig.minds[ANN].view(K::FollowUp, &item.id.0).unwrap();
|
||||
assert!(matches!(view.status, huginn_mind::PipelineStatus::InForce), "{item:?}: the heartbeat resolves nothing on an answer");
|
||||
}
|
||||
assert_eq!(rig.minds[ANN].ids(K::Question).len(), 1, "and no second question");
|
||||
assert!(inbox::derive(&rig.minds[ANN], &HashSet::new()).unwrap().is_empty(), "the retired claims stay held and untold");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
//! The one way her organs open a run and start its unit.
|
||||
//!
|
||||
//! `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
|
||||
//! hers of the request's turn are read through `slot`, which tells a live one
|
||||
//! (its unit active, or admitted within `START_GRACE_S`: it answers Busy) from a
|
||||
//! dead one (to be closed Recorded); (1) every cut-spec claim must be in the queue; (2) no claim may be held by an open question (the gate reads the hold itself, once, after the breaker reads and just before the admission, and takes no caller's word for it), and none may
|
||||
//! trip the repetition breaker (a trip raises one question in the run whose end
|
||||
//! tripped it, which holds that run's claims); (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
|
||||
|
|
@ -26,10 +27,15 @@ use eureka_pipeline::{
|
|||
Date, Label, PipelineDocument, PipelineKind, PipelineQuestion, PipelineRef, PipelineResolution, PipelineRun, QuestionOption, ResolutionOutcome,
|
||||
RunOperator, RunTurn, Slug, pipeline_key,
|
||||
};
|
||||
use huginn_mind::{MindRefusal, PipelineAdmissionOutcome, PipelineDocumentSummary, PipelineFacts};
|
||||
use huginn_mind::{
|
||||
MindRefusal, PipelineAdmissionOutcome, PipelineDocumentSummary, PipelineFacts,
|
||||
};
|
||||
|
||||
use crate::control::Grant;
|
||||
use crate::queue::{Breaker, MindPort, any_of, breaker, citing, headers, in_force, of_kind, queue};
|
||||
use crate::queue::{
|
||||
Breaker, MindPort, any_of, breaker, citing, claims_of, headers, in_force, of_kind, on_hold, queue,
|
||||
};
|
||||
use eureka_state::hold::RETIRE;
|
||||
|
||||
/// 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.
|
||||
|
|
@ -264,8 +270,9 @@ pub enum LaunchOutcome {
|
|||
NotQueued {
|
||||
item: PipelineRef,
|
||||
},
|
||||
/// The trip belongs to `run`, the run whose end tripped it; `question` is raised in it.
|
||||
Tripped {
|
||||
item: PipelineRef,
|
||||
run: PipelineRef,
|
||||
question: PipelineRef,
|
||||
},
|
||||
/// The live holder of the request's turn, from step 0 or from admission.
|
||||
|
|
@ -337,8 +344,42 @@ pub(crate) fn holders(mind: &dyn MindPort, instance: &Slug, turn: RunTurn) -> Re
|
|||
.collect())
|
||||
}
|
||||
|
||||
/// The holders of a turn's slot, told apart: the live one, if any (its unit
|
||||
/// active, or admitted within `START_GRACE_S`), and the dead, which the next
|
||||
/// launch closes. The one reader of whether a holder lives: step 0 and the
|
||||
/// heartbeat's claim of briefs both ask here.
|
||||
pub(crate) struct Slot {
|
||||
pub live: Option<PipelineRef>,
|
||||
pub dead: Vec<PipelineRef>,
|
||||
}
|
||||
|
||||
pub(crate) fn slot(
|
||||
ports: &Ports,
|
||||
instance: &Slug,
|
||||
turn: RunTurn,
|
||||
now: DateTime<Utc>,
|
||||
) -> Result<Slot> {
|
||||
let mut found = Slot {
|
||||
live: None,
|
||||
dead: Vec::new(),
|
||||
};
|
||||
for holder in holders(ports.mind, instance, turn)? {
|
||||
if ports.launcher.alive(instance, turn) || !past_grace(&holder.admission.admitted_at, now) {
|
||||
found.live = Some(holder.id);
|
||||
return Ok(found);
|
||||
}
|
||||
found.dead.push(holder.id);
|
||||
}
|
||||
Ok(found)
|
||||
}
|
||||
|
||||
pub fn open_and_launch(ports: &Ports, request: LaunchRequest) -> Result<LaunchOutcome> {
|
||||
let LaunchRequest { turn, claims, agent, grant } = request;
|
||||
let LaunchRequest {
|
||||
turn,
|
||||
claims,
|
||||
agent,
|
||||
grant,
|
||||
} = request;
|
||||
let instance = ports.mind.instance().clone();
|
||||
if grant.instance() != &instance {
|
||||
return Ok(LaunchOutcome::Refused(Declined::GrantForOtherInstance));
|
||||
|
|
@ -353,29 +394,46 @@ pub fn open_and_launch(ports: &Ports, request: LaunchRequest) -> Result<LaunchOu
|
|||
// in the batch that admits whatever comes next.
|
||||
let mut batch: Vec<PipelineDocument> = Vec::new();
|
||||
let mut ending: Vec<PipelineRef> = Vec::new();
|
||||
for holder in holders(ports.mind, &instance, turn)? {
|
||||
if ports.launcher.alive(&instance, turn) || !past_grace(&holder.admission.admitted_at, now) {
|
||||
return Ok(LaunchOutcome::Busy { run: holder.id });
|
||||
}
|
||||
batch.push(close_dead(ports.mind, &holder.id, now)?);
|
||||
ending.push(holder.id);
|
||||
let found = slot(ports, &instance, turn, now)?;
|
||||
if let Some(run) = found.live {
|
||||
return Ok(LaunchOutcome::Busy { run });
|
||||
}
|
||||
for dead in found.dead {
|
||||
batch.push(close_dead(ports.mind, &dead, now)?);
|
||||
ending.push(dead);
|
||||
}
|
||||
|
||||
if turn == RunTurn::SelfRun {
|
||||
let open = queue(ports.mind, &instance, &ending)?;
|
||||
if let Some(item) = claims.iter().find(|claim| claim.kind == PipelineKind::CutSpec && !open.contains(claim)) {
|
||||
// Every read of the breaker comes first, so the hold snapshot below is the
|
||||
// last read of the mind before the admission; a refusal by a hold still
|
||||
// outranks a trip.
|
||||
let mut tripped: Option<(&PipelineRef, PipelineRef)> = None;
|
||||
for item in &claims {
|
||||
if let Breaker::Trip { run } = breaker(ports.mind, item, &ending)? {
|
||||
tripped = Some((item, run));
|
||||
break;
|
||||
}
|
||||
}
|
||||
let held = on_hold(ports.mind)?;
|
||||
let open = queue(ports.mind, &instance, &ending, &held)?;
|
||||
if let Some(item) = claims.iter().find(|claim| {
|
||||
held.contains(claim) || (claim.kind == PipelineKind::CutSpec && !open.contains(claim))
|
||||
}) {
|
||||
return Ok(LaunchOutcome::NotQueued { item: item.clone() });
|
||||
}
|
||||
for item in &claims {
|
||||
if breaker(ports.mind, item, &ending)? == Breaker::Trip {
|
||||
let question = PipelineDocument::Question(breaker_question(item, &label, now));
|
||||
let id = PipelineRef { kind: PipelineKind::Question, id: key_of(&question)?.as_str().into() };
|
||||
batch.push(question);
|
||||
return Ok(match committed(ports.mind.admit(&agent, &label.0, batch)?) {
|
||||
Ok(()) => LaunchOutcome::Tripped { item: item.clone(), question: id },
|
||||
Err(declined) => LaunchOutcome::Refused(declined),
|
||||
});
|
||||
}
|
||||
if let Some((item, run)) = tripped {
|
||||
let count = claims_of(ports.mind, &run)?.len();
|
||||
let question =
|
||||
PipelineDocument::Question(breaker_question(item, &run, count, &label, now));
|
||||
let id = PipelineRef {
|
||||
kind: PipelineKind::Question,
|
||||
id: key_of(&question)?.as_str().into(),
|
||||
};
|
||||
batch.push(question);
|
||||
return Ok(match committed(ports.mind.admit(&agent, &label.0, batch)?) {
|
||||
Ok(()) => LaunchOutcome::Tripped { run, question: id },
|
||||
Err(declined) => LaunchOutcome::Refused(declined),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -448,22 +506,26 @@ fn breaker_label(label: &Label) -> Label {
|
|||
Label(format!("breaker-{}", label.0))
|
||||
}
|
||||
|
||||
/// The question a tripped item raises, in the item's own campaign.
|
||||
fn breaker_question(item: &PipelineRef, label: &Label, now: DateTime<Utc>) -> PipelineQuestion {
|
||||
/// The question a trip raises, in the campaign of the claim that tripped: one
|
||||
/// per trip, raised in `run` and holding the `held` claims it claimed.
|
||||
fn breaker_question(claim: &PipelineRef, run: &PipelineRef, held: usize, label: &Label, now: DateTime<Utc>) -> PipelineQuestion {
|
||||
PipelineQuestion {
|
||||
campaign: Slug(root_of(item).to_string()),
|
||||
campaign: Slug(root_of(claim).to_string()),
|
||||
label: breaker_label(label),
|
||||
title: "Repeated runs on one item admitted nothing".into(),
|
||||
question:
|
||||
"The last runs on this item left nothing that cites it, so it launches no more. Answering this reopens the item and starts a fresh count."
|
||||
.into(),
|
||||
title: "Repeated runs on the same work admitted nothing".into(),
|
||||
question: format!(
|
||||
"Run {} and the runs before it left nothing that cites the work it held (claims held: {held}), so none of it launches again. Answering with reopen, or withdrawing this, reopens every claim of that run with a fresh count. To stop working them, resolve the claims, then answer with retire.",
|
||||
run.id.0
|
||||
)
|
||||
.as_str()
|
||||
.into(),
|
||||
options: vec![
|
||||
QuestionOption { label: "reopen".into(), text: "Rule on the item, which reopens it.".into() },
|
||||
QuestionOption { label: "retire".into(), text: "Resolve the item so it is no longer worked.".into() },
|
||||
QuestionOption { label: "reopen".into(), text: "Answer to reopen every claim of the run with a fresh count.".into() },
|
||||
QuestionOption { label: RETIRE.into(), text: "Resolve the claims so they are no longer worked, and answer with this option.".into() },
|
||||
],
|
||||
recommended: "reopen".into(),
|
||||
depends: vec![],
|
||||
raised_in: Some(item.clone()),
|
||||
raised_in: Some(run.clone()),
|
||||
asked_on: date(now),
|
||||
}
|
||||
}
|
||||
|
|
@ -500,7 +562,15 @@ mod tests {
|
|||
fn try_launch_through(&self, mind: &dyn MindPort, turn: RunTurn, claims: &[PipelineRef]) -> Result<LaunchOutcome> {
|
||||
let ports = Ports { mind, launcher: &self.launcher, clock: &self.clock, host: "yggdrasil-host" };
|
||||
let grant = Grant::for_test(Slug(INSTANCE.into()));
|
||||
open_and_launch(&ports, LaunchRequest { turn, claims: claims.to_vec(), agent: "agent-x".into(), grant })
|
||||
open_and_launch(
|
||||
&ports,
|
||||
LaunchRequest {
|
||||
turn,
|
||||
claims: claims.to_vec(),
|
||||
agent: "agent-x".into(),
|
||||
grant,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn at(&self, milliseconds: i64) {
|
||||
|
|
@ -872,12 +942,22 @@ mod tests {
|
|||
let before = rig.runs();
|
||||
let outcome = rig.launch(RunTurn::SelfRun, &[spec_ref("x")]);
|
||||
let question = id("question", "breaker-mind-20261009T131500000Z");
|
||||
assert_eq!(outcome, LaunchOutcome::Tripped { item: spec_ref("x"), question: reference(K::Question, &question) });
|
||||
assert_eq!(outcome, LaunchOutcome::Tripped { run: run_ref("h2"), question: reference(K::Question, &question) });
|
||||
assert_eq!((rig.runs(), rig.started()), (before, 0));
|
||||
assert_eq!(rig.mind.ids(K::Question), vec![question.clone()]);
|
||||
let view = rig.mind.view(K::Question, &question).unwrap();
|
||||
let PipelineDocument::Question(asked) = &view.document else { panic!("not a question") };
|
||||
assert_eq!((asked.raised_in.clone(), asked.campaign.0.as_str()), (Some(spec_ref("x")), CAMPAIGN));
|
||||
assert_eq!((asked.raised_in.clone(), asked.campaign.0.as_str()), (Some(run_ref("h2")), CAMPAIGN), "raised in the run whose end tripped it");
|
||||
assert!(asked.question.0.contains(&run_ref("h2").id.0) && asked.question.0.contains("claims held: 1"), "{}", asked.question.0);
|
||||
let texts: Vec<(&str, &str)> = asked.options.iter().map(|option| (option.label.0.as_str(), option.text.0.as_str())).collect();
|
||||
assert_eq!(
|
||||
texts,
|
||||
[
|
||||
("reopen", "Answer to reopen every claim of the run with a fresh count."),
|
||||
("retire", "Resolve the claims so they are no longer worked, and answer with this option.")
|
||||
],
|
||||
"retire is resolved by its answerer: no option promises the machine will"
|
||||
);
|
||||
assert_eq!(view.admission.provenance.session.0, "mind-20261009T131500000Z");
|
||||
// Open, the question blocks the item.
|
||||
assert_eq!(rig.launch(RunTurn::SelfRun, &[spec_ref("x")]), LaunchOutcome::NotQueued { item: spec_ref("x") });
|
||||
|
|
@ -937,9 +1017,131 @@ mod tests {
|
|||
let outcome = rig.launch(RunTurn::SelfRun, &[spec_ref("x")]);
|
||||
assert!(matches!(outcome, LaunchOutcome::Tripped { .. }), "{outcome:?}");
|
||||
assert!(!rig.in_force("dead"), "the trip's batch closes the dead run too");
|
||||
let question = rig.mind.ids(K::Question).pop().expect("the trip asked");
|
||||
let PipelineDocument::Question(asked) = rig.mind.view(K::Question, &question).unwrap().document else { panic!("not a question") };
|
||||
assert_eq!(asked.raised_in, Some(run_ref("dead")), "the dead holder, closed in the same batch, is the run the question is raised in");
|
||||
assert_eq!((rig.runs(), rig.started()), (3, 0));
|
||||
}
|
||||
|
||||
/// A caller's earlier read of the hold (the heartbeat's, choosing its claims)
|
||||
/// is advisory: a question that lands after it and before the gate is seen.
|
||||
#[test]
|
||||
fn a_question_landing_before_the_gate_reads_is_seen_by_the_run_it_would_have_opened() {
|
||||
let rig = Rig::new();
|
||||
rig.mind.committed(vec![spec("x"), follow_up("brief", &spec_ref("x"))]);
|
||||
let brief = reference(K::FollowUp, &id("follow_up", "brief"));
|
||||
let landing = Landing {
|
||||
inner: &rig.mind,
|
||||
question: RefCell::new(Some(vec![question_in("fork", &brief)])),
|
||||
hold_reads: Cell::new(0),
|
||||
lands_on: reads_anything,
|
||||
};
|
||||
let outcome = rig.launch_through(&landing, RunTurn::SelfRun, std::slice::from_ref(&brief));
|
||||
assert_eq!(outcome, LaunchOutcome::NotQueued { item: brief });
|
||||
assert_eq!((landing.hold_reads.get(), rig.runs(), rig.started()), (1, 0, 0), "one read, nothing admitted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_brief_an_open_question_is_raised_in_cannot_be_launched_on() {
|
||||
let rig = Rig::new();
|
||||
rig.mind.committed(vec![spec("x"), follow_up("brief", &spec_ref("x"))]);
|
||||
let brief = reference(K::FollowUp, &id("follow_up", "brief"));
|
||||
rig.mind.committed(vec![question_in("fork", &brief)]);
|
||||
assert_eq!(rig.launch(RunTurn::SelfRun, std::slice::from_ref(&brief)), LaunchOutcome::NotQueued { item: brief });
|
||||
assert_eq!((rig.runs(), rig.started()), (0, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gate_refuses_a_claim_an_open_question_holds_whatever_its_kind() {
|
||||
let rig = Rig::new();
|
||||
rig.mind.committed(vec![spec("x"), follow_up("brief", &spec_ref("x"))]);
|
||||
let brief = reference(K::FollowUp, &id("follow_up", "brief"));
|
||||
// A question raised in a run holds the follow-up that run claimed, though the follow-up is no cut spec.
|
||||
rig.mind.committed(vec![run("failed", RunTurn::SelfRun, RunOperator::Mind, &[brief.clone(), spec_ref("x")])]);
|
||||
rig.mind.committed(vec![close(run_ref("failed"), recorded())]);
|
||||
rig.mind.committed(vec![question_in("fork", &run_ref("failed"))]);
|
||||
let runs = rig.runs();
|
||||
assert_eq!(rig.launch(RunTurn::SelfRun, std::slice::from_ref(&brief)), LaunchOutcome::NotQueued { item: brief.clone() });
|
||||
assert_eq!(rig.launch(RunTurn::SelfRun, &[spec_ref("x")]), LaunchOutcome::NotQueued { item: spec_ref("x") }, "a cut spec held by a run-raised question");
|
||||
assert_eq!((rig.runs(), rig.started()), (runs, 0), "nothing admitted, nothing started");
|
||||
rig.mind.committed(vec![close(reference(K::Question, &id("question", "fork")), withdrawn())]);
|
||||
assert!(matches!(rig.launch(RunTurn::SelfRun, &[brief]), LaunchOutcome::Launched { .. }), "withdrawn, the hold lifts");
|
||||
}
|
||||
|
||||
/// A mind where a question lands the moment `lands_on` reads a selection.
|
||||
struct Landing<'a> {
|
||||
inner: &'a TestMind,
|
||||
question: RefCell<Option<Vec<PipelineDocument>>>,
|
||||
hold_reads: Cell<u32>,
|
||||
lands_on: fn(&Selection) -> bool,
|
||||
}
|
||||
|
||||
fn reads_the_hold(selection: &Selection) -> bool {
|
||||
selection.schemas.as_deref() == Some(&[K::Question.type_id().to_string()][..])
|
||||
&& selection.fields.iter().flatten().any(|predicate| predicate.index == "in_force")
|
||||
}
|
||||
|
||||
fn reads_anything(_: &Selection) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl MindPort for Landing<'_> {
|
||||
fn instance(&self) -> &Slug {
|
||||
self.inner.instance()
|
||||
}
|
||||
|
||||
fn query(&self, selection: &Selection) -> Result<huginn_mind::PipelineSelectionPage> {
|
||||
let answer = self.inner.query(selection);
|
||||
if reads_the_hold(selection) {
|
||||
self.hold_reads.set(self.hold_reads.get() + 1);
|
||||
}
|
||||
if (self.lands_on)(selection)
|
||||
&& let Some(documents) = self.question.take()
|
||||
{
|
||||
self.inner.committed(documents);
|
||||
}
|
||||
answer
|
||||
}
|
||||
|
||||
fn admit(
|
||||
&self,
|
||||
agent: &str,
|
||||
session: &str,
|
||||
documents: Vec<PipelineDocument>,
|
||||
) -> Result<Outcome> {
|
||||
self.inner.admit(agent, session, documents)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_launch_reads_the_hold_once_and_a_question_landing_after_it_changes_no_answer_within_the_launch()
|
||||
{
|
||||
let rig = Rig::new();
|
||||
rig.mind.committed(vec![spec("x")]);
|
||||
let landing = Landing {
|
||||
inner: &rig.mind,
|
||||
question: RefCell::new(Some(vec![question_in("fork", &spec_ref("x"))])),
|
||||
hold_reads: Cell::new(0),
|
||||
lands_on: reads_the_hold,
|
||||
};
|
||||
// The gate's own snapshot is read first (the question lands behind it); the queue and the gate use that one.
|
||||
let outcome = rig.launch_through(&landing, RunTurn::SelfRun, &[spec_ref("x")]);
|
||||
assert!(
|
||||
matches!(outcome, LaunchOutcome::Launched { .. }),
|
||||
"{outcome:?}: queue and gate answered from one snapshot"
|
||||
);
|
||||
assert_eq!(
|
||||
landing.hold_reads.get(),
|
||||
1,
|
||||
"the hold was read once for the whole launch"
|
||||
);
|
||||
assert_eq!(
|
||||
crate::queue::on_hold(&rig.mind).unwrap().items(),
|
||||
[spec_ref("x")],
|
||||
"the question did land"
|
||||
);
|
||||
}
|
||||
|
||||
/// The one source of every drawn case: splitmix64 from a fixed seed, so a
|
||||
/// failure names a case that runs again.
|
||||
struct Draw(u64);
|
||||
|
|
@ -1064,7 +1266,15 @@ mod tests {
|
|||
let (launcher, clock) = (Recording::default(), Fixed(Cell::new(at(0))));
|
||||
let ports = Ports { mind, launcher: &launcher, clock: &clock, host: "yggdrasil-host" };
|
||||
let grant = Grant::for_test(Slug(grant.into()));
|
||||
let outcome = open_and_launch(&ports, LaunchRequest { turn, claims, agent: "agent-x".into(), grant });
|
||||
let outcome = open_and_launch(
|
||||
&ports,
|
||||
LaunchRequest {
|
||||
turn,
|
||||
claims,
|
||||
agent: "agent-x".into(),
|
||||
grant,
|
||||
},
|
||||
);
|
||||
assert!(launcher.started.borrow().is_empty());
|
||||
outcome
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,17 @@
|
|||
//! record (target invariant run-is-the-grant).
|
||||
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use cultnet_rs::{Citation, FieldPredicate, Incoming, RecordRef, Selection};
|
||||
use eureka_pipeline::{Line, PipelineDocument, PipelineKind, PipelineRef, ResolutionOutcome, RunOperator, RunTurn, Slug};
|
||||
use cultnet_rs::{Incoming, Selection};
|
||||
use eureka_pipeline::{
|
||||
Line, PipelineDocument, PipelineKind, PipelineRef, ResolutionOutcome, RunOperator, RunTurn,
|
||||
Slug,
|
||||
};
|
||||
use eureka_state::hold::{self, Hold};
|
||||
use eureka_state::{ClientError, HuginnClient};
|
||||
use huginn_mind::{
|
||||
Faculty, HuginnMindRequest, HuginnMindResponse, PipelineAdmissionBatch, PipelineAdmissionOutcome, PipelineDocumentSummary, PipelineFacts,
|
||||
PipelinePageItems, PipelineProvenance, PipelineSelectionPage, PipelineStatusSummary, SemanticQuery,
|
||||
Faculty, HuginnMindRequest, HuginnMindResponse, PipelineAdmissionBatch,
|
||||
PipelineAdmissionOutcome, PipelineDocumentSummary, PipelineFacts, PipelineProvenance,
|
||||
PipelineSelectionPage, PipelineStatusSummary, SemanticQuery,
|
||||
};
|
||||
|
||||
/// The last `CONSECUTIVE` ended runs over an item, all empty, trip its breaker.
|
||||
|
|
@ -109,42 +114,14 @@ fn client_error_code(error: &ClientError) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
/// The documents that cite `target`, under `role` or any.
|
||||
pub(crate) fn citing(target: &PipelineRef, role: Option<&str>) -> Citation {
|
||||
Citation { target: RecordRef::new(target.kind.type_id(), target.id.0.clone()), role: role.map(Into::into) }
|
||||
}
|
||||
pub(crate) use eureka_state::hold::{any_of, citing, in_force, of_kind};
|
||||
|
||||
pub(crate) fn of_kind(kind: PipelineKind) -> Selection {
|
||||
Selection { schemas: Some(vec![kind.type_id().to_string()]), ..Selection::default() }
|
||||
}
|
||||
|
||||
pub(crate) fn any_of(mut selection: Selection, index: &str, values: &[&str]) -> Selection {
|
||||
selection.fields.get_or_insert_with(Vec::new).push(FieldPredicate {
|
||||
index: index.into(),
|
||||
op: "any_of".into(),
|
||||
values: Some(values.iter().map(|value| value.to_string()).collect()),
|
||||
number: None,
|
||||
});
|
||||
selection
|
||||
}
|
||||
|
||||
pub(crate) fn in_force(selection: Selection) -> Selection {
|
||||
any_of(selection, "in_force", &["true"])
|
||||
}
|
||||
|
||||
/// Every page of a selection, in the mind's order. The one paging loop.
|
||||
pub(crate) fn headers(mind: &dyn MindPort, selection: &Selection) -> Result<Vec<PipelineDocumentSummary>> {
|
||||
let mut all = Vec::new();
|
||||
let mut asking = selection.clone();
|
||||
loop {
|
||||
let page = mind.query(&asking)?;
|
||||
let PipelinePageItems::Headers(items) = page.items else { bail!("the mind answered documents to a header selection") };
|
||||
all.extend(items);
|
||||
match page.next {
|
||||
Some(cursor) => asking.cursor = Some(cursor),
|
||||
None => return Ok(all),
|
||||
}
|
||||
}
|
||||
/// Every page of a selection, in the mind's order.
|
||||
pub(crate) fn headers(
|
||||
mind: &dyn MindPort,
|
||||
selection: &Selection,
|
||||
) -> Result<Vec<PipelineDocumentSummary>> {
|
||||
hold::headers(&|asking| mind.query(asking), selection)
|
||||
}
|
||||
|
||||
/// The claims of the runs of `instance` that are still in force and not in
|
||||
|
|
@ -162,27 +139,76 @@ pub(crate) fn live_claims(mind: &dyn MindPort, instance: &Slug, ending: &[Pipeli
|
|||
Ok(claims)
|
||||
}
|
||||
|
||||
/// The claims of the run `run`, resolved or not (a citation outlives its
|
||||
/// resolution). Empty when the mind has no such run.
|
||||
pub(crate) fn claims_of(mind: &dyn MindPort, run: &PipelineRef) -> Result<Vec<PipelineRef>> {
|
||||
hold::claims_of(&|asking| mind.query(asking), run)
|
||||
}
|
||||
|
||||
/// Every question holding anything and what it holds: `eureka_state::hold`,
|
||||
/// the one decider, which `huginn blocked` reads too.
|
||||
pub(crate) fn holds(mind: &dyn MindPort) -> Result<Vec<Hold>> {
|
||||
hold::holds(&|asking| mind.query(asking))
|
||||
}
|
||||
|
||||
/// A snapshot of the items an open question holds. Only `on_hold` makes one
|
||||
/// (there is no empty default), and the launch gate reads its own, once, at
|
||||
/// admission; a reader that chooses claims by one is advisory.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Held(Vec<PipelineRef>);
|
||||
|
||||
impl Held {
|
||||
pub fn contains(&self, item: &PipelineRef) -> bool {
|
||||
self.0.contains(item)
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &[PipelineRef] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The items an in-force question holds, read now: the one owner of the stop.
|
||||
pub fn on_hold(mind: &dyn MindPort) -> Result<Held> {
|
||||
Ok(Held(
|
||||
holds(mind)?
|
||||
.into_iter()
|
||||
.flat_map(|hold| hold.items)
|
||||
.collect(),
|
||||
))
|
||||
}
|
||||
|
||||
/// What may be worked, oldest first: the cut specs in force that no report
|
||||
/// answers, that no open question blocks, and that no live run claims. A run in
|
||||
/// answers, that no open question holds, and that no live run claims. A run in
|
||||
/// `ending` is one the caller closes in the same admission that opens the next,
|
||||
/// so it claims nothing here.
|
||||
pub fn queue(mind: &dyn MindPort, instance: &Slug, ending: &[PipelineRef]) -> Result<Vec<PipelineRef>> {
|
||||
let unreported = Selection { cited: Some(Incoming { role: "cut_spec".into(), exists: false }), ..in_force(of_kind(PipelineKind::CutSpec)) };
|
||||
let mut blocked: Vec<PipelineRef> = Vec::new();
|
||||
for header in headers(mind, &in_force(of_kind(PipelineKind::Question)))? {
|
||||
if let PipelineFacts::Question { raised_in: Some(item), .. } = header.facts {
|
||||
blocked.push(item);
|
||||
}
|
||||
}
|
||||
pub fn queue(
|
||||
mind: &dyn MindPort,
|
||||
instance: &Slug,
|
||||
ending: &[PipelineRef],
|
||||
held: &Held,
|
||||
) -> Result<Vec<PipelineRef>> {
|
||||
let unreported = Selection {
|
||||
cited: Some(Incoming {
|
||||
role: "cut_spec".into(),
|
||||
exists: false,
|
||||
}),
|
||||
..in_force(of_kind(PipelineKind::CutSpec))
|
||||
};
|
||||
let claimed = live_claims(mind, instance, ending)?;
|
||||
Ok(headers(mind, &unreported)?.into_iter().map(|header| header.id).filter(|spec| !blocked.contains(spec) && !claimed.contains(spec)).collect())
|
||||
Ok(headers(mind, &unreported)?
|
||||
.into_iter()
|
||||
.map(|header| header.id)
|
||||
.filter(|spec| !held.contains(spec) && !claimed.contains(spec))
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Whether an item may still be launched on.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Breaker {
|
||||
Clear,
|
||||
Trip,
|
||||
/// Tripped, and the trip belongs to `run`: the newest ended counted run on
|
||||
/// the item, the run whose end completed the streak or the share.
|
||||
Trip { run: PipelineRef },
|
||||
}
|
||||
|
||||
/// The repetition breaker, derived from the documents that cite the item.
|
||||
|
|
@ -196,29 +222,34 @@ pub enum Breaker {
|
|||
/// withdrawn run never ran and is no run here. A counted run is ended when
|
||||
/// resolved or listed in `ending`, and is empty when no document of the set
|
||||
/// other than a run was admitted from its own admission up to the next counted
|
||||
/// run's (or to now). Trip when the last `CONSECUTIVE` ended runs are empty, or
|
||||
/// run's (or to now). Trip, naming the newest ended counted run, when the last `CONSECUTIVE` ended runs are empty, or
|
||||
/// `EMPTY_SHARE` of the last `WINDOW`. What else the mind admitted, such as a
|
||||
/// Persona turn's run or an unrelated ruling, cites nothing here and counts for
|
||||
/// nothing.
|
||||
pub fn breaker(mind: &dyn MindPort, item: &PipelineRef, ending: &[PipelineRef]) -> Result<Breaker> {
|
||||
let mut set = headers(mind, &Selection { cites: Some(citing(item, None)), ..Selection::default() })?;
|
||||
set.sort_by_key(|header| header.admission.ordinal);
|
||||
let boundary = set
|
||||
let asked_in_item = set
|
||||
.iter()
|
||||
.filter(|header| matches!(&header.facts, PipelineFacts::Question { raised_in: Some(raised), .. } if raised == item))
|
||||
.map(|header| header.admission.ordinal)
|
||||
.max();
|
||||
.map(|header| header.admission.ordinal);
|
||||
let asked_in_run = Selection {
|
||||
cites: Some(citing(item, Some("claims"))),
|
||||
cited: Some(Incoming { role: "raised_in".into(), exists: true }),
|
||||
..of_kind(PipelineKind::Run)
|
||||
};
|
||||
let boundary = asked_in_item.chain(headers(mind, &asked_in_run)?.into_iter().map(|run| run.admission.ordinal)).max();
|
||||
let after = |header: &&PipelineDocumentSummary| boundary.is_none_or(|boundary| header.admission.ordinal > boundary);
|
||||
let withdrawn =
|
||||
|run: &PipelineDocumentSummary| matches!(run.status, PipelineStatusSummary::Resolved { outcome: ResolutionOutcome::Withdrawn { .. }, .. });
|
||||
// (admission ordinal, ended) of each counted run, oldest first.
|
||||
let ran: Vec<(u64, bool)> = set
|
||||
// (admission ordinal, ended, ref) of each counted run, oldest first.
|
||||
let ran: Vec<(u64, bool, PipelineRef)> = set
|
||||
.iter()
|
||||
.filter(after)
|
||||
.filter(|header| {
|
||||
matches!(header.facts, PipelineFacts::Run { turn: RunTurn::SelfRun, operated_by: RunOperator::Mind, .. }) && !withdrawn(header)
|
||||
})
|
||||
.map(|run| (run.admission.ordinal, matches!(run.status, PipelineStatusSummary::Resolved { .. }) || ending.contains(&run.id)))
|
||||
.map(|run| (run.admission.ordinal, matches!(run.status, PipelineStatusSummary::Resolved { .. }) || ending.contains(&run.id), run.id.clone()))
|
||||
.collect();
|
||||
let ended: Vec<usize> = (0..ran.len()).filter(|index| ran[*index].1).collect();
|
||||
let considered: Vec<usize> = ended.iter().rev().take(WINDOW).copied().collect();
|
||||
|
|
@ -235,7 +266,10 @@ pub fn breaker(mind: &dyn MindPort, item: &PipelineRef, ending: &[PipelineRef])
|
|||
.collect();
|
||||
let consecutive = empty.len() >= CONSECUTIVE && empty[..CONSECUTIVE].iter().all(|empty| *empty);
|
||||
let share = empty.iter().filter(|empty| **empty).count() >= EMPTY_SHARE;
|
||||
Ok(if consecutive || share { Breaker::Trip } else { Breaker::Clear })
|
||||
Ok(match ended.last() {
|
||||
Some(newest) if consecutive || share => Breaker::Trip { run: ran[*newest].2.clone() },
|
||||
_ => Breaker::Clear,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -246,6 +280,15 @@ mod tests {
|
|||
use eureka_pipeline::{RunOperator, RunTurn};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// `queue` against a hold read now.
|
||||
fn queued(
|
||||
mind: &dyn MindPort,
|
||||
instance: &Slug,
|
||||
ending: &[PipelineRef],
|
||||
) -> Result<Vec<PipelineRef>> {
|
||||
queue(mind, instance, ending, &on_hold(mind)?)
|
||||
}
|
||||
use crate::testkit::*;
|
||||
|
||||
/// A mind holding the spec `x` and a history of ended runs on it.
|
||||
|
|
@ -262,7 +305,7 @@ mod tests {
|
|||
|
||||
fn tripped(runs: &[bool]) -> bool {
|
||||
let (mind, item) = worked(runs);
|
||||
breaker(&mind, &item, &[]).unwrap() == Breaker::Trip
|
||||
matches!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { .. })
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -307,7 +350,7 @@ mod tests {
|
|||
mind.committed(vec![close(run_ref("third"), recorded())]);
|
||||
breaker(&mind, &item, &[]).unwrap()
|
||||
};
|
||||
assert_eq!(after_a_run_by(RunOperator::Mind), Breaker::Trip, "hers, the third empty one");
|
||||
assert!(matches!(after_a_run_by(RunOperator::Mind), Breaker::Trip { .. }), "hers, the third empty one");
|
||||
assert_eq!(after_a_run_by(RunOperator::Operator), Breaker::Clear, "his, counted for nothing");
|
||||
}
|
||||
|
||||
|
|
@ -362,7 +405,7 @@ mod tests {
|
|||
ended_run(&mind, &item, "h", n, false);
|
||||
mind.committed(vec![close(run_ref(&format!("p{n}")), recorded())]);
|
||||
}
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip);
|
||||
assert!(matches!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { .. }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -370,10 +413,21 @@ mod tests {
|
|||
let (mind, item) = worked(&[E, E]);
|
||||
mind.committed(vec![run("dying", RunTurn::SelfRun, RunOperator::Mind, std::slice::from_ref(&item))]);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Clear, "open, it is not yet ended");
|
||||
assert_eq!(breaker(&mind, &item, &[run_ref("dying")]).unwrap(), Breaker::Trip);
|
||||
assert!(matches!(breaker(&mind, &item, &[run_ref("dying")]).unwrap(), Breaker::Trip { .. }));
|
||||
let instance = Slug(INSTANCE.into());
|
||||
assert!(queue(&mind, &instance, &[]).unwrap().iter().all(|spec| *spec != item), "it claims the item");
|
||||
assert!(queue(&mind, &instance, &[run_ref("dying")]).unwrap().contains(&item), "an ending run claims nothing");
|
||||
assert!(
|
||||
queued(&mind, &instance, &[])
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|spec| *spec != item),
|
||||
"it claims the item"
|
||||
);
|
||||
assert!(
|
||||
queued(&mind, &instance, &[run_ref("dying")])
|
||||
.unwrap()
|
||||
.contains(&item),
|
||||
"an ending run claims nothing"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -387,7 +441,7 @@ mod tests {
|
|||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Clear, "the tenth empty run, but nine of them are before the question");
|
||||
ended_run(&mind, &item, "g", 1, false);
|
||||
ended_run(&mind, &item, "g", 2, false);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip, "three empty runs after it");
|
||||
assert!(matches!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { .. }), "three empty runs after it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -403,7 +457,7 @@ mod tests {
|
|||
ended_run(&mind, &item, "h", 2, false);
|
||||
breaker(&mind, &item, &[]).unwrap()
|
||||
};
|
||||
assert_eq!(withdrawn_between(false), Breaker::Trip, "the withdrawn run is neither counted nor does it break the streak");
|
||||
assert!(matches!(withdrawn_between(false), Breaker::Trip { .. }), "the withdrawn run is neither counted nor does it break the streak");
|
||||
assert_eq!(withdrawn_between(true), Breaker::Clear, "a document after the withdrawn run still lands in the first run's window");
|
||||
}
|
||||
|
||||
|
|
@ -417,7 +471,7 @@ mod tests {
|
|||
|
||||
let (mind, item) = worked(&[E, E, E]);
|
||||
mind.committed(vec![run("live", RunTurn::SelfRun, RunOperator::Mind, std::slice::from_ref(&item)), follow_up("with-next", &item)]);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip, "the next run's batch is not the previous run's window");
|
||||
assert!(matches!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { .. }), "the next run's batch is not the previous run's window");
|
||||
}
|
||||
|
||||
/// The adapter over the wire vocabulary, answered by a real mind.
|
||||
|
|
@ -427,12 +481,33 @@ mod tests {
|
|||
mind.committed(vec![spec("x")]);
|
||||
let port = HuginnMind::over(Slug(INSTANCE.into()), Box::new(|request| Ok(mind.answer(request))));
|
||||
assert_eq!(port.instance().0, INSTANCE);
|
||||
assert_eq!(queue(&port, port.instance(), &[]).unwrap(), vec![spec_ref("x")]);
|
||||
let outcome = port.admit("agent-x", "session-y", vec![run("p", RunTurn::PersonaTurn, RunOperator::Mind, &[])]).unwrap();
|
||||
assert!(matches!(outcome, PipelineAdmissionOutcome::Committed { .. }), "{outcome:?}");
|
||||
let facts = mind.view(PipelineKind::Run, &run_ref("p").id.0).unwrap().admission.provenance;
|
||||
assert_eq!(
|
||||
(facts.faculty, facts.agent.0.as_str(), facts.session.0.as_str(), facts.tool.0.as_str()),
|
||||
queued(&port, port.instance(), &[]).unwrap(),
|
||||
vec![spec_ref("x")]
|
||||
);
|
||||
let outcome = port
|
||||
.admit(
|
||||
"agent-x",
|
||||
"session-y",
|
||||
vec![run("p", RunTurn::PersonaTurn, RunOperator::Mind, &[])],
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(outcome, PipelineAdmissionOutcome::Committed { .. }),
|
||||
"{outcome:?}"
|
||||
);
|
||||
let facts = mind
|
||||
.view(PipelineKind::Run, &run_ref("p").id.0)
|
||||
.unwrap()
|
||||
.admission
|
||||
.provenance;
|
||||
assert_eq!(
|
||||
(
|
||||
facts.faculty,
|
||||
facts.agent.0.as_str(),
|
||||
facts.session.0.as_str(),
|
||||
facts.tool.0.as_str()
|
||||
),
|
||||
(Faculty::SelfFaculty, "agent-x", "session-y", "mind-body")
|
||||
);
|
||||
let refused = port.query(&any_of(of_kind(PipelineKind::Ruling), "turn", &["canary-turn-5d2e"])).unwrap_err();
|
||||
|
|
@ -469,7 +544,7 @@ mod tests {
|
|||
history_as(&mind, &spec_ref("x"), "x", &[E, E]);
|
||||
history_as(&mind, &spec_ref("y"), "y", &[E, E, E]);
|
||||
assert_eq!(breaker(&mind, &spec_ref("x"), &[]).unwrap(), Breaker::Clear);
|
||||
assert_eq!(breaker(&mind, &spec_ref("y"), &[]).unwrap(), Breaker::Trip);
|
||||
assert!(matches!(breaker(&mind, &spec_ref("y"), &[]).unwrap(), Breaker::Trip { .. }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -487,19 +562,173 @@ mod tests {
|
|||
let mind = TestMind::seeded();
|
||||
mind.committed(vec![spec("a"), spec("b"), spec("c"), spec("d"), spec("e")]);
|
||||
let instance = Slug(INSTANCE.into());
|
||||
let all: Vec<PipelineRef> = ["a", "b", "c", "d", "e"].iter().map(|cut| spec_ref(cut)).collect();
|
||||
assert_eq!(queue(&mind, &instance, &[]).unwrap(), all);
|
||||
let all: Vec<PipelineRef> = ["a", "b", "c", "d", "e"]
|
||||
.iter()
|
||||
.map(|cut| spec_ref(cut))
|
||||
.collect();
|
||||
assert_eq!(queued(&mind, &instance, &[]).unwrap(), all);
|
||||
|
||||
mind.committed(vec![report("b")]);
|
||||
mind.committed(vec![question_in("fork", &spec_ref("c"))]);
|
||||
mind.committed(vec![run("held", RunTurn::SelfRun, RunOperator::Operator, &[spec_ref("d")])]);
|
||||
assert_eq!(queue(&mind, &instance, &[]).unwrap(), vec![spec_ref("a"), spec_ref("e")]);
|
||||
mind.committed(vec![run(
|
||||
"held",
|
||||
RunTurn::SelfRun,
|
||||
RunOperator::Operator,
|
||||
&[spec_ref("d")],
|
||||
)]);
|
||||
assert_eq!(
|
||||
queued(&mind, &instance, &[]).unwrap(),
|
||||
vec![spec_ref("a"), spec_ref("e")]
|
||||
);
|
||||
|
||||
mind.committed(vec![close(run_ref("held"), recorded())]);
|
||||
assert_eq!(queue(&mind, &instance, &[]).unwrap(), vec![spec_ref("a"), spec_ref("d"), spec_ref("e")], "a closed run claims nothing");
|
||||
assert_eq!(
|
||||
queued(&mind, &instance, &[]).unwrap(),
|
||||
vec![spec_ref("a"), spec_ref("d"), spec_ref("e")],
|
||||
"a closed run claims nothing"
|
||||
);
|
||||
let other = Slug("another-instance".into());
|
||||
mind.committed(vec![run("again", RunTurn::SelfRun, RunOperator::Operator, &[spec_ref("a")])]);
|
||||
assert_eq!(queue(&mind, &other, &[]).unwrap().len(), 3, "claims are read for the instance asked");
|
||||
mind.committed(vec![run(
|
||||
"again",
|
||||
RunTurn::SelfRun,
|
||||
RunOperator::Operator,
|
||||
&[spec_ref("a")],
|
||||
)]);
|
||||
assert_eq!(
|
||||
queued(&mind, &other, &[]).unwrap().len(),
|
||||
3,
|
||||
"claims are read for the instance asked"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_trip_names_the_newest_ended_counted_run() {
|
||||
let (mind, item) = worked(&[E, E, E, E]);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { run: run_ref("h3") });
|
||||
mind.committed(vec![run("live", RunTurn::SelfRun, RunOperator::Mind, std::slice::from_ref(&item))]);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { run: run_ref("h3") }, "a run still open is not ended");
|
||||
assert_eq!(breaker(&mind, &item, &[run_ref("live")]).unwrap(), Breaker::Trip { run: run_ref("live") }, "a run in ending is");
|
||||
}
|
||||
|
||||
/// Two items claimed together by every run of a history; the last one ended empty.
|
||||
fn bundle() -> (TestMind, PipelineRef, PipelineRef) {
|
||||
let mind = TestMind::seeded();
|
||||
mind.committed(vec![spec("a"), spec("b")]);
|
||||
let (a, b) = (spec_ref("a"), spec_ref("b"));
|
||||
for n in 0..3 {
|
||||
mind.committed(vec![run(&format!("f{n}"), RunTurn::SelfRun, RunOperator::Mind, &[a.clone(), b.clone()])]);
|
||||
mind.committed(vec![close(run_ref(&format!("f{n}")), recorded())]);
|
||||
}
|
||||
(mind, a, b)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_raised_in_a_run_holds_every_claim_of_it_until_answered_or_withdrawn() {
|
||||
for withdraw in [false, true] {
|
||||
let (mind, a, b) = bundle();
|
||||
assert!(on_hold(&mind).unwrap().items().is_empty());
|
||||
mind.committed(vec![question_in("fork", &run_ref("f2"))]);
|
||||
let held = on_hold(&mind).unwrap();
|
||||
assert!(
|
||||
held.contains(&a) && held.contains(&b) && held.items().len() == 2,
|
||||
"{held:?}: the claims of the resolved run"
|
||||
);
|
||||
assert_eq!(
|
||||
queued(&mind, &Slug(INSTANCE.into()), &[]).unwrap(),
|
||||
Vec::<PipelineRef>::new(),
|
||||
"queue reads the same hold"
|
||||
);
|
||||
let question = id("question", "fork");
|
||||
if withdraw {
|
||||
mind.committed(vec![close(reference(PipelineKind::Question, &question), withdrawn())]);
|
||||
} else {
|
||||
mind.committed(vec![ruling("answer", Some((&question, "A")))]);
|
||||
}
|
||||
assert!(
|
||||
on_hold(&mind).unwrap().items().is_empty(),
|
||||
"answered or withdrawn, nothing is held (withdrawn: {withdraw})"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_answered_retire_keeps_holding_the_claims_that_are_still_in_force() {
|
||||
let (mind, a, b) = bundle();
|
||||
mind.committed(vec![question_in("fork", &run_ref("f2"))]);
|
||||
let question = id("question", "fork");
|
||||
mind.committed(vec![ruling(
|
||||
"answer",
|
||||
Some((&question, eureka_state::hold::RETIRE)),
|
||||
)]);
|
||||
let held = on_hold(&mind).unwrap();
|
||||
assert!(
|
||||
held.contains(&a) && held.contains(&b) && held.items().len() == 2,
|
||||
"{held:?}: retire holds what the answer retired"
|
||||
);
|
||||
// Another run's question, still open, is not this answer's: only the claims of f2 are retired.
|
||||
let c = spec_ref("c");
|
||||
mind.committed(vec![spec("c")]);
|
||||
mind.committed(vec![run("g", RunTurn::SelfRun, RunOperator::Mind, std::slice::from_ref(&c))]);
|
||||
mind.committed(vec![close(run_ref("g"), recorded())]);
|
||||
mind.committed(vec![question_in("other", &run_ref("g"))]);
|
||||
let retired: Vec<PipelineRef> = holds(&mind).unwrap().into_iter().filter(|hold| hold.retired).flat_map(|hold| hold.items).collect();
|
||||
assert_eq!(retired, [a.clone(), b.clone()]);
|
||||
mind.committed(vec![close(a, withdrawn())]);
|
||||
let held = on_hold(&mind).unwrap();
|
||||
assert!(held.contains(&b) && held.contains(&c) && held.items().len() == 2, "{held:?}: a resolved claim drops out");
|
||||
mind.committed(vec![close(b, withdrawn())]);
|
||||
assert_eq!(on_hold(&mind).unwrap().items(), [c], "all of f2's resolved, only the open question's claim is held");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_answered_with_another_choice_holds_nothing() {
|
||||
let (mind, _, _) = bundle();
|
||||
mind.committed(vec![question_in("fork", &run_ref("f2"))]);
|
||||
mind.committed(vec![ruling(
|
||||
"answer",
|
||||
Some((&id("question", "fork"), "reopen")),
|
||||
)]);
|
||||
assert!(on_hold(&mind).unwrap().items().is_empty());
|
||||
assert!(holds(&mind).unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_raised_in_anything_else_holds_that_item_alone() {
|
||||
let (mind, a, b) = bundle();
|
||||
mind.committed(vec![question_in("fork", &a)]);
|
||||
assert_eq!(
|
||||
on_hold(&mind).unwrap().items(),
|
||||
[a],
|
||||
"the legacy shape: raised in the item, it holds the item and no claimant"
|
||||
);
|
||||
assert!(!on_hold(&mind).unwrap().contains(&b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn answering_a_question_in_the_run_gives_every_claim_of_it_a_fresh_count() {
|
||||
let (mind, a, b) = bundle();
|
||||
assert_eq!(breaker(&mind, &a, &[]).unwrap(), Breaker::Trip { run: run_ref("f2") });
|
||||
assert_eq!(breaker(&mind, &b, &[]).unwrap(), Breaker::Trip { run: run_ref("f2") });
|
||||
mind.committed(vec![question_in("fork", &run_ref("f2"))]);
|
||||
mind.committed(vec![ruling("answer", Some((&id("question", "fork"), "A")))]);
|
||||
for item in [&a, &b] {
|
||||
assert_eq!(breaker(&mind, item, &[]).unwrap(), Breaker::Clear, "counts only runs after f2");
|
||||
}
|
||||
for n in 0..3 {
|
||||
mind.committed(vec![run(&format!("g{n}"), RunTurn::SelfRun, RunOperator::Mind, &[a.clone(), b.clone()])]);
|
||||
mind.committed(vec![close(run_ref(&format!("g{n}")), recorded())]);
|
||||
let expected = if n == 2 { Breaker::Trip { run: run_ref("g2") } } else { Breaker::Clear };
|
||||
assert_eq!(breaker(&mind, &b, &[]).unwrap(), expected, "b has no question of its own and trips after three fresh empty runs, never before");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_question_in_a_run_that_did_not_claim_the_item_is_no_boundary() {
|
||||
let (mind, item) = worked(&[E, E, E]);
|
||||
mind.committed(vec![spec("y")]);
|
||||
mind.committed(vec![run("other", RunTurn::SelfRun, RunOperator::Mind, &[spec_ref("y")])]);
|
||||
mind.committed(vec![question_in("fork", &run_ref("other"))]);
|
||||
assert_eq!(breaker(&mind, &item, &[]).unwrap(), Breaker::Trip { run: run_ref("h2") }, "the question holds y's run, not x's count");
|
||||
}
|
||||
|
||||
/// A daemon that is not there: the failure names no input, endpoint or
|
||||
|
|
@ -508,8 +737,12 @@ mod tests {
|
|||
fn an_unreachable_mind_names_no_input() {
|
||||
let canary = "canary-instance-7f3a91";
|
||||
let endpoint: SocketAddr = "127.0.0.1:9".parse().unwrap();
|
||||
let port = HuginnMind::new(HuginnClient::new(endpoint, Slug(canary.into()), Duration::from_millis(300)));
|
||||
let error = queue(&port, &Slug(canary.into()), &[]).unwrap_err();
|
||||
let port = HuginnMind::new(HuginnClient::new(
|
||||
endpoint,
|
||||
Slug(canary.into()),
|
||||
Duration::from_millis(300),
|
||||
));
|
||||
let error = queued(&port, &Slug(canary.into()), &[]).unwrap_err();
|
||||
let shown = format!("{error:#}");
|
||||
assert!(shown.contains("unavailable"), "{shown}");
|
||||
assert!(!shown.contains(canary) && !shown.contains("127.0.0.1"), "{shown}");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use eureka_pipeline::PipelineKind;
|
|||
use huginn_mind::{PipelineFacts, PipelineStatusSummary};
|
||||
|
||||
use crate::persona;
|
||||
use crate::queue::{MindPort, any_of, headers, in_force, of_kind};
|
||||
use crate::queue::{Held, MindPort, any_of, headers, in_force, of_kind, on_hold};
|
||||
|
||||
/// The owner a follow-up names when it is a brief for her Self.
|
||||
pub const OWNER: &str = "self-run";
|
||||
|
|
@ -65,9 +65,19 @@ fn open_briefs(mind: &dyn MindPort) -> Result<Vec<Brief>> {
|
|||
Ok(briefs)
|
||||
}
|
||||
|
||||
/// Her briefs in force that the session has not been told.
|
||||
/// Her briefs in force that the session has not been told and no open question
|
||||
/// holds: a held brief is neither claimed nor told until its question is
|
||||
/// answered or withdrawn. Reads the hold once.
|
||||
pub fn derive(mind: &dyn MindPort, told: &HashSet<String>) -> Result<Vec<Brief>> {
|
||||
Ok(open_briefs(mind)?.into_iter().filter(|brief| !told.contains(&brief.id)).collect())
|
||||
Ok(derive_counting_held(mind, &on_hold(mind)?, told)?.0)
|
||||
}
|
||||
|
||||
/// `derive` against a hold the caller already read, and how many of her briefs
|
||||
/// in force that hold keeps back.
|
||||
pub fn derive_counting_held(mind: &dyn MindPort, holds: &Held, told: &HashSet<String>) -> Result<(Vec<Brief>, usize)> {
|
||||
let (held, free): (Vec<Brief>, Vec<Brief>) =
|
||||
open_briefs(mind)?.into_iter().partition(|brief| holds.items().iter().any(|item| item.kind == PipelineKind::FollowUp && item.id.0 == brief.id));
|
||||
Ok((free.into_iter().filter(|brief| !told.contains(&brief.id)).collect(), held.len()))
|
||||
}
|
||||
|
||||
/// Her briefs in force that a closed run claimed, with that run's id: a list for
|
||||
|
|
|
|||
|
|
@ -63,7 +63,12 @@ impl Recording {
|
|||
}
|
||||
|
||||
pub(crate) fn revive(&self, turn: RunTurn) {
|
||||
self.running.borrow_mut().push((Slug(INSTANCE.into()), turn));
|
||||
self.revive_as(&Slug(INSTANCE.into()), turn);
|
||||
}
|
||||
|
||||
/// `revive` for a named instance.
|
||||
pub(crate) fn revive_as(&self, instance: &Slug, turn: RunTurn) {
|
||||
self.running.borrow_mut().push((instance.clone(), turn));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +378,7 @@ pub(crate) fn question_in(label: &str, item: &PipelineRef) -> PipelineDocument {
|
|||
label: label.into(),
|
||||
title: "A fork".into(),
|
||||
question: "Which?".into(),
|
||||
options: ["A", "B"].iter().map(|name| QuestionOption { label: (*name).into(), text: "an option".into() }).collect(),
|
||||
options: ["A", "B", "reopen", "retire"].iter().map(|name| QuestionOption { label: (*name).into(), text: "an option".into() }).collect(),
|
||||
recommended: "A".into(),
|
||||
depends: vec![],
|
||||
raised_in: Some(item.clone()),
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ mind_body::heartbeat: struct PollTrace # [derive (Clone , Debug , PartialEq , Eq
|
|||
mind_body::heartbeat: struct Seat< 'a > pub-fields[who: PersonaId, mind: & 'a dyn MindPort, chat: & 'a dyn Chat]
|
||||
mind_body::launch: # [derive (Clone , Debug , PartialEq , Eq)] pub enum Declined { Admission (MindRefusal) , Conflict , AlreadyAdmitted , StartFailed , GrantForOtherInstance , PersonaRunTakesNoClaims , }
|
||||
mind_body::launch: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum StopScope < 'a > { Mind (& 'a Slug) , Swarm , }
|
||||
mind_body::launch: # [derive (Clone , Debug , PartialEq , Eq)] pub enum LaunchOutcome { Launched { run : PipelineRef , } , NotQueued { item : PipelineRef , } , Tripped { item : PipelineRef , question : PipelineRef , } , Busy { run : PipelineRef , } , Refused (Declined) , }
|
||||
mind_body::launch: # [derive (Clone , Debug , PartialEq , Eq)] pub enum LaunchOutcome { Launched { run : PipelineRef , } , NotQueued { item : PipelineRef , } , Tripped { run : PipelineRef , question : PipelineRef , } , Busy { run : PipelineRef , } , Refused (Declined) , }
|
||||
mind_body::launch: const START_GRACE_S : i64
|
||||
mind_body::launch: fn open_and_launch (ports : & Ports , request : LaunchRequest) -> Result < LaunchOutcome >
|
||||
mind_body::launch: fn run_label (now : DateTime < Utc >) -> Label
|
||||
|
|
@ -195,17 +195,22 @@ mind_body::persona: struct Settle # [derive (Clone , Debug , PartialEq , Eq , Se
|
|||
mind_body::persona: struct StartSelfRun # [derive (Clone , Debug , PartialEq , Eq , Serialize , Deserialize)] pub-fields[brief: String, repo: String, campaign: String, for_item: Option < String >]
|
||||
mind_body::persona: struct TraceItem # [derive (Clone , Debug , PartialEq , Eq , Serialize , Deserialize)] pub-fields[provenance: String, room: String, text: String]
|
||||
mind_body::persona: struct TurnTrace # [derive (Clone , Debug , PartialEq , Eq , DatabaseEntry)] pub-fields[run: String, turn: u32, at: DateTime < Utc >, inputs: Vec < TraceItem >, outputs: Vec < TraceItem >, outcome: String]
|
||||
mind_body::queue: # [derive (Clone , Copy , Debug , PartialEq , Eq)] pub enum Breaker { Clear , Trip , }
|
||||
mind_body::queue: # [derive (Clone , Debug , PartialEq , Eq)] pub enum Breaker { Clear , Trip { run : PipelineRef } , }
|
||||
mind_body::queue: const CONSECUTIVE : usize
|
||||
mind_body::queue: const EMPTY_SHARE : usize
|
||||
mind_body::queue: const WINDOW : usize
|
||||
mind_body::queue: fn breaker (mind : & dyn MindPort , item : & PipelineRef , ending : & [PipelineRef]) -> Result < Breaker >
|
||||
mind_body::queue: fn queue (mind : & dyn MindPort , instance : & Slug , ending : & [PipelineRef]) -> Result < Vec < PipelineRef > >
|
||||
mind_body::queue: fn on_hold (mind : & dyn MindPort) -> Result < Held >
|
||||
mind_body::queue: fn queue (mind : & dyn MindPort , instance : & Slug , ending : & [PipelineRef] , held : & Held ,) -> Result < Vec < PipelineRef > >
|
||||
mind_body::queue: impl Held
|
||||
mind_body::queue: impl Held: fn contains (& self , item : & PipelineRef) -> bool
|
||||
mind_body::queue: impl Held: fn items (& self) -> & [PipelineRef]
|
||||
mind_body::queue: impl HuginnMind < 'static >
|
||||
mind_body::queue: impl HuginnMind < 'static >: fn new (client : HuginnClient) -> Self
|
||||
mind_body::queue: impl MindPort for HuginnMind < '_ >
|
||||
mind_body::queue: impl< 'a > HuginnMind < 'a >
|
||||
mind_body::queue: pub trait MindPort { fn instance (& self) -> & Slug ; fn query (& self , selection : & Selection) -> Result < PipelineSelectionPage > ; fn query_near (& self , _selection : & Selection , _text : & str , _top_k : u32) -> Result < PipelineSelectionPage > { bail ! ("this mind port has no semantic index") } fn admit (& self , agent : & str , session : & str , documents : Vec < PipelineDocument >) -> Result < PipelineAdmissionOutcome > ; }
|
||||
mind_body::queue: struct Held # [derive (Clone , Debug , PartialEq , Eq)] pub-fields[]
|
||||
mind_body::queue: struct HuginnMind< 'a > pub-fields[]
|
||||
mind_body::recall: impl Lane
|
||||
mind_body::recall: impl Recalled
|
||||
|
|
@ -262,6 +267,7 @@ mind_body::self_run::decide: impl State
|
|||
mind_body::self_run::inbox: const OWNER : & str
|
||||
mind_body::self_run::inbox: fn backlog (mind : & dyn MindPort) -> Result < Vec < (Brief , String) > >
|
||||
mind_body::self_run::inbox: fn derive (mind : & dyn MindPort , told : & HashSet < String >) -> Result < Vec < Brief > >
|
||||
mind_body::self_run::inbox: fn derive_counting_held (mind : & dyn MindPort , holds : & Held , told : & HashSet < String >) -> Result < (Vec < Brief > , usize) >
|
||||
mind_body::self_run::inbox: fn render (briefs : & [Brief] , plan : & str) -> String
|
||||
mind_body::self_run::inbox: fn resolving_sentence (id : & str) -> String
|
||||
mind_body::self_run::inbox: struct Brief # [derive (Clone , Debug , PartialEq , Eq)] pub-fields[id: String, campaign: String, repo: String, item: String, ordinal: u64]
|
||||
|
|
|
|||
Loading…
Reference in a new issue