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): reconcile self-heals outcomes persisted under the old any-close-is-merged mapping

[._.]/ Adam Eivye745ed98f05a
diff --git a/server/services/layeredIntelligenceOutcomes.js b/server/services/layeredIntelligenceOutcomes.js
index 7a0966c87d..3932ca2fe0 100644
--- a/server/services/layeredIntelligenceOutcomes.js
+++ b/server/services/layeredIntelligenceOutcomes.js
@@ -151,12 +151,17 @@ export async function listOutcomes({ appId, now = Date.now() } = {}, store = out
}
/**
- * Reconcile still-unresolved outcome records against a FRESH tracker read. For
- * each stored record whose outcome is null, find the matching existing issue (by
- * slug) and, when the tracker now reports it closed, persist the derived outcome
- * (`merged` / `rejected` / `abandoned`). Open issues stay unresolved. 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.
+ * Reconcile outcome records against a FRESH tracker read. For each stored record,
+ * find the matching existing issue (by slug) and, when the tracker now reports it
+ * closed, persist the derived outcome (`merged` / `rejected` / `abandoned`). Open
+ * issues never resolve — or flip back — a record. A record whose stored outcome
+ * DIFFERS from what the live closed state derives is reclassified (#2620): this
+ * 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.
*/
export async function reconcileOutcomes({ appId, existingIssues = [], now = Date.now() } = {}, store = outcomesStore()) {
if (!appId || !Array.isArray(existingIssues) || existingIssues.length === 0) return 0;
@@ -169,15 +174,14 @@ export async function reconcileOutcomes({ appId, existingIssues = [], now = Date
const records = await listOutcomes({ appId, now }, store);
let updated = 0;
for (const r of records) {
- if (r.outcome) continue;
const issue = bySlug.get(r.slug);
if (!issue) continue;
const outcome = deriveOutcome(issue);
- if (!outcome) continue;
+ if (!outcome || outcome === r.outcome) continue;
const next = {
...r,
outcome,
- outcomeAt: issue.closedAt || new Date(now).toISOString(),
+ outcomeAt: issue.closedAt || r.outcomeAt || new Date(now).toISOString(),
outcomeReason: issue.stateReason || 'auto-derived from tracker state'
};
const ok = await store.saveOne(outcomeId(appId, r.slug), next).then(() => true, () => false);
diff --git a/server/services/layeredIntelligenceOutcomes.test.js b/server/services/layeredIntelligenceOutcomes.test.js
index fcaa52a988..6682e25f90 100644
--- a/server/services/layeredIntelligenceOutcomes.test.js
+++ b/server/services/layeredIntelligenceOutcomes.test.js
@@ -138,10 +138,33 @@ describe('reconcileOutcomes', () => {
// Second pass with the issue now reported open should NOT flip it back.
const updated = await reconcileOutcomes({ appId: 'app-1', existingIssues: [{ slug: 's', state: 'open' }] }, store);
expect(updated).toBe(0);
+ // And a pass with the SAME closed state is a no-op write.
+ const same = await reconcileOutcomes({ appId: 'app-1', existingIssues: [{ slug: 's', state: 'closed', stateReason: 'completed' }] }, store);
+ expect(same).toBe(0);
const rows = await listOutcomes({ appId: 'app-1' }, store);
expect(rows[0].outcome).toBe('merged');
});
+ 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
+ // live tracker state must self-heal it to `abandoned` instead of letting it
+ // inflate the merge rate until the record expires.
+ await recordFiledProposal({ appId: 'app-1', slug: 'legacy', scope: 'app-improvement' }, store);
+ const legacy = (await listOutcomes({ appId: 'app-1' }, store))[0];
+ await store.saveOne('app-1--legacy', {
+ ...legacy, outcome: 'merged', outcomeAt: '2026-07-01T00:00:00Z', outcomeReason: 'duplicate'
+ });
+ const updated = await reconcileOutcomes({
+ appId: 'app-1',
+ existingIssues: [{ slug: 'legacy', state: 'closed', stateReason: 'duplicate', closedAt: '2026-07-01T00:00:00Z' }]
+ }, store);
+ expect(updated).toBe(1);
+ const rows = await listOutcomes({ appId: 'app-1' }, store);
+ expect(rows[0].outcome).toBe('abandoned');
+ expect(rows[0].outcomeAt).toBe('2026-07-01T00:00:00Z');
+ });
+
it('is a no-op with no existing issues', async () => {
await recordFiledProposal({ appId: 'app-1', slug: 's', scope: 'app-improvement' }, store);
expect(await reconcileOutcomes({ appId: 'app-1', existingIssues: [] }, store)).toBe(0);