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): revive blocked duplicates on explicit runs and scope CD dedup by project

[._.]/ Adam Eivy502697f7423c
diff --git a/server/services/cos.js b/server/services/cos.js
index de825c79a1..71288cb82c 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -789,6 +789,17 @@ async function spawnDequeuePriority0OnDemand(ctx) {
if (!persisted?.duplicate) {
cosEvents.emit('task:ready', task);
capacity.trackSpawn(task);
+ } else if (persisted.status === 'blocked') {
+ // Explicit user Run colliding with a failure-blocked twin (#2614): the
+ // retry path is reviving the existing task, not minting a duplicate —
+ // and without this branch the Run is a silent no-op that strands the
+ // bound on-demand review marker. updateTask clears the blocked
+ // metadata on the status flip and merges the fresh payload.
+ await updateTask(persisted.id, { status: 'pending', priority: task.priority, metadata: task.metadata }, 'internal');
+ const revived = { ...task, id: persisted.id };
+ cosEvents.emit('task:ready', revived);
+ capacity.trackSpawn(revived);
+ emitLog('info', `🔁 On-demand ${request.taskType} revived blocked task ${persisted.id}`, { taskId: persisted.id });
}
} else if (!task) {
// Explicit user "Run" produced no task — surface WHY (parked / transient /
@@ -1211,6 +1222,8 @@ export async function init() {
// fire tryImmediateSpawn so the just-added task starts instantly, bypassing
// the evaluation interval that's meant for system task generation.
// - 'approved': a newly approved internal task can now spawn — re-run dequeue.
+ // - 'unblocked': a blocked task flipped back to pending (revive/retry, #2614)
+ // is newly spawnable exactly like an approval — re-run dequeue.
cosEvents.on('tasks:changed', (data) => {
if (!isDaemonRunning() || !data?.action) return;
if (data.action === 'added') {
@@ -1221,7 +1234,7 @@ export async function init() {
// first; tryImmediateSpawn then handles the just-added task.
setImmediate(() => dequeueNextTask());
if (data.type === 'user' && data.task) setImmediate(() => tryImmediateSpawn(data.task));
- } else if (data.action === 'approved') {
+ } else if (data.action === 'approved' || data.action === 'unblocked') {
setImmediate(() => dequeueNextTask());
}
});
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index 59cb9f9ccc..4a3e687396 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -681,6 +681,16 @@ async function spawnPriority0OnDemand(ctx) {
if (!persisted?.duplicate) {
tasksToSpawn.push(task);
trackSpawn(task);
+ } else if (persisted.status === 'blocked') {
+ // Explicit user Run colliding with a failure-blocked twin (#2614):
+ // revive the existing task instead of silently dropping the Run and
+ // stranding the bound on-demand review marker. Mirrors the sibling
+ // dequeueNextTask on-demand engine in cos.js.
+ await updateTask(persisted.id, { status: 'pending', priority: task.priority, metadata: task.metadata }, 'internal');
+ const revived = { ...task, id: persisted.id };
+ tasksToSpawn.push(revived);
+ trackSpawn(revived);
+ emitLog('info', `🔁 On-demand ${request.taskType} revived blocked task ${persisted.id}`, { taskId: persisted.id });
}
} else if (!task) {
// Explicit user Run produced no task on THIS engine too — same feedback
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index f246c45969..0ba9f94330 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -425,6 +425,7 @@ export async function updateTask(taskId, updates, taskType = 'user', { now = Dat
metadata: updatedMetadata
};
+ const previousStatus = tasks[taskIndex].status;
tasks[taskIndex] = updatedTask;
// Write back to file
@@ -432,7 +433,12 @@ export async function updateTask(taskId, updates, taskType = 'user', { now = Dat
const markdown = generateTasksMarkdown(tasks, includeApprovalFlags);
await writeFile(filePath, markdown);
- cosEvents.emit('tasks:changed', { type: taskType, action: 'updated', task: updatedTask });
+ // A blocked → pending flip is a revive: the task is newly spawnable, exactly
+ // like an approval. Emit a distinct action so cos.init's listener re-runs the
+ // dequeue (#2614) — the generic 'updated' action doesn't wake the scheduler,
+ // which left revived tasks stranded until an unrelated event or timer fired.
+ const action = previousStatus === 'blocked' && updatedTask.status === 'pending' ? 'unblocked' : 'updated';
+ cosEvents.emit('tasks:changed', { type: taskType, action, task: updatedTask });
return updatedTask;
});
}
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index ac721e1848..3d25f2aa09 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -276,6 +276,21 @@ describe('cosTaskStore.addTask', () => {
expect(second.duplicate).toBe(true);
});
+ it('emits tasks:changed action "unblocked" on a blocked → pending flip (#2614)', async () => {
+ // cos.init re-runs the dequeue on 'unblocked' (like 'approved') so a
+ // revived task spawns without waiting for an unrelated event or timer.
+ const task = await addTask({ description: 'revive me', app: 'portos', id: 'sys-revive' }, 'internal');
+ await updateTask(task.id, { status: 'blocked', metadata: { blockedCategory: 'max-retries' } }, 'internal');
+ mock.events.length = 0;
+ await updateTask(task.id, { status: 'pending' }, 'internal');
+ const evt = mock.events.find(e => e.name === 'tasks:changed');
+ expect(evt.payload.action).toBe('unblocked');
+ // A non-status edit still emits the plain 'updated' action.
+ mock.events.length = 0;
+ await updateTask(task.id, { priority: 'HIGH' }, 'internal');
+ expect(mock.events.find(e => e.name === 'tasks:changed').payload.action).toBe('updated');
+ });
+
it('resolving a blocked task re-opens the slot for an identical task (#2614)', async () => {
const first = await addTask({ description: 'retry me', app: 'portos', id: 'sys-retry' }, 'internal');
await updateTask(first.id, { status: 'blocked', metadata: { blockedCategory: 'max-retries' } }, 'internal');
diff --git a/server/services/creativeDirector/agentBridge.js b/server/services/creativeDirector/agentBridge.js
index 9418d27f1e..b515290eb7 100644
--- a/server/services/creativeDirector/agentBridge.js
+++ b/server/services/creativeDirector/agentBridge.js
@@ -78,18 +78,23 @@ async function buildTaskRecord(project, kind, scene, context) {
}
function buildDescription(project, kind, scene) {
+ // The [cd:…] suffix makes the first line unique per project: addTask's
+ // duplicate scan keys on first-line + metadata.app, and CD tasks carry no
+ // app — without a project discriminator, two projects sharing a name would
+ // dedup against each other's tasks (#2614).
+ const tag = `[cd:${String(project.id).slice(0, 8)}]`;
if (kind === 'treatment') {
- return `Creative Director — Treatment for "${project.name}"`;
+ return `Creative Director — Treatment for "${project.name}" ${tag}`;
}
if (kind === 'plan') {
- return `Creative Director — Production Plan for "${project.name}"`;
+ return `Creative Director — Production Plan for "${project.name}" ${tag}`;
}
if (kind === 'evaluate' && scene) {
const total = project.treatment?.scenes?.length || '?';
const intent = (scene.intent || '').slice(0, 60);
- return `Creative Director — Evaluate Scene ${scene.order + 1}/${total}: "${intent}" (${project.name})`;
+ return `Creative Director — Evaluate Scene ${scene.order + 1}/${total}: "${intent}" (${project.name}) ${tag}`;
}
- return `Creative Director — ${kind} for "${project.name}"`;
+ return `Creative Director — ${kind} for "${project.name}" ${tag}`;
}
async function persistAndEmit({ id, runId, record }, project, kind, sceneId) {
@@ -102,6 +107,13 @@ async function persistAndEmit({ id, runId, record }, project, kind, sceneId) {
const persisted = await addTask(record, 'internal', { raw: true });
let effective = record;
if (persisted?.duplicate) {
+ // Belt-and-braces: the [cd:…] description tag should make a cross-project
+ // match impossible, but never revive/adopt another project's task — that
+ // would rewrite its metadata to target this project.
+ if (persisted.metadata?.creativeDirector?.projectId !== project.id) {
+ console.log(`⚠️ CD ${kind} enqueue for ${project.id} collided with unrelated task ${persisted.id} — not enqueued`);
+ return persisted;
+ }
if (persisted.status === 'blocked') {
// A CD enqueue is an explicit user re-trigger — revive the blocked
// duplicate with the fresh payload (updateTask clears the blocked
diff --git a/server/services/creativeDirector/agentBridge.test.js b/server/services/creativeDirector/agentBridge.test.js
index 911585a2a2..b0a0f6cf76 100644
--- a/server/services/creativeDirector/agentBridge.test.js
+++ b/server/services/creativeDirector/agentBridge.test.js
@@ -106,7 +106,12 @@ describe('persistAndEmit duplicate handling (#2614 — addTask dedup also matche
// a failure collides with the blocked twin. The enqueue must revive that
// task (status flip clears blocked metadata server-side) and emit
// task:ready with the EXISTING id — never with the never-persisted one.
- mocks.addTask.mockResolvedValue({ id: 'sys-cd-old', status: 'blocked', duplicate: true, metadata: { blockedCategory: 'max-retries' } });
+ mocks.addTask.mockResolvedValue({
+ id: 'sys-cd-old',
+ status: 'blocked',
+ duplicate: true,
+ metadata: { blockedCategory: 'max-retries', creativeDirector: { projectId: 'cd-1' } }
+ });
const result = await enqueueTreatmentTask(project);
@@ -124,7 +129,7 @@ describe('persistAndEmit duplicate handling (#2614 — addTask dedup also matche
});
it('does not spawn a second agent or record a run for a pending duplicate', async () => {
- const existing = { id: 'sys-cd-live', status: 'pending', duplicate: true };
+ const existing = { id: 'sys-cd-live', status: 'pending', duplicate: true, metadata: { creativeDirector: { projectId: 'cd-1' } } };
mocks.addTask.mockResolvedValue(existing);
const result = await enqueueTreatmentTask(project);
@@ -134,4 +139,27 @@ describe('persistAndEmit duplicate handling (#2614 — addTask dedup also matche
expect(mocks.recordRun).not.toHaveBeenCalled();
expect(result).toBe(existing);
});
+
+ it('never revives or adopts a duplicate belonging to a DIFFERENT project', async () => {
+ const foreign = { id: 'sys-cd-other', status: 'blocked', duplicate: true, metadata: { creativeDirector: { projectId: 'cd-other' } } };
+ mocks.addTask.mockResolvedValue(foreign);
+
+ const result = await enqueueTreatmentTask(project);
+
+ expect(mocks.updateTask).not.toHaveBeenCalled();
+ expect(mocks.emit).not.toHaveBeenCalled();
+ expect(result).toBe(foreign);
+ });
+
+ it('embeds a per-project discriminator in the task description', async () => {
+ // Two projects sharing a name must not dedup against each other: CD tasks
+ // carry no metadata.app, so the first line is the whole dedup key.
+ await enqueueTreatmentTask(project);
+ await enqueueTreatmentTask({ ...project, id: 'cd-2222' });
+ const [taskA] = mocks.addTask.mock.calls[0];
+ const [taskB] = mocks.addTask.mock.calls[1];
+ expect(taskA.description).toContain('[cd:cd-1]');
+ expect(taskB.description).toContain('[cd:cd-2222]');
+ expect(taskA.description).not.toBe(taskB.description);
+ });
});