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: park claim drains after no progress

[._.]/ Adam Eivy4bd087779099
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index 95da1de1e9..c6afb1ae93 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -147,6 +147,20 @@ export function isCooldownExemptTask(task) {
|| Boolean(meta.quotaBurnFamily);
}
+/**
+ * A claim/plan perpetual drain must stop when a completed agent leaves the
+ * complete actionable set unchanged. A null signature means the detector has
+ * no progress identity and keeps the legacy behavior; an empty signature is a
+ * valid idle result but never reaches this predicate because `actionable` is
+ * false.
+ */
+export function shouldParkUnchangedPerpetualWork(detection, lastSignature) {
+ return detection?.actionable === true
+ && detection.signature != null
+ && lastSignature != null
+ && detection.signature === lastSignature;
+}
+
/**
* Dry-run eligibility pass over auto-approved system tasks. Walks the tasks in
* file order applying the SAME gates execute mode uses — global slot cap,
@@ -2289,10 +2303,11 @@ async function resolveClaimWorkRouting(app, taskType, metadata, taskSchedule) {
* IS the detector — a programmatic detector decides whether there's anything to
* claim BEFORE building the (expensive) prompt or burning an agent:
* - actionable → stamp metadata.perpetual (skip cooldown), proceed;
+ * - unchanged actionable set → PARK after a successful no-progress run;
* - idle (definitive) → PARK on the recheck cadence, skip;
* - transient probe failure → skip WITHOUT parking so the next tick retries.
- * The detector keys on the RESOLVED promptTaskType. Returns `{ skip, spendDispatch }`
- * and mutates `metadata.perpetual` on the actionable path.
+ * The detector keys on the RESOLVED promptTaskType. Returns `{ skip, spendDispatch,
+ * signature }` and mutates `metadata.perpetual` on the actionable path.
*
* `spendDispatch` is the caller's cue to call `recordPerpetualDispatch` (which
* clears the park and spends one unit of the type's `drainDispatchCap` budget in a
@@ -2316,11 +2331,32 @@ async function applyPerpetualWorkGate(app, taskType, promptTaskType, metadata, i
ignoreTaskId
});
if (detection.actionable) {
+ // A successful claim/plan agent can still return without changing forge or
+ // PLAN state (for example, it decides not to pick the advertised item). The
+ // completion refill would otherwise dispatch the same candidate forever.
+ // The detector's signature covers the complete set; `items` is capped for
+ // the picker and is not sufficient for convergence.
+ if (detection.signature != null) {
+ const { signature: lastSignature } = await taskSchedule.getPerpetualDrainState(taskType, app.id);
+ if (shouldParkUnchangedPerpetualWork(detection, lastSignature)) {
+ const counts = detection.total != null
+ ? { open: detection.total, inFlight: detection.inFlightCount ?? 0, filtered: detection.filteredCount ?? 0 }
+ : null;
+ await taskSchedule.parkPerpetual(taskType, app.id, {
+ reason: 'no-progress',
+ actionableCount: detection.count,
+ counts,
+ signature: null
+ });
+ emitLog('info', `Perpetual ${taskType} parked for ${app.name}: actionable work unchanged after the last run`, { appId: app.id });
+ return { skip: true };
+ }
+ }
recordPerpetualTransient(taskType, app.id, null);
metadata.perpetual = true;
// The dispatch is SPENT BY THE CALLER, once a task is certain — see the note
// on `spendDispatch` in the JSDoc above.
- return { skip: false, spendDispatch: true };
+ return { skip: false, spendDispatch: true, signature: detection.signature ?? null };
}
if (detection.transient) {
emitLog('debug', `Perpetual ${taskType} skip for ${app.name} (transient: ${detection.reason})`, { appId: app.id });
@@ -3173,7 +3209,9 @@ export async function generateManagedAppImprovementTaskForType(taskType, app, st
// The reconcile drains spend theirs inside their own block, which no later gate
// can skip (their types are outside PLAN_PICK_TASK_TYPES / pr-watcher /
// reference-watch), so they are already charged only on real dispatches.
- if (perpetualGate.spendDispatch) await taskSchedule.recordPerpetualDispatch(taskType, app.id, null);
+ if (perpetualGate.spendDispatch) {
+ await taskSchedule.recordPerpetualDispatch(taskType, app.id, perpetualGate.signature ?? null);
+ }
await updateAppActivity(app.id, { lastImprovementType: taskType });
emitLog('info', `Generating improvement task for ${app.name}: ${taskType}`, { appId: app.id, analysisType: taskType });
diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.js
index fbc5bff4cb..ca6267b3a7 100644
--- a/server/services/cosTaskGenerator.test.js
+++ b/server/services/cosTaskGenerator.test.js
@@ -59,6 +59,7 @@ vi.mock('./github.js', async (importActual) => ({
import {
selectDryRunAutoApproved,
exceedsMaxSpawns,
+ shouldParkUnchangedPerpetualWork,
resolveIssueAuthorFilterBlock,
resolveIssueExcludeLabelsBlock,
resolveSwarmBlock,
@@ -90,6 +91,19 @@ const COS_SRC = readFileSync(join(__dirname, 'cos.js'), 'utf-8');
const task = (id, metadata = {}) => ({ id, metadata });
const noCooldown = () => Promise.resolve(false);
+describe('claim drain convergence', () => {
+ it('parks a successful no-progress run when the actionable set is unchanged', () => {
+ const detection = { actionable: true, signature: '[101,202]' };
+ expect(shouldParkUnchangedPerpetualWork(detection, '[101,202]')).toBe(true);
+ });
+
+ it('continues when the candidate set changed or has no progress identity', () => {
+ expect(shouldParkUnchangedPerpetualWork({ actionable: true, signature: '[202]' }, '[101,202]')).toBe(false);
+ expect(shouldParkUnchangedPerpetualWork({ actionable: true }, '[101,202]')).toBe(false);
+ expect(shouldParkUnchangedPerpetualWork({ actionable: false, signature: '[]' }, '[]')).toBe(false);
+ });
+});
+
describe('claim reviewer resolution', () => {
// The claim prompts run their local reviewers BEFORE the PR/MR is opened, so
// the diff has to come from the branch. A forge command (`gh pr diff` /
@@ -1623,7 +1637,7 @@ describe('the drain cap has exactly one implementation, at the choke point', ()
const genStart = GEN_SRC.indexOf('export async function generateManagedAppImprovementTaskForType');
const body = GEN_SRC.slice(genStart, GEN_SRC.indexOf('return task;', genStart));
- const spendIdx = body.indexOf('if (perpetualGate.spendDispatch) await taskSchedule.recordPerpetualDispatch(taskType, app.id, null)');
+ const spendIdx = body.search(/if \(perpetualGate\.spendDispatch\) \{\s*await taskSchedule\.recordPerpetualDispatch\(taskType, app\.id, perpetualGate\.signature \?\? null\)/);
expect(spendIdx, 'the choke point must spend the deferred dispatch').toBeGreaterThan(-1);
// Every `return null` gate must precede it — planId is the last one.
expect(body.indexOf('planMeta.skipReason')).toBeLessThan(spendIdx);
diff --git a/server/services/perpetualWork.js b/server/services/perpetualWork.js
index 53ac0e3f9a..713eddf63a 100644
--- a/server/services/perpetualWork.js
+++ b/server/services/perpetualWork.js
@@ -652,6 +652,10 @@ async function detectForgeIssues(forgeKey, app, { issueAuthorFilter = 'self', is
filteredCount,
reason: actionable.length > 0 ? 'actionable-issues' : 'no-actionable-issues',
sample: actionable.slice(0, 5).map((i) => i.number),
+ // The perpetual drain uses the complete candidate set to detect a
+ // successful agent that exited without claiming anything. `sample` is
+ // intentionally capped for UI payloads, so it cannot serve as that brake.
+ signature: JSON.stringify(actionable.map((i) => i.number)),
items: actionable.slice(0, WORK_ITEM_LIMIT).map((i) => ({ ref: String(i.number), title: i.title || '' }))
};
}
@@ -692,6 +696,8 @@ export async function detectPlanTask(app) {
actionable: !!pick,
count: available.length,
reason: pick ? 'actionable-plan-items' : 'no-actionable-plan-items',
+ // Keep the signature complete even though the picker payload is capped.
+ signature: JSON.stringify(available.map((it) => it.id)),
items: available.slice(0, WORK_ITEM_LIMIT).map((it) => ({ ref: it.id, title: planItemTitle(it) }))
};
}
diff --git a/server/services/perpetualWork.test.js b/server/services/perpetualWork.test.js
index c3ed3281b1..466dd3ee1e 100644
--- a/server/services/perpetualWork.test.js
+++ b/server/services/perpetualWork.test.js
@@ -250,6 +250,7 @@ describe('perpetualWork', () => {
{ ref: '1', title: 'plain' },
{ ref: '5', title: 'also plain' }
]);
+ expect(out.signature).toBe('[1,5]');
});
it('reports the "[Epic]"-prefixed issue as actionable while it is still undecomposed', async () => {
@@ -268,6 +269,7 @@ describe('perpetualWork', () => {
});
const out = await detectGithubIssues(app, { issueAuthorFilter: 'any' });
expect(out).toMatchObject({ actionable: true, count: 1, reason: 'actionable-issues', sample: [1] });
+ expect(out.signature).toBe('[1]');
expect(out.filteredCount).toBe(2);
});