Fix Idunn Gjallar empty-panel health

This commit is contained in:
Meta Vens 2026-06-15 19:44:48 +01:00
commit 7ec011f120
5 changed files with 165 additions and 20 deletions

View file

@ -601,15 +601,18 @@ fn probe_health(
detail: command_output_detail("health command exited successfully", &output),
observed_at: observed_at.to_string(),
},
Ok(output) => IdunnDaemonHealthRecord {
daemon_id: target.daemon_id.clone(),
state: "failed".to_string(),
detail: command_output_detail(
Ok(output) => {
let detail = command_output_detail(
&format!("health command exited with {}", output.status),
&output,
),
observed_at: observed_at.to_string(),
},
);
IdunnDaemonHealthRecord {
daemon_id: target.daemon_id.clone(),
state: health_state_from_detail(&detail).to_string(),
detail,
observed_at: observed_at.to_string(),
}
}
Err(error) => IdunnDaemonHealthRecord {
daemon_id: target.daemon_id.clone(),
state: "failed".to_string(),
@ -626,6 +629,22 @@ fn probe_health(
}
}
fn health_state_from_detail(detail: &str) -> &str {
for state in [
"stale-deployment",
"dependency-unavailable",
"degraded",
"failed",
] {
let marker = format!("idunn.health.state={state}");
if detail.contains(&marker) {
return state;
}
}
"failed"
}
fn run_restart(
request: &odin_core::IdunnRestartRequestRecord,
requested_at: &str,

View file

@ -37,8 +37,29 @@ pub fn plan_keepalive(
};
}
if health.state == "degraded" || health.state == "dependency-unavailable" {
let alarm_id = format!("alarm:{}:{}", desired.daemon_id, now);
let reason = format!(
"health is {}; local restart/deploy is not the owner of this failure: {}",
health.state, health.detail
);
return IdunnPlan {
decision: decision(&decision_id, desired, "alarm", &reason, &now),
deployment_request: None,
restart_request: None,
operator_alarm: Some(IdunnOperatorAlarmRecord {
alarm_id,
daemon_id: desired.daemon_id.clone(),
severity: "operator-action-required".to_string(),
reason,
escalation_target: "bifrost.operator-notification".to_string(),
raised_at: now,
}),
};
}
if let Some(command) = desired.deploy_command.as_deref() {
if !command.trim().is_empty() {
if !command.trim().is_empty() && health.state == "stale-deployment" {
let request_id = format!("deploy:{}:{}", desired.daemon_id, now);
return IdunnPlan {
decision: decision(
@ -193,7 +214,11 @@ mod tests {
fn unhealthy_daemon_with_deploy_authority_requests_deployment_before_restart() {
let mut desired = desired(Some("systemctl restart gjallar"));
desired.deploy_command = Some("deploy gjallar".to_string());
let plan = plan_keepalive(&desired, &health("failed"), "2026-06-04T00:00:02Z");
let plan = plan_keepalive(
&desired,
&health("stale-deployment"),
"2026-06-04T00:00:02Z",
);
assert_eq!(plan.decision.action, "deploy");
assert_eq!(plan.deployment_request.unwrap().command, "deploy gjallar");
@ -201,6 +226,37 @@ mod tests {
assert!(plan.operator_alarm.is_none());
}
#[test]
fn failed_daemon_with_deploy_and_restart_authority_restarts_instead_of_redeploying() {
let mut desired = desired(Some("systemctl restart gjallar"));
desired.deploy_command = Some("deploy gjallar".to_string());
let plan = plan_keepalive(&desired, &health("failed"), "2026-06-04T00:00:02Z");
assert_eq!(plan.decision.action, "restart");
assert!(plan.deployment_request.is_none());
assert_eq!(
plan.restart_request.unwrap().command,
"systemctl restart gjallar"
);
assert!(plan.operator_alarm.is_none());
}
#[test]
fn dependency_unavailable_raises_alarm_instead_of_redeploying_or_restarting() {
let mut desired = desired(Some("systemctl restart gjallar"));
desired.deploy_command = Some("deploy gjallar".to_string());
let plan = plan_keepalive(
&desired,
&health("dependency-unavailable"),
"2026-06-04T00:00:02Z",
);
assert_eq!(plan.decision.action, "alarm");
assert!(plan.deployment_request.is_none());
assert!(plan.restart_request.is_none());
assert!(plan.operator_alarm.is_some());
}
#[test]
fn unhealthy_daemon_without_authority_raises_operator_alarm() {
let plan = plan_keepalive(&desired(None), &health("failed"), "2026-06-04T00:00:02Z");

View file

@ -126,15 +126,19 @@ idunn.operator_alarm.v1
screen/audio streams as part of keepalive. Raven A/V over SRT is an explicit
activation path through `activate-muninn-raven-av-srt.ps1`, not daemon
startup behavior.
- Nightwing Gjallar deployment freshness is now part of Idunn's ops role.
`health-nightwing-gjallar.ps1` verifies both `gjallar.service` liveness and
the remote deployment manifest at
- Nightwing Gjallar deployment freshness and visible composition health are now
part of Idunn's ops role. `health-nightwing-gjallar.ps1` verifies
`gjallar.service` liveness, the remote deployment manifest at
`/opt/gamecult/gjallar/gamecult-gjallar-deploy-manifest.txt`. A missing or
stale manifest makes health fail. Idunn then runs
stale manifest emits `idunn.health.state=stale-deployment`; Idunn then runs
`deploy-nightwing-gjallar.ps1`, which publishes the committed local Gjallar
revision, writes `gamecult.gjallar.deployment_manifest.v1`, restarts
`gjallar.service`, and leaves deployment request/result records in its
keepalive `.cc`.
keepalive `.cc`. The same health probe also reads `/var/log/gjallar.status`;
an empty catalog, failed receive loop, stale status witness, or zero composed
provider panels is unhealthy even when the process is alive. Upstream deck
failure emits `idunn.health.state=dependency-unavailable` so Idunn does not
redeploy Gjallar for an Odin/provider input outage.
- Swarm-wide deployment ownership means Idunn owns the target catalog and the
freshness contract for the repo swarm. It does not mean Idunn invents deploy
authority for every repo immediately. A target without a safe noninteractive

View file

@ -1,14 +1,28 @@
param(
[string] $GjallarRoot = "E:\Projects\Gjallar",
[string] $SshTarget = "nightwing",
[string] $RemoteManifest = "/opt/gamecult/gjallar/gamecult-gjallar-deploy-manifest.txt"
[string] $RemoteManifest = "/opt/gamecult/gjallar/gamecult-gjallar-deploy-manifest.txt",
[string] $RemoteStatus = "/var/log/gjallar.status",
[int] $MaxStatusAgeSeconds = 120,
[int] $MinCatalogProviders = 1,
[int] $MinComposedProviders = 1
)
$ErrorActionPreference = "Stop"
function Fail-IdunnHealth {
param(
[string] $State,
[string] $Message
)
Write-Output "idunn.health.state=$State"
throw $Message
}
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget "systemctl is-active --quiet gjallar.service"
if ($LASTEXITCODE -ne 0) {
throw "gjallar.service is not active on Nightwing."
Fail-IdunnHealth -State "failed" -Message "gjallar.service is not active on Nightwing."
}
$localCommit = (git -C $GjallarRoot rev-parse HEAD).Trim()
@ -18,7 +32,7 @@ if ([string]::IsNullOrWhiteSpace($localCommit)) {
$manifest = ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget "cat '$RemoteManifest' 2>/dev/null"
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($manifest)) {
throw "Nightwing Gjallar deploy manifest is missing."
Fail-IdunnHealth -State "stale-deployment" -Message "Nightwing Gjallar deploy manifest is missing."
}
$remoteCommit = ""
@ -29,7 +43,43 @@ foreach ($line in $manifest) {
}
if ($remoteCommit -ne $localCommit) {
throw "Nightwing Gjallar deploy is stale. remote=$remoteCommit local=$localCommit"
Fail-IdunnHealth -State "stale-deployment" -Message "Nightwing Gjallar deploy is stale. remote=$remoteCommit local=$localCommit"
}
Write-Host "Nightwing Gjallar is active and deployed at $localCommit."
$statusJson = ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget "cat '$RemoteStatus' 2>/dev/null"
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($statusJson)) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness is missing at $RemoteStatus."
}
$status = $statusJson | ConvertFrom-Json
if ($status.schema -ne "gamecult.gjallar.frame.v1") {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness has unexpected schema '$($status.schema)'."
}
$updatedAt = [DateTimeOffset]::Parse($status.updatedAtUtc)
$ageSeconds = ([DateTimeOffset]::UtcNow - $updatedAt.ToUniversalTime()).TotalSeconds
if ($ageSeconds -gt $MaxStatusAgeSeconds) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness is stale ($([math]::Round($ageSeconds))s old)."
}
if ($status.status -ne "rendered") {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar framebuffer status is '$($status.status)', expected rendered."
}
if ($status.receive.status -ne "catalog-composed") {
$detail = $status.receive.error
if ([string]::IsNullOrWhiteSpace($detail)) {
$detail = $status.receive.providerFetchError
}
Fail-IdunnHealth -State "dependency-unavailable" -Message "Nightwing Gjallar receive status is '$($status.receive.status)', expected catalog-composed. $detail"
}
if ([int]$status.receive.catalogProviders -lt $MinCatalogProviders) {
Fail-IdunnHealth -State "dependency-unavailable" -Message "Nightwing Gjallar catalog is empty: catalogProviders=$($status.receive.catalogProviders), expected at least $MinCatalogProviders."
}
if ([int]$status.receive.composedProviders -lt $MinComposedProviders) {
Fail-IdunnHealth -State "degraded" -Message "Nightwing Gjallar composed no provider panels: composedProviders=$($status.receive.composedProviders), expected at least $MinComposedProviders."
}
Write-Host "Nightwing Gjallar is active, deployed at $localCommit, and composing $($status.receive.composedProviders)/$($status.receive.catalogProviders) providers."

View file

@ -54,7 +54,7 @@ main().catch((error) => {
async function main() {
if (cultRuntime.CultMesh && documents.surfaceDefinition) {
meshNodePromise = cultRuntime.CultMesh.createNode(config.cachePath, { documents: [documents.surfaceDefinition] });
meshNodePromise = createDurableSurfaceNode();
}
const dashboardServer = createDashboardServer({
@ -72,6 +72,22 @@ async function main() {
}, config.intervalMs);
}
async function createDurableSurfaceNode() {
try {
return await cultRuntime.CultMesh.createNode(config.cachePath, { documents: [documents.surfaceDefinition] });
} catch (error) {
if (!fs.existsSync(config.cachePath)) {
throw error;
}
const corruptPath = `${config.cachePath}.corrupt-${new Date().toISOString().replace(/[:.]/g, "-")}`;
fs.renameSync(config.cachePath, corruptPath);
console.error(`CultMesh surface cache was unreadable and has been quarantined: ${corruptPath}`);
console.error(`CultMesh surface cache read error: ${error.message}`);
return cultRuntime.CultMesh.createNode(config.cachePath, { documents: [documents.surfaceDefinition] });
}
}
async function refresh(clients) {
const started = Date.now();
lastRefresh = {