Skip to content

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

address review (codex): harden manual scheduled task runs

[._.]/ Adam Eivy1bbd57dccc82
diff --git a/client/src/components/apps/tabs/CustomTasksSection.jsx b/client/src/components/apps/tabs/CustomTasksSection.jsx
index a354ae3fbe..a378599ede 100644
--- a/client/src/components/apps/tabs/CustomTasksSection.jsx
+++ b/client/src/components/apps/tabs/CustomTasksSection.jsx
@@ -286,10 +286,10 @@ export default function CustomTasksSection({ appId, appName, providerCatalog, ac
onTrigger={handleTrigger}
onDelete={handleDelete}
onUpdate={fetchTasks}
+ validateEdit={validate}
fixedAppId={appId}
fixedType="agent"
showTaskMetadata
- silentUpdate={false}
triggering={triggering === job.id}
/>
))}
diff --git a/client/src/components/apps/tabs/CustomTasksSection.test.jsx b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
index 505c39e708..c07e043221 100644
--- a/client/src/components/apps/tabs/CustomTasksSection.test.jsx
+++ b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
@@ -125,7 +125,18 @@ describe('CustomTasksSection trigger outcomes', () => {
providerId: 'codex',
model: 'gpt-5',
effort: 'high'
- })));
+ }), { silent: true }));
+ });
+
+ it('keeps required prompt validation when editing the shared card', async () => {
+ render(<CustomTasksSection appId="app-1" appName="Example App" />);
+ await screen.findByText('Example Task');
+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }));
+ fireEvent.change(screen.getByLabelText('Prompt template'), { target: { value: '' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Prompt is required'));
+ expect(api.updateCosJob).not.toHaveBeenCalled();
});
it('reports a direct manual trigger as started', async () => {
diff --git a/client/src/components/cos/JobCard.jsx b/client/src/components/cos/JobCard.jsx
index 83d1f6760d..7f98be44cc 100644
--- a/client/src/components/cos/JobCard.jsx
+++ b/client/src/components/cos/JobCard.jsx
@@ -250,10 +250,10 @@ export default function JobCard({
onTrigger,
onDelete,
onUpdate,
+ validateEdit = null,
fixedAppId = null,
fixedType = null,
showTaskMetadata = false,
- silentUpdate = true,
triggering = false
}) {
const [expanded, setExpanded] = useState(false);
@@ -298,6 +298,7 @@ export default function JobCard({
};
const handleSave = async () => {
+ if (validateEdit && !validateEdit(editData)) return;
const providerResolutionKnown = Boolean(editData.providerId || activeProviderId || providers?.length);
if (isAgentJobType(editData.type) && providerResolutionKnown
&& !hasRunnableAgentProvider(providers, editData.providerId, activeProviderId)) {
@@ -310,10 +311,7 @@ export default function JobCard({
...(fixedType ? { type: fixedType } : {})
};
const payload = normalizeJobPayload(constrained);
- const update = silentUpdate
- ? api.updateCosJob(job.id, payload, { silent: true })
- : api.updateCosJob(job.id, payload);
- const result = await update.catch(err => {
+ const result = await api.updateCosJob(job.id, payload, { silent: true }).catch(err => {
toast.error(err.message);
return null;
});
diff --git a/server/routes/cosJobRoutes.js b/server/routes/cosJobRoutes.js
index 936e929464..43d7fac9de 100644
--- a/server/routes/cosJobRoutes.js
+++ b/server/routes/cosJobRoutes.js
@@ -210,7 +210,7 @@ router.post('/jobs/:id/trigger', asyncHandler(async (req, res) => {
// records the execution and re-registers the saved schedule.
autonomousJob: task.metadata?.autonomousJob,
jobId: task.metadata?.jobId
- }, 'internal');
+ }, 'internal', { suppressDequeue: true });
if (!taskResult?.id) {
res.json({
diff --git a/server/routes/cosJobRoutes.test.js b/server/routes/cosJobRoutes.test.js
index dd1e8f4eee..c1c1272af4 100644
--- a/server/routes/cosJobRoutes.test.js
+++ b/server/routes/cosJobRoutes.test.js
@@ -501,7 +501,8 @@ describe('CoS Job Routes', () => {
autonomousJob: true,
jobId: 'j1'
}),
- 'internal'
+ 'internal',
+ { suppressDequeue: true }
);
expect(cos.forceSpawnTask).toHaveBeenCalledWith('task-2');
});
@@ -523,7 +524,8 @@ describe('CoS Job Routes', () => {
expect(response.status).toBe(200);
expect(cos.addTask).toHaveBeenCalledWith(
expect.objectContaining({ provider: 'anthropic', model: 'claude-opus-4-8', effort: 'high' }),
- 'internal'
+ 'internal',
+ { suppressDequeue: true }
);
expect(cos.forceSpawnTask).toHaveBeenCalledWith('task-3');
});
diff --git a/server/services/cos.js b/server/services/cos.js
index 8271c91b55..0c909e170d 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -1596,6 +1596,11 @@ export async function init() {
cosEvents.on('tasks:changed', (data) => {
if (!isDaemonRunning() || !data?.action) return;
if (data.action === 'added') {
+ // An explicit dispatcher (for example a scheduled job's Run now route)
+ // owns the spawn and will call forceSpawnTask after persistence. Skipping
+ // the automatic wake here prevents that dispatcher from racing a normal
+ // internal-task dequeue and reporting a false in-progress failure.
+ if (data.suppressDequeue) return;
// Order matters: dequeueNextTask is scheduled before the user-task
// tryImmediateSpawn, matching the pre-extraction sequence (addTask emitted
// tasks:changed — registering dequeue via this listener — before it called
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index c516010433..07184766a6 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -1924,6 +1924,13 @@ describe('cos.js source — priority + capacity invariants', () => {
expect(handler).toMatch(/data\.type\s*===\s*'user'/);
});
+ it('tasks:changed listener leaves explicitly dispatched tasks to their caller', () => {
+ const onIdx = COS_SRC.indexOf("cosEvents.on('tasks:changed'");
+ const handler = COS_SRC.slice(onIdx, COS_SRC.indexOf('});', onIdx) + 3);
+
+ expect(handler).toMatch(/if\s*\(data\.suppressDequeue\)\s*return/);
+ });
+
// The retry-hold release (#3373) and the orphan sweep both requeue via an
// in_progress → pending flip, which cosTaskStore reports as 'requeued'. Without
// a wake here the released retry idles until an unrelated event or timer.
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index 287a8a26a4..d453e033e3 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -253,9 +253,11 @@ export async function getTaskById(taskId) {
* Emits `tasks:changed` with `action: 'added'` on success; cos.js's init
* listener turns that into a `tryImmediateSpawn` for user tasks so a newly
* submitted task starts instantly instead of waiting for the next evaluation
- * interval.
+ * interval. `suppressDequeue` is reserved for an explicit dispatcher that will
+ * force-spawn the returned task itself; the change event still reaches socket
+ * consumers, but the normal scheduler must not race that dispatch.
*/
-export async function addTask(taskData, taskType = 'user', { raw = false, ignoreTaskId = null, now = Date.now() } = {}) {
+export async function addTask(taskData, taskType = 'user', { raw = false, ignoreTaskId = null, now = Date.now(), suppressDequeue = false } = {}) {
return withStateLock(async () => {
const state = await loadState();
const filePath = taskType === 'user'
@@ -582,7 +584,9 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
// cos.js init listens for this event. For user tasks it fires
// tryImmediateSpawn so the task starts instantly if slots are available,
// bypassing the evaluation interval (which is meant for system task generation).
- cosEvents.emit('tasks:changed', { type: taskType, action: 'added', task: newTask });
+ const change = { type: taskType, action: 'added', task: newTask };
+ if (suppressDequeue) change.suppressDequeue = true;
+ cosEvents.emit('tasks:changed', change);
return newTask;
});
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 0a6bb029ea..3286e3ba01 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -323,6 +323,17 @@ describe('cosTaskStore.addTask', () => {
expect(mock.events.some(e => e.name === 'tasks:changed' && e.payload.action === 'added' && e.payload.type === 'user')).toBe(true);
});
+ it('marks explicitly dispatched tasks so the scheduler does not race their spawn', async () => {
+ const task = await addTask({ description: 'run this now' }, 'internal', { suppressDequeue: true });
+ const change = mock.events.find(e => e.name === 'tasks:changed' && e.payload.task?.id === task.id);
+
+ expect(change.payload).toMatchObject({
+ type: 'internal',
+ action: 'added',
+ suppressDequeue: true
+ });
+ });
+
describe('targeted instance pin (#4520)', () => {
it('persists targetInstanceId and round-trips it through markdown', async () => {
const created = await addTask({ description: 'gpu work', id: 'task-pin', targetInstanceId: 'instance-bbbb' }, 'user');