Skip to content

fix(nodepool): count a health check from when it was asked - #5626

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
rangoDJ:fix/5447-health-check-send-time
Nov 30, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
rangoDJ:fix/5447-health-check-send-time

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: none. Merge order: none. Follows #5446 (merged), which closed the larger part of this gap.

Problem

Closes #5447
Validation tasks: none

Other clients: Apple N/A, Android N/A, Roku N/A (API server's node planner)

publishHealth (internal/nodepool/health.go) stamped each health check with time.Now() when the answer arrived. pendingReservations (internal/nodepool/planner.go) drops a reservation once the node's LastHealthCheck is after the reservation's createdAt. So a reservation made while a check was in flight stopped counting when that check's answer arrived, even if the node answered before the start reached it. Both the total and the per-kind load then missed the job until the next check, and a burst of starts could pick the same node.

Approach

This is the first, narrower fix the issue lists.

  • CheckNodeReport records the time just before it sends the health request, as HealthReport.AskedAt. The sweep (checkOne), the recheck (recheckOne) and the admin check (applyHealthToPools) apply the report with that time as LastHealthCheck. A report can only include work that reached the node before it was asked, so a reservation made after that keeps counting until a later check.
  • The at-capacity hold (heldAtCapacity) compares the same field, so a refusal made after a check was sent is no longer cleared by that check's answer either.
  • UpdateHealthReport stores the same time as last_health_check, so a pool reloaded from the database draws the same boundary (fix(nodepool): count a health check from when it was asked #5626 review). A report without an ask time still stores NOW().
  • Not done: the issue's second option, having nodes report the session IDs they admitted. That changes the health contract and needs a compatible rollout. The window left is a start still in transit when the health request was sent.

Validation

  • New TestReservationMadeDuringAHealthCheckKeepsCounting:
    • A node's health handler holds its answer (0 active jobs).
    • While it is held, the planner reserves a transcode on the node.
    • Once the check is applied, the test checks that effectiveJobs still counts the reservation.
  • New TestHealthReportStoresTheTimeItWasAskedDB (Postgres) checks that the stored time is the ask time. With b62c3f1's repository.go, it stores the write time. Added to scripts/ci/db-contracts.txt.
  • Maintainer review (1ee1814): fixed the docs and comments that said a node's stats were never fresher than last_health_check, made the reservation test return instead of hanging when it fails early, and merged main.
  • With main's health.go and unreachable.go, the load drops to 0 jobs (output under Evidence).
  • With this change: go test -count=1 ./internal/nodepool/ ./internal/api/handlers/ ./internal/playback/... passes against a local Postgres 18, and the new test passes with -race. lint-changed: 0 issues.
  • Not tested: a multi-node deployment under a burst of starts.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5626-review/

No screen changes. Results of go test -count=1 -v -run TestReservationMadeDuringAHealthCheckKeepsCounting ./internal/nodepool/.

Before (health.go and unreachable.go from main bc17dc0):

    health_asked_at_test.go:57: node load after a report without the start = 0 jobs, want the reservation's 1
--- FAIL: TestReservationMadeDuringAHealthCheckKeepsCounting
FAIL
FAIL	github.com/Silo-Server/silo-server/internal/nodepool

After (this branch at b62c3f1; the test also passes at b156b2c):

--- PASS: TestReservationMadeDuringAHealthCheckKeepsCounting
ok  	github.com/Silo-Server/silo-server/internal/nodepool

Risks

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

Council review

Rounds: 1, reviewed b156b2c

Member Round 1
Sol (gpt-6.2-sol, medium) 6/10
Opus (claude-opus-5-5, medium) 8.5/10
Gemini (gemini-4-neon, medium) 8/10

Fixed: the test hang, the comment on the window this leaves, and the half of the DB test that covered an unused fallback. Answered: all three members flagged that an older health report can overwrite a newer one (the admin check doesn't take the per-node check lock, and the database write has no freshness check). That predates this change, and the report now carries its own older time, so it errs toward counting more load. Clock skew between API servers replaces the earlier skew between API servers and Postgres, so it is not new.

AI Disclosure

  • Harness: Claude Code in the Claude desktop app
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, not yet human verified
  • Adversarial review: see Council review above.

🤖 Generated with Claude Code

Note

Count health checks from when the check was asked, not when applied

Adds AskedAt to nodepool.HealthReport and a CheckedAt() method that returns it, falling back to the current time when unset. CheckNodeReport captures a timestamp before running the check and attaches it to the report.

  • Pool health updates and database persistence (Repository.UpdateHealthReport, HealthChecker.publishHealth, NodeHandler.applyHealthToPools) now use the report's check time instead of the time the result is applied. Updates without a report still store the current time.
  • Updates docs and type comments in admin-api.md, repository.go, and types.ts to clarify that last_health_check records when the check was sent and the sample can be up to 5 seconds newer.
  • Adds tests covering ask-time persistence and reservations made during an in-flight check, including the DB contract TestHealthReportStoresTheTimeItWasAskedDB.
  • Risk: stored last_health_check values shift to the ask time, so consumers comparing it to the check's five-second timeout window should check Repository.updateHealth and the admin API docs.

Macroscope summarized e80e36a.

The health checker stamped each check with the time its answer arrived.
The planner drops a reservation once a check is newer than it, so a
start reserved while a check was on its way back stopped counting even
though the node answered before the start reached it. The check is now
stamped with the time its request was sent.

Closes Silo-Server#5447

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b090f02d-3dd8-4d2f-b407-9bf26de23d85
Commits

Reviewing files that changed from the base of the PR and between 2ec1c4d and e80e36a.

Files selected for processing: 9

  • docs/admin-api.md
  • internal/api/handlers/nodes.go
  • internal/downloads/storage_read.go
  • internal/nodepool/health.go
  • internal/nodepool/health_asked_at_db_test.go
  • internal/nodepool/health_asked_at_test.go
  • internal/nodepool/repository.go
  • scripts/ci/db-contracts.txt
  • web/src/api/types.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Nov 30, 2026
Comment thread internal/nodepool/health.go Resolved
The pools recorded a check at the time its request was sent, but the
database stamped last_health_check with NOW(), so a pool reloaded from
it drew the reservation boundary at the answer's time again.
CheckNodeReport now records the ask time on the report, and the
sweep, the recheck, the admin check and the stored row all use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-kody

silo-kody Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Quick104 and others added 2 commits November 30, 2026 21:09
… test

last_health_check is now when the check was sent, so the stats and
network access a check writes can be up to its five-second timeout newer
than it. The admin API doc, the Node and storage view comments, and the
web type comment said they were never fresher; they now say they come
from that check's answer. The AskedAt comment also names the window the
change leaves: a start reserved before the check but still in transit.

The reservation test's node handler waited on its gate alone, so a test
that failed before releasing it hung in httptest.Server.Close. It now
also returns when the request is cancelled. The DB test drops its half
that covered a report without an ask time, which no caller builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Quick104 Quick104 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.

Review of b156b2c. Using the time the check was sent is the right boundary, and every writer now uses it: the sweep, the recheck, the admin check and the stored row. TestReservationMadeDuringAHealthCheckKeepsCounting fails on the base for the reported reason (the node's load reads 0 jobs) and passes here. Four small findings below. I'm fixing all four in a commit on this branch, so there's no need to change anything yourself.

🤖 Claude Code (claude-opus-5-5)

Comment thread internal/nodepool/repository.go Resolved
Comment thread internal/nodepool/health.go Resolved
@silo-kody

silo-kody Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Copy link
Copy Markdown
Contributor

Maintainer review summary

Reviewed b156b2c; fixes pushed in 1ee1814, then main merged. The head is now e80e36a.

The change fixes #5447 at the right place. A health check is now stamped with the time its request was sent, the only moment a report and a planner reservation can be compared. The sweep, the recheck, the admin check, and the stored last_health_check all use that time, so a pool reloaded from the database draws the same line as the pool the checker updated. TestReservationMadeDuringAHealthCheckKeepsCounting fails on the base with the reported symptom (the node's load reads 0 jobs, not the reservation's 1) and passes on this branch, also under -race. With the ask time no longer passed to the update, TestHealthReportStoresTheTimeItWasAskedDB fails, storing the write time instead. I didn't reproduce the race live. Its window is how long the node's answer takes to reach the API server, usually milliseconds, and a sandbox can't place a start inside it on demand.

Fixed on this branch (1ee1814)

  • The docs and comments that said a node's stats were never fresher than last_health_check now say the stats come from the answer to that check, up to its five-second timeout later. That covers docs/admin-api.md, the Node and downloads comments, and the web type comment.
  • The reservation test no longer hangs in httptest.Server.Close when it fails before releasing the node's answer.
  • The AskedAt comment now names the window this change leaves: a start reserved before the check but still on its way to the node.
  • The DB test no longer covers the "no ask time" fallback, which no caller reaches.

Left as it was

  • An older health report can still overwrite a newer one. The admin "check node" action doesn't take the per-node lock the sweep and recheck use, and the database update has no freshness check. That predates this change. What this PR changes is that the late report now carries its own older time, so the planner counts more load, not less. Every council member raised this. It is a separate fix: route the admin check through the checker's per-node lock.
  • last_health_check now comes from the clock of the API server that ran the check, not from Postgres. Clock skew between API servers replaces the earlier skew between an API server and Postgres, which is the same size of risk.
  • The unreachable mark has the same flaw this PR fixes for the at-capacity hold: a healthy answer to a check sent before the failure clears it. That predates this change and is filed as Unreachable transcode node is put back by a health check sent before it failed #5680, which needs this PR's AskedAt.

Checks

  • Validated features: none changed. Distributed transcode nodes — Server #1177 C2 (job caps across workers) only gets a more accurate job count while a start is in flight. Validation tasks: none is right.
  • Contract: no field is added, removed, or retyped. last_health_check still means when the node was last checked; it moves earlier by at most the request's time, and the admin API doc now says it is when the check was sent.
  • User manual: unaffected. The node status page's Checked reading ("how long ago the last check ran") stays accurate.
  • Other clients: none. This is the API server's node planner.
  • Council (round 1, b156b2c): Sol (gpt-6.2-sol) 6/10, Opus (claude-opus-5-5) 8.5/10, Gemini (gemini-4-neon) 8/10. Their findings are fixed or answered above. The later commit changes only docs, comments, and tests.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5626-review/

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

Fit: a bounded logic fix in the server's own load accounting, with no new setting, field, or surface. It errs toward spreading load, which suits a cluster where a node can go down mid-stream. Readiness: the bug's test fails on the base, the review fixes are verified, the validation board check ran, and nothing this PR causes is left open.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 9a098b2 into Silo-Server:main Nov 30, 2026
31 checks passed
Quick104 added a commit to rangoDJ/silo-server that referenced this pull request Nov 30, 2026
Keeps both appended db-contracts lines (Silo-Server#5626's nodepool test and this PR's webhooksync test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Transcode reservation stops counting while a start is still in transit

2 participants