You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(subtitles): keep reuse-test jobs from running against a nil translator - #3368
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.
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.
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.
This test-only change safely prevents reuse-test jobs from reaching the canceled translator.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly and concisely describes the test fixture change that prevents reuse-test jobs from running against a nil translator.
Linked Issues check
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
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
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
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.
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.
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/S0–49 added + deleted lines (all files); change volume, not priority.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
newReuseTestServicebuilds a translate-ready service with no translator and no subtitle store, and lets every job it queues run on a free dispatch slot. InTestEnqueueNamesSidecarsByContent, 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 atservice.go:383.Approach
The reuse tests check what
Enqueuedecides, 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 thatNewServicealready 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 productionWaiton 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 atservice.go:383(exit 1); passes with this change. Rechecked after rebasing onto current main: main still panics, and the rebased branch passes.-race2,000 times, and the whole package under-race100 times: pass.gofmt,go veton the package,go build ./..., andmake lint-changed: clean.make test-goor 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
AI Disclosure
make lint-changednoneabove rests on the change being test-only.🤖 Generated with Claude Code
Note
Pass a filled dispatch semaphore in
newReuseTestServicetest helperThe reuse-test helper in reuse_test.go now creates a one-slot
jobrunnersemaphore, fills its slot, and passes it toNewServiceinstead of nil. These tests exerciseEnqueuedecisions, not job execution, so queued jobs never acquire a dispatch slot before cleanup cancels them.Macroscope summarized 8a91b6c.