Let agents idle for updates required by creation cancellation

This commit is contained in:
2026-10-04 18:14:11 -04:00
parent 176b7dd86b
commit fae7775c72
5 changed files with 65 additions and 2 deletions
+7
View File
@@ -319,6 +319,13 @@ export function queueHostOperation(hostId: string, kind: string, payload: Record
export function pendingHostOperations(hostId: string): HostOperation[] {
const host = requireHost(hostId);
if (host.mode === 'disabled' || !host.connected) return [];
// Older agents hold activity.lock across the entire delivered batch, including
// observations. Filtering only the unsupported cleanup can keep the updater
// busy indefinitely. Drain the old batch by withholding ALL further work;
// heartbeats and receipts still flow, and the new capability releases this hold.
// This must live in the controller so the fix also works before an agent update.
if (!host.inventory.capabilities?.includes('instance.cancel-create') && database().prepare(`SELECT 1 FROM ec_host_operations
WHERE host_id=? AND kind='instance.cancel-create' AND state IN ('pending','accepted','running','unknown') LIMIT 1`).get(hostId)) return [];
// Accepted/running/unknown commands keep the same immutable ID. The agent
// consults its durable journal before acknowledging or executing a replay.
return database().transaction(() => {