Skip to content

health: fix tautological healthy flag in scheduler health check #114

@ng

Description

@ng

Problem

CodeRabbit identified that the healthy flag in the scheduler health endpoint may be tautological (always evaluating to true).

File: src/server/routers/health.ts:81-86

Current logic:

const healthy = jobs.length > 0 || jobCounts.total === 0

CodeRabbit's concern: Since jobCounts.total === jobs.length, this expression is always true.

Analysis Needed

Need to verify:

  1. Is this actually a tautology?
  2. What should "healthy" actually mean for the scheduler?
    • Should it check scheduler.isEnabled() && jobs.length > 0?
    • Should it compare against expected job count from DB?
    • Should it verify no jobs are in error state?

Proposed Solution

Replace with meaningful health check:

const healthy = scheduler.isEnabled() 
  ? jobs.length > 0  // If enabled, should have at least one job
  : jobCounts.total === 0  // If disabled, should have no jobs

Or compare against expected job count:

const [settings] = await db.select().from(deviceSettings).limit(1)
const expectedJobs = computeExpectedJobCount(settings)
const healthy = jobCounts.total === expectedJobs

Priority

Medium - Health checks are important for monitoring and alerting

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions