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): infer undated for legacy plan records the reconcile no-op can never stamp

[._.]/ Adam Eivyafff3fd4bf10
diff --git a/server/services/layeredIntelligence/approvalFunnel.js b/server/services/layeredIntelligence/approvalFunnel.js
index 8028deab85..8cf6f228c5 100644
--- a/server/services/layeredIntelligence/approvalFunnel.js
+++ b/server/services/layeredIntelligence/approvalFunnel.js
@@ -32,7 +32,9 @@
* synthesizes one from the reconcile clock and marks it `outcomeAtSource: 'observed'`;
* this module treats such a record as UNDATED rather than as a decision made now, so a
* PLAN.md item checked off months ago but first reconciled today cannot inflate the
- * window cohort or report a latency the user never took.
+ * window cohort or report a latency the user never took. A `plan` record that predates
+ * the provenance field is inferred the same way from its `tracker` — see
+ * `hasAuthoritativeDecisionDate` for why that cannot be left to a backfill.
*
* SENTINEL DISCIPLINE throughout — a rate whose denominator is zero is `null`, never 0:
* "no decision has been made in this window" and "every decision was a rejection" are
@@ -69,6 +71,31 @@ const parsedMs = (value) => {
*/
const elapsedSince = (ms, now) => Math.max(0, now - ms);
+// Trackers that report NO close timestamp, so a resolved record's `outcomeAt` can only
+// ever have been synthesized from the reconcile clock. `plan` (PLAN.md checkboxes) is the
+// only one: `extractPlanSlugs` documents that a checked item carries no `closedAt`.
+const TIMESTAMPLESS_TRACKERS = ['plan'];
+
+/**
+ * Can this record's `outcomeAt` be read as WHEN THE HUMAN DECIDED?
+ *
+ * Only a tracker-reported close time can. Two ways a record fails that:
+ * - `outcomeAtSource === 'observed'` — reconcile explicitly stamped it as synthesized.
+ * - a `plan`-tracker record with NO provenance stamp — written before the field
+ * existed. These cannot be trusted the way a legacy forge/jira record can: forge and
+ * jira always report `closedAt`, so their legacy `outcomeAt` IS a real close time,
+ * but a `plan` record's never was. And they will not self-heal, because
+ * `reconcileOutcomes` no-ops on an already-settled record and so never reaches the
+ * provenance write — hence deriving it here at READ time rather than backfilling.
+ * Anything else (an explicit `'tracker'` stamp, or a legacy timestamped-tracker record)
+ * is authoritative.
+ */
+const hasAuthoritativeDecisionDate = (record) => {
+ if (record?.outcomeAtSource === 'observed') return false;
+ if (record?.outcomeAtSource === 'tracker') return true;
+ return !TIMESTAMPLESS_TRACKERS.includes(record?.tracker);
+};
+
/**
* Compute the approval-funnel metrics for one app's outcome records.
*
@@ -100,13 +127,13 @@ export function computeApprovalFunnel(outcomes = [], { now = Date.now(), windowM
const decidedInWindow = [];
let undatedDecisions = 0;
for (const r of decided) {
- // A SYNTHESIZED decision timestamp (`outcomeAtSource === 'observed'`) is the
- // reconcile clock, not the human's decision: the `plan` tracker reports no close
- // time, so a PLAN.md item checked off months ago but first reconciled today carries
- // today's date. Treated exactly like an unparseable one — it lands in `undated`
- // rather than being read as a decision made now, which would both inflate the
- // window cohort and report a filing-to-decision latency the user never took.
- const decidedMs = r.outcomeAtSource === 'observed' ? null : parsedMs(r.outcomeAt);
+ // A SYNTHESIZED decision timestamp is the reconcile clock, not the human's decision:
+ // the `plan` tracker reports no close time, so a PLAN.md item checked off months ago
+ // but first reconciled today carries today's date. Treated exactly like an
+ // unparseable one — it lands in `undated` rather than being read as a decision made
+ // now, which would both inflate the window cohort and report a filing-to-decision
+ // latency the user never took.
+ const decidedMs = hasAuthoritativeDecisionDate(r) ? parsedMs(r.outcomeAt) : null;
// An undatable decision cannot be placed in or out of the window. Counting it in
// would inflate a "recent" rate with an unknown-age verdict; counting it out
// silently would undercount the user's activity. It gets its own slot.
diff --git a/server/services/layeredIntelligence/approvalFunnel.test.js b/server/services/layeredIntelligence/approvalFunnel.test.js
index 9cd7480362..cd8ee0983e 100644
--- a/server/services/layeredIntelligence/approvalFunnel.test.js
+++ b/server/services/layeredIntelligence/approvalFunnel.test.js
@@ -190,18 +190,42 @@ describe('computeApprovalFunnel (#3120)', () => {
expect(funnel.proposalPhase).toMatchObject({ totalFiled: 1, totalDecided: 1, totalPending: 0 });
});
- it('trusts a tracker-reported decision timestamp and a legacy record without the flag', () => {
+ it('trusts a tracker-reported decision timestamp and a legacy timestamped-tracker record', () => {
const outcomes = [
{ ...decidedRecord('forge-item', 'merged', 4 * DAY, 2 * DAY), outcomeAtSource: 'tracker' },
// Written before outcomeAtSource existed: forge/jira always report closedAt, so a
// legacy record is trusted rather than blanking the metric for existing installs.
- decidedRecord('legacy-item', 'rejected', 5 * DAY, DAY)
+ { ...decidedRecord('legacy-item', 'rejected', 5 * DAY, DAY), tracker: 'github' }
];
const funnel = computeApprovalFunnel(outcomes, { now: NOW });
expect(funnel.window).toMatchObject({ decided: 2, approved: 1, rejected: 1, undated: 0, approvalRate: 50 });
expect(funnel.window.timeToDecision.count).toBe(2);
});
+ it('infers undated for a LEGACY plan-tracker record with no provenance stamp', () => {
+ // reconcileOutcomes no-ops on an already-settled record, so an existing resolved
+ // PLAN.md outcome never receives the `observed` stamp — its synthesized outcomeAt
+ // would otherwise be read as authoritative. `tracker: 'plan'` is the standing signal
+ // that no close time was ever reported.
+ const outcomes = [
+ { ...decidedRecord('legacy-plan-item', 'merged', 120 * DAY, DAY), tracker: 'plan', outcomeAtSource: null }
+ ];
+ const funnel = computeApprovalFunnel(outcomes, { now: NOW });
+ expect(funnel.window).toMatchObject({ decided: 0, undated: 1, approvalRate: null });
+ expect(funnel.window.timeToDecision.medianMs).toBeNull();
+ // Still a real verdict for lifetime throughput — only its date is unusable.
+ expect(funnel.proposalPhase).toMatchObject({ totalFiled: 1, totalDecided: 1 });
+ });
+
+ it('trusts a plan record that carries an explicit tracker provenance stamp', () => {
+ // Defensive: if a future plan-style filer ever does report a real close time, the
+ // explicit stamp wins over the tracker-name inference.
+ const outcomes = [
+ { ...decidedRecord('plan-with-real-date', 'merged', 4 * DAY, 2 * DAY), tracker: 'plan', outcomeAtSource: 'tracker' }
+ ];
+ expect(computeApprovalFunnel(outcomes, { now: NOW }).window).toMatchObject({ decided: 1, approved: 1, approvalRate: 100 });
+ });
+
it('honors an injected window span', () => {
const outcomes = [decidedRecord('mid', 'merged', 6 * DAY, 5 * DAY)];
expect(computeApprovalFunnel(outcomes, { now: NOW, windowMs: 3 * DAY }).window.approvalRate).toBeNull();