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: only offer instances that can actually receive a pinned CoS task (#4520)
[._.]/ Adam Eivy1a5372f1af31
diff --git a/client/src/components/cos/tabs/TaskItem.jsx b/client/src/components/cos/tabs/TaskItem.jsxindex d50d9ec854..ca5add86a9 100644--- a/client/src/components/cos/tabs/TaskItem.jsx+++ b/client/src/components/cos/tabs/TaskItem.jsx@@ -95,18 +95,22 @@ export default function TaskItem({ task, isSystem, selected = false, onRefresh,// task actually carries one, and is omitted from the PATCH otherwise rather// than writing an empty `prompt` key onto every task the user edits.const hasPromptField = typeof task.metadata?.prompt === 'string';- // Instance pinning (#4520) is only meaningful once this install federates with- // at least one identified peer. Below that, the picker is hidden AND the field- // is withheld from the PATCH, so editing a task here can never silently clear- // a pin another machine set.// `null` means the registry has not been read yet — distinct from a read that- // found nothing — so a row never flashes "unknown instance" before the list lands.+ // found nothing — so a row never flashes "unknown instance" before the list lands,+ // and the editor never offers a picker built from a list it does not have.+ const registryLoaded = instances !== null;const knownInstances = instances || [];- const canPinInstance = knownInstances.length > 1;const targetInstanceId = task.metadata?.targetInstanceId || '';+ // Instance pinning (#4520) is only meaningful once this install federates.+ // Below that the picker is hidden AND the field is withheld from the PATCH, so+ // editing a task here can never silently clear a pin another machine set — with+ // one exception: a task that ALREADY carries a pin always gets the picker, or+ // removing the last peer would leave that pin permanently unclearable and the+ // task unrunnable on every instance.+ const canPinInstance = registryLoaded && (knownInstances.length > 1 || Boolean(targetInstanceId));// A pin naming an instance that has left the registry still renders — silently// dropping the badge would hide exactly the task nothing will ever run.- const targetInstanceName = targetInstanceId && instances+ const targetInstanceName = targetInstanceId && registryLoaded? (knownInstances.find(i => i.instanceId === targetInstanceId)?.name || 'unknown instance'): '';const taskPrompt = task.metadata?.prompt || '';diff --git a/client/src/components/cos/tabs/TaskItem.test.jsx b/client/src/components/cos/tabs/TaskItem.test.jsxindex bd4248a5ed..bd0bfeadbf 100644--- a/client/src/components/cos/tabs/TaskItem.test.jsx+++ b/client/src/components/cos/tabs/TaskItem.test.jsx@@ -627,11 +627,31 @@ describe('TaskItem federated instance pin (#4520)', () => {expect(api.updateCosTask.mock.calls[0][1].targetInstanceId).toBeNull();});- it('hides the picker AND withholds the field on a single-instance install', async () => {+ it('hides the picker AND withholds the field for an UNPINNED task on a single-instance install', async () => {// Otherwise an edit made here would silently unpin a task another machine// pinned — the field would ride along as `null` on every save.+ render(<TaskItem task={task} providers={providers} instances={[{ instanceId: SELF, name: 'workstation', isSelf: true }]} onRefresh={vi.fn()} />);+ fireEvent.click(screen.getByLabelText("Edit task"));+ expect(screen.queryByLabelText('Run on')).toBeNull();+ fireEvent.click(screen.getByText('Save'));+ await waitFor(() => expect(api.updateCosTask).toHaveBeenCalled());+ expect('targetInstanceId' in api.updateCosTask.mock.calls[0][1]).toBe(false);+ });++ it('still offers the picker for an ALREADY-pinned task after the last peer is removed', async () => {+ // Hiding it there would leave the pin permanently unclearable and the task+ // unrunnable on every instance.render(<TaskItem task={pinned} providers={providers} instances={[{ instanceId: SELF, name: 'workstation', isSelf: true }]} onRefresh={vi.fn()} />);fireEvent.click(screen.getByLabelText("Edit task"));+ fireEvent.change(screen.getByLabelText('Run on'), { target: { value: '' } });+ fireEvent.click(screen.getByText('Save'));+ await waitFor(() => expect(api.updateCosTask).toHaveBeenCalled());+ expect(api.updateCosTask.mock.calls[0][1].targetInstanceId).toBeNull();+ });++ it('hides the picker until the registry read lands, so an edit mid-load cannot unpin', async () => {+ render(<TaskItem task={pinned} providers={providers} onRefresh={vi.fn()} />);+ fireEvent.click(screen.getByLabelText("Edit task"));expect(screen.queryByLabelText('Run on')).toBeNull();fireEvent.click(screen.getByText('Save'));await waitFor(() => expect(api.updateCosTask).toHaveBeenCalled());diff --git a/server/services/cosTaskClaim.js b/server/services/cosTaskClaim.jsindex c5d55bfc59..19cc2e861c 100644--- a/server/services/cosTaskClaim.js+++ b/server/services/cosTaskClaim.js@@ -148,9 +148,14 @@ export const TARGET_INSTANCE_KEY = 'targetInstanceId';* The instance this task is pinned to, or null when it is unpinned (runnable by* any peer). Trims so a whitespace-only value reads as unpinned rather than as* a target no instance can ever match.+ *+ * `source` is anything carrying the key: a task's `metadata` (every read path)+ * or an `addTask` payload, which passes it top-level alongside `app`/`model`+ * before the store folds it into metadata. One reader for both keeps the create+ * path's normalization identical to the guards'.*/-export function getTargetInstance(metadata) {- const target = metadata?.[TARGET_INSTANCE_KEY];+export function getTargetInstance(source) {+ const target = source?.[TARGET_INSTANCE_KEY];if (typeof target !== 'string') return null;const trimmed = target.trim();return trimmed === '' ? null : trimmed;diff --git a/server/services/instances.js b/server/services/instances.jsindex 5277adf702..c93d3e75d1 100644--- a/server/services/instances.js+++ b/server/services/instances.js@@ -226,12 +226,20 @@ export async function ensureInstanceId() {/*** The instances this install can direct a CoS task at (#4520): this machine- * plus every peer whose federation identity is known. A peer that has never- * completed a probe/connect still carries `instanceId: null` — it has no- * addressable identity yet, so offering it would let a user pin a task to a- * target no instance can ever match, stranding it unrunnable on every peer.+ * plus every peer that can actually RECEIVE the task. Two filters, both of+ * which exist to stop a pin from stranding work:+ *+ * - `instanceId` must be set. A peer that has never completed a probe/connect+ * has no addressable federation identity yet, so nothing could ever match a+ * pin naming it.+ * - The peer must be an enabled full-sync peer. CoS task replication only+ * sweeps `fullSync === true && enabled !== false` peers (see+ * sharing/peerCosSync.js) — pin a task to any other peer and it never leaves+ * this machine, while this machine skips it for being pinned elsewhere, so it+ * sits pending forever.+ ** Returns only the id/name/isSelf triple the picker needs; no addresses, no- * credentials.+ * credentials, no sync state.*/export async function getAssignableInstances() {const data = await loadData();@@ -240,7 +248,7 @@ export async function getAssignableInstances() {assignable.push({ instanceId: data.self.instanceId, name: data.self.name || 'This instance', isSelf: true });}for (const peer of data.peers || []) {- if (!peer.instanceId) continue;+ if (!peer.instanceId || peer.fullSync !== true || peer.enabled === false) continue;assignable.push({ instanceId: peer.instanceId, name: peer.name || peer.address || peer.instanceId, isSelf: false });}return assignable;diff --git a/server/services/instances.test.js b/server/services/instances.test.jsindex 94c464ec59..6486452897 100644--- a/server/services/instances.test.js+++ b/server/services/instances.test.js@@ -209,14 +209,14 @@ describe('instances.js', () => {// --- Assignable instances (#4520) ---describe('getAssignableInstances', () => {- it('lists self plus every peer that has advertised a federation identity', async () => {+ it('lists self plus every enabled full-sync peer that has advertised an identity', async () => {readJSONFile.mockResolvedValue({self: { instanceId: 'self-id', name: 'workstation' },peers: [- { id: 'p1', instanceId: 'peer-id', name: 'render-box', address: '192.0.2.10' },+ { id: 'p1', instanceId: 'peer-id', name: 'render-box', address: '192.0.2.10', fullSync: true, enabled: true },// Never probed: no federation identity yet, so pinning to it would// strand the task unrunnable on every peer.- { id: 'p2', instanceId: null, name: 'not-yet-connected', address: '192.0.2.11' }+ { id: 'p2', instanceId: null, name: 'not-yet-connected', address: '192.0.2.11', fullSync: true }]});expect(await getAssignableInstances()).toEqual([@@ -225,6 +225,23 @@ describe('instances.js', () => {]);});+ it('omits peers the CoS task sweep never reaches (not full-sync, or disabled)', async () => {+ // peerCosSync only sweeps `fullSync === true && enabled !== false` peers, so+ // pinning to any other peer strands the task: it never leaves this machine,+ // and this machine skips it for being pinned elsewhere.+ readJSONFile.mockResolvedValue({+ self: { instanceId: 'self-id', name: 'workstation' },+ peers: [+ { id: 'p1', instanceId: 'category-sync-peer', name: 'partial', fullSync: false, enabled: true },+ { id: 'p2', instanceId: 'disabled-peer', name: 'paused', fullSync: true, enabled: false },+ { id: 'p3', instanceId: 'legacy-peer', name: 'legacy-no-flag' }+ ]+ });+ expect(await getAssignableInstances()).toEqual([+ { instanceId: 'self-id', name: 'workstation', isSelf: true }+ ]);+ });+it('is empty before this install has an identity of its own', async () => {readJSONFile.mockResolvedValue({ self: null, peers: [] });expect(await getAssignableInstances()).toEqual([]);@@ -234,8 +251,8 @@ describe('instances.js', () => {readJSONFile.mockResolvedValue({self: { instanceId: 'self-id', name: 'workstation' },peers: [- { id: 'p1', instanceId: 'peer-a', name: '', address: '192.0.2.10' },- { id: 'p2', instanceId: 'peer-b', name: '', address: '' }+ { id: 'p1', instanceId: 'peer-a', name: '', address: '192.0.2.10', fullSync: true },+ { id: 'p2', instanceId: 'peer-b', name: '', address: '', fullSync: true }]});const assignable = await getAssignableInstances();