---
title: Workplan Queue
---
```js
import {apiFetch, waitForVisible, pollDelay, POLL_HEAVY} from "./components/config.js";
```
```js
const queueState = (async function*() {
let failures = 0;
while (true) {
let stack = [], semantics = {}, ok = false;
try {
const [stackResponse, semanticsResponse] = await Promise.all([
apiFetch("/execution/workplan-stack"),
apiFetch("/execution/semantics"),
]);
ok = stackResponse.ok && semanticsResponse.ok;
if (ok) {
[stack, semantics] = await Promise.all([
stackResponse.json(),
semanticsResponse.json(),
]);
}
} catch {}
failures = ok ? 0 : failures + 1;
yield {stack, semantics, ok, ts: new Date()};
await waitForVisible(pollDelay({ok, base: POLL_HEAVY, failures}));
}
})();
```
```js
const stack = queueState.stack ?? [];
const semantics = queueState.semantics ?? {};
const _ok = queueState.ok ?? false;
const _ts = queueState.ts;
```
# Workplan Queue
```js
display(html`
●
${_ok ? `Live · updated ${_ts?.toLocaleTimeString()}` : html`Offline`}
`);
```
```js
const launchModes = Object.keys(semantics.launch_modes ?? {manual: "", queued: "", scheduled: "", immediate: ""});
const concurrencyModes = Object.keys(semantics.concurrency_modes ?? {sequential: "", parallel: ""});
function optionList(values, selected) {
return values.map(value => html``);
}
function statusCell(row) {
const classes = ["queue-status", row.eligible ? "eligible" : "blocked"].join(" ");
return html`${row.eligible ? "eligible" : "blocked"}`;
}
function blockers(row) {
const parts = [];
if (row.blocked_by_workstream_ids?.length) parts.push(`${row.blocked_by_workstream_ids.length} workstream`);
if (row.blocked_by_task_ids?.length) parts.push(`${row.blocked_by_task_ids.length} task`);
return parts.length ? parts.join(", ") : "—";
}
function queueControls(row) {
const root = html``;
const mode = html``;
const concurrency = html``;
const rank = html``;
const group = html``;
const message = html``;
const save = html``;
const launch = html``;
const payload = () => ({
execution_state: mode.value === "manual" ? "manual" : mode.value === "scheduled" ? "scheduled" : "queued",
launch_mode: mode.value,
concurrency_mode: concurrency.value,
queue_rank: rank.value === "" ? null : Number(rank.value),
execution_group: group.value.trim() || null,
});
async function run(label, action) {
message.textContent = label;
message.className = "queue-message";
save.disabled = true;
launch.disabled = true;
try {
await action();
message.textContent = "saved";
message.classList.add("ok");
setTimeout(() => location.reload(), 450);
} catch (error) {
message.textContent = error?.message ?? "failed";
message.classList.add("error");
save.disabled = false;
launch.disabled = false;
}
}
save.onclick = () => run("saving", async () => {
const response = await apiFetch(`/execution/workplans/${row.workstream_id}/intent`, {
method: "PATCH",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(payload()),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
});
launch.onclick = () => run("requesting", async () => {
const intent = payload();
const response = await apiFetch("/execution/launch-requests", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({
workstream_id: row.workstream_id,
requested_by: "dashboard",
requested_actor: "activity-core",
launch_mode: intent.launch_mode,
concurrency_mode: intent.concurrency_mode,
immediate_pickup: intent.launch_mode === "immediate",
priority: row.planning_priority,
notes: `Queue request from dashboard for ${row.slug}`,
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
});
root.append(mode, concurrency, rank, group, save, launch, message);
return root;
}
```
```js
if (stack.length === 0) {
display(html`No queue candidates.
`);
} else {
display(html`
| State |
Rank |
Workplan |
Lifecycle |
Priority |
Eligibility |
Blocked By |
Intent |
${stack.map(row => html`
| ${row.execution_state} |
${row.queue_rank ?? row.planning_order ?? "—"} |
${row.slug} ${row.title} |
${row.status} |
${row.planning_priority ?? "—"} |
${statusCell(row)} |
${blockers(row)} |
${queueControls(row)} |
`)}
`);
}
```