From e9f7bc36d7785cec204171a085d65167db99c2c7 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Thu, 2 Jul 2026 02:27:20 -0700 Subject: [PATCH 1/2] fix(selfhost): remove the dead gittensory_jobs_deferred_total metric gittensory_jobs_deferred_total was registered as a persisted gauge in server.ts (reading backend.queue.stats()["gittensory_jobs_deferred_total"]) but no code path in sqlite-queue.ts or pg-queue.ts ever calls recordQueueMetric(driver, "gittensory_jobs_deferred_total", ...) -- dead instrumentation that always reports 0. The similarly-named (and actually incremented) gittensory_jobs_rate_limit_deferred_total / gittensory_jobs_rate_limit_admission_deferred_total / gittensory_jobs_rate_limit_budget_deferred_total exist and ARE recorded, so this reads as a leftover/renamed metric from an earlier iteration rather than something intentionally deferred. No self-host Grafana dashboard JSON references this metric name, so remove the dead gauge registration rather than inventing new call sites for a metric name nothing currently depends on. --- src/server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 83c9a4d17c..944eacd106 100644 --- a/src/server.ts +++ b/src/server.ts @@ -525,7 +525,6 @@ async function main(): Promise { "gittensory_jobs_dead_total", "gittensory_jobs_rate_limited_total", "gittensory_jobs_rate_limit_deferred_total", - "gittensory_jobs_deferred_total", "gittensory_jobs_coalesced_total", "gittensory_jobs_recovered_total", ]) { From 484e3aaa2915ee2b8da43c5a99ece5605440de15 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Thu, 2 Jul 2026 03:20:32 -0700 Subject: [PATCH 2/2] test(selfhost): pin the persisted-gauge-vs-recorded-metric invariant Address the gate review's test-expectations concern on the dead gittensory_jobs_deferred_total removal directly, rather than treating it as a policy-heuristic override: assert every metric name in server.ts's persisted-gauge list has a real recordQueueMetric call site in both queue drivers, so a future dead entry can't reappear the same way without a test catching it. --- .../unit/server-persisted-job-metrics.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/unit/server-persisted-job-metrics.test.ts diff --git a/test/unit/server-persisted-job-metrics.test.ts b/test/unit/server-persisted-job-metrics.test.ts new file mode 100644 index 0000000000..6293148a16 --- /dev/null +++ b/test/unit/server-persisted-job-metrics.test.ts @@ -0,0 +1,33 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; + +const read = (path: string) => readFileSync(path, "utf8"); + +// Regression for #2508: gittensory_jobs_deferred_total was registered as a persisted gauge in server.ts +// but no queue driver ever called recordQueueMetric with that name -- dead instrumentation that always +// reported 0. Pin the invariant the fix establishes: every metric name in server.ts's persisted-gauge list +// must have a real recordQueueMetric call site in BOTH queue drivers, so a future dead entry can't sneak +// back in the same way. Source-text assertions, not a runtime harness: server.ts has no test harness +// (it's Codecov-ignored) and this is a static wiring invariant, not runtime behavior. +describe("server.ts persisted job-queue metrics (#2508)", () => { + it("registers only metric names both sqlite-queue.ts and pg-queue.ts actually record", () => { + const server = read("src/server.ts"); + const sqliteQueue = read("src/selfhost/sqlite-queue.ts"); + const pgQueue = read("src/selfhost/pg-queue.ts"); + + const listMatch = server.match( + /const durableJobMetric[\s\S]*?for \(const name of \[([\s\S]*?)\]\) \{/, + ); + expect(listMatch, "persisted-gauge metric list not found in server.ts").not.toBeNull(); + const registered = [...listMatch![1]!.matchAll(/"([a-z_]+)"/g)].map((m) => m[1]!); + expect(registered.length).toBeGreaterThan(0); + + for (const name of registered) { + const callSite = `recordQueueMetric(driver, "${name}"`; + expect(sqliteQueue.includes(callSite), `sqlite-queue.ts never calls recordQueueMetric for "${name}"`).toBe(true); + expect(pgQueue.includes(`recordQueueMetric("${name}"`), `pg-queue.ts never calls recordQueueMetric for "${name}"`).toBe(true); + } + + expect(registered).not.toContain("gittensory_jobs_deferred_total"); + }); +});