Skip to content

test(subtitles): keep reuse-test jobs from running against a nil translator - #3368

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-3367-reuse-test-race
Nov 5, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-3367-reuse-test-race

Conversation

@Quick104

@Quick104 Quick104 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3367
Related issue: N/A
Validation tasks: none (test-only change)

The subtitle AI reuse tests sometimes fail CI with a nil-pointer panic in a background worker. This is a fixture bug, not a product bug. It failed the Go test job on #3357, and it reproduces on main.

newReuseTestService builds a translate-ready service with no translator and no subtitle store, and lets every job it queues run on a free dispatch slot. In TestEnqueueNamesSidecarsByContent, the last enqueue queues a translation of a real sidecar file. If that worker reads the sidecar before test cleanup cancels the service, it calls the nil translator at service.go:383.

Approach

The reuse tests check what Enqueue decides, not what a job does, so the fixture now holds the only dispatch slot itself. Queued jobs never start. When cleanup cancels the service, they take the runner's existing abort path, which records a cancellation on the in-memory repo. Every identity and reuse assertion is unchanged. The fixture uses the semaphore parameter that NewService already takes, so nothing changes outside the test file.

The issue suggested supplying a translator and waiting for jobs in cleanup. That would also need a subtitle store stub, because the next nil is the store at service.go:635. It would also need either a new production Wait on the job runner that only tests call, or polling. And it would run translation code that these tests don't assert.

Validation

  • GOMAXPROCS=8 go test ./internal/subtitles/ai -run '^TestEnqueueNamesSidecarsByContent$' -count=10000: panics on the base at service.go:383 (exit 1); passes with this change. Rechecked after rebasing onto current main: main still panics, and the rebased branch passes.
  • The same test under -race 2,000 times, and the whole package under -race 100 times: pass.
  • gofmt, go vet on the package, go build ./..., and make lint-changed: clean.
  • I did not run make test-go or the web and contract gates. The change touches one test file in one package.

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

Risks

None identified. No production code changes.

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 says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): GitHub CLI, Git, Go toolchain, golangci-lint via make lint-changed
  • Model(s): claude-opus-5-5 (implementation, code review); gpt-6.1-sol (plan review, via Codex)
  • Involvement: Fully AI-generated at the maintainer's request; human verification is the review requested on this PR
  • Adversarial review: Codex (gpt-6.1-sol, xhigh) reviewed the plan against the unfixed base 81ae2ce. It found nothing and confirmed the fix by running the reproducer and the race runs on a temporary copy. A Claude code review of the final diff, with three finders and a validation check, found no defects. The background PR review is skipped because this change is test-only. The validation board could not be queried. The none above rests on the change being test-only.

🤖 Generated with Claude Code

Note

Pass a filled dispatch semaphore in newReuseTestService test helper

The reuse-test helper in reuse_test.go now creates a one-slot jobrunner semaphore, fills its slot, and passes it to NewService instead of nil. These tests exercise Enqueue decisions, not job execution, so queued jobs never acquire a dispatch slot before cleanup cancels them.

Macroscope summarized 8a91b6c.

@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026
@silo-kody

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

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T02:50:52.359666Z 8a91b6c New commits
🔒 Security Review ✅ Completed 2026-11-05T02:52:34.135869Z 8a91b6c 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.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The reuse-test fixture now occupies the service’s dispatch semaphore. This prevents queued jobs from running before cleanup cancels the service.

Changes: Subtitle reuse test fixture

Layer / File(s) Summary
Control queued reuse-test jobs
internal/subtitles/ai/reuse_test.go
The fixture fills a one-slot semaphore before creating the service. This keeps queued jobs from running until cleanup cancels the service.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other · Severity of issue fixed: Low

Suggested reviewers: rhainland

Merge Risk: Minimal · up to 9fb3f

This test-only change safely prevents reuse-test jobs from reaching the canceled translator.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly and concisely describes the test fixture change that prevents reuse-test jobs from running against a nil translator.
Linked Issues check Passed Directly linked issue #3367 is open, so its coding requirements apply. Expected behavior: the reuse test keeps its sidecar identity assertions and completes without a background panic. The diff change…
Out of Scope Changes check Passed The whole-PR diff against merge base 81ae2ce touches one file, internal/subtitles/ai/reuse_test.go. It adds one import of internal/ai/jobrunner, which service.go already imports, so no new package d…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check Passed The description states the problem (intermittent nil-pointer panic in TestEnqueueNamesSidecarsByContent caused by the test fixture), the approach (the fixture holds the only dispatch slot so queued jo…
Full details: Linked Issues check

Explanation

Directly linked issue #3367 is open, so its coding requirements apply. Expected behavior: the reuse test keeps its sidecar identity assertions and completes without a background panic. The diff changes only newReuseTestService in internal/subtitles/ai/reuse_test.go. The helper now passes a one-slot semaphore (jobrunner.NewSemaphore(1)) whose slot is already filled to NewService. NewService passes that semaphore to jobrunner.New, and Enqueue reaches runner.Dispatch. In Dispatch, the goroutine waits on either r.sem <- struct{}{} or runCtx.Done(). With the slot filled, the send cannot proceed. When cleanup cancels the parent context, onAbort runs (FailJob with storedCancelledBeforeStart) and the goroutine returns before run. Translator.Translate, and therefore the nil translator at service.go:383, is never reached. The identity and reuse assertions in TestEnqueueNamesSidecarsByContent and the other reuse tests are unchanged. The issue's technical notes suggest supplying dispatched-job dependencies and waiting for owned work during cleanup. The PR does not do either. The stated expected behavior is met by a different route: no dispatched job starts, so it needs no translator or store, and no running work remains to wait for. The PR description explains this choice. Reproduction and stress-run results in the PR description were not re-run in this assessment.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against merge base 81ae2ce touches one file, internal/subtitles/ai/reuse_test.go. It adds one import of internal/ai/jobrunner, which service.go already imports, so no new package dependency is introduced. The semaphore construction and the NewService argument change directly implement the linked issue's fixture repair. No production code, no new tests, and no unrelated file changes appear in the diff.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Full details: Description check

Explanation

The description states the problem (intermittent nil-pointer panic in TestEnqueueNamesSidecarsByContent caused by the test fixture), the approach (the fixture holds the only dispatch slot so queued jobs never start), the validation runs, and the risks. It is directly related to the changeset, which modifies newReuseTestService in reuse_test.go to pass a filled semaphore to NewService. The description is detailed and on-topic, so the check passes.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

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: 7ddc0b34-73f6-4401-b424-76ddab57b12f
Commits

Reviewing files that changed from the base of the PR and between 81ae2ce and 9fb3fbb.

Files selected for processing: 1

  • internal/subtitles/ai/reuse_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 1, 2026
@Quick104

Quick104 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

The Go test failure on 9fb3fbb is the existing playback cleanup race tracked in #3361: TestRelayMovePreservesMandatoryAudio/legacy=true reported unconfirmed rehome status=502, cleanup=0. The aggregate CI result only propagated that failure. The subtitle AI package passed, and no subtitle panic appears in this run.

This run used base 81ae2ce, where the same playback failure was already reproduced five times in 20 runs during the batch review. The single retry passed. Required CI is now green on 9fb3fbb; the other checks passed or were skipped.

CodeRabbit, Kody, and Codex have no inline findings on this PR.

— Codex in T3 Code, gpt-6-astra

…slator

The subtitle reuse fixture enabled translation without a translator or
store, and every job it queued ran on a free dispatch slot. When the
sidecar test's worker read its sidecar before cleanup, it called the
nil translator and panicked.

The reuse tests check what Enqueue decides, not what a job does, so the
fixture now holds the only dispatch slot. Queued jobs never start and
abort when cleanup cancels the service.

Closes #3367

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/issue-3367-reuse-test-race branch from 9fb3fbb to 8a91b6c Compare November 5, 2026 02:49
@Quick104
Quick104 merged commit 3b0bc93 into main Nov 5, 2026
22 checks passed
@Quick104
Quick104 deleted the fix/issue-3367-reuse-test-race branch November 5, 2026 15:57
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 priority: P2 Limited scope, workaround exists, or polish size/S 0–49 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Subtitle reuse tests intermittently panic in a nil translator

1 participant