From d0aafa974dbf0e6e72f346e2c2a382b3b502605f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 02:24:36 +0100 Subject: [PATCH 1/4] Seed sessions hold a permit of the shared inference pool, wait out a connector at capacity, and fail with the fault's own words Eight concurrent seeded Begins sent eight seed requests beside a pool sized to the connector's per-caller quota of four; the surplus was refused as over capacity and every refusal read as 'could not reach the model'. The seed request is ~90 KB, not near any bound. Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/begin.rs | 93 +++++++++++++++++++++----- crates/ghostlight-dungeon/src/play.rs | 9 ++- crates/ghostlight/src/controllers.rs | 51 ++++++++++++-- crates/ghostlight/src/elaboration.rs | 14 +++- 4 files changed, 139 insertions(+), 28 deletions(-) diff --git a/crates/ghostlight-dungeon/src/begin.rs b/crates/ghostlight-dungeon/src/begin.rs index 130cbee..fcc9b67 100644 --- a/crates/ghostlight-dungeon/src/begin.rs +++ b/crates/ghostlight-dungeon/src/begin.rs @@ -331,6 +331,7 @@ pub(crate) async fn begin( brief: seed_brief(story), catalog: catalog.clone(), scale: scale.clone(), + permits: timelines.shared().permits.clone(), }; supervise(seed); } @@ -399,8 +400,18 @@ struct Seed { brief: Option, catalog: Arc>, scale: Arc, + /// The pool every lane infers under, sized to the connector's per-caller + /// quota. A seed that did not hold one of its permits would put its + /// requests beside the pool's, and the surplus would be refused as over + /// capacity. + permits: Arc, } +/// Retryable seed faults, such as a connector at capacity, are waited out this +/// many times, a growing pause apart, before the seed reports itself failed. +const SEED_RETRIES: u32 = 5; +const SEED_RETRY_PAUSE: std::time::Duration = std::time::Duration::from_millis(if cfg!(test) { 5 } else { 3_000 }); + /// Runs a seed on its own task and watches it: a seed that panics ends /// Failed, never Seeding forever. fn supervise(seed: Seed) { @@ -440,13 +451,24 @@ impl Seed { self.evidence.clone(), self.brief.clone(), ); - runner - .sweep(self.scale.seed_sessions) - .await - .map_err(|error| { - tracing::warn!(%error, "seeding a world could not complete"); - stopped("seed", describe_seed_failure(&error)) - })?; + // A retried sweep resumes the stored session: the connector replays a + // completed request by its id, so asking again cannot spend twice. + let mut retries = 0; + loop { + match runner.sweep(self.permits.clone(), self.scale.seed_sessions).await { + Ok(_) => break, + Err(error) if retries < SEED_RETRIES && is_retryable(&error) => { + retries += 1; + tracing::info!(%error, retries, timeline = %self.timeline, "a seed fault is retried"); + tokio::time::sleep(SEED_RETRY_PAUSE * retries).await; + } + Err(error) => { + let reason = describe_seed_failure(&error); + tracing::warn!(%error, class = ?fault_class(&error), reason, timeline = %self.timeline, "seeding a world could not complete"); + return Err(stopped("seed", reason)); + } + } + } // A seed that answered nothing leaves the Draft as it was: the world // is not activated empty, and the same key seeds it again. let world = current(&self.host) @@ -467,14 +489,30 @@ impl Seed { } } -/// A seed failure reaches the player as a category, never as the error's own -/// text, which can name this process's endpoints. -fn describe_seed_failure(error: &ControllerError) -> &'static str { +fn seed_fault(error: &ControllerError) -> Option<&ghostlight::InferenceFault> { match error { - ControllerError::Inference { .. } | ControllerError::ProviderContract { .. } => { - "seeding could not reach the model" - } - _ => "seeding could not complete", + ControllerError::Inference { source, .. } => Some(source), + _ => None, + } +} + +fn fault_class(error: &ControllerError) -> Option { + seed_fault(error).map(ghostlight::InferenceFault::class) +} + +fn is_retryable(error: &ControllerError) -> bool { + seed_fault(error).is_some_and(|fault| fault.disposition() == ghostlight::InferenceFaultDisposition::Retryable) +} + +/// A seed failure reaches the player as the model fault's own fixed words (a +/// bound, a refused model, a connector at capacity), never as the error's own +/// text, which can name this process's endpoints. A fault the port could not +/// type still says only that the model was not reached. +fn describe_seed_failure(error: &ControllerError) -> String { + match error { + ControllerError::Inference { source, .. } => format!("seeding stopped: {}", source.detail()), + ControllerError::ProviderContract { .. } => "seeding could not reach the model".to_owned(), + _ => "seeding could not complete".to_owned(), } } @@ -870,20 +908,21 @@ pub(crate) mod tests { assert_eq!(others, 2, "with the two people placed there"); } - /// Spec test: a seed fault reads Failed with a category and no endpoint - /// text, leaves the world a Draft, and the same key seeds it again. + /// Spec test: a seed fault reads Failed with the fault's own fixed words, + /// so a bound refusal surfaces as itself and not as "could not reach the + /// model"; the world stays a Draft and the same key seeds it again. #[tokio::test] async fn a_seed_fault_reads_failed_and_the_same_key_seeds_again() { let rig = deferred_rig(); let key = Uuid::new_v4(); let begun = begin_vault(&rig, key).await; - rig.port.push(Err("http://10.0.0.7:9/secret endpoint down")); + rig.port.push(Err("the request exceeds the connector's payload bound")); let status = eventually(async || match rig.status(&begun.timeline).await { Some(SeedStatus::Failed(reason)) => Some(reason), _ => None, }) .await; - assert!(!status.contains("10.0.0.7") && !status.contains("http"), "{status}"); + assert_eq!(status, "the begin stopped at its seed step: seeding stopped: the request exceeds the connector's payload bound"); let host = rig.timelines.host(&begun.timeline).await.unwrap(); assert_eq!(host.world.snapshot().await.unwrap().phase, WorldPhase::Draft); @@ -892,6 +931,24 @@ pub(crate) mod tests { assert_eq!(rig.status(&begun.timeline).await, Some(SeedStatus::Seeding)); } + /// A connector at capacity is the connector asking to be tried later: the + /// seed waits and asks again, and the world seeds and activates. + #[tokio::test] + async fn a_seed_waits_out_a_connector_at_capacity() { + let rig = deferred_rig(); + let begun = begin_vault(&rig, Uuid::new_v4()).await; + let host = rig.timelines.host(&begun.timeline).await.unwrap(); + let draft = host.world.snapshot().await.unwrap(); + rig.port.push_answer(Err(ghostlight::InferenceFault::retryable("the connector refused the request: at capacity"))); + rig.port.push(Ok(author("seed-1", &draft, &["a", "b"]))); + rig.port.push(Ok(author("seed-2", &draft, &["c", "d"]))); + eventually(async || { + let world = host.world.snapshot().await.unwrap(); + (world.phase == WorldPhase::Active && rig.status(&begun.timeline).await.is_none()).then_some(()) + }) + .await; + } + /// The seed asks for places as well as people, in the brief every seed /// session reads, whether the story is the player's or the vault's. #[test] diff --git a/crates/ghostlight-dungeon/src/play.rs b/crates/ghostlight-dungeon/src/play.rs index eea15f6..4fd56b3 100644 --- a/crates/ghostlight-dungeon/src/play.rs +++ b/crates/ghostlight-dungeon/src/play.rs @@ -3512,7 +3512,7 @@ pub(crate) mod tests { /// exercise `world.play`'s own staleness comparison against a question /// that actually opened, rather than one hand-built. pub(crate) struct ScriptedPort { - queue: StdMutex>>, + queue: StdMutex>>, seen: StdMutex>, /// A deferred port waits for its next scripted answer instead of /// refusing: a test writes the answer once it has read the world the @@ -3541,6 +3541,11 @@ pub(crate) mod tests { } pub(crate) fn push(&self, answer: Result) { + self.push_answer(answer.map_err(InferenceFault::recovery_required)); + } + + /// The same, for a fault the test builds itself, such as a retryable one. + pub(crate) fn push_answer(&self, answer: Result) { self.queue.lock().unwrap().push_back(answer); self.pushed.notify_waiters(); self.pushed.notify_one(); @@ -3563,7 +3568,7 @@ pub(crate) mod tests { let waiting = self.pushed.notified(); match self.queue.lock().unwrap().pop_front() { Some(Ok(output)) => return Ok(output), - Some(Err(detail)) => return Err(InferenceFault::recovery_required(detail)), + Some(Err(fault)) => return Err(fault), None if !self.deferred => { return Err(InferenceFault::recovery_required("scripted port exhausted")); } diff --git a/crates/ghostlight/src/controllers.rs b/crates/ghostlight/src/controllers.rs index 2444c1a..307ce95 100644 --- a/crates/ghostlight/src/controllers.rs +++ b/crates/ghostlight/src/controllers.rs @@ -348,6 +348,12 @@ impl InferenceFault { self.class } + /// What this fault says happened, in words fixed at its construction: no + /// endpoint, key or provider text can reach it, so it is safe to show. + pub fn detail(&self) -> &'static str { + self.detail + } + pub(super) fn requires_recovery(&self) -> bool { self.disposition == InferenceFaultDisposition::RecoveryRequired } @@ -17601,6 +17607,39 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur .map_or(0, |row| row.deficit) } + /// A vault far larger than any request can carry seeds within the + /// connector's bounds: the seed reads a bounded excerpt of each of a bounded + /// number of notes, however many notes or bytes the vault holds. + #[tokio::test] + async fn a_seed_over_a_large_vault_asks_within_the_connector_bounds() { + let fixture = seed_mailbox(6).await; + let vault = tempfile::tempdir().unwrap(); + for index in 0..60 { + std::fs::write( + vault.path().join(format!("The Low Sere {index}.md")), + "the low sere, the rain gate and the digger ".repeat(7_000), + ) + .unwrap(); + } + let snapshot = crate::vault::VaultSnapshot::build(&crate::vault::VaultProfile { + name: "large".into(), + root: vault.path().to_path_buf(), + ..Default::default() + }) + .unwrap(); + let evidence = crate::vault::VaultEvidenceSource::from_snapshot(&snapshot, "", &[]).unwrap(); + let script = seed_script(vec![tool_round(vec![], "round-0")]); + let runner = seed_runner(&fixture, script.clone(), fresh_store(), Arc::new(evidence)); + runner.step().await.unwrap(); + let seen = script.seen.lock().unwrap(); + let sent = serde_json::to_vec(&seen[0]).unwrap().len(); + assert!(sent > 8_000, "the vault's evidence reached the request ({sent} bytes)"); + assert!( + sent < crate::sdk_inference::MAX_SIDECAR_FRAME_BYTES / 4, + "a seed request over a vault of 18 MB stays far under the frame bound ({sent} bytes)" + ); + } + /// Spec test 4. One session commits one Draft patch as the owner's own act, /// and every subject it declared qualifies. #[tokio::test] @@ -17702,7 +17741,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur fresh_store(), Arc::new(NullEvidenceSource), ); - assert_eq!(runner.sweep(8).await.unwrap(), SeedOutcome::Clean); + assert_eq!(runner.sweep(pool(1), 8).await.unwrap(), SeedOutcome::Clean); assert_eq!( root_deficit(&fixture.mailbox.snapshot().await.unwrap(), fixture.sere), 0 @@ -17739,7 +17778,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur fresh_store(), Arc::new(NullEvidenceSource), ); - assert_eq!(runner.sweep(4).await.unwrap(), SeedOutcome::NoProgress); + assert_eq!(runner.sweep(pool(1), 4).await.unwrap(), SeedOutcome::NoProgress); assert_eq!( scripted.seen.lock().unwrap().len(), 1, @@ -18206,7 +18245,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur models().elaborator, None, ); - assert_eq!(runner.sweep(3).await.unwrap(), SeedOutcome::Clean); + assert_eq!(runner.sweep(pool(1), 3).await.unwrap(), SeedOutcome::Clean); let seeded = mailbox.snapshot().await.unwrap(); assert!( seeded.scale_deficit.iter().all(|row| row.deficit == 0), @@ -18817,7 +18856,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur store.clone(), Arc::new(NullEvidenceSource), ); - assert_eq!(resumed.sweep(4).await.unwrap(), SeedOutcome::NoPatch); + assert_eq!(resumed.sweep(pool(1), 4).await.unwrap(), SeedOutcome::NoPatch); assert_eq!( scripted.seen.lock().unwrap().len(), SEED_ROUND_BUDGET, @@ -18897,7 +18936,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur store.clone(), Arc::new(NullEvidenceSource), ); - assert_eq!(runner.sweep(4).await.unwrap(), SeedOutcome::Clean); + assert_eq!(runner.sweep(pool(1), 4).await.unwrap(), SeedOutcome::Clean); let ids: BTreeSet = store.work.lock().unwrap().keys().copied().collect(); assert_eq!(ids.len(), 2, "two landed sessions shared one derived id"); @@ -19060,7 +19099,7 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur fresh_store(), Arc::new(NullEvidenceSource), ); - assert_eq!(runner.sweep(4).await.unwrap(), SeedOutcome::Clean); + assert_eq!(runner.sweep(pool(1), 4).await.unwrap(), SeedOutcome::Clean); drop(runner); let authenticated = diff --git a/crates/ghostlight/src/elaboration.rs b/crates/ghostlight/src/elaboration.rs index b14ca6c..ba84785 100644 --- a/crates/ghostlight/src/elaboration.rs +++ b/crates/ghostlight/src/elaboration.rs @@ -2250,10 +2250,20 @@ impl SeedRunner { /// One bounded sweep. The budget is the caller's, because who may spend a /// paid endpoint is a transport question and how far a deficit has fallen - /// is not. - pub async fn sweep(&self, sessions: usize) -> Result { + /// is not. So is the ceiling: each session holds one permit of the + /// caller's pool for its whole step, the same pool every other lane + /// infers under, so a crowd of seeds cannot out-number the connector's + /// per-caller quota. + pub async fn sweep( + &self, + permits: Arc, + sessions: usize, + ) -> Result { let mut last = SeedOutcome::Clean; for _ in 0..sessions { + let Ok(_permit) = permits.clone().acquire_owned().await else { + break; + }; last = self.step().await?; if !matches!(last, SeedOutcome::Committed) { break; From eeb6bd3f7cfe5a2ab359671414f9b34d0a72e4b2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 02:26:20 +0100 Subject: [PATCH 2/4] Fix seed test fixtures for the pooled seed Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/begin.rs | 3 ++- crates/ghostlight-dungeon/src/play.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ghostlight-dungeon/src/begin.rs b/crates/ghostlight-dungeon/src/begin.rs index fcc9b67..dd9f889 100644 --- a/crates/ghostlight-dungeon/src/begin.rs +++ b/crates/ghostlight-dungeon/src/begin.rs @@ -1012,7 +1012,8 @@ pub(crate) mod tests { world_id: host.world.snapshot().await.unwrap().world_id, evidence: Arc::new(PanickingEvidence), brief: None, - catalog: rig.catalog.clone(), + scale: rig.scale.clone(), + permits: rig.timelines.shared().permits.clone(), scale: rig.scale.clone(), host, }); diff --git a/crates/ghostlight-dungeon/src/play.rs b/crates/ghostlight-dungeon/src/play.rs index 4fd56b3..fc7164d 100644 --- a/crates/ghostlight-dungeon/src/play.rs +++ b/crates/ghostlight-dungeon/src/play.rs @@ -6276,7 +6276,7 @@ pub(crate) mod tests { .queue .lock() .unwrap() - .push_back(Err("provider unavailable".into())); + .push_back(Err(InferenceFault::recovery_required("provider unavailable"))); personas_port .queue .lock() From e9612e4305996b88e4e8dc385a2561ba35ef6d0d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 02:28:05 +0100 Subject: [PATCH 3/4] Restore the catalog field in the panicking-seed fixture Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/begin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ghostlight-dungeon/src/begin.rs b/crates/ghostlight-dungeon/src/begin.rs index dd9f889..5e12779 100644 --- a/crates/ghostlight-dungeon/src/begin.rs +++ b/crates/ghostlight-dungeon/src/begin.rs @@ -1012,9 +1012,9 @@ pub(crate) mod tests { world_id: host.world.snapshot().await.unwrap().world_id, evidence: Arc::new(PanickingEvidence), brief: None, + catalog: rig.catalog.clone(), scale: rig.scale.clone(), permits: rig.timelines.shared().permits.clone(), - scale: rig.scale.clone(), host, }); let reason = eventually(async || match rig.status(&timeline).await { From 964be6db4455c5408b24eb5de3aeeb75973d9a1b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 02:30:12 +0100 Subject: [PATCH 4/4] api test: a failed seed reads the fault's own fixed words Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/api.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ghostlight-dungeon/src/api.rs b/crates/ghostlight-dungeon/src/api.rs index c705a26..ecdcd28 100644 --- a/crates/ghostlight-dungeon/src/api.rs +++ b/crates/ghostlight-dungeon/src/api.rs @@ -1285,20 +1285,20 @@ mod tests { .await; } - /// Spec test: a scripted seed fault reads Failed with a reason and no - /// endpoint text. + /// Spec test: a scripted seed fault reads Failed with the fault's own fixed + /// words. #[tokio::test] - async fn a_failed_seed_reads_failed_with_a_reason_and_no_endpoint() { + async fn a_failed_seed_reads_failed_with_the_faults_own_reason() { let app = app_over(deferred_rig(), &["alice"]).await; let cookie = app.cookies[0].clone(); let timeline = begin_vault_over_http(&app, &cookie).await; - app.rig.port.push(Err("http://10.0.0.7:9/secret endpoint down")); + app.rig.port.push(Err("the connector does not allow the requested model")); let (_, reason) = eventually(async || { timeline_status(&app, &cookie, &timeline).await.filter(|(state, _)| state == "failed") }) .await; let reason = reason.as_str().unwrap(); - assert!(reason.contains("seed") && !reason.contains("10.0.0.7"), "{reason}"); + assert!(reason.contains("seed") && reason.contains("the connector does not allow the requested model"), "{reason}"); } @@ -1315,7 +1315,7 @@ mod tests { assert_eq!((status, body["status"].as_str()), (StatusCode::CONFLICT, Some("seeding")), "{body}"); assert_eq!(body["error"], "this world is still being seeded"); - app.rig.port.push(Err("http://10.0.0.7:9/secret endpoint down")); + app.rig.port.push(Err("the connector does not allow the requested model")); eventually(async || timeline_status(&app, &cookie, &timeline).await.filter(|(state, _)| state == "failed")).await; let (status, body) = play_text(&app, &cookie, &timeline, "I look around.", None).await; assert_eq!((status, body["status"].as_str()), (StatusCode::CONFLICT, Some("failed")), "{body}");