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: allocate unique on-demand receipt IDs (#9456)
[._.]/ Adam Eivye0753d52289e
diff --git a/server/services/cosTaskGenerator.programmaticOnDemand.test.js b/server/services/cosTaskGenerator.programmaticOnDemand.test.jsindex 37cc47d330..ea875fafce 100644--- a/server/services/cosTaskGenerator.programmaticOnDemand.test.js+++ b/server/services/cosTaskGenerator.programmaticOnDemand.test.js@@ -153,6 +153,28 @@ describe('drainProgrammaticOnDemandRequests — cross-engine claim', () => {expect(recordExecution).not.toHaveBeenCalled();expect(cosEvents.emit).not.toHaveBeenCalled();});++ it('removes only the programmatic receipt from a mixed agent queue', async () => {+ const agentRequest = { id: 'demand-00000000-0000-4000-8000-000000000001', taskType: 'security' };+ const programmaticRequest = { id: 'demand-00000000-0000-4000-8000-000000000002', taskType: 'universe-bible-describe' };+ const queued = [agentRequest, programmaticRequest];+ clearOnDemandRequest.mockImplementation(async (id) => {+ const index = queued.findIndex((item) => item.id === id);+ return index < 0 ? null : queued.splice(index, 1)[0];+ });++ const handled = await drainProgrammaticOnDemandRequests({+ taskScheduleMod, requests: [...queued], schedule: schedule(), state: {},+ });++ expect(handled).toEqual(new Set([programmaticRequest.id]));+ expect(queued).toEqual([agentRequest]);+ expect(runScheduledHandler).toHaveBeenCalledTimes(1);+ expect(runScheduledHandler).toHaveBeenCalledWith(expect.objectContaining({+ taskType: 'universe-bible-describe',+ }));+ expect(clearOnDemandRequest).toHaveBeenCalledWith(programmaticRequest.id);+ });});diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex d3f8d21eca..9d46f599ab 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -20,6 +20,7 @@*/import { scheduleExecutionFieldsSchema } from '../lib/scheduleExecutionFieldsValidation.js';+import { randomUUID } from 'node:crypto';import { ServerError } from '../lib/errorHandler.js';import { taskExecutionKey as executionKey } from '../lib/scheduledTaskTypes.js';import { TASK_READINESS_REASON } from '../lib/taskReadinessReasons.js';@@ -1208,7 +1209,7 @@ export async function triggerOnDemandTask(taskType, appId = null, {}const request = {- id: `demand-${Date.now().toString(36)}`,+ id: `demand-${randomUUID()}`,taskType,appId,origin,diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 52fec60299..a94502ec02 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -131,6 +131,7 @@ import {resetExecutionHistory,triggerOnDemandTask,getOnDemandRequests,+ clearOnDemandRequest,getScheduleStatus,computePerpetualRecheckAt,parkPerpetual,@@ -2183,6 +2184,37 @@ describe('taskSchedule', () => {expect(result.id).toMatch(/^demand-/)})+ it('allocates distinct receipt IDs for mixed task types within one clock tick', async () => {+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-01-02T03:04:05.000Z'))+ mockSchedule({ tasks: {+ security: { type: INTERVAL_TYPES.ON_DEMAND, enabled: true },+ 'universe-bible-describe': { type: INTERVAL_TYPES.ON_DEMAND, enabled: true },+ } })++ const agentRequest = await triggerOnDemandTask('security', null, { emit: false })+ const programmaticRequest = await triggerOnDemandTask('universe-bible-describe', null, { emit: false })++ expect(agentRequest.id).toMatch(/^demand-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)+ expect(programmaticRequest.id).toMatch(/^demand-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)+ expect(agentRequest.id).not.toBe(programmaticRequest.id)+ expect(agentRequest.requestedAt).toBe('2026-01-02T03:04:05.000Z')+ expect(programmaticRequest.requestedAt).toBe(agentRequest.requestedAt)+ })++ it('keeps legacy timestamp receipt IDs cancellable', async () => {+ const legacyRequest = {+ id: 'demand-m5d4ruo0', taskType: 'security', appId: null,+ origin: ON_DEMAND_ORIGINS.USER, requestedAt: '2024-01-01T00:00:00.000Z',+ }+ mockSchedule({ onDemandRequests: [legacyRequest] })++ await expect(clearOnDemandRequest(legacyRequest.id)).resolves.toEqual(legacyRequest)++ const persisted = JSON.parse(writeFile.mock.calls.at(-1)[1])+ expect(persisted.onDemandRequests).toEqual([])+ })+// The drain's completion refill re-issues itself through this same queue. It// must be distinguishable from a human "Run", because the engines clear the// park + convergence signature + dispatch counter for a human and MUST NOT for