Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: release persistent-mind global agent slot once local inference is endpoint-gated
[._.]/ Adam Eivye2df000679f5
diff --git a/server/services/persistentMindSupervisor.js b/server/services/persistentMindSupervisor.jsindex 647bfde2d2..19ad88195e 100644--- a/server/services/persistentMindSupervisor.js+++ b/server/services/persistentMindSupervisor.js@@ -48,7 +48,7 @@ export {import { cosEvents, emitLog } from './cosEvents.js';import { schedule, cancel, getEvent } from './eventScheduler.js';import { getDomainBudgetStatus, recordDomainUsage } from './domainUsage.js';-import { acquireLocalEndpointProviderSlot } from './cosLocalEndpointSlots.js';+import { acquireLocalEndpointProviderSlot, localEndpointOfProvider } from './cosLocalEndpointSlots.js';import { acquireCosActionReservation, acquireCosGlobalSlot } from './cosAdmissionReservations.js';import {createPersistentMindCallBoundary,@@ -745,7 +745,7 @@ async function runOnePersistentMindTurn() {const turn = await claimNextTurn();if (!turn) return;- await runClaimedPersistentMindTurn(turn, mind);+ await runClaimedPersistentMindTurn(turn, mind, globalSlot);} finally {actionReservation?.release?.();globalSlot.release();@@ -753,8 +753,16 @@ async function runOnePersistentMindTurn() {}// Admission owns the global/action reservations until the claimed turn's-// provider work, error handling, and endpoint cleanup have all settled.-async function runClaimedPersistentMindTurn(turn, mind) {+// provider work, error handling, and endpoint cleanup have all settled — with+// one exception: once a LOCAL-model turn has secured its endpoint-scoped slot+// (below), the generic global slot is released early. A local turn can run for+// minutes, far longer than the spawn-setup window the global cap models, and+// `acquireLocalEndpointProviderSlot` already serializes the real GPU+// contention on its own. Holding the global slot for the whole generation+// would otherwise starve unrelated cloud/CLI/TUI agent spawns (e.g. agy,+// gemini) that never touch this endpoint but share the same+// `maxConcurrentAgents` budget.+async function runClaimedPersistentMindTurn(turn, mind, globalSlot) {const generation = runtimeGeneration;const controller = new AbortController();activeAbortController = controller;@@ -836,6 +844,11 @@ async function runClaimedPersistentMindTurn(turn, mind) {return;}release = slot.release;+ // Local GPU contention is now serialized by the endpoint slot above, so the+ // generic global admission slot no longer needs to be held for the+ // (possibly long) inference that follows. Idempotent: the outer `finally`+ // still calls `globalSlot.release()` once the turn settles.+ if (localEndpointOfProvider(prepared.provider)) globalSlot?.release();if (!await turnCanContinue(turn.id, generation, controller.signal)) return;// Preparation and slot admission may wait. A preset revoked during those// waits must be refused before even a context-summary call can begin.diff --git a/server/services/persistentMindSupervisor.test.js b/server/services/persistentMindSupervisor.test.jsindex a33d300f31..6d5647c7ab 100644--- a/server/services/persistentMindSupervisor.test.js+++ b/server/services/persistentMindSupervisor.test.js@@ -17,6 +17,7 @@ const mock = vi.hoisted(() => ({budgetError: null,recordUsage: vi.fn(async () => {}),acquireSlot: vi.fn(async () => ({ ok: true, release: vi.fn() })),+ localEndpointOfProvider: vi.fn(() => null),appendMindEvent: vi.fn(async (event) => ({ appended: true, event })),prepareContext: vi.fn(async () => ({ text: 'bounded context', chars: 15, summaryState: 'not-needed' })),updateInProgress: false,@@ -66,6 +67,7 @@ vi.mock('./domainUsage.js', () => ({vi.mock('./cosLocalEndpointSlots.js', () => ({acquireLocalEndpointProviderSlot: (...args) => mock.acquireSlot(...args),+ localEndpointOfProvider: (...args) => mock.localEndpointOfProvider(...args),}));vi.mock('./agentRunEventLog.js', () => ({@@ -134,6 +136,8 @@ describe('persistent mind supervisor', () => {mock.providerOverride = null;mock.providerAvailable = true;mock.recordUsage.mockClear();+ mock.localEndpointOfProvider.mockReset();+ mock.localEndpointOfProvider.mockReturnValue(null);mock.profile = {ok: true,provider: { id: 'example-cloud', type: 'api' },@@ -622,6 +626,34 @@ describe('persistent mind supervisor', () => {released.release();});+ it('releases the shared global slot early for a local-model turn, once its endpoint slot is held', async () => {+ const running = deferred();+ mock.localEndpointOfProvider.mockReturnValue('localhost:11434');+ mock.profile = { ...mock.profile, provider: { id: 'local-ollama', type: 'api' } };+ await supervisor.registerPersistentMindTurnAdapter({+ prepare: vi.fn(async () => ({ ok: true, provider: { id: 'local-ollama', type: 'api' } })),+ run: vi.fn(() => running.promise),+ });+ mock.root.config.maxConcurrentAgents = 1;+ await supervisor.setPersistentMindEnabled(true);+ await supervisor.startPersistentMind();+ await supervisor.enqueuePersistentMindMessage({ id: 'message-1', text: 'Think locally.' });+ const drain = supervisor.drainPersistentMind();+ await vi.waitFor(() => expect(mock.root.persistentMind.activeTurn).not.toBeNull());++ // The endpoint-scoped local slot now owns GPU serialization for this turn,+ // so an unrelated agent spawn (e.g. agy, gemini) must be able to claim the+ // generic global slot while local inference is still running.+ await vi.waitFor(() => {+ const probe = acquireCosGlobalSlot({ agents: {}, limit: 1, reservationId: 'ordinary-task' });+ expect(probe.ok).toBe(true);+ probe.release();+ });++ running.resolve({});+ await drain;+ });+it('does not claim a turn when another admission reserved the final daily action', async () => {mock.budget = {withinBudget: true,