Release: the series job, Keep → Sonarr dubs, akon rename and transcode agents #2

Open
bugzbunny wants to merge 171 commits from develop into main
Owner

Why

main is the release branch and has not moved since 2026-11-10. Production has run develop builds since the cutover (now 6b877566), so main no longer describes what is deployed. This PR brings it up to date: 171 commits, 511 files (+19.9k / −49.8k).

What changes

The series job replaces the per-step pipeline (SJ-1 … SJ-11, cutover, rename)

  • One row per series, worked on N torrents at a time (worker.concurrency, series.torrents_at_once); Promote puts a series first.
  • Real steps: metadata, release check, download, media check, transcode, staging, Keep, Reject, Cancel, backfill search.
  • The Jobs page, adm report job and the old pipeline are removed. Running and Intake show series.
  • One-time cutover from the old jobs to the series table (migrations v78/v79), plus the fix for torrents whose marker the cutover lost.
  • Renamed to akon: services, paths, /var/lib/akon, akon-develop.sqlite, the qBittorrent akon- tags and category, akon-install.

Keep → Sonarr, Shoko, Jellyfin

  • Each file is imported with its release's quality and group. Sonarr then searches only the missing episodes, not the whole series (it was replacing what AKON had just imported).
  • After a Keep, AKON finds dub releases for Sonarr's missing episodes and pushes them (adm sonarr find-dubs).
  • Shoko is told which AniDB episode each kept file is, and Jellyfin rescans once Shoko has the links.
  • Settings offer Sonarr quality profiles by name.

Errors and resilience

  • A program error stops one series, never the worker. Outages (network, disk, dropped replies) are typed and retried. No catch-alls.
  • A file is known by size and mtime (or content), never by device or inode, so NFS remounts no longer break anything.
  • Storage folders that are mounts must be mounted: a missing mount waits. The worker unit survives an NFS remount.
  • A full download or staging disk waits instead of failing.

Identity and search

  • English titles from AniDB. One staging folder per TVDB series (the cutover merges split ones). adm retitle.
  • Season packs plan their real file names and take the season's AniDB entry. Movies, specials and OVAs are skipped with a notification.
  • Autobrr asks AKON Check first (200 / 422 / 503).

Transcode agents

  • adm agent: pack, install, upgrade, rollback, status and token for adm-agent.pyz. Agents must match the worker's AGENT_VERSION.
  • Agents take turns and stay busy. Progress comes from frames when ffmpeg reports no out_time. The source is read once, and the agent returns the upload's SHA-256.

Admin and installer

  • adm series --id <anidb> (retry, keep, reject, search, cancel, promote). adm never opens the database: it asks the API over the admin socket.
  • The installer survives outages and a deleted working folder; rollback checks compatibility first.
  • New installations fetch from Forgejo (b06f7e3c, the only commit here not yet on production).

Dashboard

  • AniKeepOrNot branding, terminal console theme, consistent controls, a Workload panel, and Transcode settings that show only the selected mode.

Testing

  • Production has run develop through 6b877566 since 2026-11-28, including the cutover and the rename. adm services check reports every service OK.
  • The whole suite was green at d3298176 (2026-11-27). Later commits were tested with their own targeted tests, not a new full-suite run.
  • Not done: CI on Forgejo. The workflows are GitHub Actions and no Forgejo runner is set up.

Not in this PR

  • #1 (Transcode: Target MB per video) targets develop and is still open.

🤖 Generated with Claude Code

## Why `main` is the release branch and has not moved since 2026-11-10. Production has run `develop` builds since the cutover (now `6b877566`), so `main` no longer describes what is deployed. This PR brings it up to date: 171 commits, 511 files (+19.9k / −49.8k). ## What changes **The series job replaces the per-step pipeline** (SJ-1 … SJ-11, cutover, rename) - One row per series, worked on N torrents at a time (`worker.concurrency`, `series.torrents_at_once`); Promote puts a series first. - Real steps: metadata, release check, download, media check, transcode, staging, Keep, Reject, Cancel, backfill search. - The Jobs page, `adm report job` and the old pipeline are removed. Running and Intake show series. - One-time cutover from the old jobs to the series table (migrations v78/v79), plus the fix for torrents whose marker the cutover lost. - Renamed to **akon**: services, paths, `/var/lib/akon`, `akon-develop.sqlite`, the qBittorrent `akon-` tags and category, `akon-install`. **Keep → Sonarr, Shoko, Jellyfin** - Each file is imported with its release's quality and group. Sonarr then searches only the missing episodes, not the whole series (it was replacing what AKON had just imported). - After a Keep, AKON finds dub releases for Sonarr's missing episodes and pushes them (`adm sonarr find-dubs`). - Shoko is told which AniDB episode each kept file is, and Jellyfin rescans once Shoko has the links. - Settings offer Sonarr quality profiles by name. **Errors and resilience** - A program error stops one series, never the worker. Outages (network, disk, dropped replies) are typed and retried. No catch-alls. - A file is known by size and mtime (or content), never by device or inode, so NFS remounts no longer break anything. - Storage folders that are mounts must be mounted: a missing mount waits. The worker unit survives an NFS remount. - A full download or staging disk waits instead of failing. **Identity and search** - English titles from AniDB. One staging folder per TVDB series (the cutover merges split ones). `adm retitle`. - Season packs plan their real file names and take the season's AniDB entry. Movies, specials and OVAs are skipped with a notification. - Autobrr asks AKON Check first (200 / 422 / 503). **Transcode agents** - `adm agent`: pack, install, upgrade, rollback, status and token for `adm-agent.pyz`. Agents must match the worker's `AGENT_VERSION`. - Agents take turns and stay busy. Progress comes from frames when ffmpeg reports no `out_time`. The source is read once, and the agent returns the upload's SHA-256. **Admin and installer** - `adm series --id <anidb>` (retry, keep, reject, search, cancel, promote). `adm` never opens the database: it asks the API over the admin socket. - The installer survives outages and a deleted working folder; rollback checks compatibility first. - New installations fetch from Forgejo (`b06f7e3c`, the only commit here not yet on production). **Dashboard** - AniKeepOrNot branding, terminal console theme, consistent controls, a Workload panel, and Transcode settings that show only the selected mode. ## Testing - Production has run `develop` through `6b877566` since 2026-11-28, including the cutover and the rename. `adm services check` reports every service OK. - The whole suite was green at `d3298176` (2026-11-27). Later commits were tested with their own targeted tests, not a new full-suite run. - Not done: CI on Forgejo. The workflows are GitHub Actions and no Forgejo runner is set up. ## Not in this PR - #1 (Transcode: Target MB per video) targets `develop` and is still open. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
[skip ci]
[skip ci]
[skip ci]
[skip ci]
An upgrade deletes old release folders. A shell sitting in one (for example
after `cd /opt/anime-discovery/current`) is left in a deleted folder, and every
later run failed in git clone with "Unable to read current working directory"
and "fetch-pack: invalid index-pack output".

The installer's commands, including the self re-run, now start from /.
Relative path arguments are made absolute against the folder they were typed
in, and fail with a clear message if that folder no longer exists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- git clone/fetch and pip install retry twice (5s, 20s) before giving up.
- A dropped SSH session no longer aborts an upgrade halfway: SIGHUP is
  ignored, terminal write errors are absorbed, and output is copied to
  <state>/installer/last-run.log (0600, root runs only).
- A failure after services stop but before the database changes restarts
  the services that were running, on the unchanged current release.
- A candidate that never became current, and that no upgraded database
  depends on, is removed instead of left behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Off shows only Mode. Local shows its encoders, temp path, VAAPI device and
target size. Remote shows the agent list, target size and the per-agent
health retry settings. Hidden fields keep their values and save unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Installer: durable upgrades (deleted shell folder, network retries, SSH hang-ups, early-failure recovery) [skip ci]
Settings: Transcode shows only the fields the selected mode uses [skip ci]
Remote agents were a single row with an unlabeled password box and a
separate "Save token" button, and with no agents there was nowhere to put a
token at all. Each agent is now a block with labeled Address and Token
fields and a status line. Generate creates a 256-bit random token and shows
the exact TRANSCODE_TOKEN= line to put on the agent, with Copy. Remote mode
with no agents shows one empty block. The section's Save changes stores the
agent list, then each typed or generated token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Settings: easy agent tokens — Address/Token fields, Generate, one Save [skip ci]
The shared output check compared audio, subtitle and attachment counts and
the duration, but never video, so an audio-only MKV passed for a video
source. It now also requires the same number of video streams as the source
and a first video stream that is HEVC Main 10, the one stream the encode
re-encodes. A source without video is refused before probing.

Local mode, the agent and the worker receiving a remote result all use this
one check. Adds docs/WORK_ITEMS_COMPACT_AGENT.md (item 0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- src/transcode_agent/cli.py holds the agent's command: `adm server agent`
  (and `python -m src.transcode_agent`) run the HTTP agent; --version prints
  AGENT_VERSION and the build revision; --help documents the environment,
  host dependencies and the service. One launcher, no src.anime imports.
- AGENT_VERSION (1) and the build revision (archive metadata, else the
  installed release, else Git) are reported by GET /health.
- Stopping the agent cancels running encodes and waits for them, so no
  ffmpeg child survives.

Work item 1 of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- compatibility() applies one rule: an agent may take new work only when its
  reported agent_version equals the worker's AGENT_VERSION. A missing version
  (agents from before versions) counts as older; a malformed one fails closed.
  Each refusal is one sentence naming the agent and what to update.
- The worker checks right before every upload, after the periodic health
  check. A refused agent gets no upload and spends no encode attempt; other
  compatible agents keep working; with none, the job waits and its detail
  carries the update-required sentence. A running encode is never cancelled
  by a health check, and an upgraded agent is used again without a restart.
- The service bar names each agent's own problem: no token set, token
  rejected (401/403), unreachable, unreadable answer, or needs an update.
  No usable agent is UNSUPPORTED, AUTH_FAILED, NOT_CONFIGURED or DOWN
  accordingly, never just "down".
- Waiting transcode/staging jobs record the reason in service_detail.

Work item 1a of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`adm server agent pack --output PATH` builds the agent as one executable
zipapp (standard library only) from the installation or checkout it runs in.

- An allowlist decides the contents: the agent modules unchanged, the
  maintained archive entry point (archive_main.py -> __main__.py), the
  service and environment templates, and build.json (AGENT_VERSION, source
  revision, per-file SHA-256). Nothing else is read, so secrets, settings,
  databases, media, .git and tests cannot be packed.
- The revision is the installed release or Git HEAD, with +modified when
  the packed files have uncommitted changes.
- The archive routes `server agent ...` to the same cli.main as adm; other
  commands fail clearly; pack is not offered inside an archive. It checks
  for Python 3.11+.
- PATH.sha256 is written for transfer checks (integrity, not authenticity).

Work item 2 of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`adm-agent.pyz server agent install` installs the archive as the
transcode-agent systemd service, checks authenticated health and explains
pairing. Scope comes only from the effective UID: root installs a system
service running as `transcode`; any other account installs a user service
in its XDG folders. No scope option, no sudo, no elevation; the account,
scope and paths are announced before any change and recorded in
install.json, which later commands check.

- Checks systemd, ffmpeg/ffprobe (libx265, libopus) and GPU access first.
  Root may install missing Debian/Ubuntu packages with apt-get (retried);
  user installs get administrator instructions. Missing user manager,
  missing GPU access (no group changes for users) and linger state are
  explained, not worked around.
- Asks for listen address, encoders, GPU device and temp folder (or --yes
  with flags); reruns keep every setting and the token. The token is
  generated (256-bit) unless pasted or given with --token-stdin, written
  only to the 0600 environment file, and shown only by `server agent token`.
- The unit and environment file come from the maintained templates in
  deploy/transcode-agent (carried inside the archive): user units drop
  User/Group/SupplementaryGroups and use default.target. The unit restarts
  on failure with a start limit and a stop timeout.
- upgrade --from checks the new archive runs here before stopping anything,
  refuses while encoding unless --interrupt, keeps the previous archive and
  restores it if the new one does not pass its health check. rollback swaps
  them back. Archives are replaced atomically; an interrupted run never
  removes the working version or rotates the token.

Tests use fake system commands and health answers with real archives;
they are not systemd verification.

Work item 3 of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs/TRANSCODE_AGENT.md now walks through the whole path: export with
adm server agent pack, transfer with scp and sha256sum -c, system and user
installs (what each announces, where files go, user manager and lingering,
GPU access), pairing in Settings with `server agent token` / `token --set`,
checking with the service bar, status and journal, a test video (verified
against an archive-run agent), crash and reboot recovery, upgrade, rollback,
and the network/HTTPS requirement.

The dashboard's agent block points at the same commands: the no-token hint
names `adm-agent.pyz server agent token`, and a generated token says to give
it to the agent with `server agent token --set`.

Work item 4 of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The archive, run outside the repository with an isolated Python, serves
  the real worker client: upload, progress, result checksum, the shared
  HEVC Main 10 validation and job deletion, with real ffmpeg.
- A real agent reporting a newer version is refused before any upload; the
  job waits and spends no attempt; the service bar says UNSUPPORTED.
- A health check during a running encode does not disturb it.
- Stopping the agent mid-encode leaves no ffmpeg process.
- Opt-in (AGENT_SYSTEMD_TESTS=1): a transient systemd user unit restarts a
  SIGKILLed agent and stopping the unit stops its ffmpeg; the unit is
  removed afterwards.

The work-items document records what was built and where it differs.

Work item 5 of docs/WORK_ITEMS_COMPACT_AGENT.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Agent 0: reject a transcode result without the encoded video [skip ci]
Agent 1: adm server agent, version in /health, clean shutdown [skip ci]
Agent 1a: workers use only agents with their AGENT_VERSION [skip ci]
Agent 2: adm server agent pack builds adm-agent.pyz [skip ci]
Agent 3: install, upgrade, rollback, status, token for adm-agent.pyz [skip ci]
Agent 4: complete operator guide; dashboard pairing hints [skip ci]
Agent 5: end-to-end acceptance of the packed agent [skip ci]
- `adm agent run|install|pack|upgrade|rollback|status|token` is the main
  spelling, in adm and in adm-agent.pyz; `adm server agent` still works.
- Installed units keep ExecStart `adm-agent.pyz server agent run`, which
  every archive version understands, so rollback still starts.
- Example unit documents running from a checkout with `adm agent run`.
- bin/anime-discovery-install is now bin/akon-install. On an existing
  install it migrates the saved destination, writes akon-install, then
  removes the legacy command and locator. Releases from before the rename
  are still accepted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
adm agent; installer renamed to akon-install [skip ci]
- Each adm command is one module in src/anime/api/adm_commands with NAME,
  SUMMARY and main(argv, prog); adm discovers them and lists them in
  adm --help. HIDDEN keeps `adm server agent` working but unlisted.
- set-password moved into its own command module; same options.
- adm transcode: prog, per-subcommand help, how intake and Settings >
  Transcode connect, and examples.
- Tests: the module contract, the listing, per-command help, cheap imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
adm lists its commands; adm transcode help [skip ci]
- akon-install records the branch's config_dir in each release's
  .anime-discovery-release.json.
- cli_config_dir(): ANIME_DISCOVERY_CONFIG_DIR, then the folder recorded
  for this release, then /etc/anime-discovery.
- adm explains a settings version mismatch (folder, found and expected
  versions, what to do) instead of a traceback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
adm from a release uses its own settings folder [skip ci]
- Worker journal (anime.worker.transcode, INFO): each agent skipped with
  its reason (in use, kept for intake, no token, no health answer, busy,
  low space, version, upload refused), the agent chosen, and hash,
  upload, encode and download times with speeds.
- Staged batch: each round's files and destinations, round duration,
  pauses for intake, and per-file requeue or failure.
- Readable sizes in log lines; the frozen-progress test's clock no longer
  depends on how often the client reads it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Log where each video goes and why agents are skipped [skip ci]
- Staged batch: one loop per destination takes the next file as soon as
  its last one finishes, instead of rounds that wait for the slowest file.
  Skipped files are logged and no longer hold an agent; intake still goes
  first; a file no agent takes waits for a busy loop to free up.
- Agent: progress in hundredths of a percent, so slow CPU encodes move
  within the worker's 60 s stall window; journal lines for each job
  (received, encoder, GPU failure reason, every 10%, done/stopped,
  cancelled by the worker). AGENT_VERSION unchanged.
- Worker stall error names the agent's progress and encoder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep every transcode agent busy; agent logs its jobs [skip ci]
On a Radeon RX 6700 XT, hevc_vaapi into Matroska reports out_time as N/A
while frames advance. The agent read only out_time, stayed at 0%, and the
worker cancelled working encodes after 60 s.

- probe reads avg_frame_rate/r_frame_rate; frame_total() = duration x rate.
- run_ffmpeg: per -progress block, out_time when usable, otherwise
  frame / expected frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Agent progress from frames when ffmpeg reports no out_time [skip ci]
CLEANUP_DECIDED_DOWNLOAD stopped in Needs review for two reasons:

- Transcoded episodes: staging publishes the transcoded output, so the
  publication's source no longer describes the torrent's file and the
  source check always failed. When the publication points at the plan's
  transcode output, ownership rests on the torrent checks alone (tag,
  recorded folder, category, file list) and the ad-* folder is purged.
- missingFiles on COPY plans: the files are already gone and staging holds
  the copy. qBittorrent now drops only the record (deleteFiles=false), then
  the pinned ad-* folder is purged as usual.

Adds two read-only diagnostics in fixes/: trace_stuck_torrents.py and
explain_download_cleanup.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NXsE95TzHjmrHbLsvv6WkH
- Integrity is proven when staging publishes the video. Cleanup no longer
  compares the publication's source path, size or folder identity with the
  torrent: owned() (hash, ad-* tag, category, save path, file list) is the
  only gate before qBittorrent removes the torrent and its files.
- failure_location falls back to the last 'src/anime/' in a frame's path,
  so bytecode compiled in another checkout still names the failed check.
- trace_stuck_torrents shows the last job's reason in each group heading.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove torrents after staging when transcoded or files are missing [skip ci]
Season packs on production stopped in review although their files were fine:
- File names: bracketed CRC32 hashes ([E02FF655]) no longer read as episode
  numbers or ranges; "S2 - 10" is not a range; "S02E01v2" and "S04E01 v2"
  keep their episode; "4th Season_-_07_" reads season 4 episode 7; an episode
  title after the tag ("S02E03 - 0 + 2 = 1") is ignored; half episodes
  ("- 20.5") are extras.
- External audio and subtitle tracks (.mka, .mks, .sup ...), covers and
  checksum files are allowed beside the videos.
- A TVDB season/number listed twice blocks only a file that maps to it.
- A planning error stops VERIFY_RELEASE once with SEASON_PACK_FILES_UNCLEAR
  instead of three retries ending in JOB_RETRY_EXHAUSTED.

Identity: when the title finds the right series but another AniDB entry
(the alternate title of season 1, or the first cour of a split season),
the Anime-Lists entry for the release's TVDB season and episode is used
(Slime S04 -> 18884, AMAIM S01E14-E25 -> 17091).

Movies are not supported yet: VERIFY_RELEASE cancels a movie (AniDB type
Movie, or a movie title with no season or episode) with RELEASE_MOVIE_SKIPPED,
posts a MOVIE_SKIPPED notification and closes the operation. Migration 074
adds the notification type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Identity (60 IDENTIFY_ANIME reviews):
- Fuzzy title matching took its words from the space-stripped text, so the
  "word" was the whole title: typos ("Alyu" for "Alya") and particle
  spellings ("wo"/"o") never matched. Words now come from the original text.
- Aliases gain cleaned forms: dotted titles ("Magic.Kaito.1412"), trailing
  years ("LIAR GAME 2026", "Look Back (2024)"), "- Season", "A (B)", an
  unbalanced "(", and a trailing "(Aoki Denshou: Welsh & Shedar, Dual-Audio)".
  They are searched and scored; scoring no longer sees only variants still
  carrying "(Season 01)" or ". . .AVC".
- A sequel entry ("Black Clover 2nd Season", "Mushoku Tensei III") agrees
  with TVDB through any AniDB entry Anime-Lists maps to the same series.
- A movie title whose identity is not found is canceled with
  RELEASE_MOVIE_SKIPPED and a notification, not left in review.

Releases: an absolutely numbered series reads "One Piece S01E1160" as
absolute episode 1160.

Retries and cleanup:
- STAGING_UNAVAILABLE waits 2, 4, 6 minutes (was 1s/2s/4s, so a brief NFS
  outage exhausted every retry) and records the failed check.
- Cancellation cleanup waits on ENOTEMPTY/EBUSY (NFS keeps deleted, still
  open files briefly) instead of stopping for review.
- A magnet that timed out waiting for its file list is removed through the
  normal cancellation cleanup.
- CLEANUP_BATCH_DOWNLOAD records the check that stopped it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Season packs, identity matching and retries: fix the production review stops [skip ci]
fixes/resend_to_identity.py cancels each given release check stopped for an
episode-mapping reason and queues its stored delivery again as a fresh
IDENTIFY_ANIME, like the webhook. No search, no Auto BR. Preview by default;
--apply backs up the database first; a second run does nothing.
Tried on production with job 835: re-identified as Sasaki to P-chan Season 2
(18563) and its release check passed.

Backups made by the shared helper are now named after the fix that made them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AniDB stays the root of trust and Anime-Lists the only TVDB link; no TVDB
data is used to choose.

- "JoJo's Bizarre Adventure" ties several AniDB entries; the one ranked first
  (788, the OVA) is under an Anime-Lists series without a season 6. When the
  season lookup finds nothing there, the other eligible candidates' series are
  checked and the season entry is used only when exactly one exists
  (9304 -> TVDB 262954 -> 19287 Steel Ball Run). Note: season_entry_other_candidate.
- Alias forms: "A Part N: B" also tries "B: A" (AniDB's word order) and "A";
  "A: B" also tries "B: A".

Production IDENTIFY_ANIME jobs 385, 542, 548, 549, 8758, 8759, 8764, 9066,
9988, 9989, 10004 (IDENTITY_INCOMPLETE).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AniDB is the root of trust and Anime-Lists the only TVDB link, so neither
case can be fixed in review:

- ANIDB_ENTRY_MISSING: no title in the name, or no AniDB entry matches it
  (T00393120, Tom and Jerry Forbidden Compass, Puss 'n Boots 1976,
  Cardfight!! Vanguard 15th Anniversary Remastered, Ao no Exorcist: Ura Ex).
- ANIME_LISTS_ENTRY_MISSING: AniDB has the anime, Anime-Lists has no TVDB
  link (Welsh and Shedar 20379, cocoon 18084).

Both cancel IDENTIFY_ANIME through the movie-skip path and notify with the
new RELEASE_UNSUPPORTED type (migration v75). A tie between AniDB entries
still stops for review.

Replayed all 24 IDENTITY_INCOMPLETE release names from production against its
cached AniDB titles and Anime-Lists: 11 JoJo releases identify as 19287,
the other 13 cancel with these reasons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
journal.start records START_UNCERTAIN before the start request. When the
attempt gave up before the client took its start permit (cancel, a re-read
racing a state change, qBittorrent unreachable), nothing was sent, but the
transfer stayed START_UNCERTAIN and waited forever on a paused torrent.
Download, batch E01 transfer and batch unlock now undo it, fenced to the
attempt that recorded it. A start that may have been sent is still never
repeated.

fixes/rearm_unsent_starts.py re-arms jobs already stuck this way, only when
their history proves the start was not sent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Anime-Lists writes a word instead of a TVDB ID for entries with no TVDB
  series ("movie", "OVA", "hentai", "web", "tv special", "music video",
  "other"). It read as a broken provider response, retried until exhausted
  and stopped in review (Look Back, Land of the Lustrous). "movie" is now
  canceled as RELEASE_MOVIE_SKIPPED with the movie notification; any other
  word as ANIME_LISTS_ENTRY_MISSING.
- An aired episode Anime-Lists does not place on TVDB is searched by its
  AniDB number with no TVDB season; building its titles compared None > 1
  (Black Clover S02E02 discovery, TypeError).
- Reset "replay" refused Auto BR deliveries, which carry only the release
  name and info hash; the pipeline builds the magnet from the hash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Batch staging, batch decision cleanup, batch Keep import and post-Keep
  cleanup accepted only COPY. A transcoded episode is staged by MOVE from the
  staging root, so every transcoded batch stopped after downloading the
  whole pack (prod 10961, Call of the Night). MOVE is accepted when the
  source is in the staging root: the torrent's own file is never moved.
- Season pack parser: "Clean Opening/Closing", "Menu 1", "insert song",
  NC/OP.mkv, "S01OP-..." are extras, not unclear files; "S01E01-1st Night"
  is an episode title, not a range.
- Specials (TVDB season 0) and OVA-only releases are canceled with a
  RELEASE_UNSUPPORTED notification instead of Needs review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prod 2026-11-22 06:07: staging, 26 download cleanups, transcodes and
identification all wrote at once. SQLite's busy handler is not fair; one
writer waited past the 5 s busy timeout, its job saw "database is locked"
(QueueUnavailable) and the whole worker exited.

- storage/adapter.py: one place for connection settings and write
  transactions. Writers in a process take one write lock per database file
  before BEGIN IMMEDIATE, so job threads queue in order. No retries, no
  backoff; other processes (API, adm) use SQLite's busy timeout, now 60 s.
  A write transaction held over 1 s logs "Slow database write" with the
  code that opened it. Measured on the production disk at 64 threads:
  worst wait 4.3 s without the adapter, 0.76 s with it.
- transaction(), connect(), migrations._open, the job queue and provider
  cache connections go through the adapter.
- The batch transcode publish deleted the 1.5 GB original on the NFS staging
  share under the write lock; it now deletes it after the commit.
- A storage error in one attempt is logged and the worker keeps running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
QueueUnavailable turned every sqlite3.Error and OSError into "storage
unavailable": a disk-full database, a constraint a bug broke, a missing
column, an NFS error in staging and a busy lock all read the same, and a
handler's error skipped the job's outcome entirely (job left RUNNING until
its lease expired, the cause only in the log).

- QueueUnavailable is gone. Readers and the job queue no longer convert
  errors; the schema version check is one adapter function
  (DatabaseVersionMismatch, a MigrationUnsupported). A job with no operation
  raises JobOperationMissing. Lookups that swallowed database errors and
  carried on with a wrong answer (manual release, manual identity, movie
  check, release candidates, discovery window) no longer catch them.
- A handler's database error is recorded as DATABASE_ERROR with SQLite's
  error name (storage_error, e.g. SQLITE_FULL, SQLITE_CONSTRAINT_CHECK) and
  the failed check; a file error as STORAGE_UNAVAILABLE with the errno name
  and path. Both show in the job's activity and history.
- STORAGE_UNAVAILABLE now means the staging/download share only. New
  reasons: DATABASE_ERROR, DATABASE_VERSION_MISMATCH, JOB_OPERATION_MISSING.
  Stored rows already match (the 3 stored causes were download-share
  ENOTEMPTY), so no data migration.
- The worker logs a database error in one attempt and keeps running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A job in Needs review that cannot be recovered, or one retrying forever, is a
program bug. Enforced where the job queue picks a job's next state, so every
path (a review outcome, retries exhausted, a service down too long) obeys:

- IDENTIFY_ANIME: Needs review, recoverable with a manual match.
- A step working on a torrent (check, choose, download, verify, transcode,
  stage): canceled with a notification naming the torrent and why; anything
  this app downloaded for it goes through the normal cancellation cleanup and
  the next torrent for the episode is tried. Exhausted retries keep the step's
  own reason, not JOB_RETRY_EXHAUSTED.
- Housekeeping (cleanup, Keep, Reject, refresh, search, reset, bulk): the
  normal retry budget, then FAILED with a JOB_FAILED notification naming the
  job, the torrent and the failed check. Nothing retries forever.

Migration v76 allows the JOB_FAILED notification type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A job waiting on a download was checked every 30 s, and each check stored
four history rows (job started, step started, step finished, waiting),
counted as another attempt and printed four DEBUG lines. On production that
is 94% of job history (job 8766: 72,804 rows).

- JobQueue.finish: a wait that repeats the previous one (same reason,
  activity and facts, nothing else recorded since) removes this check's
  claim and step-start rows, puts the attempt count back and only moves
  the next check time. The first wait and every change stay in History.
  Giving up on a service is still recorded.
- Job started / Step started / Step finished log at TRACE, not DEBUG.
- "Not finished" is logged only when the check recorded something.
- close_skipped_release never moves an operation's updated time backwards.
- Old tests that expected Needs review updated to the review policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner's design, 2026-11-22: the API identifies, then gives the worker a job.

- Webhook: a decided series is refused from local data (API Reject, as
  before); everything else is queued in identity_requests and Autobrr gets
  202 at once.
- Identity bridge (identity_bridge.py): the API starts a separate identity
  process when releases are due, so the API stays fast. The process
  (identity_process.py) runs the AniDB-first resolver with the shared
  pacing and reports one JSON line per release; AniDB is the truth. It
  exits when nothing is due, and the API stops it on shutdown.
- The API applies each result in one transaction: identified -> delivery,
  identity and the worker's first job (VERIFY_RELEASE). Anything the worker
  could not complete is refused with API Reject: the notification says why
  and keeps the release. The worker never sees it and no longer identifies.
- Match by hand moved from the Needs review job to the API Reject
  notification (bell action match_by_hand).
- Migration v77: unfinished identification jobs move to the bridge; every
  old identification job whose release was never identified is removed with
  its delivery, so no stale rows are left. Tested on a copy of production:
  72 dead deliveries/jobs removed, 1 release queued, schema valid.
- Migrations no longer copy the database first (owner): each step rolls
  back whole, and a migration moves old data into the new shape itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/v1/check is Autobrr's External filter and works like SMTP
greylisting. A release never seen gets 503 while the identity process gets
the real AniDB data at AniDB's pace; Autobrr retries and gets 200 or 422.
A decided series, hand match or recognized name is answered at once from
local data. identity_requests is keyed by info hash and keeps its outcome
for a day, so retries and the webhook action get the same answer and a
torrent is identified once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Log lines: each request and its answer (reads at DEBUG), each release
  decision in plain words, the identity process starting and finishing,
  and each identity result naming the AniDB entry and the worker job.
- The log formatter prints the full traceback (work item 1), redacted.
- One boundary per API request: a program error answers 500
  API_PROGRAM_ERROR naming file:line and logs the full trace. The webhook
  decision and candidate-evidence catch-alls are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sonarr's UI shows profile names but never their IDs, yet Keep needs the ID.
GET /api/v1/settings/sonarr/quality-profiles asks Sonarr for its profiles;
the Settings page shows them in a drop-down and stores the ID. If Sonarr
can't be reached, the number field stays, with why.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shoko's hash match often fails and Jellyfin (Shokofin) only shows files Shoko
has linked. Keep (single episode and season pack) now queues LINK_SHOKO for
the series: Shoko fetches the series, scans if it hasn't seen a file, and each
kept file is linked to its episode by AniDB episode ID. Idempotent; waits 10
minutes between checks, fails after a day naming the files.
adm shoko link --id <anidb_id> catches up series kept before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shoko runs on its own VM over NFS, so its watcher can miss new files, and
Shoko 5.3 can't take a file before hashing it. So: Keep asks Shoko to fetch
the series before Sonarr copies anything; the link job asks Shoko to import
new files and links each kept file as soon as Shoko records it, checking
every 30 s. It fails only if a file is still unrecorded 30 minutes after
Shoko answered (its NFS mount) or an episode unfetched after 2 hours; time
Shoko is down doesn't count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jellyfin reads Shoko's VFS, and Keep's own rescan runs before the Shoko link.
When LINK_SHOKO finishes (after a Keep, or adm shoko link) it queues
REFRESH_JELLYFIN, which waits if Jellyfin is down.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sonarr searches indexers for the series name only, so dub releases rarely
reach it. FIND_DUBS_FOR_SONARR runs 10 minutes after each Keep (after
Sonarr's own search): it asks Sonarr which monitored, aired episodes are
missing and not downloading, searches Prowlarr with AKON's dub rules, and
pushes the best release to Sonarr (release/push). Sonarr judges, grabs and
imports it; a rejection is logged with Sonarr's reason and the next
candidate is tried. adm sonarr find-dubs --id <anidb_id> runs it now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TVDB placement lookups caught every exception silently, so a dub search
saw episodes without placement and no reason. Catch only provider errors and
log them; anything else raises.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TVDB's episode pages are paced and were deferred, leaving no placement, so no
missing episode matched. Matching Sonarr's S/E needs only the cached
Anime-Lists map; release matching already uses the AniDB number.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The row keeps the fetch time and the file's SHA-256, so freshness and the
once-a-day limit work as before. Writing the list into the database held the
write lock for about 10 seconds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A search is the series, season, episode and mode. Every search added a row and
none was removed (22 MB). Migration 078 drops the older copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An E13-E24 pack went to review because the trial looked for episode 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When qBittorrent stops a torrent with an error and its disk has no room for
the rest, the download job waits (TORRENT_DISK_FULL, every 10 minutes). Once
there is room AKON restarts that torrent, only if the job was waiting for disk;
any other torrent error goes to review as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
For the Running page ("downloading, 53%"); the series job reads them from
the one sync/maindata call that covers every torrent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
qBittorrent client, providers, Prowlarr search, torrent metadata and service
checks. Anything else passes through with its trace; the two service-health
loops stay as boundaries and log the full trace at ERROR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
develop's 078 keeps only the latest Prowlarr search result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The identity bridge gives the series the torrent and the identity (TVDB ID),
so the release check uses the real TVDB series. Process anyway reopens a
decided series. The API's switch branches and the setting are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- An unexpected error stops the torrent with 'program error at file:line'
  and its full trace; its files stay and Retry resumes it at that step
  (before, it was dropped and its files deleted).
- A series whose torrents all wait sleeps until the soonest wake time or
  until woken; before, a wait without a time re-ran it ~20 times a second.
- The lease is renewed after each torrent. Torrents further along go first.
- A repeated wait logs nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- get_metadata (new first step): the version adapter decides. 5.2+ fetches
  the metadata without adding; 4.5-5.1 adds the magnet stopped with the
  torrent's own marker and folder, resumes it only until the file list is
  in, stops it and exports it. The add is saved to the row before it is
  sent, so it is never sent twice. The .torrent bytes go in a file beside
  the database.
- check_release: the real verifier, with the identity's TVDB ID; a pack is
  verified from the saved bytes and its trial starts at its first episode.
  Each chosen file keeps its AniDB episode ID.
- download: adds from the saved bytes on 5.2+, selects only the chosen
  files, starts, follows progress (logged every 10%); a full disk waits and
  restarts once there is room.
- drop: removes only a torrent AKON owns, with its files and saved metadata.
- qBittorrent down or not set up is a wait; the worker gets the real
  context (verifier, clients, a real cancel event).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- check_media: acquisition/media.verify_path (new; the same checks as
  verify_file without a job intent): size, container and audio by ffprobe,
  on the file in the torrent's own folder. Wrong audio drops the torrent.
- transcode: services/transcode as before; its try count is saved to the
  row before each try; output in <staging>/.transcode.
- stage: staging.specification and Publisher; the plan with its temporary
  names is saved before any file is created; the Publisher's records live
  in the torrent's entry, written under the series lease. A downloaded file
  is copied (qBittorrent keeps seeding); a transcoded one is moved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_series_steps.py covers media check, transcode (and a failed one) and
staging with the real code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-26: everything becomes series work; the jobs table goes.

- series.work_json (migration 079, not deployed yet) holds series-level work.
- Keep (series_job/keep.py): drop working torrents, add the series to Sonarr
  once (recorded before the send), import each staged episode as keep_service
  did (recorded before the command), one Sonarr search, Shoko link, dubs
  (japanese_english, 10 minutes later), Jellyfin rescan, cleanup of AKON's
  torrents and staged copies; then KEPT. A Sonarr refusal stops Keep with
  why and Retry resumes it. Replaces KEEP_MEDIA/KEEP_BATCH, LINK_SHOKO,
  FIND_DUBS_FOR_SONARR, REFRESH_JELLYFIN and the cleanup jobs.
- Reject (series_job/reject.py): remove AKON's torrents with their files and
  the staged files; then REJECTED.
- Cancel: drop the working torrents and stop searching.
- Search (series_job/search.py): a single episode wants its trial window;
  Prowlarr finds the episodes no torrent covers, each added as a torrent;
  nothing found is searched again every 6 hours. Replaces
  DISCOVER_EPISODE_RELEASES.
- Actions only record the request and take the lease; the worker does the
  work, so a running attempt never saves over a Keep.
- decision(): keeping counts as ACCEPT, rejecting as REJECT; no catch-all.
- The Keep handlers save from a thread through their own connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-26: one job per series; the jobs table goes (option 1).

- worker.py runs only the series job: service checks at startup (refusing
  when a required service is not set up), due re-checks, status for the API,
  the maintenance gate around each attempt, the systemd watchdog.
- Migration 080 drops the 60 old job and step tables with their history. It
  refuses while any old job is unfinished (the cutover script converts that
  work first). Recognized names and title metadata are rebuilt without
  their references to the dropped tables. A new database has only the
  series table and what it keeps.
- API: Running, Intake (one row per series, searchable), the series view and
  its actions (keep, reject, search, retry, cancel, add a release by hand).
  Job routes, batch scopes and backfill retries are removed.
  storage/connection.database() opens the database for the API and adm.
- The release check records Recognized names (series, alias, season,
  episodes), so /check answers known series at once from local data; the
  identity bridge records title metadata and the identity's names.
- adm: report intake, running, keep/reject/retry/search, shoko link and
  sonarr find-dubs work on series rows; recover and transcode are removed.
- The dub search, Shoko link and KeepSelection moved into series_job.
  Notifications open the series; the job-based notices are gone.
- 117 old modules (about 20,600 lines), their tests and the obsolete one-time
  fixes are deleted. Tests of kept code are kept and moved to series rows.

Known: test_admin_socket fails as on develop; test_adm_settings_folder waits
for the rename fix; fixes/test_cutover_series_job.py waits for the cutover
rework (item 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Work items 2 and 4 (docs/WORK_ITEMS_JOB_CLARITY.md).

- An error no code expected is a bug, not a temporary problem: the worker
  logs it at ERROR with the full trace, the job ends FAILED with
  JOB_HANDLER_FAILED after one attempt, History names the file:line and
  function where it was raised, and the bell says "Program error in <step>".
  It is not retried: the same code gives the same error.
- A cancel or a lost lease raised inside a handler is handled by the attempt
  as before, not taken for a program error.
- A fail outcome records "Step failed", not "Step finished".
- "Job started", "Step started" and "Step finished" are back at DEBUG. The
  worker holds them until the result is known: a check that only repeats the
  same wait prints nothing, and an error prints them before its trace.
- Lines that can't be written after commit are logged with their trace
  (one boundary) instead of a one-line warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Work item 3 (docs/WORK_ITEMS_JOB_CLARITY.md).

- Narrowed to the errors each place expects: the worker's service-status
  save and credentials revision, the job report's JSON and database open,
  job diagnostics, the backlog audit's qBittorrent read, adm's settings
  mismatch.
- Removed where nothing could be raised or nothing should be hidden: keep
  resolver creation, a cancellation log `pass`, the worker's database path.
- Boundaries that must keep going are marked and show the trace: the
  admin socket logs it to the API log; `__main__`, `install_support` and
  `adm recover` print it, redacted (new diagnostics.trace_text); a
  broken log sink prints it to stderr, as logging's handleError does.
- test_no_catch_alls.py fails on a new catch-all that neither re-raises nor
  is marked Boundary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A program error now fails its job at once, so everything that is not a bug
must be handled before it reaches that boundary (owner, 2026-11-27).

- qBittorrent and the AniDB/TVDB client: a dropped, truncated or garbled
  reply (http.client IncompleteRead, BadStatusLine) is ClientUnavailable /
  ProviderUnavailable, like a refused connection. It was not an OSError,
  so it would have failed the job.
- Worker boundary: a connection error or timeout the code did not attribute
  to a service is retried as NETWORK_UNAVAILABLE (new reason); a full or
  failing disk with no path named (ENOSPC, EDQUOT, EIO, EROFS, ENOMEM,
  EAGAIN) is retried as STORAGE_UNAVAILABLE. Any other OSError is a bug.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The old-pipeline files develop changed stay deleted here (job queue, job
report/recovery/diagnostics, keep and cancellation services, backlog audit,
their tests). notifications.py and the migration list keep the series side;
the series worker keeps its own loop and its service-status save also
catches disk errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: only a bug stops work, so an outage must never look like one.
- A step raising an untyped outage (connection reset, timeout, full or gone disk,
  busy database) waits a minute; it no longer stops the torrent as a program error.
- Search, Keep, Reject and Cancel had no boundary: an error there ended the worker.
  Now an outage makes the series wait, and a program error stops that series
  (work.stopped, logged with its trace, one bell) until Retry.
- Taking or saving a series failing with a program error is logged and the worker
  goes on after a minute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- ON_HOLD was treated as stopped. The old code held a job to wait (an episode
  another torrent held, a dub, a decision) and released it itself, so held work
  now converts waiting; only Needs review and Blocked convert stopped.
- A job a program error failed (JOB_HANDLER_FAILED, failed at once since the
  develop merge) is unfinished work: it converts stopped, and Retry resumes it.
  Other FAILED jobs stay as they are.
- A Keep in Needs review became a running Keep at the cutover; it now keeps its
  reason in keep.stopped and waits for Retry.
- A job of a kept or rejected series closes with no torrent instead of becoming
  a stopped torrent (or being refused without an infohash).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: one job per series knows what it is working on, so there is
nothing to hold. The ON_HOLD event and state label go from the catalog and the
audit, and the old job rendering's held badge goes from the dashboard. The
cutover converts a held job as ordinary waiting work (or closes it when the
series is decided); the work items say so. Migration tests keep ON_HOLD rows:
they are the old schema's data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: a file staged or downloaded earlier is the same file when its
size and mtime match (small files are hashed). An NFS remount gives the share a new
device number, so the saved device/inode must never decide.
- verify_file, VerifiedMedia and FileCleanup (with CleanupPermit, owned and
  fingerprint) compared a saved device and inode across time. Nothing called them
  since the per-step jobs went; they are removed. cleanup.py keeps the fd walks.
- Their filesystem tests now run against verify_path, the series media check.
  That found a bug: a symlink where the video or a folder should be raised
  MediaUnavailable, so the series waited for ever. ELOOP/ENOTDIR are now
  MediaInvalid; other OS errors (the share away) are still checked again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-27: three series (Kill la Kill, both Oshi no Ko seasons) were
cleaned up after staging hit share outages. Cleanup canceled the acquisition and
removed its staged files, but the old rows still say PUBLISHED, so the cutover
would have shown 9 staged episodes that do not exist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27 (P0): with the staging mount missing, /mnt/media/Anime-Trial is a
plain folder on the share above it. Staging there looks like it works, and the
files vanish under the mount when it comes back.

- storage_mounts: each storage folder (downloads, staging, library) is looked up in
  /proc/self/mountinfo when used. The first time it is a mount point or on a network
  filesystem, its mount point and source are learned (storage-mounts.json beside the
  database; no one is asked). From then on it must resolve to that mount, or a deeper
  one; otherwise StorageNotMounted, an outage: the series waits and retries. Local
  folders stay as before. No device numbers: a remount keeps the mount.
- The folder is opened, not stat'ed, before the lookup: NFSv4 mounts a share below
  an export only when a path goes into it (production: /mnt/media/Anime was its own
  share yet missing from mountinfo until opened).
- One wrapper, @uses_storage(...), on each step that touches storage: media check,
  transcode, stage, Keep, Reject. A test pins which steps declare which folders.
- The worker logs what it learned at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: production canceled 27 good releases since 11-22 (13 at staging,
14 at transcode, e.g. Fool Night three times) because the share was unreachable;
each cancel removed the download and waited for a torrent that may never come.
The series job had the same shape:
- Transcode counted our own share failing (a stale read, the result not written)
  as a failed attempt; three, and the torrent was dropped with its download. Now
  storage trouble raises TranscodeStorageUnavailable: the torrent waits and the
  attempt is given back. Agent trouble (connection, timeout, network errno) still
  fails over and counts.
- A step can now stop (StepResult.stop): the torrent keeps its files, its reason is
  noted, you are told once, and Retry resumes it at that step. Staging's file
  checks not matching, and every transcoder failing, stop instead of drop: neither
  proves the release bad. Drop stays for a torrent that is itself unusable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27:
- content_id: SHA-256 of the size and three 64 KB samples (start, middle, end); about
  9 ms over NFS on any size of video (production, 60 staged files). A touch, a copy or
  a remount keeps it; a replaced, truncated or re-encoded file differs. Recorded by
  the media check for every torrent (transcode on or off), for a transcoded result,
  and for the staged copy. Staging's source checks, transcode's source check and
  Keep compare size and content instead of size and mtime; rows from before
  content_id compare size only.
- Reject and Keep remove what AKON planned, not only what reached PUBLISHED
  (production: 5 videos of rejected series were left by publications stuck in
  PLANNED, tvshow.nfo because its mtime moved), with the episode NFOs, tvshow.nfo
  and the empty folders. A file whose content differs is left and noted; your own
  files in the folder are never removed.
- Staging full: a torrent starts downloading only when staging has room for its
  files after everything already on its way there; until then it waits
  (STAGING_FULL). The download step is guarded by the staging mount too.
- Cutover: Needs review for an outage converts as waiting, never stopped; converted
  staged episodes get their content id (production copy: 219 of 219, all accepted
  by Keep, including the 11 whose mtime moved).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27:
- Titles: with English chosen, Intake showed AniDB's main title (usually romaji) for most
  series: only anime_title_metadata was read (English for 112 of 153 on production).
  AniDB's title list, already cached for identification, has the official English
  title of 141; together 149 (the other 4 have English main titles). One lookup
  (anime_titles.names/title_for): the metadata, then the cached list, stale or not,
  parsed once per version. Intake, Running (now in the chosen language too) and the
  Names page use it.
- Jellyfin showed some series twice: each AniDB entry (a season) had its own staging
  folder. Now one folder per TVDB series, '<series> [tvdbid-N]', named in the chosen
  language after the entry Anime-Lists maps to its season 1; a folder that already
  holds the series is used, so it never splits again.
- The cutover merges the split ones (production: Cyberpunk Edgerunners, Tensei
  Kizoku, Tougen Anki) by moving their Season folders into the Season 01 folder, and
  rewrites the converted rows' paths. Moves happen before the conversion and are
  undone if it fails; a season that would collide, or a folder holding files AKON
  did not stage, is reported and left.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The full run had 49 failures, 48 of them from before today (also on develop).
- configuration_schema raised MetadataSourceConfigurationError, defined in a module the
  series job removed: an invalid metadata source URL was a NameError. Its caller makes
  a ValueError a ConfigurationError, so it raises that.
- Refactor ledger: entries for modules the series job removed are dropped (a removed
  module cannot bring a name back); its self-check names a module that exists.
- Identity tests (sequel discovery, AniDB scoring) gave a database that does not exist
  or is in memory; identification opens the configured database itself, so they use
  an empty real one (and the match threshold setting).
- Installer, storage overlap tests: the akon names and folders after the rename.
- The worker command runs the series worker; there are no backfill flags now.
- SQL parameter scan: its sanity bound follows the smaller SQL of the series job.
- Intake rows carry 'stopped' (a series stopped by a program error).

Full suite: 1044 passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
usermod -l renames the account but keeps its home, /var/lib/anime-discovery, which
the rename moves to /var/lib/akon. Same UID and GID, so every file the service owns
(local and on the NFS share) is akon's with no chown; usermod -l also renames it in
the media group's member list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: without Jellyfin or AKON the owner cannot tell which series a staged
folder is, and Jellyfin showed some in romaji. series_job/retitle.py renames what is
already staged the way new staging names it: one folder per TVDB series, named after
its season-1 entry in the chosen language; each video '<series> - SxxEyy' (a rename:
content and content_id unchanged); NFOs written again by staging's own code. The rows
follow (paths; NFO size, hash and text), so Keep and Reject still know the files.

Only AKON's files move; a destination holding a file AKON did not stage leaves that
series as it is. Undo puts everything back. It replaces the cutover's folder merge
(retitling brings a series' seasons into one folder anyway).

- Cutover: retitles before converting (undone if the conversion fails); --language,
  default english. Production copy: 49 series, all 219 staged episodes, none skipped.
- adm retitle: preview by default; --apply with the worker stopped; uses the title
  language setting, so it can be run again after changing it.
- The title lookups work before the series table exists, and read the provider cache
  at any schema version (the cutover previews at v77).

Full suite: 1049 passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27:
- The branch stays in the database name, as the installer names a branch's database
  (<state>/akon-<branch>.sqlite); the settings' database_path, which the installer
  reads, follows. Its files folder becomes akon-develop-files.
- The old pipeline left 1571 per-operation locks (.<db>.nextgen-operation-N) and 250
  staging locks (.nextgen-stage-N.lock) in the data folder; with the old database
  name's gate locks (the gate makes its own for the new name) they are removed. Only
  empty regular files; the other branches' databases keep theirs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-27: the rename failed after renaming the user and moving /etc: it
updated every settings.json under /etc, and the first it reached was an old conversion
backup (.settings-backup-*/settings.json) with no schema version. Nothing else changed;
the printed undo was complete.
- The live settings (branches/develop) and their qBittorrent credentials are read
  before the first change, so a file it cannot read stops it with nothing done.
- Only the develop branch's settings are updated. The other copies (other branches,
  the old top-level settings at schema 14, backups) are unused; they are left as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: /etc keeps branches/develop's settings.json, secrets.json,
management-password.json and their locks; the old NextGen top-level settings
(schema 14), its secrets and secrets.json.old, the .bak copies, the conversion backup
folder and branches/refactor are removed, and the installer state lists only develop.
It is the rename's last step, once everything else worked, so the undo printed for a
failed step still applies; the preview lists every file it removes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-27: One Piece (absolute numbering) has no TVDB episode in its search
target. The reason written for a result that did not match formatted
S{season:02d}E{None:02d}: TypeError, and the series stopped as a program error. A
season pack's parsed episode is None the same way. episode_label() writes S01E05, S01,
E1160 or 'unknown' from what is known; the test searches a target with no TVDB episode
against an other-episode result and a pack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-27: after the upgrade the dashboard looked broken. The open tab was
/jobs, the Jobs page removed with the per-step jobs, and the API answered it with a bare
404 (the only page the browser asked for). /jobs, under /, /akon or /anime-discovery,
now redirects to Intake. The links that still went there (an episode's related jobs,
View job, the notification's open jobs) open the series view or Running instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-27: the dashboard showed nothing and made no request. At load,
dashboard.js attached listeners to the Jobs page's controls (search, status filter,
select page, bulk buttons, next/previous page), removed with the per-step jobs;
$('search') was null and the TypeError stopped the whole script. Those listeners go.
dashboard_load.js runs the script at load against a page with exactly index.html's
IDs: it fails on the deployed version at the same line and passes now.

A dashboard page that is not there (the old /jobs, a mistyped address) redirects to
Intake, under /, /akon or /anime-discovery; files and API routes still answer their errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: each reload found the next element or route the series job had
removed. dashboard.js (2122 lines, written for the per-step jobs) loses what can no
longer run: the Jobs list and its controls, bulk actions, job history, job matching and
coverage, the transcode batch panel and the old series view (now 1404 lines). Intake's
loader is Intake only; a release added by hand goes to /series/{id}/release (its old
route was gone); the history dialog goes.

Static checks (test_dashboard_static.py), in the normal suite: every element the script
looks up is on the page, every API path it requests is served. On the deployed script
they report all 15 missing elements and 10 dead routes at once. dashboard_load.js runs
the script at load for all four pages.

What the series job records is shown now: why a torrent waits or stopped (staging full,
storage not mounted, ...), a series stopped by a program error, why a Keep stopped, the
next check time, and the series' recent history.

A browser test of every page against the real API is written up for later:
docs/DASHBOARD_BROWSER_TEST.md.

Full suite: 1063 passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: one command for a series, its actions as options. Without an action
it shows the series (state, torrents and why each waits or stopped, episodes, recent
history; --json). It replaces adm keep, reject, search, retry and report intake; --cancel
is new (the dashboard had it). --reason and --note go with --reject only; one action at
a time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-27: production sent every transcode to the first agent (10.1.1.2) and
the second sat idle: the list was always tried in order and the first was always free
(the worker runs one series at a time). in_turn() rotates the list for each transcode,
for any number of agents; a busy, unreachable or failing agent still hands the video to
the next one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-28: both settings existed but the series worker read neither: one series
at a time, and every series took the row's default of one torrent, so work queued for
ever. Now worker.concurrency lanes run at the same time (default 2, was 4; production
sets 2), each attempt with its own copy of the context (they ran on one shared object);
one lane at a time checks the services. A series works on series.torrents_at_once
torrents per attempt (default 1). Two lanes also keep two transcode agents busy.

Full suite: 1071 passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-28: 'Torrents worked on at once per series' was in a Settings panel of its
own (Series), apart from 'Series worked on at once' (Worker). Both are in one Workload
panel now. A panel's save sends each field under its own section (it sent them all under
the panel's), in one request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-28: every release that needed AniDB failed with NameError:
IdentityRequest. identity_process.py ran sys.exit(main()) in its __main__ block above
the class (and _movie_request). Imported, as the tests do, the module loads whole and
nothing failed; run with python -m, as the API starts it, main() ran first. The block
is last now, and test_module_entry_points checks that for every module in src/anime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner, 2026-11-28: 'I want to watch this first', or a failed series retried and then put
first. A promoted series is the next one a free lane takes, before every other series
(the latest promotion first), and a sleeping one is woken. Its own column (migration 081,
promoted_at_ms): the worker's save of a series it holds never writes it, so a promotion
made meanwhile stays.

- API: POST /series/{id}/promote and /unpromote; decided series are refused.
- adm series --id N --promote | --unpromote, alone or with an action
  (adm series --id 69 --retry --promote).
- Dashboard: Running lists promoted series first (marked), with promote/unpromote per
  row; the series view has promote/unpromote next to retry.

Full suite: 1083 passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The worker copies the context per attempt (worker.concurrency lanes); the
catalog was a closure over the original context, whose settings are None,
so every backfill search stopped with AttributeError.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sonarr marks a ManualImport completed even when it imported nothing (here it
could not write its library folder); Keep waited for ever. Five minutes after
completed with no file, Keep stops with IMPORT_NOT_DONE and points at Sonarr's
log; the import goes back to PLANNED, so Retry sends it again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With an old-pipeline folder '... [tvdbid-N] [anidbid-N]' next to the current
'<name> [tvdbid-N]', series_folder took the first by name, so Marronnier's new
episodes went into both and Jellyfin showed the series twice. The exact current
name comes first, then any current-form folder, then the old layout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dashboard showed the download's 100% through the transcode. transcode()
reports a numeric progress (agent or local encoder); the step saves it as
transcode_progress whenever its whole percent changes, under the lease. The
views send the current step's progress (download, transcode) and none for
steps that do not measure one; the dashboard and adm show '-' then.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the import only follow-ups are left (Shoko linking, which can wait up to
two hours for AniDB data, the dub search, Jellyfin, cleanup); webhooks for the
series are already refused. A stopped Keep still shows, since it needs you.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sonarr upgraded the kept episodes minutes after the import and deleted AKON's
files; the Shoko step asked for them for 30 minutes and reported them unlinked.
It now asks Sonarr which file each episode has, links only AKON's that are
still there, and notes how many Sonarr replaced (Sonarr's own are Shoko's to find).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A SeriesSearch also searches every episode below the profile's cutoff: Sonarr
replaced each episode AKON had just imported (HDTV-1080p, under Anime's
Bluray-1080p cutoff) minutes after the Keep. Keep now sends an EpisodeSearch
for the monitored, aired episodes with no file that are not downloading, and
none at all when nothing is missing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AKON's renamed files carry no source or group, so Sonarr guessed HDTV-1080p
(and a group from the title): any WEB 1080p release was an upgrade, and Sonarr
downloaded the episode again. The quality and group now come from the release
name; a name with no source tag (most fansub and encode groups) counts as
WEBRip, which Sonarr ranks with WEB-DL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ProtectSystem=strict with the media in ReadWritePaths pinned each share to the
mount present when the worker started; after a remount or an expired NFS
submount the worker saw the share read-only until restarted. The worker now
uses ProtectSystem=full (/usr, /boot, /etc stay read-only) and writes media by
file permissions. The API keeps strict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The worker's old ProtectSystem=strict unit bound each ReadWritePaths folder
onto itself, so /mnt/media/Torrents/anime, a plain folder of the media share,
was learned as its own mount. Once the unit stopped binding it, downloads
waited for a mount that never existed. A mount with the device of the mount it
sits in is now passed over, and facts learned before this are learned again
from what is mounted now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Relearning facts from before binds were passed over could drop the gate of a
real share that happened to be missing at that moment, and AKON would write
into the empty folder under it. Production's one wrong fact is already
relearned, and the worker unit no longer binds media folders, so the
relearning goes; the bind filter stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An outage that made a step or a series wait logged a warning on every attempt
(about 430 lines in two hours on production) and was never saved, so the
dashboard and adm showed a step that did not move with no reason. A wait is
now logged and noted once, when it starts or its reason changes. The torrent
keeps the reason in its why ('STORAGE_UNAVAILABLE: ...') and the series in
work['waiting'] until a step gets through, which notes that the wait is over.
adm running, adm series and the dashboard show it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The worker hashed the whole source before sending it (15-20 s for 1.5-2 GB),
only to put the SHA-256 in a header, then hashed it again while sending. Agent
version 2 takes no X-Sha256: it returns the SHA-256 of the body it received,
and the worker compares it with the one computed while sending, deleting the
job when they differ. Agents and workers must both be version 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cutover read markers only from torrent_submissions and batch_torrent_submissions.
Torrents still waiting for their file list had theirs in batch_metadata_admissions and
magnet_intents, so their series torrents got new markers, and AKON dropped its own
torrent as one it did not add (SERVICE_RESPONSE_INVALID). On production, 7 series
torrents take back their old marker and 13 torrents no series has are deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Production, 2026-11-29: a root adm that opened the database could leave its -wal/-shm
owned by root, and the worker failed with "attempt to write a readonly database".

- The admin socket takes {"command": "api", ...} and runs the dashboard's own routes
  behind sign-in (Application._signed_in); being local as root or the service account
  (SO_PEERCRED) is the sign-in. The HTTP path is unchanged.
- adm series, running, shoko link, sonarr find-dubs and services check go through it
  (new routes: series/N/shoko-link, series/N/find-dubs, services/check). With the API
  stopped adm says so (exit 3).
- adm retitle --apply asks the worker (v82 worker_requests): the worker finishes the
  series it holds, starts none, retitles, and goes on. It no longer has to be stopped.
  Staging not mounted waits; a program error fails the request with where.
- A test fails if any adm command imports the database, settings or secrets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The repository moved to git.bugzbunny.net/bugzbunnynet/AniKeepOrNot (public,
so HTTPS needs no key). GitHub stays as it is but is no longer updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'develop:develop'
git switch 'develop'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'develop'
git switch 'develop'
git rebase 'main'
git switch 'main'
git merge --ff-only 'develop'
git switch 'develop'
git rebase 'main'
git switch 'main'
git merge --no-ff 'develop'
git switch 'main'
git merge --squash 'develop'
git switch 'main'
git merge --ff-only 'develop'
git switch 'main'
git merge 'develop'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bugzbunnynet/AniKeepOrNot!2
No description provided.