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: harden perpetual claim convergence

[._.]/ Adam Eivyd0a8dfa525f1
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index c6afb1ae93..5e76b652ae 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -2336,9 +2336,12 @@ async function applyPerpetualWorkGate(app, taskType, promptTaskType, metadata, i
// 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 drainSignature = detection.signature == null
+ ? null
+ : JSON.stringify({ taskType: promptTaskType, candidates: detection.signature });
+ if (drainSignature != null) {
const { signature: lastSignature } = await taskSchedule.getPerpetualDrainState(taskType, app.id);
- if (shouldParkUnchangedPerpetualWork(detection, lastSignature)) {
+ if (shouldParkUnchangedPerpetualWork({ ...detection, signature: drainSignature }, lastSignature)) {
const counts = detection.total != null
? { open: detection.total, inFlight: detection.inFlightCount ?? 0, filtered: detection.filteredCount ?? 0 }
: null;
@@ -2356,7 +2359,7 @@ async function applyPerpetualWorkGate(app, taskType, promptTaskType, metadata, i
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, signature: detection.signature ?? null };
+ return { skip: false, spendDispatch: true, signature: drainSignature };
}
if (detection.transient) {
emitLog('debug', `Perpetual ${taskType} skip for ${app.name} (transient: ${detection.reason})`, { appId: app.id });
@@ -2378,7 +2381,7 @@ async function applyPerpetualWorkGate(app, taskType, promptTaskType, metadata, i
: null;
// Terminal park — parkPerpetual zeroes the dispatch budget in the same write, so
// the next drain window starts fresh instead of capping early on this one's spend.
- await taskSchedule.parkPerpetual(taskType, app.id, { reason: detection.reason, actionableCount: detection.count, counts });
+ await taskSchedule.parkPerpetual(taskType, app.id, { reason: detection.reason, actionableCount: detection.count, counts, signature: null });
emitLog('info', `Perpetual ${taskType} parked for ${app.name}: ${detection.reason}`, { appId: app.id });
return { skip: true };
}
diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.js
index ca6267b3a7..63d4e9d39c 100644
--- a/server/services/cosTaskGenerator.test.js
+++ b/server/services/cosTaskGenerator.test.js
@@ -102,6 +102,13 @@ describe('claim drain convergence', () => {
expect(shouldParkUnchangedPerpetualWork({ actionable: true }, '[101,202]')).toBe(false);
expect(shouldParkUnchangedPerpetualWork({ actionable: false, signature: '[]' }, '[]')).toBe(false);
});
+
+ it('does not confuse tracker-specific signatures', () => {
+ expect(shouldParkUnchangedPerpetualWork(
+ { actionable: true, signature: '{"taskType":"claim-issue-gitlab","candidates":"[1]"}' },
+ '{"taskType":"claim-issue","candidates":"[1]"}'
+ )).toBe(false);
+ });
});
describe('claim reviewer resolution', () => {
diff --git a/server/services/perpetualWork.js b/server/services/perpetualWork.js
index 713eddf63a..29bb84c6e2 100644
--- a/server/services/perpetualWork.js
+++ b/server/services/perpetualWork.js
@@ -307,9 +307,17 @@ const normalizeIssues = (raw, numberKey, authorKey) => raw.map((r) => ({
title: r.title,
labels: r.labels,
assignees: r.assignees,
- authorLogin: (r.author?.[authorKey] || '').toLowerCase()
+ authorLogin: (r.author?.[authorKey] || '').toLowerCase(),
+ updatedAt: r.updatedAt || r.updated_at || null
}));
+// A forge can return the same candidate set in a different order, especially
+// after the collaborators author fan-out. Keep picker order untouched, but use
+// a canonical representation for the perpetual drain's set comparison.
+const canonicalizeIds = (ids) => [...new Set(ids
+ .filter((id) => id != null)
+ .map((id) => String(id)))].sort();
+
const GLAB_SELF_LOGIN_ARGS = ['api', 'user', '-q', '.username'];
// Upper bound on the `--author <login>` queries the `collaborators` gate fans
@@ -343,7 +351,7 @@ const FORGE_ISSUE_CONFIG = {
// happens to be full of excluded/in-flight/decomposed-epic issues even
// though real work exists further down the queue. Matches the same
// tradeoff the /do:next auto-pick walk already makes for the same reason.
- listArgs: ['issue', 'list', '--state', 'open', '--search', 'sort:created-asc', '--json', 'number,assignees,labels,title,author', '--limit', '500'],
+ listArgs: ['issue', 'list', '--state', 'open', '--search', 'sort:created-asc', '--json', 'number,assignees,labels,title,author,updatedAt', '--limit', '500'],
listFail: 'gh-list-failed',
parseFail: 'gh-parse-failed',
// Park reason when the owner filter resolves to a non-authoring owner. On
@@ -655,7 +663,11 @@ async function detectForgeIssues(forgeKey, app, { issueAuthorFilter = 'self', is
// 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)),
+ // updatedAt changes when the claim flow posts a partial-delivery comment
+ // or releases its markers, so a same-issue continuation remains eligible.
+ // The ID is retained as the primary identity for forge responses that omit
+ // the timestamp (and for older test/mocked CLI output).
+ signature: JSON.stringify(canonicalizeIds(actionable.map((i) => `${i.number}@${i.updatedAt || ''}`))),
items: actionable.slice(0, WORK_ITEM_LIMIT).map((i) => ({ ref: String(i.number), title: i.title || '' }))
};
}
@@ -697,7 +709,7 @@ export async function detectPlanTask(app) {
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)),
+ signature: JSON.stringify(canonicalizeIds(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 466dd3ee1e..097ec00598 100644
--- a/server/services/perpetualWork.test.js
+++ b/server/services/perpetualWork.test.js
@@ -250,7 +250,7 @@ describe('perpetualWork', () => {
{ ref: '1', title: 'plain' },
{ ref: '5', title: 'also plain' }
]);
- expect(out.signature).toBe('[1,5]');
+ expect(out.signature).toBe('["1@","5@"]');
});
it('reports the "[Epic]"-prefixed issue as actionable while it is still undecomposed', async () => {
@@ -269,10 +269,25 @@ 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.signature).toBe('["1@"]');
expect(out.filteredCount).toBe(2);
});
+ it('canonicalizes candidate order and keeps forge updates in the signature', async () => {
+ routeSpawn({
+ 'gh issue': { stdout: JSON.stringify([
+ { number: 10, title: 'later', updatedAt: '2026-08-27T02:00:00Z', assignees: [], labels: [] },
+ { number: 2, title: 'first', updatedAt: '2026-08-27T01:00:00Z', assignees: [], labels: [] },
+ { number: 10, title: 'duplicate', updatedAt: '2026-08-27T02:00:00Z', assignees: [], labels: [] }
+ ]) },
+ 'git branch': { stdout: 'main\n' },
+ 'gh pr': { stdout: '' }
+ });
+ const out = await detectGithubIssues(app, { issueAuthorFilter: 'any' });
+ expect(out.sample).toEqual([10, 2, 10]);
+ expect(out.signature).toBe('["10@2026-08-27T02:00:00Z","2@2026-08-27T01:00:00Z"]');
+ });
+
it('converges (0 actionable) once that epic carries the decomposed label', async () => {
// The convergence marker: the claim agent stamps `decomposed` on an epic
// after filing its slices, so the drain stops re-picking the parent and