feat(hub): the hardware chart marks a blocked queue head and suspect-hung jobs
Each resources sample runs queue.py list --json once (the installed kvb-org-queue script, --queue in the unit, AGENTS_COUNCIL_ROOT set to the council) and keeps queue.head, {id, kind, waited_s, reason} of the first waiting row, and queue.hung, the ids of active rows whose reason says suspect hung; both are left out without one or while that run fails or prints no JSON list, and id, kind and reason are cut to 64 and 240 characters. Folded 15-minute and daily rows keep the last head and every hung id. The hardware chart draws a red band where the queue head waited blocked and a violet dashed band for suspect-hung jobs, each clickable for its job. MB becomes MEGABYTE.
The unit takes --queue /kvb-org-queue/scripts/queue.py; the install writes KVB_ORCHESTRATOR_SKILLS into the hub's .env (scripts/orchestrator.sh), which the offices unit already uses.
Applied cleanly onto motion (86a60c7); none of the 7 files changed on master since its base 2aea6d1.
Tests: test_hub_resources and test_resources_sample. Written, not run: the full suite runs once on master after all bundles (operator order).
Security: MEDUSA over the staged tree on master: 100, no findings over 5 files; kvb-orchestrator-resources.service (one added --queue argument) and style-resources.css (four style rules) are not covered and were read by hand.
🎯 Fix: 90 %
💥 Break: 5 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %
Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86a60c7998
commit
9d313f227d
7 files changed
+370
-36
No files matched your search
@@ -3,6 +3,7 @@ const Resources = (() => {
|
||||
const IDLE = 30;
|
||||
const SATURATED = 90;
|
||||
const CALM = 50;
|
||||
const BLOCKED = 600;
|
||||
const GAP = 1800;
|
||||
const STEP = 60;
|
||||
const HOUR = 3600;
|
||||
@@ -98,6 +99,73 @@ const Resources = (() => {
|
||||
return spans(samples, (row) => waiting(row) > 0 && finite(row.cpu) && finite(row.ram) && row.cpu < CALM && row.ram < CALM, waiting);
|
||||
}
|
||||
|
||||
function headOf(row) {
|
||||
const head = row.queue && row.queue.head;
|
||||
if (!head || typeof head !== "object" || typeof head.id !== "string" || !finite(head.waited_s)) {
|
||||
return null;
|
||||
}
|
||||
return {id: head.id, waited: head.waited_s, reason: typeof head.reason === "string" ? head.reason : ""};
|
||||
}
|
||||
|
||||
const hungOf = (row) => (row.queue && Array.isArray(row.queue.hung) ? row.queue.hung.filter((id) => typeof id === "string") : []);
|
||||
|
||||
function headSteps(rows) {
|
||||
const found = [];
|
||||
for (const row of rows) {
|
||||
const head = headOf(row);
|
||||
if (!head) {
|
||||
continue;
|
||||
}
|
||||
const last = found[found.length - 1];
|
||||
if (last && last.id === head.id && last.reason === head.reason) {
|
||||
last.to = row.t;
|
||||
} else {
|
||||
found.push({id: head.id, reason: head.reason, from: row.t, to: row.t});
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param samples - sampler rows.
|
||||
* @param test - whether a row belongs to a span.
|
||||
* @param value - the number of a row its span's peak is the largest of.
|
||||
* @param more - the extra keys of a span from the rows in it.
|
||||
* @returns spans() of test and value, each with more() of its rows, steps (per run of one head with one reason
|
||||
* its id, reason and first and last row time) and hung, every id suspect hung in it, once.
|
||||
*/
|
||||
function queueSpans(samples, test, value, more) {
|
||||
const rows = timed(samples).filter(test);
|
||||
return spans(samples, test, value).map((span) => {
|
||||
const inside = rows.filter((row) => row.t === span.from || (row.t > span.from && row.t < span.to));
|
||||
return {...span, ...more(inside), steps: headSteps(inside), hung: [...new Set(inside.flatMap(hungOf))]};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param samples - sampler rows.
|
||||
* @returns queueSpans() where the queue head had waited at least BLOCKED seconds, peak the longest wait in
|
||||
* seconds, head and reason those of the span's last row.
|
||||
*/
|
||||
function blocked(samples) {
|
||||
const waited = (row) => {
|
||||
const head = headOf(row);
|
||||
return head === null ? 0 : head.waited;
|
||||
};
|
||||
return queueSpans(samples, (row) => waited(row) >= BLOCKED, waited, (inside) => {
|
||||
const last = headOf(inside[inside.length - 1]);
|
||||
return {head: last.id, reason: last.reason};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param samples - sampler rows.
|
||||
* @returns queueSpans() where the queue listed an active job as suspect hung, peak the most such jobs at once.
|
||||
*/
|
||||
function hung(samples) {
|
||||
return queueSpans(samples, (row) => hungOf(row).length > 0, (row) => hungOf(row).length, () => ({}));
|
||||
}
|
||||
|
||||
function gpuSpans(samples, test) {
|
||||
const names = [...new Set(timed(samples).flatMap((row) => listOf(row, "gpus").filter(test).map((gpu) => String(gpu.name))))];
|
||||
return names.map((name) => ({name, spans: spans(samples, (row) => listOf(row, "gpus").some((gpu) => String(gpu.name) === name && test(gpu)), () => 1)}));
|
||||
@@ -190,7 +258,7 @@ const Resources = (() => {
|
||||
return unit ? `${(value / unit[0]).toFixed(1)}${unit[1]}` : String(Math.round(value));
|
||||
}
|
||||
|
||||
return {IDLE, SATURATED, CALM, GAP, HOUR, COUNTS, ZONES, lines, hardware, segments, spans, waits, asleep, unknown, stack, accumulate, burnup, compact};
|
||||
return {IDLE, SATURATED, CALM, BLOCKED, GAP, HOUR, COUNTS, ZONES, lines, hardware, segments, spans, waits, blocked, hung, asleep, unknown, stack, accumulate, burnup, compact};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Resources;
|
||||
|
||||
Reference in new issue
Block a user