Summary
Deleting a server now resolves its open monitoring incidents. The health watch also closes incidents that earlier deletions already orphaned, so the Monitoring badge no longer stays stuck after an unreachable server is removed.
Motivation
When a server is unreachable, it has an open server_unreachable incident. If you delete that server, the incident stays open forever:
service_incident.server_idisonDelete: "set null". Deleting the server leaves the rowopen, withserver_idandproject_idbothNULL.- Only a successful sweep of that server resolves its incident (
findOpenForServer(serverId)), and a deleted server is never swept again. GET /issuesstill shows rows with a null server to unrestricted users, so the sidebar Monitoring badge keeps counting it.
I hit this on a self-hosted instance. After I removed an unreachable server, GET /issues kept returning its server_unreachable row with 1839 confirmations, and the badge stayed at 1.
Related issue
None (bug fix).
Changes
packages/db
serviceIncident.resolveOpenForServer(serverId)resolves every open incident on that server and returns how many it closed.serviceIncident.resolveOrphanedServerIncidents()resolves openserver_unreachablerows whoseserver_idandproject_idare bothNULL.
packages/platform
deleteServerUnderLockcallsresolveOpenForServer(id)right beforerepos.server.delete(id), whileserver_idstill points at the server.- It is silent: the server was removed, not recovered, so there is no "answering again" notification.
- It is best-effort: if it fails, the error is logged and the deletion still goes through.
- Each full (non-
currentOnly) health sweep callsresolveOrphanedServerIncidents()as part of the existing stale reap. The closed rows count towardsummary.staleand are never announced. This repairs rows orphaned before this fix.
CHANGELOG: Unreleased entry.
Verification
Each new test failed before the fix and passes with it. The repo tests run against real PGlite, and the platform test runs the real resources.remove with its dependencies mocked.
cd packages/db && npx vitest run src/repos/service-incident.repo.test.ts
# Tests 15 passed (15)
cd packages/platform && npx vitest run src/engine/modules/system/server-delete-incidents.test.ts
# Tests 2 passed (2)
cd packages/db && npx tsc --noEmit -p . # exit 0
cd packages/platform && npx tsc --noEmit -p . # only pre-existing errors in managed-mail/sending.ts, unchanged from mainI also confirmed the symptom on a live instance: after the orphaned row was resolved, GET /issues/summary went from actionRequired: 1 to total: 0.
The sweep hook has no unit test: runHealthWatch has no test harness yet, and the method it calls is covered by the PGlite test.
Checklist
- One change per PR — one bug, or one agreed feature, with nothing unrelated bundled in
- The diff is scoped — no reformatting or lint fixes on lines I wasn't otherwise changing (the touched files already fail
prettier --checkonmain, so I didn't reformat them) - A test fails without this change and passes with it (or I explained above why there isn't one)
-
bun run test,bun run --cwd <workspace> lint, andbun formatall pass locally (I ran the targeted tests and tsc above, not the full suite) - I understand every line of this diff and can explain it in review
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.