fix: auto-create knowledge webhook + periodic pull fallback

hive-c0re now auto-creates the Forgejo push webhook for
internal/knowledge at startup (ensure_webhook). this is what was
missing — the webhook endpoint existed but was never registered in
forgejo, so merging iris's PR didn't trigger a pull.

also adds a periodic hourly pull as a fallback (and an immediate pull
at startup to reconcile commits that landed while c0re was offline).

fixes #1244.
This commit is contained in:
damocles 2026-06-04 09:52:32 +02:00 committed by mara
commit 78db47b00b
2 changed files with 112 additions and 6 deletions

View file

@ -13,8 +13,8 @@ use hive_sh4re::{HostRequest, HostResponse};
use hive_c0re::coordinator::Coordinator;
use hive_c0re::{
agent_sockets, auto_update, bash_tasks_vacuum, broker, client, crash_watch, dashboard,
dashboard_events, events_vacuum, forge, manager_server, matrix, migrate, rebuild_queue,
reminder_scheduler, scheduled_prompts_worker, server, stats_vacuum,
dashboard_events, events_vacuum, forge, knowledge, manager_server, matrix, migrate,
rebuild_queue, reminder_scheduler, scheduled_prompts_worker, server, stats_vacuum,
};
#[derive(Parser)]
@ -262,6 +262,43 @@ async fn cmd_serve(
tokio::spawn(async move {
forge::ensure_all().await;
});
// Knowledge webhook setup: ensure the Forgejo push webhook for
// `internal/knowledge` exists so `pull()` fires on merge. Runs
// after forge::ensure_all so the core token + repo are present.
// No-op when the core token or forge are absent.
let webhook_port = dashboard_port;
tokio::spawn(async move {
if let Some(token) = forge::core_token() {
if let Err(e) = knowledge::ensure_webhook(&token, webhook_port).await {
tracing::warn!(error = ?e, "knowledge: ensure_webhook failed");
}
}
});
// Knowledge periodic pull: hourly fallback in case the webhook is
// missed (e.g. hive-c0re was down during a push). First fires at
// startup (immediate pull after the clone is already present).
let mut knowledge_shutdown = coord.shutdown_rx();
tokio::spawn(async move {
// Initial pull — reconcile any commits that landed while c0re
// was offline, including the push that triggered #1244.
if let Err(e) = knowledge::pull().await {
tracing::debug!(error = ?e, "knowledge: startup pull skipped (no clone yet?)");
}
let interval = std::time::Duration::from_hours(1);
loop {
tokio::select! {
() = tokio::time::sleep(interval) => {
if let Err(e) = knowledge::pull().await {
tracing::warn!(error = ?e, "knowledge: periodic pull failed");
}
}
_ = knowledge_shutdown.changed() => {
tracing::info!("knowledge pull: shutdown signal received");
break;
}
}
}
});
// Matrix user sweep: same shape — ensure every container has
// an account on the local matrix-tuwunel homeserver with an
// access_token persisted to `<state>/matrix-token`. No-op when