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
1 change: 1 addition & 0 deletions changelog.d/fixed-18813-paused-resume-role-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A paused agent no longer shows an empty slot where its resume button belongs: the focused agent panel kept the toggle it first rendered (its fast path never added one, and the panel ignored the role), so a panel opened before the viewer's role settled stayed without resume until reload. Agent cards, the detail panel and the cadence table now repaint when the role settles, and a viewer below owner (or one still being checked) sees the pause/resume control disabled with "Needs the owner role" or "Checking your access..." instead of nothing. A paused sandboxed agent offers plain resume rather than "start & resume" (it has no session to start), and the cadence table shows one `paused` chip with its reason on hover instead of repeating it in every mode column (#18813).
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ Full entry: [Agent Logs](dashboard-sections/workflow-and-agents.md#agent-logs).

Each worker Hive runs, what it is doing now, and buttons to pause, restart or configure it.

The pause/resume control is owner-only but never absent: below the owner role, or while the role is still being checked, it renders disabled with the tooltip "Needs the owner role" or "Checking your access...". Cards and the detail panel repaint when the role settles. A paused sandboxed agent offers plain `resume` (no session to start). The cadence table shows a single `paused` chip (with its reason on hover) beside the agent name; the mode columns show plain `paused` text.

Full entry: [Agents](dashboard-sections/workflow-and-agents.md#agents).

## Hive activity monitor
Expand Down
119 changes: 119 additions & 0 deletions src/pkg/dashboard/agent_paused_toggle_role_18813.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// #18813: a paused agent must always show a reachable (or explained) resume
// control, and the role-gated slot repaints when the role settles.
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');

const js = n => fs.readFileSync(path.join(__dirname, 'static-src', 'js', n), 'utf8');
const cards = js('agent-cards.js');
const detail = js('agent-detail.js');
const gov = js('governor-view.js');

// Pull a top-level `function name(...) {...}` out of a source by brace matching.
function fn(src, name) {
const start = src.indexOf('function ' + name + '(');
assert.ok(start >= 0, name + ' not found');
let i = src.indexOf('{', src.indexOf(')', start));
let depth = 0;
for (; i < src.length; i++) {
if (src[i] === '{') depth++;
else if (src[i] === '}' && --depth === 0) return src.slice(start, i + 1);
}
throw new Error('unbalanced ' + name);
}
function consts(src, names) {
return names.map(n => src.match(new RegExp('const ' + n + ' = [^;]+;'))[0]).join('\n');
}

const win = {};
const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
const body = [
consts(cards, ['AGENT_GATE_NEEDS_OWNER', 'AGENT_GATE_CHECKING']),
fn(gov, 'dashboardRoleAtLeast'),
fn(cards, 'agentRoleKnown'),
fn(cards, 'agentToggleGateReason'),
fn(cards, 'agentGatedToggleHtml'),
fn(cards, 'agentToggleTitle'),
fn(cards, 'agentCadenceModesLabel' in {} ? '' : 'pausedAgentActionHtml'),
'return { agentToggleGateReason, agentGatedToggleHtml, pausedAgentActionHtml };',
].join('\n');
const api = new Function('window', 'esc', 'agentCadenceOffLabel', 'agentCadenceModesLabel', body)(win, esc, () => 'no cadence', () => 'busy');

function setRole(role, settled) {
win._hiveRole = role;
if (settled) win._hiveRoleSettled = true; else delete win._hiveRoleSettled;
}
const paused = (o) => Object.assign({ name: 'reviewer', paused: true, state: 'paused', enabled: true }, o);
const matrix = [
paused({ sandboxed: true }), paused({ sandboxed: false }),
paused({ sandboxed: true, state: 'running' }), paused({ sandboxed: false, state: 'running' }),
];

test('role unknown: control is disabled with the checking hint, never empty', () => {
setRole(undefined, false);
assert.strictEqual(api.agentToggleGateReason(), 'Checking your access...');
for (const a of matrix) {
const h = api.agentGatedToggleHtml(a, true, false);
assert.ok(/<button[^>]* disabled /.test(h));
assert.ok(h.includes('title="Checking your access..."'));
assert.ok(h.includes('resume'));
assert.ok(!h.includes('data-action'));
}
});

test('role read and read-write: disabled with the owner hint', () => {
for (const role of ['read', 'read-write', 'merger']) {
setRole(role, true);
assert.strictEqual(api.agentToggleGateReason(), 'Needs the owner role');
const h = api.agentGatedToggleHtml(paused({ sandboxed: true }), true, false);
assert.ok(h.includes('title="Needs the owner role"') && h.includes(' disabled '));
}
setRole(undefined, true); // /api/role gave up
assert.strictEqual(api.agentToggleGateReason(), 'Needs the owner role');
});

test('role settles to owner: the live resume control appears', () => {
setRole(undefined, false);
assert.notStrictEqual(api.agentToggleGateReason(), '');
setRole('owner', true);
assert.strictEqual(api.agentToggleGateReason(), '');
for (const a of matrix) {
const h = api.pausedAgentActionHtml(a);
assert.ok(h.includes('data-action='));
assert.ok(!h.includes(' disabled'));
}
});

test('sandboxed paused agent gets plain resume, not start & resume', () => {
const sb = paused({ sandboxed: true });
assert.ok(api.pausedAgentActionHtml(sb).includes('data-action="toggleAgent"'));
assert.ok(api.pausedAgentActionHtml(sb).includes('▶ resume'));
assert.ok(!api.pausedAgentActionHtml(sb).includes('start &amp; resume'));
assert.ok(!api.agentGatedToggleHtml(sb, true, false).includes('start &amp; resume'));
const plain = paused({ sandboxed: false });
assert.ok(api.pausedAgentActionHtml(plain).includes('data-action="startResumeAgent"'));
assert.ok(api.agentGatedToggleHtml(plain, true, false).includes('start &amp; resume'));
});

test('running agent below owner shows a disabled pause', () => {
setRole('read', true);
const h = api.agentGatedToggleHtml({ name: 'deps', state: 'running' }, false, false);
assert.ok(h.includes('pause') && h.includes(' disabled ') && h.includes('Needs the owner role'));
});

test('card grid, detail and fast path use the gate and repaint on role settle', () => {
assert.ok(cards.includes('(window._hiveRoleListeners = window._hiveRoleListeners || []).push(agentsOnRoleReady)'));
assert.ok(fn(cards, 'agentsOnRoleReady').includes('renderAgents(window._lastAgents)'));
assert.ok(fn(cards, 'agentsOnRoleReady').includes('ocRenderAgentDetail()'));
assert.ok(detail.includes('agentToggleGateReason()].join'), 'role is part of the detail fingerprint');
assert.ok(detail.includes('agentGatedToggleHtml(a, true, false)'));
assert.ok(!/!dashboardRoleAtLeast\(window\._hiveRole \|\| 'read', 'owner'\)\s*\? ''/.test(detail), 'no silent empty slot');
});

test('collapsed cadence row: one paused chip, plain text in the mode columns', () => {
assert.ok(gov.includes("showPaused ? '<span class=\"muted-xs\">paused</span>' : val"));
const chipUses = gov.match(/pausedBadgeHtml/g) || [];
// definition + the single name-column use
assert.strictEqual(chipUses.length, 2);
});
43 changes: 39 additions & 4 deletions src/pkg/dashboard/static-src/js/agent-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
function agentToggleTitle(a, isPaused, isOff) {
if (isPaused) {
const rest = [];
if (a.state !== 'running') rest.push('its session is down (use \u21bb restart)');
if (a.state !== 'running' && a.sandboxed !== true) rest.push('its session is down (use \u21bb restart)');
if (a.offByCadence === true) rest.push('its cadence for the current governor mode is off (\u2699\uFE0F \u2192 Cadences)');
if (a.unscheduledInMode === true) rest.push(`it has a cadence only in ${agentCadenceModesLabel(a)}, none for the current governor mode (\u2699\uFE0F \u2192 Cadences)`);
if (a.noCadence === true) rest.push('no governor mode gives it a cadence (\u2699\uFE0F \u2192 Cadences)');
Expand Down Expand Up @@ -763,7 +763,12 @@
return `<button class="hv-btn btn-secondary btn-sm btn-toggle off" data-action="openConfigDialog" data-config-type="agent" data-agent="${esc(a.name)}" data-tab="Cadences" title="${who} is enabled, but the governor has no cadence for it in the current mode — click to set one">⚙ ${esc(agentCadenceOffLabel())}</button>`;
}
function pausedAgentActionHtml(a) {
if (a.state === 'running') {
/* A sandboxed agent has no long-lived session: it sits in state 'paused'
or 'idle' and runs each kick in a throwaway container, so "session
down" is never its blocker. Offering "start & resume" there chained a
restart that has nothing to restart (#18813); plain resume is the
whole action. */
if (a.state === 'running' || a.sandboxed === true) {
return `<button class="hv-btn btn-danger btn-sm btn-toggle paused" data-action="toggleAgent" data-agent="${esc(a.name)}" data-paused="true" title="${esc(agentToggleTitle(a, true, false))}">\u25b6 resume</button>`;
}
const rest = [];
Expand All @@ -774,6 +779,34 @@
if (rest.length > 0) title += ` Still not enough on its own: ${rest.join('; ')}.`;
return `<button class="hv-btn btn-danger btn-sm btn-toggle paused" data-action="startResumeAgent" data-agent="${esc(a.name)}" data-paused="true" title="${esc(title)}">\u25b6 start &amp; resume</button>`;
}
/* Owner-gated pause/resume slot (#18813). Never an empty slot: a viewer
below owner, or one whose role has not settled yet, sees the control
DISABLED with the reason in its tooltip. agentToggleGateReason returns
'' when the viewer may act. The role is "known" under the same rule the
Inbox uses: /api/role answered or gave up. */
const AGENT_GATE_NEEDS_OWNER = 'Needs the owner role';
const AGENT_GATE_CHECKING = 'Checking your access...';
function agentRoleKnown() { return window._hiveRoleSettled === true || window._hiveRole !== undefined; }
function agentToggleGateReason() {
if (dashboardRoleAtLeast(window._hiveRole || 'read', 'owner')) return '';
return agentRoleKnown() ? AGENT_GATE_NEEDS_OWNER : AGENT_GATE_CHECKING;
}
function agentGatedToggleHtml(a, isPaused, isOff) {
const reason = agentToggleGateReason() || AGENT_GATE_NEEDS_OWNER;
const label = isPaused
? (a.state === 'running' || a.sandboxed === true ? '\u25b6 resume' : '\u25b6 start &amp; resume')
: '\u23f8 pause';
const cls = isPaused ? 'btn-danger paused' : 'btn-secondary running';
return `<button type="button" class="hv-btn ${cls} btn-sm btn-toggle gated" disabled aria-disabled="true" data-agent="${esc(a.name)}" data-gate="${agentRoleKnown() ? 'role' : 'checking'}" title="${esc(reason)}">${label}</button>`;
}
/* Repaint the role-gated agent surfaces the moment the role settles. The
cards used to be left as rendered with whatever role was known then. */
function agentsOnRoleReady() {
if (window._lastAgents) renderAgents(window._lastAgents);
if (typeof ocRenderAgentDetail === 'function') ocRenderAgentDetail();
if (typeof renderGovernorFromLastStatus === 'function') renderGovernorFromLastStatus();
}
(window._hiveRoleListeners = window._hiveRoleListeners || []).push(agentsOnRoleReady);
function neverScheduledChipHtml(a, configTarget) {
if (a.noCadence !== true) return '';
const who = a.displayName || a.name;
Expand Down Expand Up @@ -935,7 +968,7 @@
// Healthy-but-governor-paused → hollow green dot (see detail-header renderer).
const dotState = isOff ? 'off-healthy' : dotCls;
const canToggle = a.beadRole !== 'supervisor';
const canPauseToggle = canToggle && dashboardRoleAtLeast(window._hiveRole || 'read', 'owner');
const canPauseToggle = canToggle && agentToggleGateReason() === '';
/* RESUME LEADS (#5594). A paused agent's card offers its pause toggle
FIRST and unconditionally; the governor-cadence gear must never take
the slot, or the pause stays hidden until the gear's blocker is
Expand All @@ -952,13 +985,15 @@
only lever that means anything here, so it is the only one shown. */
const toggleBtn = (canToggle && !agentIsDisabled(a)) ? (isPaused && canPauseToggle
? pausedAgentActionHtml(a)
: isPaused
? agentGatedToggleHtml(a, true, false)
: isOff
? cadenceOffAgentActionHtml(a)
: isOnDemand
? `<button class="hv-btn btn-secondary btn-sm btn-toggle on-demand" title="On-demand agent — kicked manually, not by governor cadence">⚡ on demand</button>`
: canPauseToggle
? `<button class="hv-btn btn-secondary btn-sm btn-toggle running" data-action="toggleAgent" data-agent="${esc(a.name)}" data-paused="false" title="${esc(agentToggleTitle(a, false, false))}">⏸ pause</button>`
: '') : '';
: agentGatedToggleHtml(a, false, false)) : '';
// liveSummary is pushed via SSE every 5s — no separate fetch needed
let summaryEl = '';
if (a.liveSummary) {
Expand Down
13 changes: 9 additions & 4 deletions src/pkg/dashboard/static-src/js/agent-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@
// The fingerprint guards the fields only the full template renders
// (method/model/pins): without it a CLI or model switch stayed stale
// in the focused panel until a hard refresh.
const cfgSig = [a.cli || '', a.model || '', a.pinnedCli ? 1 : 0, a.pinnedModel ? 1 : 0, a.pinnedBoth ? 1 : 0, a.displayName || '', a.emoji || '', a.color || '', JSON.stringify(a.subAgentModels || [])].join('|');
const cfgSig = [a.cli || '', a.model || '', a.pinnedCli ? 1 : 0, a.pinnedModel ? 1 : 0, a.pinnedBoth ? 1 : 0, a.displayName || '', a.emoji || '', a.color || '', JSON.stringify(a.subAgentModels || []), agentToggleGateReason()].join('|');
if (existingSummary && detail.dataset.agent === a.name && detail.dataset.cfgSig === cfgSig) {
if (a.detailSummary) {
const newText = escBlock(a.detailSummary);
Expand All @@ -695,7 +695,12 @@
// button would otherwise persist until the user navigates away.
const fastToggle = detail.querySelector('.oc-detail-actions .btn-toggle');
if (fastToggle && !isOnDemand) {
if (isPaused) {
if (!isPaused && !isOff && agentToggleGateReason() !== '') {
// Below owner / role unknown: keep the disabled, explained control.
fastToggle.outerHTML = agentGatedToggleHtml(a, false, false);
} else if (isPaused && agentToggleGateReason() !== '') {
fastToggle.outerHTML = agentGatedToggleHtml(a, true, false);
} else if (isPaused) {
// Paused gets the full combined-action rebuild — '▶ start &
// resume' when the session is also down — so data-action tracks
// the session state too, not just the label (#5594 follow-up).
Expand Down Expand Up @@ -836,8 +841,8 @@
? ''
: isOnDemand
? '<button class="hv-btn btn-secondary btn-sm btn-toggle on-demand" title="On-demand agent — kicked manually, not by governor cadence">⚡ on demand</button>'
: !dashboardRoleAtLeast(window._hiveRole || 'read', 'owner')
? ''
: agentToggleGateReason() !== '' && !isOff
? agentGatedToggleHtml(a, isPaused, false)
: isPaused
? pausedAgentActionHtml(a)
: isOff
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/static-src/js/governor-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@
const colCls = isActive ? `col-active mode-${m}` : '';
const stateCls = isContinuous ? ' continuous' : showOnDemand ? ' on-demand' : showOff ? ' off' : showPaused ? ' paused' : '';
const dot = (isActive && isWorking && !agentPaused && !showOff && !showOnDemand && !agentDisabled && !isContinuous) ? '<span class="active-dot"></span>' : '';
const badge = isContinuous ? '<span class="on-demand-badge" data-status="info">∞ continuous</span>' : showOnDemand ? '<span class="on-demand-badge" data-status="info">on demand</span>' : showOff ? '<span class="off-badge" data-status="neutral" title="No cadence configured for this mode — the governor never kicks this agent while the hive is in it. The agent is still enabled; this is a per-mode schedule gap, not the 0/1 switch.">no cadence</span>' : showPaused ? pausedBadgeHtml : val;
const badge = isContinuous ? '<span class="on-demand-badge" data-status="info">∞ continuous</span>' : showOnDemand ? '<span class="on-demand-badge" data-status="info">on demand</span>' : showOff ? '<span class="off-badge" data-status="neutral" title="No cadence configured for this mode — the governor never kicks this agent while the hive is in it. The agent is still enabled; this is a per-mode schedule gap, not the 0/1 switch.">no cadence</span>' : showPaused ? '<span class="muted-xs">paused</span>' : val;
if (agentDisabled) {
return `<td class="${colCls} cadence-disabled-cell" title="${esc((agentData && (agentData.displayName || agentData.name)) || aname)} is disabled; cadence intervals apply again when the agent is enabled">${badge}</td>`;
}
Expand Down
Loading
Loading