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): refresh outcomeAt when a proposal re-closes to the same outcome

[._.]/ Adam Eivy4781a543e72f
diff --git a/server/services/layeredIntelligenceOutcomes.js b/server/services/layeredIntelligenceOutcomes.js
index 3932ca2fe0..396486df03 100644
--- a/server/services/layeredIntelligenceOutcomes.js
+++ b/server/services/layeredIntelligenceOutcomes.js
@@ -159,9 +159,11 @@ export async function listOutcomes({ appId, now = Date.now() } = {}, store = out
* self-heals records persisted under the old any-close-is-merged mapping (e.g.
* `merged` with a duplicate-close reason) instead of letting them inflate the
* merge rate until they expire, and it tracks a reopened-then-re-closed issue's
- * latest fate. Returns the number of records updated. Never throws — a
- * per-record write failure is swallowed so one bad row can't abort the whole
- * reconciliation.
+ * latest fate. A re-close to the SAME outcome with a newer `closedAt` also
+ * refreshes the record, so retention/GC (which keys on `outcomeAt`) measures
+ * from the latest closure, not the first. Returns the number of records
+ * updated. Never throws — a per-record write failure is swallowed so one bad
+ * row can't abort the whole reconciliation.
*/
export async function reconcileOutcomes({ appId, existingIssues = [], now = Date.now() } = {}, store = outcomesStore()) {
if (!appId || !Array.isArray(existingIssues) || existingIssues.length === 0) return 0;
@@ -177,7 +179,15 @@ export async function reconcileOutcomes({ appId, existingIssues = [], now = Date
const issue = bySlug.get(r.slug);
if (!issue) continue;
const outcome = deriveOutcome(issue);
- if (!outcome || outcome === r.outcome) continue;
+ if (!outcome) continue;
+ // A same-outcome record is only rewritten when the tracker reports a NEWER
+ // close time (closed → reopened → re-closed): outcomeAt drives retention/GC,
+ // so it must track the latest closure. Timestampless trackers (plan) and an
+ // unchanged closedAt skip the write — no churn on every reconcile.
+ const closedMs = Date.parse(issue.closedAt);
+ const storedMs = Date.parse(r.outcomeAt);
+ const newerClose = Number.isFinite(closedMs) && (!Number.isFinite(storedMs) || closedMs > storedMs);
+ if (outcome === r.outcome && !newerClose) continue;
const next = {
...r,
outcome,
diff --git a/server/services/layeredIntelligenceOutcomes.test.js b/server/services/layeredIntelligenceOutcomes.test.js
index 6682e25f90..058ebb20d5 100644
--- a/server/services/layeredIntelligenceOutcomes.test.js
+++ b/server/services/layeredIntelligenceOutcomes.test.js
@@ -145,6 +145,24 @@ describe('reconcileOutcomes', () => {
expect(rows[0].outcome).toBe('merged');
});
+ it('refreshes outcomeAt when a proposal re-closes to the same outcome with a newer close time (#2620)', async () => {
+ // closed → reopened → re-closed completed: the derived outcome is unchanged,
+ // but retention/GC keys on outcomeAt, so it must advance to the latest close.
+ await recordFiledProposal({ appId: 'app-1', slug: 'recycled', scope: 'app-improvement' }, store);
+ await reconcileOutcomes({
+ appId: 'app-1',
+ existingIssues: [{ slug: 'recycled', state: 'closed', stateReason: 'completed', closedAt: '2026-07-01T00:00:00Z' }]
+ }, store);
+ const updated = await reconcileOutcomes({
+ appId: 'app-1',
+ existingIssues: [{ slug: 'recycled', state: 'closed', stateReason: 'completed', closedAt: '2026-07-10T00:00:00Z' }]
+ }, store);
+ expect(updated).toBe(1);
+ const rows = await listOutcomes({ appId: 'app-1' }, store);
+ expect(rows[0].outcome).toBe('merged');
+ expect(rows[0].outcomeAt).toBe('2026-07-10T00:00:00Z');
+ });
+
it('reclassifies a record persisted under the old any-close-is-merged mapping (#2620)', async () => {
// Simulate an install upgrading: a duplicate-closed issue was reconciled as
// `merged` by the pre-#2620 mapping. The next reconcile against the same