diff --git a/crates/ghostlight-dungeon/src/playtest_atlas.rs b/crates/ghostlight-dungeon/src/playtest_atlas.rs index 970f583..4b8f05a 100644 --- a/crates/ghostlight-dungeon/src/playtest_atlas.rs +++ b/crates/ghostlight-dungeon/src/playtest_atlas.rs @@ -47,6 +47,8 @@ const POLL_EVERY: Duration = Duration::from_secs(4); /// Sweeps in a row that commit nothing before the run stops: what is left is /// refused or unanswerable, not undone. const STALL_SWEEPS: u32 = 3; +/// Times the run asks Begin to seed the one key before it gives up. +const SEED_ATTEMPTS: u32 = 4; // ------------------------------------------------------------- the options @@ -767,16 +769,29 @@ pub(super) async fn run(options: AtlasOptions) -> anyhow::Result { "era": options.era, "lenses": weights, }); - let (status, reply) = client.call(Method::POST, "/api/begin", Some(body)).await; - if !status.is_success() { - bail!("/api/begin answered {status}: {reply}"); + // A seed that authored no one fails and leaves the world a Draft; the same + // key seeds it again. The model's first draft is not deterministic, so the + // run asks up to `SEED_ATTEMPTS` times before it gives up. + let (mut timeline, mut seed_secs) = (String::new(), 0.0); + for attempt in 1..=SEED_ATTEMPTS { + let (status, reply) = client.call(Method::POST, "/api/begin", Some(body.clone())).await; + if !status.is_success() { + bail!("/api/begin answered {status}: {reply}"); + } + timeline = reply["timeline"].as_str().context("begin named no timeline")?.to_owned(); + log(format!( + "begun as {timeline} (attempt {attempt}): targets person {} institution {} population {}, all eight lenses at 1, era {}; seeding", + options.persons, options.institutions, options.populations, options.era + )); + match poll_seed(&client, &timeline, Instant::now()).await { + Ok(secs) => { + seed_secs = secs; + break; + } + Err(fault) if attempt < SEED_ATTEMPTS => log(format!("seed attempt {attempt} failed: {fault}; ${:.2} spent", dollars(&plan, &global.by_model()))), + Err(fault) => bail!("the seed failed {SEED_ATTEMPTS} times: {fault}"), + } } - let timeline = reply["timeline"].as_str().context("begin named no timeline")?.to_owned(); - log(format!( - "begun as {timeline}: targets person {} institution {} population {}, all eight lenses at 1, era {}; seeding", - options.persons, options.institutions, options.populations, options.era - )); - let seed_secs = poll_seed(&client, &timeline, Instant::now()).await.map_err(|fault| anyhow::anyhow!("{fault}"))?; log(format!("seeded in {seed_secs:.0}s; ${:.2}", dollars(&plan, &global.by_model()))); let host = state.timelines.host(&timeline).await?;