Skip to content

feat(tracker-core): activate persistence-free v3 runtime composition - #2112

Merged
josecelano merged 23 commits into
torrust:developfrom
josecelano:2107-activate-persistence-free-v3-runtime-composition
Aug 31, 2026
Merged

josecelano merged 23 commits into
torrust:developfrom
josecelano:2107-activate-persistence-free-v3-runtime-composition

Conversation

@josecelano

@josecelano josecelano commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #2107, a subissue of the configuration-overhaul EPIC #1978.

  • honor an omitted v3 database configuration with a persistence-free public tracker runtime
  • validate persistence-required capabilities before application composition
  • keep REST key and whitelist routes available with configuration-disabled HTTP 409 responses
  • preserve configured SQLite, MySQL, and PostgreSQL initialization and shared migrations
  • provide a no-persistence release-container startup path without a packaged SQLite seed
  • preserve selected SQLite targets across persistence disable, target change, and target reuse
  • add and enforce the release-image persistence-transition regression in the Docker workflow

Validation

  • focused configuration, bootstrap, tracker-core, REST API, and E2E tests
  • SQLite qBittorrent HTTP and UDP seeder-to-leecher transfers
  • release-image persistence-transition regression in CI-equivalent no-rebuild mode
  • pre-commit and pre-push checks, including the full workspace test suite

Follow-up

The broader replacement of the Bash regression with fast policy tests and a Rust-owned container suite is recorded as a deferred refactor plan in the issue documentation. The current Bash regression is named by scenario and is enforced in the Docker workflow.

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.00686% with 83 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.97%. Comparing base (576f366) to head (9be7ae0).

Files with missing lines Patch % Lines
src/app.rs 71.83% 17 Missing and 3 partials ⚠️
src/bootstrap/jobs/tracker_core.rs 54.54% 10 Missing ⚠️
...ages/tracker-core/src/statistics/event/listener.rs 75.67% 9 Missing ⚠️
...kages/axum-http-server/src/v1/handlers/announce.rs 50.00% 5 Missing ⚠️
...est-api-server/src/v1/context/auth_key/handlers.rs 73.68% 5 Missing ⚠️
packages/http-core/src/services/announce.rs 50.00% 5 Missing ⚠️
packages/http-core/src/services/scrape.rs 50.00% 5 Missing ⚠️
packages/tracker-core/src/test_helpers.rs 50.00% 5 Missing ⚠️
packages/udp-server/src/handlers/mod.rs 50.00% 5 Missing ⚠️
...kages/tracker-core/src/statistics/event/handler.rs 76.47% 4 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2112      +/-   ##
===========================================
- Coverage    83.99%   83.97%   -0.03%     
===========================================
  Files          349      349              
  Lines        26996    27240     +244     
  Branches     26996    27240     +244     
===========================================
+ Hits         22676    22875     +199     
- Misses        3981     4021      +40     
- Partials       339      344       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR activates persistence-free runtime composition for the v3 configuration path by removing the fixed SQLite fallback, introducing an explicit optional PersistenceServices group in tracker-core, and keeping REST API capability routes registered while returning controlled 409 Conflict responses when their corresponding capabilities are disabled.

Changes:

  • Removed the temporary fixed-SQLite compatibility bridge and composed tracker-core from core.database: Option<Database>.
  • Grouped database-backed services under TrackerCoreContainer::persistence: Option<PersistenceServices> and threaded optional persistence dependencies through core handlers/jobs.
  • Made REST key/whitelist routes capability-aware (returning 409 with ActionStatus::Err when disabled) and added/updated focused integration tests plus manual verification evidence docs.

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/container.rs Removes the fixed SQLite bridge and asserts persistence-free initialization in a test.
src/bootstrap/jobs/tracker_core.rs Starts tracker-core event listener with optional persistence repositories.
src/bootstrap/app.rs Adds bootstrap persistence-requirement validation before container composition.
src/app.rs Gates persistence-only startup calls behind persistence.as_ref() and adds a persistence-free listener test.
packages/udp-server/src/handlers/mod.rs Updates handler construction to accept optional persistent metrics repository.
packages/udp-server/src/handlers/announce.rs Updates announce test wiring for optional persistent metrics repository.
packages/tracker-core/tests/common/test_env.rs Updates test env to use persistence for persistence-backed dependencies.
packages/tracker-core/src/torrent/manager.rs Makes DB downloads metrics repo optional and adds persistence-required expectations.
packages/tracker-core/src/test_helpers.rs Updates test helper wiring for optional persistent metrics repository.
packages/tracker-core/src/statistics/event/listener.rs Makes the persisted metrics repo optional in the event listener.
packages/tracker-core/src/statistics/event/handler.rs Uses optional persisted metrics repo when persistent completed stats are enabled.
packages/tracker-core/src/container.rs Introduces PersistenceServices and composes a persistence-free container when no database is configured.
packages/tracker-core/src/announce_handler.rs Makes persisted metrics dependency optional and asserts when required by config.
packages/rest-api-protocol/src/v1/context/whitelist/resources/whitelist.rs Adds a disabled-by-configuration whitelist error variant and display message.
packages/rest-api-protocol/src/v1/context/auth_key/resources/auth_key.rs Adds a disabled-by-configuration auth-key error variant and display message.
packages/http-core/src/services/scrape.rs Updates scrape test wiring for optional persistent metrics repository.
packages/http-core/src/services/announce.rs Updates announce test wiring for optional persistent metrics repository.
packages/http-core/benches/helpers/util.rs Updates bench helper wiring for optional persistent metrics repository.
packages/axum-rest-api-server/tests/server/v1/contract/context/whitelist.rs Adds contract ensuring disabled whitelist behavior returns 409 without DB access; updates configs for listed tests.
packages/axum-rest-api-server/tests/server/v1/contract/context/auth_key.rs Adds contract ensuring disabled auth-key behavior returns 409 without DB access; updates configs for private tests.
packages/axum-rest-api-server/tests/server/v1/asserts.rs Adds shared assert helper for disabled-by-configuration 409 responses.
packages/axum-rest-api-server/src/v1/routes.rs Builds auth-key/whitelist services only when capabilities are enabled; otherwise routes are still registered with disabled behavior.
packages/axum-rest-api-server/src/v1/responses.rs Adds a 409 disabled-by-configuration response helper.
packages/axum-rest-api-server/src/v1/context/whitelist/routes.rs Passes an optional whitelist service through router state.
packages/axum-rest-api-server/src/v1/context/whitelist/mod.rs Updates docs to reflect 409 Conflict behavior when capability is disabled.
packages/axum-rest-api-server/src/v1/context/whitelist/handlers.rs Short-circuits to 409 when whitelist capability is disabled (no service in state).
packages/axum-rest-api-server/src/v1/context/auth_key/routes.rs Passes an optional auth-key service through router state.
packages/axum-rest-api-server/src/v1/context/auth_key/handlers.rs Short-circuits to 409 when private capability is disabled (no service in state).
packages/axum-http-server/tests/server/v1/contract/configured_as_whitelisted.rs Updates whitelisted tests to use persistence.whitelist_manager.
packages/axum-http-server/tests/server/v1/contract/configured_as_private.rs Updates private tests to use persistence.keys_handler.
packages/axum-http-server/src/v1/handlers/announce.rs Updates announce test wiring for optional persistent metrics repository.
docs/issues/open/2107-1978-activate-persistence-free-v3-runtime-composition/manual-t3-persistence-free-runtime.md Adds manual evidence for a persistence-free v3 local runtime run.
docs/issues/open/2107-1978-activate-persistence-free-v3-runtime-composition/manual-t2-rest-route-contract.md Adds manual evidence for REST disabled-capability 409 contract.
docs/issues/open/2107-1978-activate-persistence-free-v3-runtime-composition/ISSUE.md Updates issue spec status/task tracking and links evidence artifacts.
docs/issues/open/2107-1978-activate-persistence-free-v3-runtime-composition/bootstrap-error-propagation-draft.md Adds a deferred design draft for typed bootstrap error propagation (out of scope for this issue).
docs/issues/open/1978-configuration-overhaul-epic/EPIC.md Updates EPIC links to the issue-local folder path for #2107.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/tracker-core/src/container.rs Resolved
Comment thread src/app.rs Resolved
@josecelano
josecelano force-pushed the 2107-activate-persistence-free-v3-runtime-composition branch from 8998e78 to a105f9d Compare August 28, 2026 17:47
@josecelano
josecelano force-pushed the 2107-activate-persistence-free-v3-runtime-composition branch from 8ffb78e to 4545e57 Compare August 30, 2026 14:26
@josecelano
josecelano marked this pull request as ready for review August 31, 2026 12:57
@josecelano
josecelano requested a review from a team as a code owner August 31, 2026 12:57
@josecelano
josecelano force-pushed the 2107-activate-persistence-free-v3-runtime-composition branch from fae1d22 to 9be7ae0 Compare August 31, 2026 14:20
@josecelano

Copy link
Copy Markdown
Member Author

ACK 9be7ae0

@josecelano
josecelano merged commit 6361374 into torrust:develop Aug 31, 2026
28 of 29 checks passed

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a post-merge review of the change from #2112 as it stands at a94c3ced8 on the default branch.

Most of what this change added still runs. TrackerCoreContainer::initialize_from builds persistence services only from [core.database]. bootstrap::app::setup runs validate_persistence_requirements before composition. Completed-download persistence has its own listener, separate from the in-memory statistics listener, and the startup loaders skip their work when no persistence is composed. The REST key and whitelist routes answer 409 when their capability is off. On a fresh configuration mount with no driver selected, the container entrypoint installs tracker.container.no-persistence.toml, and the container workflow runs test-mounted-no-persistence-configuration.sh against the release image it builds. Later commits replaced the panics with typed startup errors, added a drain on cancellation to both listeners, and made the check's run_tracker forward SIGINT (08e4d2b).

[Minor] The documentation calls the database-driver variable a selector that leaves a mounted configuration alone, but the tracker process still applies it as an override. docs/containers.md:256 says it "does not override an existing mounted configuration file", and packages/configuration/docs/migrate-v2-to-v3.md:323-326 says the same. share/container/entry_script_sh:34 uses it only to pick a template, then hands the unchanged environment to the tracker (line 93). packages/configuration/src/v3_0_0/mod.rs:397 merges every TORRUST_TRACKER_CONFIG_OVERRIDE_* variable over the loaded file. A [core.database] table that holds only driver = "sqlite3" resolves to the relative default path ./storage/tracker/lib/database/sqlite3.db (packages/configuration/src/v3_0_0/database.rs:60-62 and 181-186). Sequence: an operator moving an SQLite deployment to no persistence mounts tracker.container.no-persistence.toml as /etc/torrust/tracker/tracker.toml and keeps TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=sqlite3 in the container environment. The entrypoint leaves the file alone, but the tracker composes SQLite at /home/torrust/storage/tracker/lib/database/sqlite3.db, because the entrypoint changes to /home/torrust at line 90. That directory does not exist, so startup fails with a persistence error instead of running without persistence. With mysql or postgresql as the value, loading fails on the missing connection fields. The check written for this case, contrib/dev-tools/containers/tests/test-mounted-no-persistence-configuration.sh:71-85, sets the variable but runs only entry.sh true and never starts the tracker. The tracker runs in the transition steps (lines 95-121) do not set the variable. Smallest fix: unset TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER in the entrypoint after the template is chosen and before exec. This is safe for the end-to-end runner, whose inline configuration already carries its own [core.database]. Then extend the check to start the tracker with the variable set.

[Minor] A mounted SQLite configuration on an empty /var/lib/torrust/tracker volume no longer starts. Before this change the entrypoint always ran mkdir -p /var/lib/torrust/tracker/database/. Now share/container/entry_script_sh:66-69 creates the directory only when it installs the packaged SQLite template on a fresh /etc/torrust/tracker. The SQLite connection options create a missing database file but not its parent directory (packages/tracker-core/src/databases/driver/sqlite/mod.rs:42). Sequence: an operator keeps an existing tracker.toml with path = "/var/lib/torrust/tracker/database/sqlite3.db" (bind-mounted, read-only, or carried over to a new host) and attaches a new, empty data volume. Composition fails with "unable to open database file", where the tracker used to start on an empty database. The transition check hides this because it creates the directory itself (test-mounted-no-persistence-configuration.sh:96). Smallest fix: have the SQLite driver create the parent directory of the configured path before connecting, or have the entrypoint create /var/lib/torrust/tracker/database/ when the mounted file names that path. Then remove the mkdir from the check so the check covers this case.

[Nit] src/bootstrap/persistence.rs:1-6 still says the check "is intentionally not called while the active runtime uses v2 configuration" and that a follow-up will call it. This change made setup call it (src/bootstrap/app.rs:62), so the module comment now contradicts the code. Replace it with one sentence saying setup runs the check before composition.

[Nit] This change added a rule that persistent_torrent_completed_stat requires tracker_usage_statistics (src/bootstrap/persistence.rs:27-31 and 41-43), and three places describe it inaccurately. First, its doc comment says completed metrics are "collected by the tracker usage statistics listener". The real dependency is that tracker_usage_statistics turns on the swarm event bus (src/container.rs:80-82), and the separate persistent listener consumes that bus's completion events. Second, it is reported under the wrapper "unmet persistence requirements. Configure [core.database] or disable the dependent capability" (src/bootstrap/app.rs:36-41), but adding a database does not satisfy it. Third, the migration guide lists only the three database rules (packages/configuration/docs/migrate-v2-to-v3.md:317-321). The rule itself is right: before this change that combination silently persisted nothing, because the bus was off. Smallest fix: correct the doc comment, add the rule to the migration guide, and give it a startup error variant whose advice fits.

[Nit] Only the whitelist module notice documents the new 409 answer. The auth-key module documentation (packages/axum-rest-api-server/src/v1/context/auth_key/mod.rs:1-21) and the response lists of all seven key and whitelist handlers leave it out, for example packages/axum-rest-api-server/src/v1/context/auth_key/handlers.rs:18-30 and packages/axum-rest-api-server/src/v1/context/whitelist/handlers.rs:18-26. Also, when the private capability is off, add_auth_key_handler answers a request body that does not parse with the JSON extractor's rejection, not the 409 (auth_key/handlers.rs:31-37). Add the 409 line to those response lists and a notice to the auth-key module documentation.

Checked and found sound:

  • Persistence is composed only from [core.database], and persistent completed statistics without it return a typed error (packages/tracker-core/src/container.rs:83-136).
  • Every public start path validates capabilities before composition, so an enabled capability never reaches a loader without persistence.
  • The key and whitelist services are built only when both the capability and persistence are present (packages/axum-rest-api-server/src/v1/routes.rs:25-67).
  • Announcements read persisted downloads only for swarms that are absent from memory (packages/tracker-core/src/announce_handler.rs:196-205).
  • The persistent listener refuses to start without persistence (src/bootstrap/jobs/tracker_core.rs:40-63).
  • The runtime image no longer bakes in the driver override or ships the SQLite seed (Containerfile:238).
  • The workflow runs the check against the release image built in the same job (.github/workflows/container.yaml:76 and 132-136).

This branch was previously deployed

1 inactive deployment
coverage — 9be7ae08 Deployed Aug 31, 2026 by josecelano via Generate Coverage Report #1867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activate persistence-free v3 runtime composition

3 participants