fix(dashboard): scope reliability endpoints by projectId (FUX-042)

Reliability GET and reset endpoints were always using the server's
root store, ignoring projectId. Mirror the Command Center pattern by
using getProjectIdFromRequest and getScopedStore so multi-project
servers report per-project reliability stats.

Refs FUX-042
This commit is contained in:
ddonaldson130
2026-07-09 03:15:17 -04:00
committed by gsxdsm
parent 7ed71ccd37
commit 47f889a0da

View File

@@ -1653,6 +1653,8 @@ export function createServer(store: TaskStore, options?: ServerOptions): ReturnT
});
app.get("/api/health/reliability", async (req, res) => {
const projectId = getProjectIdFromRequest(req);
const scopedStore = projectId ? await getScopedStore(projectId) : store;
const rawWindowDays = req.query.windowDays;
const parsedWindowDays = rawWindowDays === undefined ? 7 : Number.parseInt(String(rawWindowDays), 10);
@@ -1664,7 +1666,7 @@ export function createServer(store: TaskStore, options?: ServerOptions): ReturnT
return;
}
const settings = await store.getSettings();
const settings = await scopedStore.getSettings();
const resetAt = typeof settings.reliabilityStatsResetAt === "string" ? settings.reliabilityStatsResetAt : null;
const nowMs = Date.now();
@@ -1675,11 +1677,11 @@ export function createServer(store: TaskStore, options?: ServerOptions): ReturnT
const endIso = new Date(nowMs).toISOString();
const [runAuditEvents, enteredByDay, bouncedByDay, durationEvents, mergedTaskIds] = await Promise.all([
Promise.resolve(store.getRunAuditEvents({ startTime: startIso, endTime: endIso, limit: 50_000 })),
store.getTaskMovedCountsByDay({ since: startIso, until: endIso, toColumn: "in-review" }),
store.getTaskMovedCountsByDay({ since: startIso, until: endIso, fromColumn: "in-review", toColumn: "in-progress" }),
store.getInReviewDurationEvents({ since: startIso, until: endIso }),
store.getTaskMergedTaskIds({ since: startIso, until: endIso }),
Promise.resolve(scopedStore.getRunAuditEvents({ startTime: startIso, endTime: endIso, limit: 50_000 })),
scopedStore.getTaskMovedCountsByDay({ since: startIso, until: endIso, toColumn: "in-review" }),
scopedStore.getTaskMovedCountsByDay({ since: startIso, until: endIso, fromColumn: "in-review", toColumn: "in-progress" }),
scopedStore.getInReviewDurationEvents({ since: startIso, until: endIso }),
scopedStore.getTaskMergedTaskIds({ since: startIso, until: endIso }),
]);
const postMergeByDay = postMergeAuditFailuresPerDay(runAuditEvents, effectiveStartMs, nowMs);
@@ -1756,9 +1758,11 @@ export function createServer(store: TaskStore, options?: ServerOptions): ReturnT
});
});
app.post("/api/health/reliability/reset", async (_req, res) => {
app.post("/api/health/reliability/reset", async (req, res) => {
const projectId = getProjectIdFromRequest(req);
const scopedStore = projectId ? await getScopedStore(projectId) : store;
const resetAt = new Date().toISOString();
await store.updateSettings({ reliabilityStatsResetAt: resetAt });
await scopedStore.updateSettings({ reliabilityStatsResetAt: resetAt });
res.json({ resetAt });
});