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 <noreply@anthropic.com>
This commit is contained in:
parent
9f22513b83
commit
d0aafa974d
4 changed files with 139 additions and 28 deletions
|
|
@ -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<String>,
|
||||
catalog: Arc<Mutex<Catalog>>,
|
||||
scale: Arc<Scale>,
|
||||
/// 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<tokio::sync::Semaphore>,
|
||||
}
|
||||
|
||||
/// 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<ghostlight::InferenceFaultClass> {
|
||||
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]
|
||||
|
|
|
|||
|
|
@ -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<VecDeque<Result<InferenceOutput, &'static str>>>,
|
||||
queue: StdMutex<VecDeque<Result<InferenceOutput, InferenceFault>>>,
|
||||
seen: StdMutex<Vec<InferenceRequest>>,
|
||||
/// 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<InferenceOutput, &'static str>) {
|
||||
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<InferenceOutput, InferenceFault>) {
|
||||
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"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<CommandId> = 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 =
|
||||
|
|
|
|||
|
|
@ -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<SeedOutcome, ControllerError> {
|
||||
/// 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<Semaphore>,
|
||||
sessions: usize,
|
||||
) -> Result<SeedOutcome, ControllerError> {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue