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

address review (codex): dedupe markAppReviewStarted in the dequeueNextTask on-demand loop too

[._.]/ Adam Eivyf25609260041
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 5321a503c4..1fa72cd3af 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -33,7 +33,7 @@
- **[mediacollections-deterministic-loadone-fastpath]** Universe/series media-collection lookups now resolve their linked bucket in one direct read instead of scanning every collection, trimming the work done on each cross-machine sync push (no user-facing change).
- **[data-versioning-centralize-cosagents-settings] Saving settings is now crash-safe and serialized.** `settings.json` is written through the shared atomic temp-file/rename writer and overlapping saves run one at a time, so a mid-write crash can no longer truncate the file and two near-simultaneous settings changes can no longer clobber each other (no user-facing change).
- **[setup-data-import-drift-tables-from-migrations]** The setup script's "a prompt migration is pending" warning now derives its hash tables directly from the migration files instead of a hand-maintained copy, so the warning can't silently fall out of sync when a new prompt migration ships (no user-facing change).
-- **[cos-on-demand-mark-app-review-started-dedupe]** When several on-demand improvement requests for the same app are processed in one CoS evaluation cycle, the app's activity record is now marked review-started once instead of once per request (no user-facing change).
+- **[cos-on-demand-mark-app-review-started-dedupe]** When several on-demand improvement requests for the same app are processed in one CoS dispatch cycle, the app's activity record is now marked review-started once instead of once per request (no user-facing change).
## Fixed
diff --git a/server/services/cos.js b/server/services/cos.js
index 748faef33c..bd538637c8 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -2551,6 +2551,9 @@ async function dequeueNextTask() {
const taskSchedule = await taskScheduleMod.loadSchedule();
const onDemandRequests = await taskScheduleMod.getOnDemandRequests();
+ // Track apps already marked review-started this cycle so multiple on-demand
+ // requests for the same app don't each rewrite its activity record.
+ const reviewStartedApps = new Set();
for (const request of onDemandRequests) {
if (spawned >= availableSlots) break;
@@ -2584,7 +2587,10 @@ async function dequeueNextTask() {
if (targetApp) {
emitLog('info', `Processing on-demand improvement: ${request.taskType} for ${targetApp.name}`, { requestId: request.id, appId: targetApp.id });
- await markAppReviewStarted(targetApp.id, `on-demand-${Date.now()}`);
+ if (!reviewStartedApps.has(targetApp.id)) {
+ await markAppReviewStarted(targetApp.id, `on-demand-${Date.now()}`);
+ reviewStartedApps.add(targetApp.id);
+ }
await taskScheduleMod.recordExecution(`task:${request.taskType}`, targetApp.id);
task = await generateManagedAppImprovementTaskForType(request.taskType, targetApp, state, { skipPreconditions: true });
} else {
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index 6fa86c5814..7780df564b 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -649,22 +649,25 @@ describe('cos.js source — priority + capacity invariants', () => {
expect(evalFn).toMatch(/tasksToSpawn\.length\s*===\s*0\s*&&\s*state\.config\.idleReviewEnabled/);
});
- it('on-demand loop dedupes markAppReviewStarted per app via reviewStartedApps set', () => {
+ it('both on-demand loops dedupe markAppReviewStarted per app via reviewStartedApps set', () => {
// Multiple on-demand requests targeting the same app should mark its
- // activity record review-started only once per evaluation cycle — without
- // the guard, each request rewrites the same record. Pin (a) the set is
- // declared and (b) markAppReviewStarted is gated on it.
- const fnStart = COS_SRC.indexOf('export async function evaluateTasks');
- const fnBody = extractFnBody(COS_SRC, fnStart);
-
- expect(
- fnBody,
- 'evaluateTasks must declare a reviewStartedApps set to dedupe per-app marks'
- ).toMatch(/const\s+reviewStartedApps\s*=\s*new\s+Set\(/);
- expect(
- fnBody,
- 'markAppReviewStarted must be gated on !reviewStartedApps.has(targetApp.id)'
- ).toMatch(/if\s*\(\s*!\s*reviewStartedApps\.has\(\s*targetApp\.id\s*\)\s*\)/);
+ // activity record review-started only once per cycle — without the guard,
+ // each request rewrites the same record. BOTH on-demand loops carry the
+ // duplication: the startup/manual `evaluateTasks` loop AND the
+ // event-driven `dequeueNextTask` loop (the common "Run Now" path). Pin
+ // (a) the set is declared and (b) markAppReviewStarted is gated on it in
+ // each.
+ for (const fnName of ['export async function evaluateTasks', 'async function dequeueNextTask']) {
+ const fnBody = extractFnBody(COS_SRC, COS_SRC.indexOf(fnName));
+ expect(
+ fnBody,
+ `${fnName} must declare a reviewStartedApps set to dedupe per-app marks`
+ ).toMatch(/const\s+reviewStartedApps\s*=\s*new\s+Set\(/);
+ expect(
+ fnBody,
+ `${fnName} must gate markAppReviewStarted on !reviewStartedApps.has(targetApp.id)`
+ ).toMatch(/if\s*\(\s*!\s*reviewStartedApps\.has\(\s*targetApp\.id\s*\)\s*\)/);
+ }
});
it('queueEligibleImprovementTasks routes through generateManagedAppImprovementTaskForType', () => {