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): re-read the replacement PR when a proposal is re-linked

[._.]/ Adam Eivy725593accbf7
diff --git a/server/services/layeredIntelligenceOutcomes.js b/server/services/layeredIntelligenceOutcomes.js
index cb2c1ca297..cff77a3f5b 100644
--- a/server/services/layeredIntelligenceOutcomes.js
+++ b/server/services/layeredIntelligenceOutcomes.js
@@ -380,14 +380,17 @@ export async function reconcileOutcomes({ appId, existingIssues = [], now = Date
// label / specific close-reason / prose rationale already wins and skips the read.
const implementingPr = Number.isInteger(issue.implementingPr) && issue.implementingPr > 0 ? issue.implementingPr : null;
if (implementingPr && cli && isPrRefinableReason(rejectionReason)) {
- if (isPrFailureReason(r.rejectionReason)) {
- // Already diagnosed from THIS PR on a prior tick, and the free signals still
- // don't supersede it — a new authoritative label/close-reason would have made
- // the free classification specific (not refinable), taking the branch above.
- // Keep the settled diagnosis instead of re-spawning `gh pr view` on every tick
- // for the record's whole 30-day retention (codex P2). Preserving it here (rather
- // than just skipping the fetch) also stops the write-guard below from downgrading
- // the stored PR token back to the generic free reason.
+ if (isPrFailureReason(r.rejectionReason) && r.implementingPr === implementingPr) {
+ // Already diagnosed from THIS SAME PR on a prior tick, and the free signals
+ // still don't supersede it — a new authoritative label/close-reason would have
+ // made the free classification specific (not refinable), taking the branch
+ // above. Keep the settled diagnosis instead of re-spawning `gh pr view` on every
+ // tick for the record's whole 30-day retention (codex P2). Preserving it here
+ // (rather than just skipping the fetch) also stops the write-guard below from
+ // downgrading the stored PR token back to the generic free reason. The PR-number
+ // match is required: if the issue was RE-LINKED to a different implementing PR
+ // (`r.implementingPr !== implementingPr`), the old diagnosis no longer applies —
+ // fall through and read the replacement PR (codex P2, follow-up).
rejectionReason = r.rejectionReason;
} else {
const prView = await readPrState({ cli, cwd, env, number: implementingPr }).catch(() => null);
diff --git a/server/services/layeredIntelligenceOutcomes.test.js b/server/services/layeredIntelligenceOutcomes.test.js
index 8e437b02ff..6effbb9ba5 100644
--- a/server/services/layeredIntelligenceOutcomes.test.js
+++ b/server/services/layeredIntelligenceOutcomes.test.js
@@ -567,6 +567,30 @@ describe('reconcileOutcomes', () => {
expect((await rowsBySlug())['settled'].rejectionReason).toBe('validation-failed');
});
+ it('re-reads the replacement PR when the issue is re-linked to a different PR (codex P2 follow-up)', async () => {
+ await recordFiledProposal({ appId: 'app-1', slug: 'relinked' }, store);
+ // Settle on PR 920 as merge-conflict.
+ const readA = vi.fn().mockResolvedValue({ state: 'OPEN', mergeStateStatus: 'DIRTY' });
+ await reconcileOutcomes({
+ appId: 'app-1', cli: 'gh', readPrState: readA,
+ existingIssues: [{ slug: 'relinked', state: 'closed', stateReason: 'not_planned', implementingPr: 920, closedAt: '2026-07-01T00:00:00Z' }]
+ }, store);
+ expect((await rowsBySlug())['relinked'].rejectionReason).toBe('merge-conflict');
+
+ // Re-linked to PR 921 (CI-failed): the stale merge-conflict must NOT be inherited —
+ // the new PR is read and re-diagnosed, and the stored ref advances.
+ const readB = vi.fn().mockResolvedValue({ state: 'CLOSED', statusCheckRollup: [{ conclusion: 'FAILURE' }] });
+ const updated = await reconcileOutcomes({
+ appId: 'app-1', cli: 'gh', readPrState: readB,
+ existingIssues: [{ slug: 'relinked', state: 'closed', stateReason: 'not_planned', implementingPr: 921, closedAt: '2026-07-01T00:00:00Z' }]
+ }, store);
+ expect(readB).toHaveBeenCalledWith({ cli: 'gh', cwd: null, env: undefined, number: 921 });
+ expect(updated).toBe(1);
+ const row = (await rowsBySlug())['relinked'];
+ expect(row.rejectionReason).toBe('validation-failed');
+ expect(row.implementingPr).toBe(921);
+ });
+
it('lets a newly-added authoritative label supersede a settled PR-failure token', async () => {
await recordFiledProposal({ appId: 'app-1', slug: 'relabelled' }, store);
const firstRead = vi.fn().mockResolvedValue({ state: 'OPEN', mergeStateStatus: 'DIRTY' });