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

fix: close CoS prompt split follow-up findings

[._.]/ Adam Eivy214b6e1defc3
diff --git a/.changelog/next/fixed-cos-task-prompt-followup.md b/.changelog/next/fixed-cos-task-prompt-followup.md
new file mode 100644
index 0000000000..b8537ca0df
--- /dev/null
+++ b/.changelog/next/fixed-cos-task-prompt-followup.md
@@ -0,0 +1 @@
+- CoS tasks preserve cleared prompts, keep customized prompt templates supplied, and retain prompt edits after queue refreshes.
diff --git a/client/src/components/cos/tabs/TaskItem.jsx b/client/src/components/cos/tabs/TaskItem.jsx
index d82bcf262f..c4cd53828c 100644
--- a/client/src/components/cos/tabs/TaskItem.jsx
+++ b/client/src/components/cos/tabs/TaskItem.jsx
@@ -49,6 +49,14 @@ const APPROVAL_REASON_HINTS = {
'investigation-loop:failure-storm': 'Held for you: this hour is nearly out of investigation budget — failures are cascading, not isolated.'
};
+const getTaskEditData = (task) => ({
+ description: task.description,
+ prompt: task.metadata?.prompt || '',
+ context: task.metadata?.context || '',
+ model: task.metadata?.model || '',
+ provider: task.metadata?.provider || ''
+});
+
// Get success rate styling based on percentage
function getSuccessRateStyle(rate) {
if (rate >= 70) return { bg: 'bg-port-success/15', text: 'text-port-success', label: 'high' };
@@ -79,13 +87,11 @@ export default function TaskItem({ task, isSystem, onRefresh, providers, duratio
// 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';
- const [editData, setEditData] = useState({
- description: task.description,
- prompt: task.metadata?.prompt || '',
- context: task.metadata?.context || '',
- model: task.metadata?.model || '',
- provider: task.metadata?.provider || ''
- });
+ const taskPrompt = task.metadata?.prompt || '';
+ const taskContext = task.metadata?.context || '';
+ const taskModel = task.metadata?.model || '';
+ const taskProvider = task.metadata?.provider || '';
+ const [editData, setEditData] = useState(() => getTaskEditData(task));
const [showBlockedModal, setShowBlockedModal] = useState(false);
const [blockedReason, setBlockedReason] = useState('');
const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();
@@ -103,6 +109,13 @@ export default function TaskItem({ task, isSystem, onRefresh, providers, duratio
}
}, [showBlockedModal]);
+ // Queue refreshes can replace a legacy task with its split form while this
+ // component stays mounted under the same task id. Keep the draft current
+ // whenever it is safe to do so, but never overwrite an active edit.
+ useEffect(() => {
+ if (!editing) setEditData(getTaskEditData(task));
+ }, [editing, task.id, task.description, taskPrompt, taskContext, taskModel, taskProvider, task]);
+
// Get models for selected provider in edit mode
const editProvider = providers?.find(p => p.id === editData.provider);
const editModels = filterSelectableModels(editProvider?.models);
@@ -212,17 +225,10 @@ export default function TaskItem({ task, isSystem, onRefresh, providers, duratio
// Discarding must actually revert the draft, not just hide it — without this,
// reopening Edit after a confirmed discard would show the just-discarded text
- // again instead of the task's real values, since editData is otherwise only
- // ever seeded once at mount.
+ // again instead of the task's real values.
const handleConfirmDiscard = () => {
confirmDiscard(() => {
- setEditData({
- description: task.description,
- prompt: task.metadata?.prompt || '',
- context: task.metadata?.context || '',
- model: task.metadata?.model || '',
- provider: task.metadata?.provider || ''
- });
+ setEditData(getTaskEditData(task));
setEditing(false);
});
};
diff --git a/client/src/components/cos/tabs/TaskItem.test.jsx b/client/src/components/cos/tabs/TaskItem.test.jsx
index fc01c4da2d..ec558fed27 100644
--- a/client/src/components/cos/tabs/TaskItem.test.jsx
+++ b/client/src/components/cos/tabs/TaskItem.test.jsx
@@ -327,6 +327,26 @@ describe('TaskItem prompt field (#4153)', () => {
expect(payload).not.toHaveProperty('prompt');
expect(payload.context).toBe('edited note');
});
+
+ it('refreshes the prompt draft when a mounted legacy task gains split metadata', async () => {
+ const legacy = { ...task, id: 'sys-refresh', metadata: { context: 'legacy body' } };
+ const splitTask = {
+ ...legacy,
+ metadata: { prompt: 'the refreshed body\nsecond line', context: 'a short note' },
+ };
+ const { rerender } = render(<TaskItem task={legacy} isSystem onRefresh={vi.fn()} providers={providers} />);
+ rerender(<TaskItem task={splitTask} isSystem onRefresh={vi.fn()} providers={providers} />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Edit task' }));
+ await waitFor(() => expect(screen.getByPlaceholderText('Prompt')).toHaveValue('the refreshed body\nsecond line'));
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => expect(api.updateCosTask).toHaveBeenCalledWith(
+ 'sys-refresh',
+ expect.objectContaining({ prompt: 'the refreshed body\nsecond line', context: 'a short note' }),
+ { silent: true }
+ ));
+ });
});
describe('TaskItem cancel-edit confirmation (#4037)', () => {
diff --git a/scripts/migrations/270-cos-task-prompt-split.test.js b/scripts/migrations/270-cos-task-prompt-split.test.js
index dc9927d7a2..d6b7700269 100644
--- a/scripts/migrations/270-cos-task-prompt-split.test.js
+++ b/scripts/migrations/270-cos-task-prompt-split.test.js
@@ -76,8 +76,8 @@ describe('splitPromptMetadata', () => {
.toEqual(['sys-b', 'sys-i', 'sys-p', 'sys-x']);
});
- it('ignores a JSON-encoded array value that happens to serialize with a newline escape', () => {
- const md = queue(task('sys-1', { context: 'short note', reviewers: ['claude', 'codex'] }));
+ it('ignores a JSON-encoded context array that happens to serialize with a newline escape', () => {
+ const md = queue(task('sys-1', { context: ['line one\nline two'] }));
expect(splitPromptMetadata(md, { stamp: STAMP })).toEqual({ markdown: md, split: [] });
});
diff --git a/server/lib/cosTaskPrompt.js b/server/lib/cosTaskPrompt.js
index 46937b3da0..36aa237591 100644
--- a/server/lib/cosTaskPrompt.js
+++ b/server/lib/cosTaskPrompt.js
@@ -79,10 +79,14 @@ export function getTaskContextNote(task) {
* neither. Every prompt-building path uses this so the split is invisible to the
* templates (including the ones an install has customized): a legacy task
* renders exactly what it rendered before, and a split task renders its payload
- * followed by its note.
+ * followed by its note. A queue-round-tripped task may already have folded the
+ * prompt into `description`; in that shape, omit the duplicate prompt here while
+ * retaining any separate note.
*/
export function taskContextBlock(task) {
- const parts = [getTaskPrompt(task), getTaskContextNote(task)]
+ const prompt = getTaskPrompt(task);
+ const promptIsAlreadyDescription = typeof prompt === 'string' && task?.description === prompt;
+ const parts = [promptIsAlreadyDescription ? null : prompt, getTaskContextNote(task)]
.filter(v => typeof v === 'string' && v.trim() !== '');
return parts.length ? parts.join('\n\n') : null;
}
diff --git a/server/lib/cosTaskPrompt.test.js b/server/lib/cosTaskPrompt.test.js
index c527a95d20..c443f33601 100644
--- a/server/lib/cosTaskPrompt.test.js
+++ b/server/lib/cosTaskPrompt.test.js
@@ -67,6 +67,14 @@ describe('taskContextBlock', () => {
expect(taskContextBlock({ metadata: { [TASK_CONTEXT_KEY]: AGENT_BODY } })).toBe(AGENT_BODY);
});
+ it('does not repeat a queue prompt already folded into description', () => {
+ const task = {
+ description: AGENT_BODY,
+ metadata: { [TASK_PROMPT_KEY]: AGENT_BODY, [TASK_CONTEXT_KEY]: 'a note' },
+ };
+ expect(taskContextBlock(task)).toBe('a note');
+ });
+
it('returns null when the task carries neither', () => {
expect(taskContextBlock({ metadata: {} })).toBeNull();
expect(taskContextBlock({ metadata: { [TASK_PROMPT_KEY]: ' ' } })).toBeNull();
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index df047e24f7..dca61a297f 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -389,10 +389,12 @@ function resolveTaskFileRef(ref) {
* generated/scheduled/system task that round-trips through the queue.
*
* When the split signature is present (the payload's first non-empty line
- * equals `description`), fold it back into `description` and drop the redundant
- * metadata key so the prompt renders once, as one clean body with no spurious
- * header. A genuinely-separate user-supplied note (first line differs from
- * `description`) is left untouched.
+ * equals `description`), fold it back into `description` so the prompt renders
+ * once, as one clean body with no spurious header. The split `prompt` key stays
+ * available to customized briefing templates; the legacy `context` payload key
+ * is dropped because it is already represented by `description`. A genuinely-
+ * separate user-supplied note (first line differs from `description`) is left
+ * untouched.
*
* Pure and idempotent: returns the same task when nothing matched, otherwise a
* shallow clone (never mutates the caller's task, so the stored task keeps its
@@ -404,14 +406,15 @@ export function reconcileSplitContext(task) {
// `prompt` first: that is where the payload lives on a task written by
// current code (#4153). `context` stays in the loop so a task written before
// the split — or synced from a peer still on the old code — reconciles too.
- // Only the key that CARRIED the payload is dropped, so a split task's short
- // `metadata.context` note survives and still renders.
+ // Keep the new prompt key available to customized templates. Drop only the
+ // legacy context key, whose payload is already represented by description.
for (const key of [TASK_PROMPT_KEY, TASK_CONTEXT_KEY]) {
const payload = task.metadata?.[key];
if (typeof payload !== 'string') continue;
// Mirror firstLine() in cosTaskStore.js: first non-empty, trimmed line.
const firstNonEmpty = payload.split('\n').map(l => l.trim()).find(Boolean) || '';
if (firstNonEmpty !== description) continue;
+ if (key === TASK_PROMPT_KEY) return { ...task, description: payload };
const { [key]: _dropped, ...restMeta } = task.metadata;
return { ...task, description: payload, metadata: restMeta };
}
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index d7d330531b..21b6b3c378 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -147,7 +147,7 @@ describe('reconcileSplitContext', () => {
const task = { description: 'Line one is the title', metadata: { prompt: body, context: 'a note', app: 'comics' } };
const out = reconcileSplitContext(task);
expect(out.description).toBe(body);
- expect(out.metadata.prompt).toBeUndefined();
+ expect(out.metadata.prompt).toBe(body); // customized templates can still address the raw field
expect(out.metadata.context).toBe('a note'); // the note is NOT the payload
expect(out.metadata.app).toBe('comics');
});
@@ -1636,6 +1636,20 @@ describe('buildAgentPrompt — provider type routing', () => {
expect(context.task.metadata.prompt).toBe('the agent body\nsecond line');
});
+ it('keeps a queue-path prompt available to a customized briefing template', async () => {
+ vi.mocked(buildPrompt).mockClear();
+ await buildAgentPrompt(
+ makeTask({
+ description: 'the agent body',
+ metadata: { prompt: 'the agent body\nsecond line', context: 'a short note' },
+ }),
+ {}, '/r', null, isTruthyMeta, { providerType: 'api' });
+ const [, context] = vi.mocked(buildPrompt).mock.calls.at(-1);
+ expect(context.task.description).toBe('the agent body\nsecond line');
+ expect(context.task.metadata.prompt).toBe('the agent body\nsecond line');
+ expect(context.task.metadata.context).toBe('a short note');
+ });
+
it('leaves a legacy context-only task untouched on the briefing template path', async () => {
vi.mocked(buildPrompt).mockClear();
const task = makeTask({ metadata: { context: 'legacy body\nsecond line' } });
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index ef031aaba6..28e6ff2930 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -325,7 +325,7 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
// The full agent-facing payload, when the producer names it explicitly
// (#4153). Producers that still pass a multi-line `context` are classified
// by `splitTaskPromptFields` below, so both call shapes converge.
- if (taskData.prompt) metadata.prompt = taskData.prompt;
+ if (typeof taskData.prompt === 'string') metadata.prompt = taskData.prompt;
if (taskData.model) metadata.model = taskData.model;
if (taskData.provider) metadata.provider = taskData.provider;
if (taskData.effort) metadata.effort = taskData.effort;
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 83feea3d6b..26b1655016 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -350,6 +350,19 @@ describe('cosTaskStore.addTask', () => {
expect(created.metadata.context).toBe('one-line note');
});
+ it('preserves an explicitly cleared prompt alongside a note', async () => {
+ const created = await addTask(
+ { description: 'claim', id: 'task-empty-prompt', prompt: '', context: 'one-line note' },
+ 'user'
+ );
+ expect(created.metadata).toHaveProperty('prompt', '');
+ expect(created.metadata.context).toBe('one-line note');
+
+ const reloaded = await getTaskById('task-empty-prompt');
+ expect(reloaded.metadata).toHaveProperty('prompt', '');
+ expect(reloaded.metadata.context).toBe('one-line note');
+ });
+
// The generator, the reference-watch filer and the repo-study filer all queue
// pre-built (raw) tasks carrying the same multi-thousand-character body.
it('classifies a raw pre-built task too, without mutating the caller object', async () => {