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

refactor: declare CLAIM_FLOW_TASK_TYPES once so the claim writer and reader cannot drift (#6613)

[._.]/ Adam Eivy2e6db5ddeca7
diff --git a/server/lib/README.md b/server/lib/README.md
index 762f74cc47..9b33ae6c4b 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -434,6 +434,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and
| `appResolver.js` | Fuzzy-match a spoken/typed phrase to a managed app (`{ id, name }`). Tiered exact → prefix → substring, used by voice tools that target a specific app. |
| `autonomousJobIntervals.js` | Autonomous-job cadence vocabulary (pure). `INTERVAL_OPTIONS` (picker rows, `ms: null` for a cadence with no recurrence), `ON_DEMAND_INTERVAL`, `JOB_INTERVAL_VALUES` (every legal stored cadence, incl. `custom`), `resolveIntervalMs(interval, customMs)` → ms or `null` (the no-interval sentinel — never falls through to `DAY`), and `isOnDemandJob(job)` for the three due/next-fire implementations. Lives here so `cosValidation.js` can validate the cadence without a lib → services import; `services/autonomousJobs/constants.js` re-exports it. Separate vocabulary from the scheduled-CoS-task `INTERVAL_TYPES`. |
| `capabilityMap.js` | Pure row builders for Setup & Capabilities, including strict network/provider first-run readiness and optional-integration health rollups; fed by `routes/capabilities.js`. |
+| `claimFlowTaskTypes.js` | `CLAIM_FLOW_TASK_TYPES` — the ONE list of task kinds whose prompts own their own `claim/<item>` worktree and push/PR/MR/review lifecycle (#6613). `services/cosTaskGenerator.js` stamps `metadata.claimFlow` from it (WRITE side); `services/agentPromptBuilder.js` reads it back through `isClaimFlowTask()` to pick a run's claim posture (READ side). It lived as two byte-identical copies, so a new claim type added to one silently split the writer from the reader — no error, just a claim run treated as a plain commit-only handoff; `claimFlowTaskTypes.test.js` fails if a local copy reappears. Imports nothing. |
| `chiptuneRender.js` | Deterministic chiptune score → mono PCM → 16-bit WAV buffer (pure Node, no audio deps); `renderScoreToPcm` / `pcmToWavBuffer` / `renderScoreToWav`. |
| `chiptuneScore.js` | Chiptune score contract (#2911): `chiptuneScoreSchema` (Zod) + `sanitizeChiptuneScore`, pitch math (`pitchToMidi`/`midiToFreq`), and `buildScoreEvents` — the pattern/order → absolute-time flatten mirrored by `client/src/lib/chiptunePlayback.js`. |
| `civitai.js` | Civitai URL parsing + API client. |
diff --git a/server/lib/claimFlowTaskTypes.js b/server/lib/claimFlowTaskTypes.js
new file mode 100644
index 0000000000..5307807d10
--- /dev/null
+++ b/server/lib/claimFlowTaskTypes.js
@@ -0,0 +1,20 @@
+// The task kinds whose prompts own their own claim/<item> worktree and
+// push/PR/MR/review lifecycle, declared ONCE for both sides of the contract:
+//
+// - WRITE side (`services/cosTaskGenerator.js`) stamps `metadata.claimFlow`
+// on a queued task.
+// - READ side (`services/agentPromptBuilder.js` → `isClaimFlowTask`) decides
+// a run's claim posture (prompt shape, `configClaimFlow`,
+// `configCodingOnMain`).
+//
+// A type added to one copy and not the other used to split the writer from the
+// reader silently — no error, just a claim run treated as a plain commit-only
+// handoff (#6613). The list is also the backstop for schedules queued before
+// the explicit `claimFlow` marker existed, which carry their kind only in
+// `metadata.analysisType`.
+//
+// Pure leaf: this module imports NOTHING. `server/lib/` is reached by ~400
+// suites, so keep it that way.
+export const CLAIM_FLOW_TASK_TYPES = new Set([
+ 'plan-task', 'claim-issue', 'claim-issue-gitlab', 'claim-issue-jira', 'claim-work'
+]);
diff --git a/server/lib/claimFlowTaskTypes.test.js b/server/lib/claimFlowTaskTypes.test.js
new file mode 100644
index 0000000000..bdcaccaf04
--- /dev/null
+++ b/server/lib/claimFlowTaskTypes.test.js
@@ -0,0 +1,70 @@
+import { describe, it, expect } from 'vitest';
+import { readFileSync, readdirSync, statSync } from 'fs';
+import { join, dirname, relative } from 'path';
+import { fileURLToPath } from 'url';
+
+import { CLAIM_FLOW_TASK_TYPES } from './claimFlowTaskTypes.js';
+import { isClaimFlowTask } from '../services/agentPromptBuilder.js';
+
+const LIB_DIR = dirname(fileURLToPath(import.meta.url));
+const SERVER_DIR = join(LIB_DIR, '..');
+const OWNING_MODULE = join(LIB_DIR, 'claimFlowTaskTypes.js');
+
+// A LOCAL binding of the name — `const`/`let`/`var CLAIM_FLOW_TASK_TYPES = …`.
+// An `import { CLAIM_FLOW_TASK_TYPES } from …` line binds the same name but is
+// exactly what this issue asks for, so it must NOT match (probed below).
+const LOCAL_DECLARATION = /(?:^|[;{}\n])\s*(?:const|let|var)\s+CLAIM_FLOW_TASK_TYPES\s*=/;
+
+const SKIP_DIRS = new Set(['node_modules', '.git', 'coverage', 'dist', 'build']);
+
+function collectSourceFiles(dir, out = []) {
+ for (const entry of readdirSync(dir)) {
+ if (SKIP_DIRS.has(entry)) continue;
+ const full = join(dir, entry);
+ if (statSync(full).isDirectory()) collectSourceFiles(full, out);
+ else if (/\.(js|mjs|jsx)$/.test(entry) && !full.endsWith('.test.js')) out.push(full);
+ }
+ return out;
+}
+
+describe('CLAIM_FLOW_TASK_TYPES is declared exactly once', () => {
+ it('detects a re-declaration and ignores an import of the same name', () => {
+ // Bypass probe: without this, a detector that silently matched nothing
+ // would pass every assertion below while guarding nothing.
+ expect(LOCAL_DECLARATION.test("const CLAIM_FLOW_TASK_TYPES = new Set(['plan-task']);")).toBe(true);
+ expect(LOCAL_DECLARATION.test('import foo from "x";\nlet CLAIM_FLOW_TASK_TYPES = [];')).toBe(true);
+ expect(LOCAL_DECLARATION.test("import { CLAIM_FLOW_TASK_TYPES } from '../lib/claimFlowTaskTypes.js';")).toBe(false);
+ });
+
+ it('has no second declaration anywhere under server/', () => {
+ const offenders = collectSourceFiles(SERVER_DIR)
+ .filter(file => file !== OWNING_MODULE)
+ .filter(file => LOCAL_DECLARATION.test(readFileSync(file, 'utf8')))
+ .map(file => relative(SERVER_DIR, file));
+ expect(offenders).toEqual([]);
+ });
+
+ it.each([
+ ['services/agentPromptBuilder.js', 'reads the set back via isClaimFlowTask()'],
+ ['services/cosTaskGenerator.js', 'stamps metadata.claimFlow from the set'],
+ ])('%s imports the shared set (%s)', (relPath) => {
+ const source = readFileSync(join(SERVER_DIR, relPath), 'utf8');
+ expect(source).toMatch(/import\s*\{[^}]*\bCLAIM_FLOW_TASK_TYPES\b[^}]*\}\s*from\s*'\.\.\/lib\/claimFlowTaskTypes\.js'/);
+ expect(LOCAL_DECLARATION.test(source)).toBe(false);
+ });
+});
+
+describe('the shared set drives the read side', () => {
+ it('lists the claim-owned task kinds', () => {
+ expect([...CLAIM_FLOW_TASK_TYPES].sort()).toEqual(
+ ['claim-issue', 'claim-issue-gitlab', 'claim-issue-jira', 'claim-work', 'plan-task']
+ );
+ });
+
+ it('treats every member as a claim-flow run via its legacy analysisType', () => {
+ for (const analysisType of CLAIM_FLOW_TASK_TYPES) {
+ expect(isClaimFlowTask({ metadata: { analysisType } })).toBe(true);
+ }
+ expect(isClaimFlowTask({ metadata: { analysisType: 'ux' } })).toBe(false);
+ });
+});
diff --git a/server/lib/index.js b/server/lib/index.js
index 96cd4daec4..b3cbfb755f 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -399,6 +399,7 @@ export * from './appIdentity.js';
export * from './appResolver.js';
export * from './autonomousJobIntervals.js';
export * from './capabilityMap.js';
+export * from './claimFlowTaskTypes.js';
export * from './chiptuneRender.js';
export * from './chiptuneScore.js';
export * from './civitai.js';
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index eac24ed4da..b095a5d733 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -20,6 +20,8 @@ import { doneSentinelName } from '../lib/agentSentinel.js';
import { canTypeSlashCommands, SLASHDO_INLINE_BUDGET_CHARS } from '../lib/slashdoInvocation.js';
import { TASK_CONTEXT_KEY, taskContextBlock } from '../lib/cosTaskPrompt.js';
import { PR_COMPLETIONS, leavesPrForHuman, resolvePrCompletion } from '../lib/prDisposition.js';
+// Shared with cosTaskGenerator.js, which stamps the same set as metadata.claimFlow.
+import { CLAIM_FLOW_TASK_TYPES } from '../lib/claimFlowTaskTypes.js';
import { PORTOS_APP_ID } from './apps.js';
import { getCodeReviewDefaults } from './codeReview.js';
import { LIGHT_CONTEXT_PROVIDER_TYPES, SIMPLIFY_INLINE_REVIEW } from './promptSections/constants.js';
@@ -76,13 +78,6 @@ export { createJiraTicketForTask, generateJiraTitle, getAppDataForTask, getAppWo
const AGENTS_DIR = PATHS.cosAgents;
-// Scheduled claim tasks created before the explicit marker was introduced still
-// carry their task kind in analysisType. Keep those persisted queue records on
-// the claim-owned lifecycle while new/manual tasks use the explicit marker.
-const CLAIM_FLOW_TASK_TYPES = new Set([
- 'plan-task', 'claim-issue', 'claim-issue-gitlab', 'claim-issue-jira', 'claim-work'
-]);
-
// These scheduled audits inspect a running web UI. Keep their runtime contract
// in the builder rather than only in the default prompt bodies so customized
// prompts and tasks queued before a prompt revision get the same guidance.
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index fadb33fab3..cceb6356e3 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -62,6 +62,10 @@ import {
FILE_ISSUES_DELIVERY_SETTINGS,
} from '../lib/auditCatalog.js';
import { TIMED_COOLDOWN_BLOCKED_CATEGORIES } from '../lib/taskBlockCategories.js';
+// The claim marker this stamps is separate from `openPR: false`, which is the
+// CoS provisioning posture that prevents a nested worktree. agentPromptBuilder.js
+// reads the same set back via isClaimFlowTask().
+import { CLAIM_FLOW_TASK_TYPES } from '../lib/claimFlowTaskTypes.js';
import { ServerError } from '../lib/errorHandler.js';
import { isReconcileDrainTaskType } from './taskScheduleConstants.js';
import { isProgrammaticScheduledTaskType, requiresInstallWideTarget } from './taskScheduleRegistry.js';
@@ -115,14 +119,6 @@ export {
// security preflight moved beside the rest of that pipeline's contract.
export { buildSecurityScanPipelineOutput } from './prReviewerPipeline.js';
-// Claim prompts create and manage their own claim/<item> worktree and
-// push/PR/MR/review lifecycle. This marker is separate from `openPR: false`,
-// which is the CoS provisioning posture that prevents a nested worktree. Keep
-// the type list here as a backstop for old schedules that predate claimFlow.
-const CLAIM_FLOW_TASK_TYPES = new Set([
- 'plan-task', 'claim-issue', 'claim-issue-gitlab', 'claim-issue-jira', 'claim-work'
-]);
-
/**
* Block a task that has exceeded the max spawn limit. Returns true if blocked.
*/