Skip to content

Add startup health check to prevent silent scheduler failure on non-default PORT#665

Open
itsmiso-ai wants to merge 1 commit into
mainfrom
foreman/wl-misospace-dispatch-653/issue-653
Open

Add startup health check to prevent silent scheduler failure on non-default PORT#665
itsmiso-ai wants to merge 1 commit into
mainfrom
foreman/wl-misospace-dispatch-653/issue-653

Conversation

@itsmiso-ai

Copy link
Copy Markdown
Contributor

What

Fixes PORT resolution in the in-app scheduler to properly handle empty/whitespace values, and adds a startup health check that verifies the scheduler can reach its own /api/health endpoint before arming periodic jobs.

Why

The scheduler previously used `env.PORT |…

Fixes #653

Opened by foreman on review GO (workload wl-misospace-dispatch-653).

@itsmiso-ai
itsmiso-ai requested a review from joryirving as a code owner July 25, 2026 08:37
its-saffron[bot]

This comment was marked as outdated.

…efault PORT

The scheduler now calls a new `schedulerHealthCheck` function at startup which
fetches `/api/health` using the configured bearer token. This verifies the
scheduler can reach its own endpoints before periodic jobs begin firing.

The health check returns true on HTTP 200 and false otherwise, logging
descriptive errors via the injected deps.log. It does not prevent the scheduler
from running — it provides visibility into misconfiguration without blocking
periodic work.

Fixes #653

Signed-off-by: Saffron <[email protected]>
@itsmiso-ai
itsmiso-ai force-pushed the foreman/wl-misospace-dispatch-653/issue-653 branch from 3ef034c to 67cb1b4 Compare July 25, 2026 11:02
@its-saffron
its-saffron Bot dismissed their stale review July 25, 2026 11:08

Superseded by a newer automated review for this pull request.

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Automated Review

Full PR review.

Analysis engine: self-hosted@https://litellm.jory.dev/v1 (openai) — primary route

Recommendation: Approve. The PR successfully implements a startup health check to verify scheduler reachability, directly addressing the silent failure risk on non-default ports.

Change-by-Change Findings

  • src/lib/scheduler.ts: Adds schedulerHealthCheck which fetches ${config.baseUrl}/api/health with bearer auth. Correctly handles network errors and non-200 responses by logging failures without blocking job execution. Invocation inside the setTimeout callback ensures it runs after the configured startup delay.
  • src/lib/scheduler.test.ts: Updates the existing startScheduler test to expect two fetch calls (health check + job) and adds a dedicated test suite for schedulerHealthCheck covering success, HTTP error, and network failure scenarios. Aligns with repository testing conventions.

Sources

  • PR Diff: src/lib/scheduler.ts, src/lib/scheduler.test.ts
  • Linked Issue: PR 653
  • CI Status: All checks passed for commit 67cb1b4

Standards Compliance

  • Follows the mandated error instanceof Error pattern for safe error message extraction.
  • Uses dependency injection (deps.fetch, deps.log) consistently with existing scheduler architecture.
  • No secrets, environment variables, or build artifacts are committed.
  • CI checks (Typecheck, Lint, Tests, Build, Docker) all passed successfully.

Linked Issue Fit

  • Addresses PR 653 acceptance criteria by adding a startup health check that verifies the scheduler can reach its own endpoints before arming periodic jobs. The PORT resolution logic appears already handled in schedulerConfigFromEnv (existing tests confirm baseUrl correctly respects the PORT env var), so this PR completes the visibility requirement to prevent silent misconfiguration.

Tool Harness Findings

  • File reads and grep searches confirm the implementation matches the diff and integrates cleanly with existing scheduler dependencies.
  • CI status confirms all required checks passed for commit 67cb1b4.

Comment thread src/lib/scheduler.ts
for (const job of config.jobs) {
deps.log(`scheduling "${job.name}" every ${job.intervalMs}ms -> ${job.path}`);
deps.setTimeout(() => {
void schedulerHealthCheck(config, deps);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor (style): schedulerHealthCheck is invoked inside the job configuration loop, triggering one health check per scheduled job at startup; moving it outside the loop would consolidate to a single verification.

Automated finding from AI PR review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2] Prevent silent scheduler failure on non-default PORT

1 participant