fix: call matrix::sync_agent on rebuild, mirrors startup sweep
This commit is contained in:
parent
188f3ea5ec
commit
044ff5523c
2 changed files with 35 additions and 0 deletions
|
|
@ -119,6 +119,12 @@ pub async fn rebuild_agent(
|
||||||
// (e.g. first-spawn seeding failed transiently) without
|
// (e.g. first-spawn seeding failed transiently) without
|
||||||
// requiring a full hive-c0re restart.
|
// requiring a full hive-c0re restart.
|
||||||
crate::forge::sync_agent(name, crate::forge::core_token().as_deref()).await;
|
crate::forge::sync_agent(name, crate::forge::core_token().as_deref()).await;
|
||||||
|
// Mirror the matrix side of the startup sweep: if hive-matrix
|
||||||
|
// is present, ensure this agent has a registered user + token.
|
||||||
|
// Idempotent (skips if token file already exists). Keeps the
|
||||||
|
// rebuild path equivalent to the startup sweep for newly-spawned
|
||||||
|
// agents that missed ensure_all().
|
||||||
|
crate::matrix::sync_agent_standalone(name).await;
|
||||||
// Wake the agent on its next turn so claude sees a
|
// Wake the agent on its next turn so claude sees a
|
||||||
// "you were rebuilt — check /state/ for notes, --continue
|
// "you were rebuilt — check /state/ for notes, --continue
|
||||||
// session intact" hint. Covers dashboard rebuild, admin
|
// session intact" hint. Covers dashboard rebuild, admin
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,35 @@ pub async fn sync_agent(client: &reqwest::Client, name: &str, register_token: &s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Standalone per-agent sync that handles its own setup: checks if
|
||||||
|
/// hive-matrix is present, reads the registration token, and builds
|
||||||
|
/// an HTTP client before delegating to [`sync_agent`]. Mirrors the
|
||||||
|
/// setup in [`ensure_all`] so the rebuild path and the startup sweep
|
||||||
|
/// stay equivalent. No-op when the matrix container is absent.
|
||||||
|
pub async fn sync_agent_standalone(name: &str) {
|
||||||
|
if !is_present().await {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let register_token = match ensure_register_token() {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(%name, error = ?e, "matrix: ensure_register_token failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let client = match reqwest::Client::builder()
|
||||||
|
.timeout(std::time::Duration::from_secs(HTTP_TIMEOUT_SECS))
|
||||||
|
.build()
|
||||||
|
{
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(%name, error = ?e, "matrix: build HTTP client failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
sync_agent(&client, name, ®ister_token).await;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sweep every existing container (manager + sub-agents) and ensure
|
/// Sweep every existing container (manager + sub-agents) and ensure
|
||||||
/// each has a matrix user + token on the local homeserver. Called once
|
/// each has a matrix user + token on the local homeserver. Called once
|
||||||
/// at hive-c0re startup, alongside `forge::ensure_all`. No-op when the
|
/// at hive-c0re startup, alongside `forge::ensure_all`. No-op when the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue