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
57 changes: 53 additions & 4 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ jobs:
- 'scripts/incus-canary.mjs'
- '.dockerignore'
- '.github/workflows/docker-build.yml'
- 'scripts/promote-main-image.sh'
worker:
- 'worker/**'
- '.github/workflows/docker-build.yml'
- 'scripts/promote-main-image.sh'
validation:
- 'orchestrator/**'
- 'worker/**'
Expand All @@ -52,6 +54,7 @@ jobs:
- 'scripts/agentor-incus-network-service.py'
- 'scripts/setup-incus-host.sh'
- 'scripts/profile-ci-workflow.py'
- 'scripts/promote-main-image.sh'
- '.dockerignore'
- 'tests/**'
- 'docker-compose.tests.yml'
Expand Down Expand Up @@ -366,11 +369,11 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/agentor-orchestrator
tags: |
type=ref,event=branch
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=long

- run: |
cd /tmp/digests
Expand Down Expand Up @@ -468,15 +471,61 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/agentor-worker
tags: |
type=ref,event=branch
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=long

- run: |
cd /tmp/digests
IMAGE=${{ env.REGISTRY }}/${{ github.repository_owner }}/agentor-worker
TAGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
SOURCES=$(for f in *; do echo "$IMAGE@$(cat $f)"; done)
docker buildx imagetools create $TAGS $SOURCES

promote-main:
name: Promote main (${{ matrix.image }})
needs: [merge-orchestrator, merge-worker]
if: >-
always() && github.ref == 'refs/heads/main' &&
github.event_name != 'pull_request' &&
(needs.merge-orchestrator.result == 'success' || needs.merge-worker.result == 'success')
strategy:
fail-fast: false
matrix:
include:
- image: agentor-orchestrator
merge-result: ${{ needs.merge-orchestrator.result }}
- image: agentor-worker
merge-result: ${{ needs.merge-worker.result }}
# Keep the freshness check and both shared tags under the same per-image lock.
concurrency:
group: main-image-promotion-${{ github.repository }}-${{ matrix.image }}
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
if: matrix.merge-result == 'success'
with:
persist-credentials: false

- uses: docker/setup-buildx-action@v3
if: matrix.merge-result == 'success'

- uses: docker/login-action@v3
if: matrix.merge-result == 'success'
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Promote only the current main revision
if: matrix.merge-result == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
run: bash scripts/promote-main-image.sh
30 changes: 30 additions & 0 deletions docs/image-publication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Image publication

Orchestrator and worker builds publish multi-platform manifests only after the
CI test gate. Pull requests build without registry login or publication. Release
tags retain their existing version and major/minor tags.

Each successful merge publishes `sha-<full-commit-sha>` before shared-tag
promotion. The existing short SHA tags remain available for compatibility;
use the full SHA reference for commit-specific deployments.

Main promotion uses a separate job with a per-image concurrency group and
`cancel-in-progress: false`. The lock covers the main HEAD check and the single
manifest command that updates `main` and `latest`. An older run finishing after
a newer run cannot move either shared tag back to its older revision. Pending
promotion jobs may be replaced by GitHub concurrency scheduling, but immutable
SHA publication has already completed outside that lock.

A run whose commit is no longer main HEAD skips shared tags and reports that
its SHA references remain available. This also applies when a newer commit only
changes unrelated files: shared tags stay on the previously promoted image until
a current-head image build succeeds (a manual main run builds both images).
If the HEAD lookup fails, promotion fails closed with a bounded reason; it does
not affect the already published SHA references. Registry failures may partially
update shared tags; rerun the current main workflow to recover.

Run the registry-free reverse-completion regression with:

```sh
python3 -m unittest discover -s tests/helpers -p test_main_image_promotion.py
```
17 changes: 17 additions & 0 deletions docs/pane-lifecycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Pane discovery during worker lifecycle changes

`GET /api/containers/:id/panes` requires the same authenticated ownership checks
as before. It executes guest commands only for confirmed running compute without
an unsettled lifecycle operation.

A confirmed stopped worker returns HTTP 409. Unknown/unresponsive or changing
compute returns HTTP 503. Both include `data.code: WORKER_PANES_UNAVAILABLE` and
the observed `data.status`; desired stopped intent alone is not proof of a stop.
Missing workers return 404. An expected lifecycle rejection never changes stopped
state into unknown, and delayed probes cannot overwrite newer lifecycle state.

The GUI uses the shared worker inventory to suspend discovery when compute is
not confirmed running. Failed discovery backs off from six seconds to at most
48 seconds, without overlapping periodic requests. A verified transition back
to running resumes discovery immediately. Closing a pane cancels its polling,
including after a late response.
49 changes: 48 additions & 1 deletion docs/vm-vcpu-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The **Virtual CPU cores** editor is available in ordinary VM settings and in
platform/group administrative VM management. It shows the assigned count from
the owned VM definition and the maximum reported by the Incus backend.
the owned VM definition and the maximum allowed by the Incus backend and inherited group policy.

1. Stop the VM, then select **Refresh vCPU count**.
2. Enter a positive integer within the backend maximum and select **Save vCPU
Expand Down Expand Up @@ -35,3 +35,50 @@ Administrative VM changes also require an installed host policy that advertises
CPU-count update support. Older policy installations reject the update before
changing compute. Follow the bounded policy update procedure in
[administrative networking](incus-admin-private-networks.md).

## Group ceilings and delegation

Groups have an optional **Maximum vCPUs per worker** setting. It limits each VM
independently; there is no cumulative group CPU pool. The effective ceiling is
the lowest configured value in the group's ancestry, including the group itself.
A blank setting inherits. A new explicit child ceiling cannot exceed its effective
parent ceiling. The effective maximum shown by the CPU editor also respects the
backend's CPU capacity.

Global administrators can configure root and child ceilings. Group administrators
can configure only descendant groups, within the effective parent ceiling; they
cannot raise or clear the ceiling of their own administrative group. No delegated
resize is allowed until an inherited ceiling has been configured. Ordinary owner
REST access remains subject to applicable group ceilings. Platform administrative
VMs remain restricted to global administration.

Ceilings apply to ordinary and group administrative VM allocation, including new
VM definitions and replacement/import paths. Existing VM allocations remain
visible and are not automatically shrunk or stopped after a ceiling is lowered.
Their next new allocation must fit. Reading or reconciling an already submitted
CPU operation does not submit another allocation and remains available.

Moving a capped worker to an uncapped or more permissive group is rejected;
a global administrator must first adjust the source ceiling. Group administrators
cannot reparent groups to escape an inherited ceiling. The server enforces these
checks for GUI, REST and management MCP callers.

vCPU counts describe guest CPUs, not reserved host CPU time. A per-worker ceiling
does not prevent aggregate host CPU contention when many workers run together.

## Management MCP

Use `workers.cpu.get`, `workers.cpu.set`, and `workers.cpu.reconcile` for ordinary
workers (`workerId`). Use `admin-workspace.cpu.get/set/reconcile` for the calling
administrative workspace, and `groups.admin-workspace.cpu.get/set/reconcile`
with `groupId` for a group administrative workspace. Group identities can target
only their bound group and live descendants. Global identities can administer
all applicable targets.

Set requests take a positive integer `vcpuCount` and, when required, `lockPassword`.
Stop the VM explicitly first, inspect its CPU settings, set the count, start it,
and inspect again. A caller timeout does not cancel the backend operation.
Inspect pending state and use the explicit reconciliation tool; it can observe
only the recorded operation and cannot create a new resize. Group ceilings can
be configured through `groups.create` and `groups.update` using `maxVcpuCount`
(a positive integer or null to inherit), subject to the delegation rules above.
2 changes: 1 addition & 1 deletion orchestrator/app/components/VcpuEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ onMounted(() => { void request(); });
<p class="text-xs">Stop the VM before changing its vCPU count. Save, then start it normally; storage is retained.</p>
<p v-if="error" role="alert" class="text-sm text-red-500">{{ error }}</p>
<template v-if="settings">
<p class="text-xs">Assigned: {{ settings.vcpuCount }} · Backend maximum: {{ settings.maxVcpuCount }}</p>
<p class="text-xs">Assigned: {{ settings.vcpuCount }} · Maximum allowed: {{ settings.maxVcpuCount }}</p>
<p v-if="settings.status === 'running'" role="status" class="text-xs">Stop the VM, then refresh to edit its vCPU count.</p>
<p v-if="settings.pending" role="status" class="text-xs text-amber-500">A previous CPU change needs reconciliation before another change.</p>
<UButton v-if="settings.pendingVcpuCount !== undefined" :disabled="busy" color="warning" @click="request(true, true)">Reconcile pending CPU change</UButton>
Expand Down
29 changes: 29 additions & 0 deletions orchestrator/app/components/WorkerGroupsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const open = defineModel<boolean>("open", { default: false });
const props = defineProps<{ containers: ContainerInfo[] }>();
const emit = defineEmits<{ service: [workspaceId: string, service: string] }>();
const { groups, refresh: refreshGroups, create, update, remove, assignWorker, adminAction } = useWorkerGroups();
const { isAdmin } = useAuth();
const vcpuDrafts = reactive<Record<string, string>>({});
const name = ref("");
const createParentId = ref("");
const createWorkerSelfApiAccess = ref<import("~/types").WorkerSelfApiAccess>("inherit");
Expand Down Expand Up @@ -65,6 +67,15 @@ async function setWorkerSelfApiAccess(group: WorkerGroup, value: string) {
}),
);
}
function parentVcpuLimit(group: WorkerGroup) {
return groups.value.find(parent => parent.id === group.parentId)?.effectiveMaxVcpuCount ?? null;
}
async function saveVcpuLimit(group: WorkerGroup) {
const raw = vcpuDrafts[group.id] ?? String(group.maxVcpuCount ?? '');
const maximum = raw.trim() === '' ? null : Number(raw);
const saved = await run(`vcpu-${group.id}`, () => update(group.id, { maxVcpuCount: maximum }));
if (saved) delete vcpuDrafts[group.id];
}
const orderedGroups = computed(() => {
const result: Array<{ group: WorkerGroup; depth: number }> = [];
const visit = (parentId: string | undefined, depth: number, seen: Set<string>) => {
Expand Down Expand Up @@ -195,6 +206,24 @@ function serviceIcon(service: string) {
<p class="text-xs text-gray-500">
Applies to ordinary workers in this subtree. Platform and group administrative workspaces remain reachable for management MCP.
</p>
<form class="mt-3" @submit.prevent="saveVcpuLimit(entry.group)">
<label :for="`group-vcpu-${entry.group.id}`" class="block text-sm font-medium">Maximum vCPUs per worker</label>
<p class="text-xs text-gray-500">
Effective ceiling: {{ entry.group.effectiveMaxVcpuCount ?? 'not configured' }}.
Each VM has this limit independently, including group admin VMs.
<template v-if="entry.group.parentId">Parent ceiling: {{ parentVcpuLimit(entry.group) ?? 'not configured' }}.</template>
</p>
<div v-if="isAdmin || parentVcpuLimit(entry.group) !== null" class="mt-2 flex items-center gap-2">
<UInput
:id="`group-vcpu-${entry.group.id}`"
:model-value="vcpuDrafts[entry.group.id] ?? String(entry.group.maxVcpuCount ?? '')"
type="number" :min="1" :max="parentVcpuLimit(entry.group) ?? undefined" step="1" placeholder="Inherit"
@update:model-value="vcpuDrafts[entry.group.id] = String($event)"
/>
<UButton type="submit" size="xs" :loading="busy === `vcpu-${entry.group.id}`">Save ceiling</UButton>
</div>
<p class="mt-1 text-xs text-gray-500">Leave blank to inherit. Group admins can resize only after a ceiling is configured; lowering it does not resize existing VMs.</p>
</form>
<label
v-for="worker in props.containers.filter(
(c) => c.userId === entry.group.userId && !c.administrativeKind,
Expand Down
62 changes: 29 additions & 33 deletions orchestrator/app/composables/useTmuxTabs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { TmuxWindow } from '~/types';
import type { ContainerInfo, TmuxWindow } from '~/types';

const POLL_INTERVAL = 3000;

export function useTmuxTabs(containerId: Ref<string>) {
const { data: workers } = useNuxtData<ContainerInfo[]>('workers');
const available = computed(() => workers.value?.some(worker => worker.id === containerId.value && worker.status === 'running') ?? false);
const { getTmuxActiveWindow, setTmuxActiveWindow } = useUiState();
const windows = ref<TmuxWindow[]>([]);
const activeWindowIndex = ref<number | null>(null);
Expand All @@ -11,14 +13,18 @@ export function useTmuxTabs(containerId: Ref<string>) {

let pollTimer: ReturnType<typeof setTimeout> | null = null;
let fetchGeneration = 0;
let destroyed = false;
let pollGeneration = 0;
let failures = 0;

async function fetchWindows() {
if (destroyed || !available.value) return false;
const currentGeneration = ++fetchGeneration;
try {
const data = await $fetch<TmuxWindow[]>(`/api/containers/${containerId.value}/panes`);
const data = await $fetch<TmuxWindow[]>(`/api/containers/${containerId.value}/panes`, { retry: 0 });

// Discard stale response if containerId changed during fetch
if (currentGeneration !== fetchGeneration) return;
if (destroyed || !available.value || currentGeneration !== fetchGeneration) return false;

windows.value = data;

Expand All @@ -29,42 +35,34 @@ export function useTmuxTabs(containerId: Ref<string>) {

// Auto-select first window when nothing is active
if (activeWindowIndex.value == null && data.length > 0) {
activeWindowIndex.value = data[0]!.index;
const saved = getTmuxActiveWindow(containerId.value);
activeWindowIndex.value = data.some(window => window.index === saved) ? saved! : data[0]!.index;
}

// Persist for reopen
if (activeWindowIndex.value != null) {
setTmuxActiveWindow(containerId.value, activeWindowIndex.value);
}
return true;
} catch {
// Container may be stopped or removed
}
}

async function init() {
await fetchWindows();

// Restore last active window if it still exists
const saved = getTmuxActiveWindow(containerId.value);
if (saved != null && windows.value.some((w) => w.index === saved)) {
activeWindowIndex.value = saved;
} else if (windows.value.length > 0 && activeWindowIndex.value == null) {
activeWindowIndex.value = windows.value[0]!.index;
return false;
}

startPolling();
}

function startPolling() {
stopPolling();
pollTimer = setInterval(() => fetchWindows(), POLL_INTERVAL);
async function poll() {
const generation = pollGeneration;
const succeeded = await fetchWindows();
if (destroyed || !available.value || generation !== pollGeneration) return;
failures = succeeded ? 0 : Math.min(failures + 1, 4);
// Expected unavailable responses back off; inventory must still confirm running.
pollTimer = setTimeout(poll, POLL_INTERVAL * 2 ** failures);
}

function stopPolling() {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
pollGeneration++;
fetchGeneration++;
if (pollTimer) clearTimeout(pollTimer);
pollTimer = null;
}

async function createWindow(name?: string, lockPassword?: string): Promise<TmuxWindow | null> {
Expand Down Expand Up @@ -124,19 +122,17 @@ export function useTmuxTabs(containerId: Ref<string>) {
}

function destroy() {
destroyed = true;
stopPolling();
}

// Re-init when containerId changes
watch(containerId, () => {
watch([containerId, available], () => {
stopPolling();
windows.value = [];
activeWindowIndex.value = null;
init();
});

// Start on creation
init();
failures = 0;
if (!destroyed && available.value) void poll();
}, { immediate: true });

return {
windows,
Expand Down
4 changes: 3 additions & 1 deletion orchestrator/app/composables/useWorkerGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface WorkerGroup {
archived: number;
};
parentId?: string;
maxVcpuCount?: number | null;
effectiveMaxVcpuCount?: number | null;
workerSelfApiAccess?: import("~/types").WorkerSelfApiAccess;
effectiveWorkerSelfApiAccess?: import("~/types").EffectiveWorkerSelfApiAccess;
adminWorkspace?: GroupAdminWorkspace;
Expand All @@ -51,7 +53,7 @@ export function useWorkerGroups() {
};
const update = async (
id: string,
patch: Partial<Pick<WorkerGroup, "name" | "workerIds" | "workerSelfApiAccess">> & {
patch: Partial<Pick<WorkerGroup, "name" | "workerIds" | "workerSelfApiAccess" | "maxVcpuCount">> & {
parentId?: string | null;
},
) => {
Expand Down
Loading
Loading