Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 12 additions & 87 deletions loom-daemon/src/cli/status_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ pub(crate) fn build_status_json_value_for(
// dead, and reconcile rather than re-dispatching. Empty in the
// overwhelmingly common case.
"unregistered_locked_count": report.unregistered_locked.len(),
"unregistered_locked": report.unregistered_locked.iter().map(|u| serde_json::json!({
"root": u.root,
"issue": u.issue,
"owner_pid": u.owner_pid,
})).collect::<Vec<_>>(),
"unregistered_locked": report.unregistered_locked,
// Stale-untracked-sweep backstop (Issue #7529): in-flight sweeps
// unreachable by either the startup-hang (#3887) or review-stall
// (#3910) watchdog — see `DaemonStatusReport::stale_sweeps`'s doc.
Expand Down Expand Up @@ -415,32 +411,11 @@ pub(crate) fn build_status_json_value_for(
// daemon binary, which a consumer must NOT read as "unsharded" — an
// older daemon does not shard, but that is not something this payload
// asserts.
"role_runner_shard": report.role_runner_shard.as_ref().map(|s| serde_json::json!({
"index": s.index,
"count": s.count,
"configured": s.configured,
"summary": s.summary,
// Roster section (Issue #7690 / #7691, #6704) — `null` when the
// roster is disabled (the default) or has never completed a
// heartbeat cycle. With `roster.enabled` it is also the source of
// `index`/`count` above (`summary` says so), and `fence` names
// the admission verdict.
"roster": s.roster.as_ref().map(|r| serde_json::json!({
"issue": r.issue,
"live_count": r.live_count,
"seen_count": r.seen_count,
"generation": r.generation,
"settled_secs": r.settled_secs,
"fence": r.fence,
"members": r.members.iter().map(|m| serde_json::json!({
"host": m.host,
"fresh": m.fresh,
"last_beat_secs_ago": m.last_beat_secs_ago,
"serves_count": m.serves_count,
"is_this_host": m.is_this_host,
})).collect::<Vec<_>>(),
})),
})),
// A configured roster can supply index/count once it has completed a
// heartbeat (#7690, #7691, #6704); its fence records the admission
// verdict. The roster itself is null when disabled or still awaiting
// its first heartbeat.
"role_runner_shard": report.role_runner_shard,
// Startup forge-credential preflight (#4005) — resolved once at
// daemon boot, before the daemon's first `gh` consumer. Never
// contains a token value; `null` only from a pre-#4005 daemon binary
Expand Down Expand Up @@ -483,12 +458,7 @@ pub(crate) fn build_status_json_value_for(
// Per-role `onIdleMaxWait` age/promoted status (issue #7511) —
// one entry per role that is both `onIdle` and has a configured
// max-wait; empty when the key is unconfigured.
"role_runner_on_idle_promotions": r.role_runner_on_idle_promotions.iter().map(|p| serde_json::json!({
"role": p.role,
"max_wait_secs": p.max_wait_secs,
"age_secs": p.age_secs,
"promoted": p.promoted,
})).collect::<Vec<_>>(),
"role_runner_on_idle_promotions": r.role_runner_on_idle_promotions,
// Which tier decided `role_runner_enabled` (#6470): `Some(v)`
// only when the host-wide `LOOM_ROLE_RUNNER` env override (not
// this root's own config) is the cause — see
Expand All @@ -501,14 +471,7 @@ pub(crate) fn build_status_json_value_for(
// one failure mode deterministic sharding cannot rule out
// structurally — two hosts resolving *different keys* for the
// same workspace, which would let both (or neither) own it.
"role_runner_shard": r.role_runner_shard.as_ref().map(|s| serde_json::json!({
"owned_here": s.owned_here,
"key": s.key,
"key_source": s.key_source,
"owning_shard": s.owning_shard,
"host_shard": s.host_shard,
"shard_count": s.shard_count,
})),
"role_runner_shard": r.role_runner_shard,
// Fleet-wide quarantine-stash visibility (#5692): per-repo
// `refs/stash` counts, aggregated by
// `quarantine_stash_status::collect_stash_summary`. Builds on
Expand All @@ -534,14 +497,7 @@ pub(crate) fn build_status_json_value_for(
// from "collected, and the repo has none". `total_bytes` is itself
// `null` when the worktree root could not be read at all, so an
// unmeasurable repo never reads as a genuine 0 bytes.
"worktrees": worktree_disk.map(|summaries| summaries.iter().map(|w| serde_json::json!({
"root": w.root,
"total_count": w.total_count,
"issue_count": w.issue_count,
"pr_count": w.pr_count,
"other_count": w.other_count,
"total_bytes": w.total_bytes,
})).collect::<Vec<_>>()),
"worktrees": worktree_disk,
// Forge-side pipeline snapshot (#3977) — present only when `--pipeline`
// was passed; `null` otherwise so a consumer can tell "not requested"
// apart from "requested but empty".
Expand Down Expand Up @@ -633,46 +589,15 @@ pub(crate) fn build_status_json_value_for(
// `enabled: false` (feature never spawned) MUST be read as
// "cannot determine here", never as eligible. `null` only from a
// pre-#5565 daemon binary that never computed one.
"idle_exit": report.idle_exit.as_ref().map(|i| serde_json::json!({
"enabled": i.enabled,
"eligible": i.eligible,
"trigger": i.trigger,
"idle_minutes": i.idle_minutes,
"in_flight_sweeps": i.in_flight_sweeps,
"active_role_runs": i.active_role_runs,
"healthy_tokens": i.healthy_tokens,
"total_tokens": i.total_tokens,
"idle_elapsed_secs": i.idle_elapsed_secs,
"starved_elapsed_secs": i.starved_elapsed_secs,
"starvation_enabled": i.starvation_enabled,
"observed_at": i.observed_at,
})),
"rate_limit_breaker": report.rate_limit_breaker.as_ref().map(|r| serde_json::json!({
"enabled": r.enabled,
"phase": r.phase,
"suppressed": r.suppressed,
"source": r.source,
"tripped_at": r.tripped_at,
"cooldown_until": r.cooldown_until,
"trips_total": r.trips_total,
"core_remaining": r.core_remaining,
"graphql_remaining": r.graphql_remaining,
"core_used": r.core_used,
"graphql_used": r.graphql_used,
"budget_probed_at": r.budget_probed_at,
})),
"idle_exit": report.idle_exit,
"rate_limit_breaker": report.rate_limit_breaker,
// Per-caller forge call accounting (#9251); `null` from an older daemon.
"forge_calls": report.forge_calls,
// Live safehouse fleet-comms connection state (#4345) — `null` only
// from a pre-#4345 daemon binary that never computed one. `state` is
// one of "not_configured" / "unreachable" / "connected" /
// "send_rejected" (#4464, carries `reason`).
"safehouse": report.safehouse.as_ref().map(|s| serde_json::json!({
"state": s.state,
"socket": s.socket,
"room": s.room,
"reason": s.reason,
})),
"safehouse": report.safehouse,
// Watchdog protection state (#4354) — client-side, host-local, read-only.
// `state` is one of "protected" / "no-marker" /
// "watchdog-not-provisioned" / "unknown". `marker_present` and
Expand Down
245 changes: 245 additions & 0 deletions loom-daemon/src/cli/status_render/status_render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,248 @@ fn gate_column_label_missing_sweep_overrides_every_underlying_verdict() {
assert_eq!(gate_column_label(true, &v), "no-sweep");
}
}

fn status_contract_report() -> DaemonStatusReport {
let mut report = crate::cli::status::sample_report::sample_report();
// The shared fixture uses the current time. Keep the compatibility inputs
// deterministic so the full payload can also be compared before and after.
report.main_health_gate_verdict_at = None;
report.credential_preflight = None;
report.per_repo = vec![super::role_runner_diagnostic_source_render_tests::repo(
true,
&["auditor"],
None,
)];
report
}

fn render_status_contract(
report: &DaemonStatusReport,
worktrees: Option<&[WorktreeDiskSummary]>,
) -> serde_json::Value {
let update = self_update::SelfUpdateStatus {
built_commit: "abc1234".into(),
source_commit: None,
update_available: None,
commits_behind: None,
hours_behind: None,
};
// The fleet-store and pending-restart sections consult local daemon files.
// Keep these contract fixtures independent of the machine running them.
let sections = SectionSet::only(
Section::all()
.iter()
.copied()
.filter(|section| !matches!(section, Section::FleetStore | Section::PendingRestart)),
);
build_status_json_value_for(report, None, &update, None, None, worktrees, &sections)
}

fn assert_status_subtrees(actual: &serde_json::Value, expected: serde_json::Value) {
for (key, value) in expected.as_object().unwrap() {
// get() distinguishes an omitted key from a key whose value is null.
assert_eq!(actual.get(key), Some(value), "status field {key}");
}
}

#[test]
fn status_json_shared_types_keep_their_public_fields_and_values() {
use crate::types::{
IdleExitStatus, RateLimitBreakerStatus, RoleOnIdlePromotionStatus, RoleRunnerShardPosture,
RoleRunnerShardStatus, RosterMemberStatus, RosterStatus, SafehouseStatus,
UnregisteredLockedSweep,
};

let mut report = status_contract_report();
report.unregistered_locked = vec![UnregisteredLockedSweep {
root: "/repos/locked".into(),
issue: 42,
owner_pid: 321,
}];
report.role_runner_shard = Some(RoleRunnerShardPosture {
index: Some(1),
count: Some(3),
summary: "sharded by roster".into(),
configured: true,
roster: Some(RosterStatus {
issue: "acme/roster#55".into(),
live_count: 1,
seen_count: 2,
generation: Some("2026-11-20T01:02:03Z".parse().unwrap()),
settled_secs: Some(120),
fence: Some("admitted".into()),
members: vec![
RosterMemberStatus {
host: "host-active".into(),
fresh: true,
last_beat_secs_ago: 7,
serves_count: 20,
is_this_host: true,
},
RosterMemberStatus {
host: "host-expired".into(),
fresh: false,
last_beat_secs_ago: 300,
serves_count: 0,
is_this_host: false,
},
],
}),
});
report.per_repo[0].role_runner_on_idle_promotions = vec![
RoleOnIdlePromotionStatus {
role: "auditor".into(),
max_wait_secs: 60,
age_secs: Some(70),
promoted: true,
},
RoleOnIdlePromotionStatus {
role: "hermit".into(),
max_wait_secs: 90,
age_secs: None,
promoted: true,
},
];
report.per_repo[0].role_runner_shard = Some(RoleRunnerShardStatus {
owned_here: false,
key: "acme/repo".into(),
key_source: "origin".into(),
owning_shard: Some(2),
host_shard: Some(1),
shard_count: Some(3),
});
report.idle_exit = Some(IdleExitStatus {
enabled: true,
eligible: false,
trigger: None,
idle_minutes: 11,
in_flight_sweeps: 2,
active_role_runs: 3,
healthy_tokens: 4,
total_tokens: 5,
idle_elapsed_secs: 82,
starved_elapsed_secs: 19,
starvation_enabled: true,
observed_at: Some("2026-11-20T05:06:07Z".parse().unwrap()),
});
report.rate_limit_breaker = Some(Box::new(RateLimitBreakerStatus {
enabled: true,
phase: "cooldown".into(),
suppressed: true,
source: Some("work_finder".into()),
tripped_at: Some("2026-11-20T08:00:00Z".parse().unwrap()),
cooldown_until: Some("2026-11-20T08:02:00Z".parse().unwrap()),
trips_total: 2,
core_remaining: Some(0),
graphql_remaining: Some(21),
core_used: Some(5000),
graphql_used: None,
budget_probed_at: Some("2026-11-20T08:00:01Z".parse().unwrap()),
}));
report.safehouse = Some(SafehouseStatus {
state: "connected".into(),
socket: Some("/fixture/safehouse.sock".into()),
room: Some("fixture-room".into()),
reason: None,
});
let worktrees = [
WorktreeDiskSummary {
root: "/repos/unknown".into(),
total_count: 6,
issue_count: 1,
pr_count: 2,
other_count: 3,
total_bytes: None,
},
WorktreeDiskSummary {
root: "/repos/empty".into(),
total_bytes: Some(0),
..WorktreeDiskSummary::default()
},
];

let json = render_status_contract(&report, Some(&worktrees));
// The expected public schema is independent of the shared Rust serializers.
assert_status_subtrees(
&json,
serde_json::json!({
"unregistered_locked": [{"root": "/repos/locked", "issue": 42, "owner_pid": 321}],
"role_runner_shard": {
"index": 1, "count": 3, "configured": true, "summary": "sharded by roster",
"roster": {
"issue": "acme/roster#55", "live_count": 1, "seen_count": 2,
"generation": "2026-11-20T01:02:03Z", "settled_secs": 120, "fence": "admitted",
"members": [
{"host": "host-active", "fresh": true, "last_beat_secs_ago": 7, "serves_count": 20, "is_this_host": true},
{"host": "host-expired", "fresh": false, "last_beat_secs_ago": 300, "serves_count": 0, "is_this_host": false}
]
}
},
"worktrees": [
{"root": "/repos/unknown", "total_count": 6, "issue_count": 1, "pr_count": 2, "other_count": 3, "total_bytes": null},
{"root": "/repos/empty", "total_count": 0, "issue_count": 0, "pr_count": 0, "other_count": 0, "total_bytes": 0}
],
"idle_exit": {
"enabled": true, "eligible": false, "trigger": null, "idle_minutes": 11,
"in_flight_sweeps": 2, "active_role_runs": 3, "healthy_tokens": 4, "total_tokens": 5,
"idle_elapsed_secs": 82, "starved_elapsed_secs": 19, "starvation_enabled": true,
"observed_at": "2026-11-20T05:06:07Z"
},
"rate_limit_breaker": {
"enabled": true, "phase": "cooldown", "suppressed": true, "source": "work_finder",
"tripped_at": "2026-11-20T08:00:00Z", "cooldown_until": "2026-11-20T08:02:00Z",
"trips_total": 2, "core_remaining": 0, "graphql_remaining": 21, "core_used": 5000,
"graphql_used": null, "budget_probed_at": "2026-11-20T08:00:01Z"
},
"safehouse": {"state": "connected", "socket": "/fixture/safehouse.sock", "room": "fixture-room", "reason": null}
}),
);
assert_status_subtrees(
&json["per_repo"][0],
serde_json::json!({
"role_runner_on_idle_promotions": [
{"role": "auditor", "max_wait_secs": 60, "age_secs": 70, "promoted": true},
{"role": "hermit", "max_wait_secs": 90, "age_secs": null, "promoted": true}
],
"role_runner_shard": {
"owned_here": false, "key": "acme/repo", "key_source": "origin",
"owning_shard": 2, "host_shard": 1, "shard_count": 3
}
}),
);
}

#[test]
fn status_json_shared_types_keep_null_and_empty_distinct() {
let mut report = status_contract_report();
let uncollected = render_status_contract(&report, None);
assert_status_subtrees(
&uncollected,
serde_json::json!({
"unregistered_locked": [], "role_runner_shard": null, "worktrees": null,
"idle_exit": null, "rate_limit_breaker": null, "safehouse": null
}),
);
assert_status_subtrees(
&uncollected["per_repo"][0],
serde_json::json!({"role_runner_on_idle_promotions": [], "role_runner_shard": null}),
);

report.role_runner_shard = Some(crate::types::RoleRunnerShardPosture {
index: None,
count: None,
summary: "not configured".into(),
configured: false,
roster: None,
});
let collected_empty = render_status_contract(&report, Some(&[]));
assert_status_subtrees(
&collected_empty,
serde_json::json!({
"worktrees": [],
"role_runner_shard": {
"index": null, "count": null, "configured": false, "summary": "not configured", "roster": null
}
}),
);
}
Loading