Watch
0
0
Fork
You've already forked hyperhive
0

closure_pullable judges an agent by its own pins, not the whole meta head

This commit is contained in:
atlas 2026-11-01 14:20:00 +01:00
commit 567cd12300
2 changed files with 158 additions and 11 deletions

View file

@ -591,7 +591,7 @@ async fn pull_closure(
host.realise_closure(name, &record.store_path)
.await
.map_err(|e| NoClosure::Unpullable(format!("{e:#}")))?;
if record.meta_rev != rev {
if record.meta_rev != rev && !same_pins(host, name, &record.meta_rev, rev).await {
tracing::warn!(
%name, %rev, built_from = %record.meta_rev,
"{step}: the swarm built {} from internal/meta {}, not the {rev} this hive chose; deploying the swarm's",
@ -604,6 +604,18 @@ async fn pull_closure(
})
}
/// Whether the agent has the same pins at the commits `built` and `chosen`. A
/// commit whose pins cannot be read counts as different.
async fn same_pins(host: &impl Host, name: &str, built: &str, chosen: &str) -> bool {
match (
host.pins_at(name, built).await,
host.pins_at(name, chosen).await,
) {
(Ok(built), Ok(chosen)) => built.same_pins(&chosen),
_ => false,
}
}
/// The pins to record for a deploy of `closure` when this hive chose the commit
/// `rev`: those of the commit the closure was built from, so the markers say
/// what runs. `None` when they are the same commit.

View file

@ -41,6 +41,8 @@ struct FakeHost {
failing: Vec<&'static str>,
/// The sweeps and pulls never finish, so only a deadline ends them.
hang: bool,
/// The agent has the same pins at every commit.
unmoved: bool,
runtime: PathBuf,
purge: Vec<PathBuf>,
calls: Mutex<Vec<String>>,
@ -71,6 +73,11 @@ impl FakeHost {
self
}
fn unmoved(mut self) -> Self {
self.unmoved = true;
self
}
fn without_record(mut self) -> Self {
self.built = None;
self
@ -134,7 +141,11 @@ impl Host for FakeHost {
Ok(MetaBuild {
rev: rev.to_owned(),
hyperhive: "dh".to_owned(),
config: Some("dc".to_owned()),
config: Some(if self.unmoved {
"dc".to_owned()
} else {
format!("dc-{rev}")
}),
})
}
@ -442,6 +453,16 @@ async fn a_rebuild_without_a_closure_fails_the_prebuild_and_logs_an_error() {
}
}
/// Another commit that pins the agent the same is nothing to warn about.
#[tokio::test]
async fn a_closure_built_from_a_commit_with_the_same_pins_is_deployed_quietly() {
let host = FakeHost::up().built(OTHER_REV, true).unmoved();
let (result, log) = logging(run_prebuild(&host, "alice")).await;
result.expect("drift is not a refusal");
assert!(host.calls().contains(&format!("realise alice {CLOSURE}")));
assert!(log.at(tracing::Level::WARN).is_empty());
}
/// The builder's record is not for the commit this hive chose: its closure is
/// deployed and the difference is a warning.
#[tokio::test]
@ -546,6 +567,8 @@ async fn swap_applies_a_closure_built_from_another_commit_with_a_warning() {
"closure_record alice".to_owned(),
format!("realise alice {CLOSURE}"),
format!("pins_at alice {OTHER_REV}"),
format!("pins_at alice {REV}"),
format!("pins_at alice {OTHER_REV}"),
format!("swap_update alice {CLOSURE} node={}", id.get()),
format!("record_meta alice {OTHER_REV}"),
]
@ -943,6 +966,8 @@ async fn create_uses_a_closure_built_from_another_commit_with_a_warning() {
"closure_record alice".to_owned(),
format!("realise alice {CLOSURE}"),
format!("pins_at alice {OTHER_REV}"),
format!("pins_at alice {REV}"),
format!("pins_at alice {OTHER_REV}"),
format!("create_only alice {CLOSURE}"),
format!("mark_deployed alice {OTHER_REV}"),
]