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

register preflight- as a task-id prefix so a run's progress card stops freezing at step 1

[._.]/ Adam Eivy8a06aaa83764
diff --git a/server/lib/taskParser.js b/server/lib/taskParser.js
index a2c2f76cd5..4d3647d79b 100644
--- a/server/lib/taskParser.js
+++ b/server/lib/taskParser.js
@@ -28,8 +28,15 @@
* - [ ] #sys-002 | MEDIUM | APPROVAL | Needs user approval
*/
-// Canonical prefix lists — add new prefixes here, not in scattered startsWith checks
-const INTERNAL_PREFIXES = ['sys-', 'app-improve-', 'cd-'];
+// Canonical prefix lists — add new prefixes here, not in scattered startsWith checks.
+//
+// REGISTERING A PREFIX IS MANDATORY, not cosmetic. An id whose prefix is absent
+// here is rewritten to `task-<id>` the next time the row is read, so a producer
+// that re-derives its own id can never address its record again — and because
+// those reads and writes are deliberately best-effort, they miss SILENTLY. That
+// is how a preflight card (`preflight-`) sat at "Waiting for a free task slot"
+// through an entire pr-reviewer run, then got reaped as interrupted.
+const INTERNAL_PREFIXES = ['sys-', 'app-improve-', 'cd-', 'preflight-'];
const ALL_KNOWN_PREFIXES = ['task-', ...INTERNAL_PREFIXES];
export const hasKnownPrefix = (id) => ALL_KNOWN_PREFIXES.some(p => id?.startsWith(p));
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index cd60e738fc..16398e3ab6 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -17,7 +17,7 @@ import { reviewerModelsFromDefaults } from '../lib/reviewerConfig.js';
import { readFile, writeFile, stat } from 'fs/promises';
import { existsSync } from 'fs';
import { join } from 'path';
-import { parseTasksMarkdown, groupTasksByStatus, getAutoApprovedTasks, getAwaitingApprovalTasks, generateTasksMarkdown, toRepresentableTask, PRIORITY_VALUES } from '../lib/taskParser.js';
+import { parseTasksMarkdown, groupTasksByStatus, getAutoApprovedTasks, getAwaitingApprovalTasks, generateTasksMarkdown, hasKnownPrefix, toRepresentableTask, PRIORITY_VALUES } from '../lib/taskParser.js';
import { MAX_TOTAL_SPAWNS } from '../lib/validation.js';
import { RETRY_HOLD_KEY, RETRY_HOLD_SINCE_KEY } from '../lib/taskRetryHold.js';
import { resolveTaskTargetBranch, shouldStripTaskTargetBranch } from '../lib/taskTargetBranch.js';
@@ -397,6 +397,16 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
// When raw=true, use the pre-built task object directly (for on-demand/generated tasks)
let newTask = raw ? taskData : buildQueuedTask(taskData, taskType, { now });
+ // A raw producer mints its own id and this path writes it verbatim, but the
+ // next READ rewrites an unregistered prefix to `task-<id>` — so a producer
+ // that re-derives its id instead of keeping the one returned here misses on
+ // every later read and write, silently (those call sites are best-effort).
+ // The preflight card lost a whole pr-reviewer run that way. The fix is to
+ // register the prefix in lib/taskParser.js, not to rename the producer.
+ if (raw && newTask?.id && !hasKnownPrefix(newTask.id)) {
+ console.error(`❌ Task id ${newTask.id} uses an unregistered prefix — it will be read back as task-${newTask.id}. Register the prefix in lib/taskParser.js`);
+ }
+
// Route a multi-line context payload to `metadata.prompt` (#4153). Applied to
// BOTH branches — the raw path is how the generator, the reference-watch
// analysis, and the repo-study filer queue their pre-built tasks, and they
diff --git a/server/services/preflightTaskCard.test.js b/server/services/preflightTaskCard.test.js
index 85ee841f56..fc24256db5 100644
--- a/server/services/preflightTaskCard.test.js
+++ b/server/services/preflightTaskCard.test.js
@@ -41,6 +41,27 @@ describe('preflightTaskCard', () => {
expect(task.metadata.preflight.steps[0]).toMatchObject({ key: 'queued', status: 'active' });
});
+ it('mints an id the task FILE round-trips, or every later write to the card misses in silence', async () => {
+ // Every later report and close re-derives `preflightCardId(requestId)` rather
+ // than keeping a handle from addTask, so that id has to survive a COS-TASKS.md
+ // round trip byte for byte. `preflight-` was unregistered, so the card
+ // persisted as `task-preflight-demand-1`: every `getTaskById` after it
+ // returned null and every best-effort write wrote NOTHING, leaving the card
+ // on "Waiting for a free task slot" for a whole pr-reviewer run.
+ //
+ // The rest of this suite mocks the store, which is exactly why that was
+ // invisible here; this test runs the real markdown boundary.
+ const { generateTasksMarkdown, parseTasksMarkdown, isInternalTaskId } = await import('../lib/taskParser.js');
+ await startPreflightCard({ requestId: 'demand-1', taskType: 'pr-reviewer', appId: 'portos', appName: 'PortOS', targetPullRequest: 42 });
+ const [card] = addTask.mock.calls[0];
+ const [reparsed] = parseTasksMarkdown(generateTasksMarkdown([card], true));
+ expect(reparsed.id).toBe(preflightCardId('demand-1'));
+ // And it has to parse as INTERNAL, or the sweep that closes a stranded card
+ // infers 'user' from the id and looks for it in the wrong task file.
+ expect(isInternalTaskId(reparsed.id)).toBe(true);
+ expect(isPreflightCard(reparsed)).toBe(true);
+ });
+
it('writes nothing when there is no card — an automated run carries no reporter branch', async () => {
getTaskById.mockResolvedValue(null);
await reportPreflightStep('preflight-missing', 'security-scan');