Skip to content

fix(transcodenode): count a start in the health report before it runs - #5446

Merged
Quick104 merged 5 commits into
mainfrom
fix/issue-5445-reservation-until-reported
Nov 27, 2026
Merged

Quick104 merged 5 commits into
mainfrom
fix/issue-5445-reservation-until-reported

Conversation

@Quick104

@Quick104 Quick104 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #5445
Related issue: N/A
Validation tasks: changes #1177 C2

Other clients: N/A (no client-visible change)

During a burst of playback starts, the API server could send several of them to the same transcode node, or to a node that then refused them at its job cap. The server counts a start it placed against the node only until that node's next health check. The node, though, left a new start out of the active_jobs and active_jobs_by_kind it reports until FFmpeg was ready, for example a 4K start still encoding its first segment. A health check in that window cleared the server's reservation, and the report didn't include the job yet. For that moment the node looked one job lighter than it was.

With this change the node reports a start from the moment it accepts it, so the job counts against the node throughout.

Approach

The node already counts accepted-but-not-yet-running work against its own job cap. Its health report now adds that same work to active_jobs, and to active_jobs_by_kind under the kind it will run as (video transcode, audio transcode, remux, trickplay). The report reads both under the same lock the node holds when a job moves from accepted to running, so each job is counted exactly once. A start that fails or is abandoned before it runs drops out of the report.

The fix is on the node side because only the node knows what it has accepted. The API server can't tell from a count which jobs a report includes. The health response keeps its shape. A new node gives API servers of any version the accurate count, and an old node with a new API server behaves as before, so a rolling upgrade needs no ordering. Draining, hardware re-probes and /status still count running jobs only. A drained node leaves admitted work out of its report, since anything it admits after draining is a start it is about to refuse.

Validation

  • A new node test starts a RequireReady transcode against an FFmpeg that never becomes ready and reads /health while it waits. On main it reports active_jobs 0. With the fix it reports one video transcode, and none after the caller abandons the start. A second test shows that a running start is counted once, and a third that a drained node leaves admitted work out.
  • transcodenode and nodepool package tests pass with -race. make lint-changed reports no issues.
  • Not reproduced on a live multi-node deployment. The window is a timing gap the test holds open.

Evidence: https://evidence.siloserver.org/r/silo-server/issue-5445/

Risks

While a start waits for FFmpeg, the admin node list shows it in the node's active jobs, one higher than before. That matches what the node enforces.

A shorter window remains: a start still in transit when the node answers a health check whose response arrives after the reservation was made. That timing is on main too, and this PR doesn't change it. It is tracked in #5447.

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

Ran as a follow-up of the #5412 review, with one member per round.

Plan check: Opus (claude-opus-5-5, medium) confirmed the node-side boundary and found no double count or leak. Its suggestion to add per-kind counts before clamping was adopted.

Rounds: 2, last reviewed 472ac66

Member Round 1 Round 2
Sol (gpt-6.2-sol, medium) 8/10 8/10

Fixed: health could report drained with a job admitted after the drain completed. It now reads the status first and, once drained, reports only the jobs it counts (round 2 narrowed an earlier version that reported none, which could hide a counted session replacement). The admin docs now say the total and per-kind sums can differ while a job starts. Answered: a start still in transit when a health response is published is a timing window on main as well, filed as #5447. A false drained while a same-session replacement swaps its job is possible on main too; this PR no longer hides it.

No visual review: nothing a user sees changes.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5 (implementation, plan check, code review), claude-sonnet-5-5 (code review cleanup angles and validation check), gpt-6.2-sol (background review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: a medium code review (two comment and doc fixes, no correctness findings), a plan check, and a background review; see Council review.

Note

Count admitted jobs in transcodenode health reports before they run

  • Admission now records a job kind per slot via Server.admitJob, and the new Server.unadmitLocked helper keeps total and per-kind admitted counts in sync when a slot completes or is released
  • Server.reportedJobs combines running jobs with admitted, uncounted slots for the health response, including per-kind totals in active_jobs_by_kind
  • Every admission path (start, preparation, remux, trickplay) passes its job kind; a start's kind is derived from its target video and audio codecs
  • When the node is drained, health reports only running-job totals and excludes admitted slots
  • Behavioral Change: active_jobs and active_jobs_by_kind in the health response now include admitted work that has not started yet (e.g. a start waiting on its first segment), so totals can be briefly higher than before; see admin-api.md and jobcap.go

Macroscope summarized f8668ab.

Quick104 and others added 3 commits November 27, 2026 02:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A transcode node admits a new start under its job cap well before it
counts the job in active_jobs: a RequireReady start waits for FFmpeg's
first segment first. The API server stops counting its reservation once
a health check is newer than it, so a check in that gap showed the node
a job lighter than it was, and a burst of starts could all pick it.

The health report now adds the admitted slots, by kind as well, read
under the admission lock countJob holds while it moves a slot from
admitted to counted, so a job is counted exactly once. The report's
shape is unchanged, so API servers of any version read it.

Fixes #5445

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 27, 2026
@silo-kody

silo-kody Bot commented Nov 27, 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 ❌

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 12 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: 051a6126-d799-417d-ac4a-3dbfb0a841e8
Commits

Reviewing files that changed from the base of the PR and between 88db53a and f8668ab.

Files selected for processing: 7

  • docs/admin-api.md
  • docs/architecture/worker-http-protocol.md
  • internal/transcodenode/drain.go
  • internal/transcodenode/jobcap.go
  • internal/transcodenode/jobcap_test.go
  • internal/transcodenode/server.go
  • internal/transcodenode/trickplay.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T02:27:15.719166Z f8668ab New commits
🔒 Security Review ✅ Completed 2026-11-27T02:28:48.947130Z f8668ab New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 27, 2026
Health read the job counts before the drain status, so a start admitted
while the node finished draining could show a drained node with a job.
Read the status first and report no jobs once it is drained: what a
drained node admits is a start it is about to refuse.

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

silo-kody Bot commented Nov 27, 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 ❌

Zeroing every count on a drained node could hide a session replacement
the node had already counted. Leave out only the admitted slots, the
starts a drained node is about to refuse, and say in the admin docs
that the total and per-kind sums can differ while a job starts too.

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

silo-kody Bot commented Nov 27, 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
Quick104 merged commit 078265d into main Nov 27, 2026
17 checks passed
@Quick104
Quick104 deleted the fix/issue-5445-reservation-until-reported branch November 27, 2026 02:37
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 before the node reports the job

1 participant