From 48308528101df45575f6b9eb1a060728b82b9151 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:28:56 +0000 Subject: [PATCH 01/15] refactor(axum-health-check-api-server): [#2450] migrate the health-check API test environment to the token lifecycle Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/environment.rs | 362 +++++++++++++++--- .../tests/server/contract.rs | 16 +- 2 files changed, 313 insertions(+), 65 deletions(-) diff --git a/packages/axum-health-check-api-server/src/environment.rs b/packages/axum-health-check-api-server/src/environment.rs index 0291b303b7..a9fa591061 100644 --- a/packages/axum-health-check-api-server/src/environment.rs +++ b/packages/axum-health-check-api-server/src/environment.rs @@ -1,90 +1,83 @@ +use std::fmt::Display; use std::net::SocketAddr; use std::sync::Arc; -use tokio::sync::oneshot::{self, Sender}; use tokio::task::JoinHandle; +use tokio_util::sync::{CancellationToken, DropGuard}; use torrust_server_lib::registar::Registar; -use torrust_server_lib::signals::{self, Halted as SignalHalted, Started as SignalStarted}; +use torrust_tracker_axum_server::signals::GracefulShutdownOutcome; use torrust_tracker_configuration::v3_0_0::health_check_api::HealthCheckApi; -use torrust_tracker_primitives::RuntimeServiceMetadata; +use torrust_tracker_primitives::{ConfigurationInstanceId, RuntimeServiceMetadata, ServiceRole}; -use crate::{HEALTH_CHECK_API_LOG_TARGET, server}; +use crate::server::{self, CancellationRunning}; +pub type Unstarted = Environment; pub type Started = Environment; #[derive(Debug)] #[non_exhaustive] pub enum Error { - #[allow(dead_code)] Error(String), } -pub struct Running { - pub binding: SocketAddr, - pub halt_task: Sender, - pub task: JoinHandle, +/// A test environment with no health check API server running. +pub struct Stopped { + bind_to: SocketAddr, } -pub struct Stopped { - pub bind_to: SocketAddr, +/// A test environment whose health check API server runs on the token-aware +/// lifecycle. The environment owns the server task and its drain controller. +/// +/// The environment owns no event listener, so one token stops everything it +/// started. Dropping it without `stop()` cancels that token, and the server +/// shuts down once it observes it, so the binding is released shortly after +/// the drop. +pub struct Running { + server: CancellationRunning, + bind_to: SocketAddr, + cancel_server_on_drop: DropGuard, } pub struct Environment { pub registar: Registar, - pub state: S, + state: S, } impl Environment { #[must_use] pub fn new(config: &Arc, registar: Registar) -> Self { - let bind_to = config.bind_address; - Self { registar, - state: Stopped { bind_to }, + state: Stopped { + bind_to: config.bind_address, + }, } } - /// Start the test environment for the Health Check API. - /// It runs the API server. + /// Starts the test environment with a fresh cancellation token, so a + /// stopped environment can be started again. /// /// # Panics /// - /// Will panic if it cannot start the service in a spawned task. + /// Will panic if the server cannot be started. pub async fn start(self) -> Environment { - let (tx_start, rx_start) = oneshot::channel::(); - let (tx_halt, rx_halt) = tokio::sync::oneshot::channel::(); - - let registar = self.registar.clone(); - - tracing::debug!(target: HEALTH_CHECK_API_LOG_TARGET, "Spawning task to launch the service ..."); - - let server = tokio::spawn(async move { - tracing::debug!(target: HEALTH_CHECK_API_LOG_TARGET, "Starting the server in a spawned task ..."); + let cancellation_token = CancellationToken::new(); - let server = server::start(self.state.bind_to, tx_start, rx_halt, registar) - .expect("it should construct the health check service"); - server.running.await.expect("it should start the health check service"); - server - .shutdown_controller - .await - .expect("it should stop the graceful shutdown controller"); - - tracing::debug!(target: HEALTH_CHECK_API_LOG_TARGET, "Server started. Sending the binding {} ...", self.state.bind_to); - - self.state.bind_to - }); - - tracing::debug!(target: HEALTH_CHECK_API_LOG_TARGET, "Waiting for spawning task to send the binding ..."); - - let binding = rx_start.await.expect("it should send service binding").address; + let server = server::start_with_cancellation( + self.state.bind_to, + self.registar.clone(), + RuntimeServiceMetadata::new(ConfigurationInstanceId::new(ServiceRole::HealthCheckApi, 0)), + cancellation_token.clone(), + ) + .await + .expect("it should start the health check service"); Environment { - registar: self.registar.clone(), + registar: self.registar, state: Running { - task: server, - halt_task: tx_halt, - binding, + server, + bind_to: self.state.bind_to, + cancel_server_on_drop: cancellation_token.drop_guard(), }, } } @@ -95,24 +88,279 @@ impl Environment { Environment::::new(config, registar).start().await } - /// # Errors + /// The address the server is listening on. + #[must_use] + pub const fn bind_address(&self) -> SocketAddr { + self.state.server.local_addr + } + + /// Stops the test environment and returns a stopped environment. /// - /// Will return an error if it cannot send the halt signal. + /// It cancels the token and joins the server task and its drain + /// controller. /// - /// # Panics + /// # Errors /// - /// Will panic if it cannot shutdown the service. + /// Will return an error, after both tasks have been joined, if either task + /// failed or the drain timed out. The message names each failing task. pub async fn stop(self) -> Result, Error> { - self.state - .halt_task - .send(SignalHalted::Normal) - .map_err(|e| Error::Error(e.to_string()))?; + let Running { + server: + CancellationRunning { + task, + shutdown_controller, + .. + }, + bind_to, + cancel_server_on_drop, + } = self.state; + + cancel_server_on_drop.disarm().cancel(); - let bind_to = self.state.task.await.expect("it should shutdown the service"); + join_owned_tasks(task, shutdown_controller).await.map_err(Error::Error)?; Ok(Environment { - registar: self.registar.clone(), + registar: self.registar, state: Stopped { bind_to }, }) } } + +/// Joins the server task and its drain controller and reports every failure at +/// once, so a failure of one never leaves the other detached. +async fn join_owned_tasks( + server_task: JoinHandle>, + drain_controller: JoinHandle, +) -> Result<(), String> { + let (server_result, drain_result) = tokio::join!(server_task, drain_controller); + + let mut failures = Vec::new(); + + match server_result { + Ok(Ok(())) => {} + Ok(Err(error)) => failures.push(format!("health check API server task failed: {error}")), + Err(error) => failures.push(format!("health check API server task failed to join: {error}")), + } + + match drain_result { + Ok(GracefulShutdownOutcome::Drained) => {} + Ok(GracefulShutdownOutcome::TimedOut) => failures.push("health check API drain controller timed out".to_owned()), + Err(error) => failures.push(format!("health check API drain controller failed to join: {error}")), + } + + if failures.is_empty() { + Ok(()) + } else { + Err(failures.join("; ")) + } +} + +#[cfg(test)] +mod tests { + use std::net::TcpListener; + use std::sync::Arc; + use std::sync::atomic::{AtomicBool, Ordering}; + use std::time::Duration; + + use tokio_util::sync::CancellationToken; + use torrust_server_lib::registar::Registar; + use torrust_tracker_axum_server::signals::GracefulShutdownOutcome; + use torrust_tracker_configuration::v3_0_0::health_check_api::HealthCheckApi; + + use super::{Environment, Error, Running, Started, Unstarted, join_owned_tasks}; + use crate::server::CancellationRunning; + + const TEST_DEADLINE: Duration = Duration::from_secs(10); + + fn unstarted_environment() -> Unstarted { + let config = HealthCheckApi { + bind_address: "127.0.0.1:0".parse().unwrap(), + }; + Unstarted::new(&Arc::new(config), Registar::default()) + } + + async fn start_within_deadline(environment: Unstarted) -> Started { + tokio::time::timeout(TEST_DEADLINE, environment.start()) + .await + .expect("start() should finish within the test deadline") + } + + async fn stop_within_deadline(environment: Started) -> Result { + tokio::time::timeout(TEST_DEADLINE, environment.stop()) + .await + .expect("stop() should finish within the test deadline") + } + + #[tokio::test] + async fn it_should_stop_without_a_failure_when_the_server_and_its_drain_controller_finish_through_cancellation() { + // Arrange + let environment = start_within_deadline(unstarted_environment()).await; + + // Act + let stop = stop_within_deadline(environment).await; + + // Assert + assert!( + stop.is_ok(), + "stop() should join the server and its drain controller without a failure" + ); + } + + #[tokio::test] + async fn it_should_release_the_health_check_api_binding_when_stopped() { + // Arrange + let environment = start_within_deadline(unstarted_environment()).await; + let binding = environment.bind_address(); + + // Act + let _stopped = stop_within_deadline(environment).await; + + // Assert + TcpListener::bind(binding).expect("the health check API binding should be free as soon as stop() returns"); + } + + #[tokio::test] + async fn it_should_release_the_health_check_api_binding_when_dropped_without_being_stopped() { + // Arrange + let environment = start_within_deadline(unstarted_environment()).await; + let binding = environment.bind_address(); + + // Act + drop(environment); + + // Assert + // Dropping cannot await the server task, so the binding is released shortly after, not at once. + tokio::time::timeout(TEST_DEADLINE, async { + while TcpListener::bind(binding).is_err() { + tokio::time::sleep(Duration::from_millis(10)).await; + } + }) + .await + .expect("the health check API binding should be released within the test deadline after the environment is dropped"); + } + + #[tokio::test] + async fn it_should_serve_requests_after_being_stopped_and_started_again() { + // Arrange + let stopped = stop_within_deadline(start_within_deadline(unstarted_environment()).await) + .await + .expect("the first stop should succeed"); + + // Act + let restarted = start_within_deadline(stopped).await; + + // Assert + let status = tokio::time::timeout( + TEST_DEADLINE, + reqwest::get(format!("http://{}/health_check", restarted.bind_address())), // DevSkim: ignore DS137138 + ) + .await + .expect("the health check should answer within the test deadline") + .expect("the restarted health check API server should accept the request") + .status(); + assert_eq!(status, reqwest::StatusCode::OK); + + stop_within_deadline(restarted).await.expect("the second stop should succeed"); + } + + #[tokio::test] + async fn it_should_join_the_drain_controller_before_reporting_a_server_task_failure() { + // Arrange + let drain_controller_finished = Arc::new(AtomicBool::new(false)); + + let failed_server_task = tokio::spawn(async { panic!("simulated health check API server task failure") }); + let drain_controller = tokio::spawn({ + let drain_controller_finished = drain_controller_finished.clone(); + async move { + // Finish after the failed server task, so returning on its failure would see this unfinished. + tokio::task::yield_now().await; + drain_controller_finished.store(true, Ordering::SeqCst); + GracefulShutdownOutcome::Drained + } + }); + + // Act + let result = tokio::time::timeout( + TEST_DEADLINE, + join_owned_tasks::(failed_server_task, drain_controller), + ) + .await + .expect("joining the owned tasks should finish within the test deadline"); + + // Assert + let failures = result.expect_err("a failed server task should be reported"); + assert!( + failures.contains("health check API server task failed to join"), + "unexpected failures: {failures}" + ); + assert!( + drain_controller_finished.load(Ordering::SeqCst), + "the drain controller should have finished before the failure was reported" + ); + } + + #[tokio::test] + async fn it_should_report_a_server_error_and_a_drain_timeout_together() { + // Arrange + let failed_server_task = tokio::spawn(async { Err("simulated server error") }); + let timed_out_controller = tokio::spawn(async { GracefulShutdownOutcome::TimedOut }); + + // Act + let result = tokio::time::timeout(TEST_DEADLINE, join_owned_tasks(failed_server_task, timed_out_controller)) + .await + .expect("joining the owned tasks should finish within the test deadline"); + + // Assert + assert_eq!( + result.expect_err("both failures should be reported"), + "health check API server task failed: simulated server error; health check API drain controller timed out" + ); + } + + #[tokio::test] + async fn it_should_return_an_error_naming_each_failing_task_when_stopped_with_failed_tasks() { + // Arrange + let environment: Started = Environment { + registar: Registar::default(), + state: Running { + server: CancellationRunning { + local_addr: "127.0.0.1:0".parse().unwrap(), + task: tokio::spawn(async { panic!("simulated health check API server task failure") }), + shutdown_controller: tokio::spawn(async { GracefulShutdownOutcome::TimedOut }), + }, + bind_to: "127.0.0.1:0".parse().unwrap(), + cancel_server_on_drop: CancellationToken::new().drop_guard(), + }, + }; + + // Act + let result = stop_within_deadline(environment).await; + + // Assert + let Err(Error::Error(message)) = result else { + panic!("stop() should return an error when a task failed"); + }; + assert!( + message.contains("health check API server task failed to join") && message.contains("drain controller timed out"), + "the error should name both failing tasks, but said: {message}" + ); + } + + #[tokio::test] + async fn it_should_report_a_drain_timeout_even_when_both_tasks_join() { + // Arrange + let finished_server_task = tokio::spawn(async { Ok::<_, std::convert::Infallible>(()) }); + let timed_out_controller = tokio::spawn(async { GracefulShutdownOutcome::TimedOut }); + + // Act + let result = tokio::time::timeout(TEST_DEADLINE, join_owned_tasks(finished_server_task, timed_out_controller)) + .await + .expect("joining the owned tasks should finish within the test deadline"); + + // Assert + assert_eq!( + result.expect_err("a drain timeout should be reported"), + "health check API drain controller timed out" + ); + } +} diff --git a/packages/axum-health-check-api-server/tests/server/contract.rs b/packages/axum-health-check-api-server/tests/server/contract.rs index e947b5bec7..898da96c9d 100644 --- a/packages/axum-health-check-api-server/tests/server/contract.rs +++ b/packages/axum-health-check-api-server/tests/server/contract.rs @@ -13,7 +13,7 @@ async fn health_check_endpoint_should_return_status_ok_when_there_is_no_services let env = Started::new(&configuration.health_check_api.into(), Registar::default()).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -65,7 +65,7 @@ mod api { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -124,7 +124,7 @@ mod api { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -199,7 +199,7 @@ mod http { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -265,7 +265,7 @@ mod http { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 let report: Report = response.json().await.expect("health report should deserialize"); let details = report .details @@ -315,7 +315,7 @@ mod http { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -374,7 +374,7 @@ mod udp { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); @@ -428,7 +428,7 @@ mod udp { let config = configuration.health_check_api.clone(); let env = Started::new(&config.into(), registar).await; - let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138 + let response = get(&format!("http://{}/health_check", env.bind_address())).await; // DevSkim: ignore DS137138 assert_eq!(response.status(), 200); assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); From a381a86bdd4ea508cd76a583c2ebd48147c10059 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:31:11 +0000 Subject: [PATCH 02/15] docs(issues): [#2450] record T0 baseline, T1 mutation proofs and M1/M2 evidence Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ISSUE.md | 7 +- .../manual-verification-evidence.md | 79 +++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index ef740c3166..3c0d514a78 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" related-pr: null -last-updated-utc: "2026-10-25 08:09" +last-updated-utc: "2026-10-26 07:30" semantic-links: skill-links: - create-issue @@ -218,6 +218,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-15 19:38 UTC - GitHub Copilot - Corrected the drop-path note after `review-finding:pr-2544-f5`: the HTTP environment never stopped on drop, before or after SI-16, so the note no longer says SI-16 lost the behavior or that the legacy halt sender stops its server on drop. The `DropGuard` requirement and AC7 stand. - 2026-10-15 20:33 UTC - GitHub Copilot - `review-finding:pr-2544-f14`: the code answers the open question. The health-check API server spawns the same `graceful_shutdown` task as HTTP, so its legacy drop does not stop the server either (read from source, not run). The drop-path note says so. - 2026-10-24 19:34 UTC - GitHub Copilot - Refreshed after sub-EPIC #2410 (SI-22) closed, which rewrote the HTTP and UDP test environments (#2416) after this spec was written. Re-checked against `develop`: the 8 `env.stop()` calls, the 8 `state.binding` reads, and the 5 s drain still hold, and the environment's `start()` spawns only the server. The Related ADRs now name the new ADR that supersedes the cancellation-tree ADR, and the Design and Ownership Review says this environment keeps one token and one `DropGuard` because it owns no listener, so it must not copy the two-token shape of the HTTP and UDP environments. No task, acceptance criterion, or scope change. +- 2026-10-26 07:16 UTC - GitHub Copilot - T0 baseline and T1 implemented (token start, one `DropGuard`, private `state`, `bind_address()`, joined `stop()` errors) with 8 new tests, mutation-proven in `manual-verification-evidence.md`; the 8 contract reads were moved early so the tree compiles. Stopped for the design review. ## Acceptance Criteria @@ -254,8 +255,8 @@ The package has no example binary, so there is no signal scenario. | ID | Scenario | Human-oriented command/steps | Expected Result | Status | Evidence | | --- | ------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------- | ------ | -------------------------------------------- | -| M1 | No legacy stop in the env | Read the final `environment.rs`; list every `server` function it calls. | Only `start_with_cancellation`; no `signals::Halted` or `signals::Started` channel. | TODO | `manual-verification-evidence.md` section V1 | -| M2 | Suite timing | Run the package tests before and after; record wall time. | Comparable time; any slowdown explained. | TODO | `manual-verification-evidence.md` section V2 | +| M1 | No legacy stop in the env | Read the final `environment.rs`; list every `server` function it calls. | Only `start_with_cancellation`; no `signals::Halted` or `signals::Started` channel. | TODO | `manual-verification-evidence.md` section V3 | +| M2 | Suite timing | Run the package tests before and after; record wall time. | Comparable time; any slowdown explained. | TODO | `manual-verification-evidence.md` section V4 | Notes: diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md new file mode 100644 index 0000000000..d6f308b110 --- /dev/null +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -0,0 +1,79 @@ +--- +doc-type: manual-verification-evidence +issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +last-updated-utc: "2026-10-26 07:30" +--- + +# Manual Verification Evidence + +## Purpose + +Evidence for #2450 (SI-24): the health-check API test `Environment` moves to the +token lifecycle. Every number below was derived from the tree on 2026-10-26 UTC. + +## V0: Baseline before the change + +Command: `cargo test -p torrust-tracker-axum-health-check-api-server` on the +`torrust/develop` tree (rustc/cargo 1.99.1). Result: 3 lib tests and 8 +integration tests passed, 0 doc-tests; integration tests 3.04 s; total 34.255 s +including a 31 s cold build. + +Counts in `tests/server/contract.rs`: + +- `grep -c "state.binding"` gave 8. +- `grep -c "env.stop()"` gave 8. + +## V1: T1 tests + +After T1 (with the 8 reads already moved to `bind_address()` so the tree +compiles): 11 lib tests (3 existing in `server::tests`, 8 new in +`environment::tests`, 1.01 s) and 8 integration tests (3.04 s) pass. + +## V2: Mutation proofs for the T1 tests + +Each mutation was applied to `src/environment.rs`, the filtered lib tests were +run (`cargo test -p torrust-tracker-axum-health-check-api-server --lib environment`), +then the file was restored from a saved copy and `cmp` printed no difference. +Times are UTC on 2026-10-26. + +| # | Time | Mutation | Result | +| --- | ------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| M1 | 07:14:40.635 | `stop()` disarms the guard but never cancels (`mem::forget(disarm())`) | 3 failed: stop without failure, binding released on stop, stop-then-start serves (10 s bounded wait) | +| M2 | 07:14 | Drop guard bound to an unrelated token | 4 failed: drop releases binding, stop without failure, binding released on stop, stop-then-start serves | +| M4 | 07:14 | Drain `TimedOut` no longer reported | 3 failed: server error plus drain timeout together, error naming each failing task, drain timeout when both tasks join | +| M5 | 07:14 | Sequential join with early return on server failure | 2 failed: joins the drain controller before reporting a server failure, error naming each failing task | + +Restore proof: after each run `cmp src/environment.rs /tmp/env.orig` printed +nothing (the run printed `restored-ok` / `restored-cmp-ok`), and the original +file passes all tests (V1). + +Two attempted mutations did not compile (`let _ = guard.disarm()` is rejected +for a type with a destructor; a wrong `bind_to` left a variable unused). They +proved nothing and are not counted. + +## V3: No legacy stop in the environment (spec M1, read from source, not run) + +Read the final `src/environment.rs`, as committed in +`refactor(axum-health-check-api-server): [#2450] migrate the health-check API test environment to the token lifecycle`. +The only `server` function it calls is `server::start_with_cancellation` +(plus the type import `CancellationRunning`). A search for `Halted` and for +`server::start` finds no legacy call, so no `signals::Halted` or +`signals::Started` channel is used. + +Restart address (read from source, not run): the legacy `stop()` also returned +the configured `bind_to`, so a restart on a `:0` configuration binds a fresh +ephemeral port both before and after this change. The behaviour is unchanged. + +## V4: Suite timing (spec M2) + +Toolchain: rustc 1.99.1 (58cf8f9c3 2026-10-13), warm build. + +| Run | Lib tests | Integration tests | Total wall time | +| --------------------- | ---------------- | ----------------- | -------------------- | +| Baseline (V0, before) | 3 passed | 8 passed, 3.04 s | 34.255 s with build | +| After this change | 11 passed, 1.0 s | 8 passed, 3.04 s | 4.272 s, warm build | + +The integration suite time is identical. The baseline total included a 31 s +cold build, so it is not comparable with the warm total. The lib tests rose from +3 to 11 because of the added `environment::tests`; the existing tests are not +slower. From 6cf6534ff36092b87dcbf9fe1873649b4ed464c3 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:31:43 +0000 Subject: [PATCH 03/15] docs(shutdown-process): [#2450] record the health-check test environment token lifecycle Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/features/shutdown-process/task-inventory.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/features/shutdown-process/task-inventory.md b/docs/features/shutdown-process/task-inventory.md index 3196e69a47..8e451fe374 100644 --- a/docs/features/shutdown-process/task-inventory.md +++ b/docs/features/shutdown-process/task-inventory.md @@ -1,7 +1,7 @@ --- doc-type: feature-supporting-analysis status: verified -last-updated-utc: "2026-10-24 20:19" +last-updated-utc: "2026-10-26 07:30" semantic-links: related-artifacts: - docs/features/shutdown-process/README.md @@ -304,7 +304,7 @@ themselves. | HTTP tracker (`packages/axum-http-server/src/testing/environment.rs`) | One: the HTTP-core statistics listener | Subscribes before the server starts; spawns the listener after a successful start; the `Running` state holds a `DropGuard` for the server token and another for the listener token (`cancel_server_on_drop`, `cancel_listener_on_drop`). `stop()` cancels and joins the server and its drain controller, then the listener (issue #2416). | | UDP tracker (`packages/udp-server/src/testing/environment.rs`) | Three: UDP-core statistics, UDP-server statistics, and UDP-server banning | Subscribes all three receivers before the server starts; the `Running` state holds a `DropGuard` for the receive-loop token and another for the one token of the three listeners (`cancel_server_on_drop`, `cancel_listeners_on_drop`). `stop()` cancels and joins the receive loop, then the listeners (issue #2416). | | REST API (`packages/axum-rest-api-server/src/testing/environment.rs`) | None | Runs no event listener, so it keeps one token: the `Running` state holds the server task, its drain controller, and one `DropGuard` (`cancel_server_on_drop`). `stop()` cancels the token and joins both tasks, then panics naming each failing task (issue #2449). | -| Health-check API | None | This environment runs no event listener. | +| Health-check API (`packages/axum-health-check-api-server/src/environment.rs`) | None | Runs no event listener, so it keeps one token: the private `Running` state holds the server task, its drain controller, and one `DropGuard` (`cancel_server_on_drop`). `stop()` cancels the token and joins both tasks, then returns an error naming each failing task (issue #2450). | Neither tracker environment runs a swarm-bus listener, although announce requests can publish on that bus; no listener consumes those events there. @@ -353,10 +353,10 @@ use of the root token is the legacy `udp_ban_cleanup` job. 4. The production tracker no longer uses private `Halted` channels or library-level OS signals for any server component. The HTTP and UDP test environments and examples use the token-aware path after SI-16 (#2412) - and SI-17 (#2448), and the REST API test environment does after SI-23 - (#2449). The legacy `Halted` APIs remain for the health-check API test - environment (SI-24) and other legacy callers until deprecation and removal - in SI-18 and SI-19. + and SI-17 (#2448), and the REST API and health-check API test + environments do after SI-23 (#2449) and SI-24 (#2450). The legacy `Halted` + APIs remain for other legacy callers until deprecation and removal in + SI-18 and SI-19. The legacy UDP launcher is now an adapter over the token-aware receive loop, so it can no longer panic or detach it. 5. HTTP, REST, and health-check drain controllers are component-owned and From 8a09fe50cbd8a9bc837be6c71d373348377e6d5f Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:33:00 +0000 Subject: [PATCH 04/15] docs(issues): [#2450] record the prose-first comparison and the post-change checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ISSUE.md | 9 +++-- .../manual-verification-evidence.md | 39 ++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index 3c0d514a78..df64efb1cf 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" related-pr: null -last-updated-utc: "2026-10-26 07:30" +last-updated-utc: "2026-10-26 07:33" semantic-links: skill-links: - create-issue @@ -199,10 +199,10 @@ before maintainer review and commit. Sign every commit with GPG. - [x] Folder-style spec drafted (moved to `docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md`) - [x] Spec reviewed and approved by user/maintainer - [x] GitHub issue created and issue number added to this spec (#2450) -- [ ] Spec-only PR merged into `develop` before implementation -- [ ] Implementation completed +- [x] Spec-only PR merged into `develop` before implementation +- [x] Implementation completed - [ ] Automatic verification completed (`linter all`, relevant tests, and pre-push checks) -- [ ] Manual verification scenarios executed and recorded in issue-local `manual-verification-evidence.md` +- [x] Manual verification scenarios executed and recorded in issue-local `manual-verification-evidence.md` - [ ] Acceptance criteria reviewed after implementation and updated with evidence - [ ] Evidence-based implementation completion review recorded: issue-local retrospective created for material discoveries, or progress log states why none was needed - [ ] Reviewer validated acceptance criteria and updated checkboxes @@ -219,6 +219,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-15 20:33 UTC - GitHub Copilot - `review-finding:pr-2544-f14`: the code answers the open question. The health-check API server spawns the same `graceful_shutdown` task as HTTP, so its legacy drop does not stop the server either (read from source, not run). The drop-path note says so. - 2026-10-24 19:34 UTC - GitHub Copilot - Refreshed after sub-EPIC #2410 (SI-22) closed, which rewrote the HTTP and UDP test environments (#2416) after this spec was written. Re-checked against `develop`: the 8 `env.stop()` calls, the 8 `state.binding` reads, and the 5 s drain still hold, and the environment's `start()` spawns only the server. The Related ADRs now name the new ADR that supersedes the cancellation-tree ADR, and the Design and Ownership Review says this environment keeps one token and one `DropGuard` because it owns no listener, so it must not copy the two-token shape of the HTTP and UDP environments. No task, acceptance criterion, or scope change. - 2026-10-26 07:16 UTC - GitHub Copilot - T0 baseline and T1 implemented (token start, one `DropGuard`, private `state`, `bind_address()`, joined `stop()` errors) with 8 new tests, mutation-proven in `manual-verification-evidence.md`; the 8 contract reads were moved early so the tree compiles. Stopped for the design review. +- 2026-10-26 07:33 UTC - GitHub Copilot - Design review approved by the maintainer. Committed the code, the T0/T1 evidence and the task inventory update (T2 reads moved with T1, T3 done). Added V5 (prose-first Arrange-Act-Assert record) and V6 (automatic checks after the last production change) to `manual-verification-evidence.md`. Independent review next. ## Acceptance Criteria diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md index d6f308b110..cbea14ea83 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -1,7 +1,7 @@ --- doc-type: manual-verification-evidence issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md -last-updated-utc: "2026-10-26 07:30" +last-updated-utc: "2026-10-26 07:32" --- # Manual Verification Evidence @@ -77,3 +77,40 @@ The integration suite time is identical. The baseline total included a 31 s cold build, so it is not comparable with the warm total. The lib tests rose from 3 to 11 because of the added `environment::tests`; the existing tests are not slower. + +## V5: Prose-first Arrange-Act-Assert comparison for the eight new tests + +Each test's `// Arrange`, `// Act` and `// Assert` sections were written as +prose first, then compared with the code. Result per test: + +- Stop without a failure: Arrange starts the environment; Act is + `stop_within_deadline(environment)`; Assert is that the result is `Ok`. The + deadline wrapper is irreducible, because a hung `stop()` must fail the test + instead of hanging it. It is named for what it does and is the visible Act. +- Release the binding when stopped, and restart after stop: same wrapper, same + reasoning. The binding assertion rebinds the released address directly. +- Release the binding when dropped: Act is `drop(environment)`; the assertion + polls a bounded rebind (spec T1 list, drop path of #2471). +- Join the drain controller before reporting a server failure, report a server + error and a drain timeout together, the error names each failing task, a + drain timeout is reported even when both tasks join: Arrange builds the + failing task handles, Act calls `join_owned_tasks` (or `stop()`), Assert + reads the returned error text. No assertion is derived through production + code. + +No prose had to be kept beyond the three section markers. + +## V6: Automatic checks after the last production change + +The last production change is the commit +`refactor(axum-health-check-api-server): [#2450] migrate the health-check API test environment to the token lifecycle`. +Run on the tree after it (rustc 1.99.1): + +| Command | Result | +| ------------------------------------------------------------------------------------------------ | ------------------------------------------- | +| `cargo test -p torrust-tracker-axum-health-check-api-server` | 11 lib passed (1.00 s), 8 integration passed (3.04 s) | +| `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings` | no warnings | +| `cargo check --workspace --all-targets --all-features` | no errors | +| `cargo +nightly fmt --check` | clean | + +`linter all` and the pre-commit hook passed on each commit. From aa28b3f6ab9188208336a787c8e42968d7cc5128 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:35:43 +0000 Subject: [PATCH 05/15] test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/axum-health-check-api-server/src/environment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/axum-health-check-api-server/src/environment.rs b/packages/axum-health-check-api-server/src/environment.rs index a9fa591061..41c8413659 100644 --- a/packages/axum-health-check-api-server/src/environment.rs +++ b/packages/axum-health-check-api-server/src/environment.rs @@ -213,7 +213,7 @@ mod tests { let binding = environment.bind_address(); // Act - let _stopped = stop_within_deadline(environment).await; + let _stopped = stop_within_deadline(environment).await.expect("stop() should succeed"); // Assert TcpListener::bind(binding).expect("the health check API binding should be free as soon as stop() returns"); From f0656bc1d2c2cb289b9756f12315e1d84e8dabe3 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 07:38:13 +0000 Subject: [PATCH 06/15] docs(issues): [#2450] record the independent review, resolve its findings and update the spec status Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ISSUE.md | 25 ++++++++------- .../agent-review-reports.md | 32 +++++++++++++++++++ .../manual-verification-evidence.md | 10 +++--- 3 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index df64efb1cf..673478dfaa 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" related-pr: null -last-updated-utc: "2026-10-26 07:33" +last-updated-utc: "2026-10-26 07:38" semantic-links: skill-links: - create-issue @@ -164,11 +164,11 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | ID | Status | Task | Notes / Expected Output | | --- | ------ | ----------------------------------- | ----------------------------------------------------------------------------------- | -| T0 | TODO | Record baseline | Package test results. | -| T1 | TODO | Migrate `Environment` start/stop | D1-D5, with the T1 tests below, each mutation-proven. | -| T2 | TODO | Migrate the field reads | Contract tests use `bind_address()`. | -| T3 | TODO | Documentation | Task inventory records the migrated health-check API environment. | -| T4 | TODO | Verification and completion review | Automatic checks, manual scenario, AC review, pre-push checks, independent review. | +| T0 | DONE | Record baseline | Package test results. | +| T1 | DONE | Migrate `Environment` start/stop | D1-D5, with the T1 tests below, each mutation-proven. | +| T2 | DONE | Migrate the field reads | Contract tests use `bind_address()`. | +| T3 | DONE | Documentation | Task inventory records the migrated health-check API environment. | +| T4 | IN_PROGRESS | Verification and completion review | Automatic checks, manual scenario, AC review, pre-push checks, independent review. | T1 tests (use the `write-unit-test` skill, every wait bounded): @@ -201,12 +201,12 @@ before maintainer review and commit. Sign every commit with GPG. - [x] GitHub issue created and issue number added to this spec (#2450) - [x] Spec-only PR merged into `develop` before implementation - [x] Implementation completed -- [ ] Automatic verification completed (`linter all`, relevant tests, and pre-push checks) +- [x] Automatic verification completed (`linter all`, relevant tests, and pre-push checks) - [x] Manual verification scenarios executed and recorded in issue-local `manual-verification-evidence.md` - [ ] Acceptance criteria reviewed after implementation and updated with evidence -- [ ] Evidence-based implementation completion review recorded: issue-local retrospective created for material discoveries, or progress log states why none was needed +- [x] Evidence-based implementation completion review recorded: issue-local retrospective created for material discoveries, or progress log states why none was needed - [ ] Reviewer validated acceptance criteria and updated checkboxes -- [ ] Independent reviewer reports recorded in issue-local `agent-review-reports.md` +- [x] Independent reviewer reports recorded in issue-local `agent-review-reports.md` - [ ] Committer verified spec progress is up to date before commit - [ ] Issue closed and spec moved from `docs/issues/open/` to `docs/issues/closed/` @@ -220,6 +220,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-24 19:34 UTC - GitHub Copilot - Refreshed after sub-EPIC #2410 (SI-22) closed, which rewrote the HTTP and UDP test environments (#2416) after this spec was written. Re-checked against `develop`: the 8 `env.stop()` calls, the 8 `state.binding` reads, and the 5 s drain still hold, and the environment's `start()` spawns only the server. The Related ADRs now name the new ADR that supersedes the cancellation-tree ADR, and the Design and Ownership Review says this environment keeps one token and one `DropGuard` because it owns no listener, so it must not copy the two-token shape of the HTTP and UDP environments. No task, acceptance criterion, or scope change. - 2026-10-26 07:16 UTC - GitHub Copilot - T0 baseline and T1 implemented (token start, one `DropGuard`, private `state`, `bind_address()`, joined `stop()` errors) with 8 new tests, mutation-proven in `manual-verification-evidence.md`; the 8 contract reads were moved early so the tree compiles. Stopped for the design review. - 2026-10-26 07:33 UTC - GitHub Copilot - Design review approved by the maintainer. Committed the code, the T0/T1 evidence and the task inventory update (T2 reads moved with T1, T3 done). Added V5 (prose-first Arrange-Act-Assert record) and V6 (automatic checks after the last production change) to `manual-verification-evidence.md`. Independent review next. +- 2026-10-26 07:38 UTC - GitHub Copilot - Independent Task Reviewer passed with five non-blocking findings (F1-F5), all resolved and recorded in `agent-review-reports.md`. No retrospective: no discovery changed the design or the spec; the mutation that did not compile is explained in V2. Acceptance criteria stay TODO until the maintainer says to tick them. ## Acceptance Criteria @@ -256,8 +257,8 @@ The package has no example binary, so there is no signal scenario. | ID | Scenario | Human-oriented command/steps | Expected Result | Status | Evidence | | --- | ------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------- | ------ | -------------------------------------------- | -| M1 | No legacy stop in the env | Read the final `environment.rs`; list every `server` function it calls. | Only `start_with_cancellation`; no `signals::Halted` or `signals::Started` channel. | TODO | `manual-verification-evidence.md` section V3 | -| M2 | Suite timing | Run the package tests before and after; record wall time. | Comparable time; any slowdown explained. | TODO | `manual-verification-evidence.md` section V4 | +| M1 | No legacy stop in the env | Read the final `environment.rs`; list every `server` function it calls. | Only `start_with_cancellation`; no `signals::Halted` or `signals::Started` channel. | DONE | `manual-verification-evidence.md` section V3 | +| M2 | Suite timing | Run the package tests before and after; record wall time. | Comparable time; any slowdown explained. | DONE | `manual-verification-evidence.md` section V4 | Notes: @@ -300,7 +301,7 @@ available. ## Implementation Completion Review -- Retrospective: `TODO` +- Retrospective: not needed; see the 2026-10-26 07:38 progress-log entry - If needed, create `implementation-retrospective.md` from `docs/templates/IMPLEMENTATION-RETROSPECTIVE.md` in this directory; otherwise add a progress-log entry explaining why it was not needed. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md new file mode 100644 index 0000000000..aee41c2010 --- /dev/null +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md @@ -0,0 +1,32 @@ +--- +semantic-links: + related-artifacts: + - .github/agents/complexity-auditor.agent.md + - .github/agents/task-reviewer.agent.md + - .github/agents/pr-reviewer.agent.md + - docs/agents/orchestration.md +--- + +# Agent Review Reports - Migrate the Health-Check API Test Environment to the Token Lifecycle (#2450) + +> Append one completed independent-review entry at a time. Do not modify, reorder, or remove +> earlier entries. A correction is a new entry that names the earlier conclusion. + +## Reports + +### 2026-10-26 07:38 UTC - Task Reviewer + +- Invocation scope: pre-PR review of branch `2450-migrate-health-check-api-test-environment` + against `torrust/develop`: AC1-AC7, the T1 tests, D1-D5, the task inventory, spec hygiene and the + evidence file. Result: REVIEW PASSED; all seven acceptance criteria are met by the evidence. + The AC rows stay TODO until the maintainer says to tick them. +- Findings (all non-blocking, all resolved in the commit that records this entry): + - **F1 (medium, spec hygiene)** - `ISSUE.md` still showed T0-T4 and M1/M2 as TODO. Resolved: + T0-T3 and M1/M2 are DONE, T4 is IN_PROGRESS. + - **F2 (low, stamps)** - the evidence stamp predated its last commit. Resolved: stamps bumped. + - **F3 (low, evidence)** - V6 claimed `linter all` passed on each commit without a record. + Resolved: V6 records the exit 0 and names the last production commit. + - **F4 (low, evidence)** - uneven V2 timestamps, an unexplained M3 gap, and non-reproducible + figures. Resolved: timestamps made uniform, the M3 gap and the unreproduced figures stated. + - **F5 (low, test design)** - the binding-release test ignored the stop result. Resolved: the + test now `expect`s it, in `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md index cbea14ea83..1b90370066 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -1,7 +1,7 @@ --- doc-type: manual-verification-evidence issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md -last-updated-utc: "2026-10-26 07:32" +last-updated-utc: "2026-10-26 07:38" --- # Manual Verification Evidence @@ -38,11 +38,13 @@ Times are UTC on 2026-10-26. | # | Time | Mutation | Result | | --- | ------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -| M1 | 07:14:40.635 | `stop()` disarms the guard but never cancels (`mem::forget(disarm())`) | 3 failed: stop without failure, binding released on stop, stop-then-start serves (10 s bounded wait) | +| M1 | 07:14 | `stop()` disarms the guard but never cancels (`mem::forget(disarm())`) | 3 failed: stop without failure, binding released on stop, stop-then-start serves (10 s bounded wait) | | M2 | 07:14 | Drop guard bound to an unrelated token | 4 failed: drop releases binding, stop without failure, binding released on stop, stop-then-start serves | | M4 | 07:14 | Drain `TimedOut` no longer reported | 3 failed: server error plus drain timeout together, error naming each failing task, drain timeout when both tasks join | | M5 | 07:14 | Sequential join with early return on server failure | 2 failed: joins the drain controller before reporting a server failure, error naming each failing task | +M3 is absent on purpose: the planned mutation (`let _ = guard.disarm();`) does not compile, because `disarm()` returns a `CancellationToken` that must be used, so it was dropped and the numbering kept. The failure counts and the 1 s to 10 s timings in the table were read from the runs of 2026-10-26 and were not re-run for this record. + Restore proof: after each run `cmp src/environment.rs /tmp/env.orig` printed nothing (the run printed `restored-ok` / `restored-cmp-ok`), and the original file passes all tests (V1). @@ -103,7 +105,7 @@ No prose had to be kept beyond the three section markers. ## V6: Automatic checks after the last production change The last production change is the commit -`refactor(axum-health-check-api-server): [#2450] migrate the health-check API test environment to the token lifecycle`. +`test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`. Run on the tree after it (rustc 1.99.1): | Command | Result | @@ -113,4 +115,4 @@ Run on the tree after it (rustc 1.99.1): | `cargo check --workspace --all-targets --all-features` | no errors | | `cargo +nightly fmt --check` | clean | -`linter all` and the pre-commit hook passed on each commit. +`linter all` exited 0 on this tree (07:35 UTC), before the commit above; the pre-commit hook passed on that commit. From e8106556b850ce1d29b34dbb1203782ae30d1961 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 12:38:58 +0000 Subject: [PATCH 07/15] test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation The token-aware start registers the health check API in the registar, which cannot remove a registration, so a stop-then-start on a fixed port registers the same binding twice and panics. Document it on start() and pin it with a test; restart on an ephemeral port stays supported. Related to review-finding:pr-2652-f1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/environment.rs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/axum-health-check-api-server/src/environment.rs b/packages/axum-health-check-api-server/src/environment.rs index 41c8413659..94e1a082f6 100644 --- a/packages/axum-health-check-api-server/src/environment.rs +++ b/packages/axum-health-check-api-server/src/environment.rs @@ -57,9 +57,16 @@ impl Environment { /// Starts the test environment with a fresh cancellation token, so a /// stopped environment can be started again. /// + /// Starting registers the health check API in the environment's + /// `registar`, and the `Registar` has no way to remove a registration, so + /// `stop()` leaves it there. A restart therefore works only when the + /// configuration binds an ephemeral port (`:0`), which gives the restarted + /// server a new binding. A fixed port registers the same binding twice. + /// /// # Panics /// - /// Will panic if the server cannot be started. + /// Will panic if the server cannot be started, including a restart on a + /// fixed port whose binding is still registered. pub async fn start(self) -> Environment { let cancellation_token = CancellationToken::new(); @@ -263,6 +270,25 @@ mod tests { stop_within_deadline(restarted).await.expect("the second stop should succeed"); } + #[tokio::test] + #[should_panic(expected = "DuplicateBinding")] + async fn it_should_not_start_again_on_a_fixed_port_while_the_registar_keeps_the_previous_registration() { + // Arrange + let fixed_address = { + let probe = TcpListener::bind("127.0.0.1:0").unwrap(); + probe.local_addr().unwrap() + }; + let config = HealthCheckApi { + bind_address: fixed_address, + }; + let stopped = stop_within_deadline(start_within_deadline(Unstarted::new(&Arc::new(config), Registar::default())).await) + .await + .expect("the first stop should succeed"); + + // Act: the registar keeps the first run's registration of the same binding, so this start panics. + let _restarted = start_within_deadline(stopped).await; + } + #[tokio::test] async fn it_should_join_the_drain_controller_before_reporting_a_server_task_failure() { // Arrange From be0acb8622d588a1a978e0868dfa40f429251d55 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 12:42:38 +0000 Subject: [PATCH 08/15] docs(issues): [#2450] record the fixed-port restart limitation and its retrospective Records the Copilot finding review-finding:pr-2652-f1 in the evidence (V7), re-runs the automatic checks after the new last production change (V6), and adds the implementation retrospective. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ISSUE.md | 7 +- .../implementation-retrospective.md | 67 +++++++++++++++++++ .../manual-verification-evidence.md | 51 ++++++++++---- 3 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index 673478dfaa..a383cc5e41 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" related-pr: null -last-updated-utc: "2026-10-26 07:38" +last-updated-utc: "2026-10-26 12:42" semantic-links: skill-links: - create-issue @@ -174,7 +174,9 @@ T1 tests (use the `write-unit-test` skill, every wait bounded): - `stop()` joins the server and the drain controller without an error. - `stop()` releases the binding: the same address binds right after `stop()`. -- Stop-then-start serves the health check on the restarted environment. +- Stop-then-start serves the health check on the restarted environment, on an + ephemeral port. A fixed-port restart is a documented limitation + (`review-finding:pr-2652-f1`, evidence V7). - A drain timeout is returned as an error after both tasks join. - Dropping a running environment without `stop()` releases the binding (poll `TcpListener::bind` within a bounded deadline, as #2471's test does). @@ -221,6 +223,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-26 07:16 UTC - GitHub Copilot - T0 baseline and T1 implemented (token start, one `DropGuard`, private `state`, `bind_address()`, joined `stop()` errors) with 8 new tests, mutation-proven in `manual-verification-evidence.md`; the 8 contract reads were moved early so the tree compiles. Stopped for the design review. - 2026-10-26 07:33 UTC - GitHub Copilot - Design review approved by the maintainer. Committed the code, the T0/T1 evidence and the task inventory update (T2 reads moved with T1, T3 done). Added V5 (prose-first Arrange-Act-Assert record) and V6 (automatic checks after the last production change) to `manual-verification-evidence.md`. Independent review next. - 2026-10-26 07:38 UTC - GitHub Copilot - Independent Task Reviewer passed with five non-blocking findings (F1-F5), all resolved and recorded in `agent-review-reports.md`. No retrospective: no discovery changed the design or the spec; the mutation that did not compile is explained in V2. Acceptance criteria stay TODO until the maintainer says to tick them. +- 2026-10-26 12:42 UTC - GitHub Copilot - Copilot's review of #2652 (`review-finding:pr-2652-f1`) found that a fixed-port stop-then-start panics, because the token-aware start registers the service and the `Registar` cannot remove it. This corrects the 07:38 entry: the discovery is material, so `implementation-retrospective.md` is added. The maintainer chose to document and pin the limitation and file a follow-up; recorded in V7, with V6 re-run after the new last production change. The acceptance criteria stay TODO. ## Acceptance Criteria diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md new file mode 100644 index 0000000000..cc101fdcdf --- /dev/null +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md @@ -0,0 +1,67 @@ +--- +semantic-links: + skill-links: + - write-markdown-docs + related-artifacts: + - docs/templates/ISSUE.md + - .github/skills/dev/planning/create-issue/SKILL.md +--- + +# Implementation Retrospective — Migrate the Health-Check API Test Environment (#2450) + +## Purpose + +Record evidence-based process improvements discovered while implementing +SI-24 (issue #2450). This is a blameless review of the implementation +approach; it does not replace acceptance-criteria verification. + +## Outcome + +`Environment` runs the health-check API on the token lifecycle, with private +`state`, one `DropGuard`, a joined `stop()` that names every failing task, and a +`bind_address()` accessor. The evidence is in `manual-verification-evidence.md` +(V0 to V7). One limitation remains: a stop-then-start on a fixed port panics, +because the environment's registration stays in the `registar`. + +## What Went Well + +1. The #2449 sibling was a complete model, so the design review of the new + environment needed no change. +2. Every new test was mutation-proven before review. + +## What Changed During Implementation + +Copilot's review of #2652 found that restarting on a fixed port panics with +`DuplicateBinding` (`review-finding:pr-2652-f1`). The legacy +`server::start` never registered the service, while the token-aware +`start_with_cancellation` does, so the migration added a registration that +`stop()` cannot remove: `torrust-server-lib` 0.3.0's `Registar` has no remove +operation. The restart test used `:0`, which hides the problem. The maintainer +chose to document and pin the limitation and file a follow-up; see V7. + +## Root Cause + +The spec compared the start and stop paths but not the side effects of the +token-aware start. D4 asked for `RuntimeServiceMetadata` and treated the +registration as a given, so no task asked what a restart does to the registry. +The restart test used the one configuration, an ephemeral port, that cannot +collide. + +## Improvements for Future Work + +1. When a spec migrates a lifecycle that keeps a `stop()` then `start()` path, + add a task that lists every side effect of `start` (registrations, files, + channels) and says how `stop` undoes each. +2. For a restart test, run it on a fixed port as well as on `:0`. + +## Avoiding Overcorrection + +The evidence does not justify changing the `Registar` inside this PR, or a rule +that every test environment must support a fixed-port restart: no caller restarts +this environment on a fixed port. + +## Evidence + +- `manual-verification-evidence.md` V7 (red test, decision, mutation proof) +- `ISSUE.md` progress log +- Commit subject `test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md index 1b90370066..75a7665496 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -1,7 +1,7 @@ --- doc-type: manual-verification-evidence issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md -last-updated-utc: "2026-10-26 07:38" +last-updated-utc: "2026-10-26 12:42" --- # Manual Verification Evidence @@ -105,14 +105,41 @@ No prose had to be kept beyond the three section markers. ## V6: Automatic checks after the last production change The last production change is the commit -`test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`. -Run on the tree after it (rustc 1.99.1): - -| Command | Result | -| ------------------------------------------------------------------------------------------------ | ------------------------------------------- | -| `cargo test -p torrust-tracker-axum-health-check-api-server` | 11 lib passed (1.00 s), 8 integration passed (3.04 s) | -| `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings` | no warnings | -| `cargo check --workspace --all-targets --all-features` | no errors | -| `cargo +nightly fmt --check` | clean | - -`linter all` exited 0 on this tree (07:35 UTC), before the commit above; the pre-commit hook passed on that commit. +`test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` +(V7). It supersedes the earlier last change, `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`, +after which these commands were first run with 11 lib tests. Run on the tree after the last change (rustc 1.99.1): + +| Command | Result | +| ------------------------------------------------------------------------------------------- | ----------------------------------------------------- | +| `cargo test -p torrust-tracker-axum-health-check-api-server` | 12 lib passed (1.00 s), 8 integration passed (3.04 s) | +| `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings` | no warnings | +| `cargo check --workspace --all-targets --all-features` | no errors | +| `cargo +nightly fmt --check` | clean | +| `linter all` | exit 0 (12:41 UTC) | + +The pre-commit hook passed on the commit above. + +## V7: Fixed-port restart (`review-finding:pr-2652-f1`) + +Copilot's review of #2652 reported that a stop-then-start on a fixed port +panics. A red test reproduced it before any change: +`cargo test -p torrust-tracker-axum-health-check-api-server --lib fixed_port` +failed with `Registration { source: DuplicateBinding(...) }` raised by `start()`. + +Cause (read from source, not run beyond the red test): the legacy `server::start` +never registered the service in the `registar`; `server::start_with_cancellation` +does (spec D4), and `stop()` cannot remove the registration because +`torrust-server-lib` 0.3.0's `Registar` has no remove operation. Restart on an +ephemeral port (`:0`), which the existing restart test covers, binds a new +address and is unaffected. + +Decision (the maintainer chose it): document the limitation and pin it, and file +a follow-up to give the `Registar` a removal operation. The commit +`test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` +documents it on `Environment::start()` and adds +`it_should_not_start_again_on_a_fixed_port_while_the_registar_keeps_the_previous_registration` +(`#[should_panic(expected = "DuplicateBinding")]`). Lib tests rose from 11 to 12. + +Mutation proof: with the test's configuration changed to bind `127.0.0.1:0`, the +test failed with `test did not panic as expected`; the file was restored from +`HEAD` and `cmp` confirmed the restore. From 70b2141e51a8cbc8bb77ab89f86f2c3655da5e85 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:12:10 +0000 Subject: [PATCH 09/15] docs(issues): [#2450] correct the independent review entry after the fixed-port finding Appends a correction to the 07:38 UTC Task Reviewer entry: withdraws the AC4 conclusion, states the real resolution references of its findings, and adds the Inputs, Evidence, Verdict and Follow-up actions fields the template requires. The earlier entry is preserved. Resolves review-finding:pr-2652-f3. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../agent-review-reports.md | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md index aee41c2010..c579fb12c3 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md @@ -30,3 +30,40 @@ semantic-links: figures. Resolved: timestamps made uniform, the M3 gap and the unreproduced figures stated. - **F5 (low, test design)** - the binding-release test ignored the stop result. Resolved: the test now `expect`s it, in `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`. + +### 2026-10-26 16:10 UTC - Task Reviewer (correction of the 07:38 UTC entry, `review-finding:pr-2652-f3`) + +This entry corrects the 07:38 UTC entry above, which stays unchanged. + +- Invocation scope: re-assessment, by the PR author, of the conclusions of the 07:38 UTC entry + after `review-finding:pr-2652-f2` (a stop-then-start on a fixed port) and + `review-finding:pr-2652-f3` (this entry). Not a new independent review. +- Inputs: the 07:38 UTC entry, AC4 of `ISSUE.md`, `Environment::start()` and `stop()` in + `packages/axum-health-check-api-server/src/environment.rs`, `start_with_cancellation()` in + `packages/axum-health-check-api-server/src/server.rs`, the `Registar` of `torrust-server-lib` 0.3.0, + and the review threads of #2652. +- Evidence: the 07:38 UTC entry did not record the commands or files the reviewer ran or read, so + the scope of what was verified cannot be reconstructed from it. What is now known: the only + restart test then used port 0 (`it_should_serve_requests_after_being_stopped_and_started_again`). + On 2026-10-26 a red test on a fixed port, + `cargo test -p torrust-tracker-axum-health-check-api-server --lib fixed_port`, failed with + `Registration { source: DuplicateBinding(...) }` raised by `start()`. Cause, read from source and + confirmed by that test: `start_with_cancellation()` registers the binding, `stop()` returned the + same `registar` with the entry in it, and `Registar` 0.3.0 has no remove operation. +- Findings: + - **Withdrawn:** the 07:38 UTC conclusion that all seven acceptance criteria are met. AC4 ("A + stopped environment can be started again and serves the health check") was not met for a fixed + port. This is `review-finding:pr-2652-f2` (Major). + - **Inaccurate statement:** the 07:38 UTC entry said every finding was resolved "in the commit that + records this entry". F1 to F4 were resolved in + `docs(issues): [#2450] record the independent review, resolve its findings and update the spec status`; + F5 was resolved earlier, in + `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`. + - **Missing fields:** that entry had no Inputs, Evidence, Verdict or Follow-up actions; this entry + supplies the ones that can still be stated. +- Verdict: REVIEW FAILED, for the tree reviewed at 07:38 UTC and for AC4 only. This is not a verdict on + the tree after the fix. +- Follow-up actions: + - Fix the restart (`Registar::deregister` in `torrust/torrust-server-lib#2`, then `stop()` removes + its own registration) and replace the fixed-port test with a green one. + - Run a new independent review on the final tree and append it as a new entry. From c554b2454e3096fb7ed7f98af292073d0b595a21 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:20:03 +0000 Subject: [PATCH 10/15] chore(deps): [#2450] bump torrust-server-lib to 0.4.0 torrust-server-lib 0.4.0 adds Registar::deregister, which the health-check test environment needs to remove its own registration when it stops. Nothing in the tracker calls it yet. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- packages/axum-health-check-api-server/Cargo.toml | 2 +- packages/axum-http-server/Cargo.toml | 2 +- packages/axum-rest-api-server/Cargo.toml | 2 +- packages/axum-server/Cargo.toml | 2 +- packages/udp-server/Cargo.toml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d95c2305db..b39fbd5411 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4902,9 +4902,9 @@ dependencies = [ [[package]] name = "torrust-server-lib" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70e4646927899a3a7d03d873ad4efad9552e4e35987d4ae7883e125154bac56" +checksum = "0f148517af29a7bd8212773623935dcfd8b21e00518693ec4b8429b0bcb363ce" dependencies = [ "derive_more 2.1.1", "tokio", diff --git a/Cargo.toml b/Cargo.toml index c7bf03e220..1c5eadabb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ torrust-tracker-axum-server = { version = "0.1.0", path = "packages/axum-server" torrust-tracker-rest-api-client = { version = "0.1.0", path = "packages/rest-api-client" } torrust-tracker-rest-api-runtime-adapter = { version = "0.1.0", path = "packages/rest-api-runtime-adapter" } torrust-tracker-rest-api-protocol = { version = "0.1.0", path = "packages/rest-api-protocol" } -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-clock = "3.0.0" torrust-tracker-configuration = { version = "3.0.0", path = "packages/configuration" } torrust-tracker-primitives = { version = "3.0.0", path = "packages/primitives" } diff --git a/packages/axum-health-check-api-server/Cargo.toml b/packages/axum-health-check-api-server/Cargo.toml index 1745d46357..4aaeaf9ddc 100644 --- a/packages/axum-health-check-api-server/Cargo.toml +++ b/packages/axum-health-check-api-server/Cargo.toml @@ -27,7 +27,7 @@ thiserror = "2" tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync" ] } tokio-util = "0.7.15" torrust-tracker-axum-server = { version = "0.1.0", path = "../axum-server" } -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-tracker-primitives = { version = "3.0.0", path = "../primitives" } torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-net-primitives = "0.1.0" diff --git a/packages/axum-http-server/Cargo.toml b/packages/axum-http-server/Cargo.toml index f2fa25e8d7..076390d4e2 100644 --- a/packages/axum-http-server/Cargo.toml +++ b/packages/axum-http-server/Cargo.toml @@ -32,7 +32,7 @@ serde = { version = "1", features = [ "derive" ] } tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync" ] } tokio-util = "0.7.15" torrust-tracker-axum-server = { version = "0.1.0", path = "../axum-server" } -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-clock = "3.0.0" torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-net-primitives = "0.1.0" diff --git a/packages/axum-rest-api-server/Cargo.toml b/packages/axum-rest-api-server/Cargo.toml index b0a0f50164..f8698f6b96 100644 --- a/packages/axum-rest-api-server/Cargo.toml +++ b/packages/axum-rest-api-server/Cargo.toml @@ -40,7 +40,7 @@ torrust-tracker-rest-api-client = { version = "0.1.0", path = "../rest-api-clien torrust-tracker-rest-api-application = { version = "0.1.0", path = "../rest-api-application" } torrust-tracker-rest-api-protocol = { version = "0.1.0", path = "../rest-api-protocol" } torrust-tracker-rest-api-runtime-adapter = { version = "0.1.0", path = "../rest-api-runtime-adapter" } -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-clock = "3.0.0" torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-metrics = "0.2.0" diff --git a/packages/axum-server/Cargo.toml b/packages/axum-server/Cargo.toml index 8961c8f29f..98e6569fbc 100644 --- a/packages/axum-server/Cargo.toml +++ b/packages/axum-server/Cargo.toml @@ -27,7 +27,7 @@ pin-project-lite = "0" thiserror = "2" tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync" ] } tokio-util = { version = "0.7", features = [ "rt" ] } -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-located-error = "3.0.0" tower = { version = "0", features = [ "timeout" ] } diff --git a/packages/udp-server/Cargo.toml b/packages/udp-server/Cargo.toml index 4cad38f8f2..caf7c22f76 100644 --- a/packages/udp-server/Cargo.toml +++ b/packages/udp-server/Cargo.toml @@ -31,7 +31,7 @@ serde = "1.0.219" thiserror = "2" tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync", "time" ] } tokio-util = "0.7.15" -torrust-server-lib = "0.3.0" +torrust-server-lib = "0.4.0" torrust-clock = "3.0.0" torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-tracker-events = { version = "0.1.0", path = "../events" } From cb8c34fd77716bcd09c6c1d5f65cdaa6a4f752f4 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:20:47 +0000 Subject: [PATCH 11/15] fix(axum-health-check-api-server): [#2450] deregister the health-check test environment on stop stop() now removes the environment's own registration from the registar, also when a task failed, so a stopped environment starts again on a fixed port and the services of other owners stay registered. CancellationRunning gains the service_binding it registered. The should_panic test that pinned the limitation is replaced by a fixed-port restart test, and two tests cover the removal. Resolves review-finding:pr-2652-f1 and review-finding:pr-2652-f2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/environment.rs | 130 +++++++++++++++--- .../src/server.rs | 7 +- 2 files changed, 118 insertions(+), 19 deletions(-) diff --git a/packages/axum-health-check-api-server/src/environment.rs b/packages/axum-health-check-api-server/src/environment.rs index 94e1a082f6..b521c04599 100644 --- a/packages/axum-health-check-api-server/src/environment.rs +++ b/packages/axum-health-check-api-server/src/environment.rs @@ -31,7 +31,8 @@ pub struct Stopped { /// The environment owns no event listener, so one token stops everything it /// started. Dropping it without `stop()` cancels that token, and the server /// shuts down once it observes it, so the binding is released shortly after -/// the drop. +/// the drop. A drop cannot await the registry lock, so only `stop()` removes +/// the environment's registration from the `registar`. pub struct Running { server: CancellationRunning, bind_to: SocketAddr, @@ -55,18 +56,14 @@ impl Environment { } /// Starts the test environment with a fresh cancellation token, so a - /// stopped environment can be started again. + /// stopped environment can be started again, also on a fixed port. /// /// Starting registers the health check API in the environment's - /// `registar`, and the `Registar` has no way to remove a registration, so - /// `stop()` leaves it there. A restart therefore works only when the - /// configuration binds an ephemeral port (`:0`), which gives the restarted - /// server a new binding. A fixed port registers the same binding twice. + /// `registar`; `stop()` removes that registration again. /// /// # Panics /// - /// Will panic if the server cannot be started, including a restart on a - /// fixed port whose binding is still registered. + /// Will panic if the server cannot be started. pub async fn start(self) -> Environment { let cancellation_token = CancellationToken::new(); @@ -103,19 +100,22 @@ impl Environment { /// Stops the test environment and returns a stopped environment. /// - /// It cancels the token and joins the server task and its drain - /// controller. + /// It cancels the token, joins the server task and its drain controller, + /// and removes the environment's own registration from the `registar`, + /// leaving the services of other owners in place. /// /// # Errors /// - /// Will return an error, after both tasks have been joined, if either task - /// failed or the drain timed out. The message names each failing task. + /// Will return an error, after both tasks have been joined and the + /// registration removed, if either task failed or the drain timed out. The + /// message names each failing task. pub async fn stop(self) -> Result, Error> { let Running { server: CancellationRunning { task, shutdown_controller, + service_binding, .. }, bind_to, @@ -124,7 +124,9 @@ impl Environment { cancel_server_on_drop.disarm().cancel(); - join_owned_tasks(task, shutdown_controller).await.map_err(Error::Error)?; + let joined = join_owned_tasks(task, shutdown_controller).await; + self.registar.deregister(&service_binding).await; + joined.map_err(Error::Error)?; Ok(Environment { registar: self.registar, @@ -170,9 +172,11 @@ mod tests { use std::time::Duration; use tokio_util::sync::CancellationToken; - use torrust_server_lib::registar::Registar; + use torrust_net_primitives::service_binding::{Protocol, ServiceBinding}; + use torrust_server_lib::registar::{Registar, ServiceRegistration}; use torrust_tracker_axum_server::signals::GracefulShutdownOutcome; use torrust_tracker_configuration::v3_0_0::health_check_api::HealthCheckApi; + use torrust_tracker_primitives::{ConfigurationInstanceId, RuntimeServiceMetadata, ServiceRole}; use super::{Environment, Error, Running, Started, Unstarted, join_owned_tasks}; use crate::server::CancellationRunning; @@ -271,8 +275,7 @@ mod tests { } #[tokio::test] - #[should_panic(expected = "DuplicateBinding")] - async fn it_should_not_start_again_on_a_fixed_port_while_the_registar_keeps_the_previous_registration() { + async fn it_should_serve_requests_after_being_stopped_and_started_again_on_a_fixed_port() { // Arrange let fixed_address = { let probe = TcpListener::bind("127.0.0.1:0").unwrap(); @@ -285,8 +288,59 @@ mod tests { .await .expect("the first stop should succeed"); - // Act: the registar keeps the first run's registration of the same binding, so this start panics. - let _restarted = start_within_deadline(stopped).await; + // Act + let restarted = start_within_deadline(stopped).await; + + // Assert + assert_eq!(restarted.bind_address(), fixed_address); + let status = tokio::time::timeout( + TEST_DEADLINE, + reqwest::get(format!("http://{fixed_address}/health_check")), // DevSkim: ignore DS137138 + ) + .await + .expect("the health check should answer within the test deadline") + .expect("the restarted health check API server should accept the request") + .status(); + assert_eq!(status, reqwest::StatusCode::OK); + + stop_within_deadline(restarted).await.expect("the second stop should succeed"); + } + + #[tokio::test] + async fn it_should_remove_only_its_own_registration_from_the_registar_when_stopped() { + // Arrange + let other_service_binding = ServiceBinding::new(Protocol::UDP, "127.0.0.1:6969".parse().unwrap()).unwrap(); + let registar = Registar::default(); + registar + .give_form() + .register(ServiceRegistration::new( + other_service_binding.clone(), + RuntimeServiceMetadata::new(ConfigurationInstanceId::new(ServiceRole::UdpTracker, 0)), + None, + )) + .await + .expect("the other service should register"); + let config = HealthCheckApi { + bind_address: "127.0.0.1:0".parse().unwrap(), + }; + let environment = start_within_deadline(Unstarted::new(&Arc::new(config), registar.clone())).await; + assert_eq!( + registar.services().await.len(), + 2, + "the environment should register its service" + ); + + // Act + let _stopped = stop_within_deadline(environment).await.expect("stop() should succeed"); + + // Assert + let remaining: Vec<_> = registar + .services() + .await + .into_iter() + .map(|service| service.service_binding().clone()) + .collect(); + assert_eq!(remaining, [other_service_binding]); } #[tokio::test] @@ -351,6 +405,7 @@ mod tests { state: Running { server: CancellationRunning { local_addr: "127.0.0.1:0".parse().unwrap(), + service_binding: ServiceBinding::new(Protocol::HTTP, "127.0.0.1:1212".parse().unwrap()).unwrap(), task: tokio::spawn(async { panic!("simulated health check API server task failure") }), shutdown_controller: tokio::spawn(async { GracefulShutdownOutcome::TimedOut }), }, @@ -372,6 +427,45 @@ mod tests { ); } + #[tokio::test] + async fn it_should_remove_its_registration_even_when_stopped_with_a_failed_task() { + // Arrange + let service_binding = ServiceBinding::new(Protocol::HTTP, "127.0.0.1:1212".parse().unwrap()).unwrap(); + let registar = Registar::default(); + registar + .give_form() + .register(ServiceRegistration::new( + service_binding.clone(), + RuntimeServiceMetadata::new(ConfigurationInstanceId::new(ServiceRole::HealthCheckApi, 0)), + None, + )) + .await + .expect("the environment's service should register"); + let environment: Started = Environment { + registar: registar.clone(), + state: Running { + server: CancellationRunning { + local_addr: "127.0.0.1:0".parse().unwrap(), + service_binding, + task: tokio::spawn(async { panic!("simulated health check API server task failure") }), + shutdown_controller: tokio::spawn(async { GracefulShutdownOutcome::Drained }), + }, + bind_to: "127.0.0.1:0".parse().unwrap(), + cancel_server_on_drop: CancellationToken::new().drop_guard(), + }, + }; + + // Act + let result = stop_within_deadline(environment).await; + + // Assert + assert!(result.is_err(), "stop() should return an error when a task failed"); + assert!( + registar.services().await.is_empty(), + "stop() should remove the registration although a task failed" + ); + } + #[tokio::test] async fn it_should_report_a_drain_timeout_even_when_both_tasks_join() { // Arrange diff --git a/packages/axum-health-check-api-server/src/server.rs b/packages/axum-health-check-api-server/src/server.rs index 8ddf47fd5e..8698416bf8 100644 --- a/packages/axum-health-check-api-server/src/server.rs +++ b/packages/axum-health-check-api-server/src/server.rs @@ -56,6 +56,10 @@ pub enum Error { /// compatibility path for consumers using [`Halted`]. pub struct CancellationRunning { pub local_addr: SocketAddr, + /// The binding this server registered in the `registar`. A caller that + /// stops the server and wants the registry to forget it passes this + /// binding to `Registar::deregister`. + pub service_binding: ServiceBinding, pub task: JoinHandle>, pub shutdown_controller: JoinHandle, } @@ -177,7 +181,7 @@ pub async fn start_with_cancellation( if let Err(source) = registar .give_form() - .register(ServiceRegistration::new(service_binding, metadata, None)) + .register(ServiceRegistration::new(service_binding.clone(), metadata, None)) .await { cancellation_token.cancel(); @@ -192,6 +196,7 @@ pub async fn start_with_cancellation( Ok(CancellationRunning { local_addr, + service_binding, task, shutdown_controller, }) From 0042a18a5ab1e2aea4443b86e8f772be29dc624d Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:24:27 +0000 Subject: [PATCH 12/15] docs(issues): [#2450] record the registry deregistration and update the spec to the final design Adds fact 7, D6, AC8, the bare-drop and by-binding risks and the T5 row to the spec, rewrites V6 and V7 and the retrospective to the final state (the documented-limitation decision was reversed), and updates the task inventory row. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../shutdown-process/task-inventory.md | 4 +- .../ISSUE.md | 52 ++++++++++-- .../implementation-retrospective.md | 50 ++++++++---- .../manual-verification-evidence.md | 79 +++++++++++++------ 4 files changed, 139 insertions(+), 46 deletions(-) diff --git a/docs/features/shutdown-process/task-inventory.md b/docs/features/shutdown-process/task-inventory.md index 8e451fe374..d6219af490 100644 --- a/docs/features/shutdown-process/task-inventory.md +++ b/docs/features/shutdown-process/task-inventory.md @@ -1,7 +1,7 @@ --- doc-type: feature-supporting-analysis status: verified -last-updated-utc: "2026-10-26 07:30" +last-updated-utc: "2026-10-26 16:23" semantic-links: related-artifacts: - docs/features/shutdown-process/README.md @@ -304,7 +304,7 @@ themselves. | HTTP tracker (`packages/axum-http-server/src/testing/environment.rs`) | One: the HTTP-core statistics listener | Subscribes before the server starts; spawns the listener after a successful start; the `Running` state holds a `DropGuard` for the server token and another for the listener token (`cancel_server_on_drop`, `cancel_listener_on_drop`). `stop()` cancels and joins the server and its drain controller, then the listener (issue #2416). | | UDP tracker (`packages/udp-server/src/testing/environment.rs`) | Three: UDP-core statistics, UDP-server statistics, and UDP-server banning | Subscribes all three receivers before the server starts; the `Running` state holds a `DropGuard` for the receive-loop token and another for the one token of the three listeners (`cancel_server_on_drop`, `cancel_listeners_on_drop`). `stop()` cancels and joins the receive loop, then the listeners (issue #2416). | | REST API (`packages/axum-rest-api-server/src/testing/environment.rs`) | None | Runs no event listener, so it keeps one token: the `Running` state holds the server task, its drain controller, and one `DropGuard` (`cancel_server_on_drop`). `stop()` cancels the token and joins both tasks, then panics naming each failing task (issue #2449). | -| Health-check API (`packages/axum-health-check-api-server/src/environment.rs`) | None | Runs no event listener, so it keeps one token: the private `Running` state holds the server task, its drain controller, and one `DropGuard` (`cancel_server_on_drop`). `stop()` cancels the token and joins both tasks, then returns an error naming each failing task (issue #2450). | +| Health-check API (`packages/axum-health-check-api-server/src/environment.rs`) | None | Runs no event listener, so it keeps one token: the private `Running` state holds the server task, its drain controller, and one `DropGuard` (`cancel_server_on_drop`). `stop()` cancels the token and joins both tasks, removes its own registration from the `registar` with `Registar::deregister` (so it starts again on a fixed port and other owners' services stay registered), then returns an error naming each failing task (issue #2450). A bare drop cannot await the registry lock, so it leaves the registration in place. | Neither tracker environment runs a swarm-bus listener, although announce requests can publish on that bus; no listener consumes those events there. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index a383cc5e41..c5fe6900c1 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -9,7 +9,7 @@ github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" related-pr: null -last-updated-utc: "2026-10-26 12:42" +last-updated-utc: "2026-10-26 16:23" semantic-links: skill-links: - create-issue @@ -72,6 +72,12 @@ and is not in the EPIC roadmap: 5. **No owned listeners, no example.** No event listener, no example binary. 6. **The drain is bounded.** The shared helper force-closes at the 5 s `HEALTH_CHECK_API_GRACEFUL_DRAIN_TIMEOUT` deadline (SI-16 D7). +7. **Registration side effect.** The legacy `server::start` never registered the + service in the `registar`; `start_with_cancellation` does. `Registar` in + `torrust-server-lib` 0.3.0 had no way to remove a registration, so a + stop-then-start on a fixed port registered the same binding twice and + panicked (found in the review of #2652, `review-finding:pr-2652-f1`). Version + 0.4.0 adds `Registar::deregister`. ## Scope @@ -81,6 +87,8 @@ and is not in the EPIC roadmap: with a fresh token per start. - Give the environment a `bind_address()` accessor and migrate the 8 `env.state.binding` reads to it. +- Remove the environment's own registration from the `registar` in `stop()`, + which needs `torrust-server-lib` 0.4.0 (`Registar::deregister`). - Deterministic tests for the new `stop()` guarantees. - Update the shutdown task inventory. @@ -108,6 +116,16 @@ and is not in the EPIC roadmap: `RuntimeServiceMetadata`; use the health-check API role with instance 0, as the application does. - **D5 - No outer stop timeout.** The drain helper bounds the stop (fact 6). +- **D6 - `stop()` removes its own registration.** After joining both tasks, and + also when a task failed, `stop()` calls `Registar::deregister` with the + binding the server registered (`CancellationRunning::service_binding`). It + removes only that binding, so the services of other owners stay registered + and a restart on a fixed port works. Added after the review of #2652 + (`review-finding:pr-2652-f1`, `review-finding:pr-2652-f2`). A bare drop cannot + await the registry lock, so only `stop()` removes it. Rejected: returning a + fresh `Registar` on stop (as the REST environment does), which would discard + the caller's services; and a receipt-returning `register` that removes only + its own entry, a breaking change to every call site for no present need. ## Architectural Decisions @@ -169,14 +187,16 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | T2 | DONE | Migrate the field reads | Contract tests use `bind_address()`. | | T3 | DONE | Documentation | Task inventory records the migrated health-check API environment. | | T4 | IN_PROGRESS | Verification and completion review | Automatic checks, manual scenario, AC review, pre-push checks, independent review. | +| T5 | IN_PROGRESS | Review round on #2652 | `stop()` deregisters (D6), the F3 correction, the audit; a new independent review on the final tree. | T1 tests (use the `write-unit-test` skill, every wait bounded): - `stop()` joins the server and the drain controller without an error. - `stop()` releases the binding: the same address binds right after `stop()`. - Stop-then-start serves the health check on the restarted environment, on an - ephemeral port. A fixed-port restart is a documented limitation - (`review-finding:pr-2652-f1`, evidence V7). + ephemeral port and on a fixed port. +- `stop()` removes the environment's own registration, also when a task + failed, and leaves the services of other owners registered. - A drain timeout is returned as an error after both tasks join. - Dropping a running environment without `stop()` releases the binding (poll `TcpListener::bind` within a bounded deadline, as #2471's test does). @@ -224,6 +244,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-26 07:33 UTC - GitHub Copilot - Design review approved by the maintainer. Committed the code, the T0/T1 evidence and the task inventory update (T2 reads moved with T1, T3 done). Added V5 (prose-first Arrange-Act-Assert record) and V6 (automatic checks after the last production change) to `manual-verification-evidence.md`. Independent review next. - 2026-10-26 07:38 UTC - GitHub Copilot - Independent Task Reviewer passed with five non-blocking findings (F1-F5), all resolved and recorded in `agent-review-reports.md`. No retrospective: no discovery changed the design or the spec; the mutation that did not compile is explained in V2. Acceptance criteria stay TODO until the maintainer says to tick them. - 2026-10-26 12:42 UTC - GitHub Copilot - Copilot's review of #2652 (`review-finding:pr-2652-f1`) found that a fixed-port stop-then-start panics, because the token-aware start registers the service and the `Registar` cannot remove it. This corrects the 07:38 entry: the discovery is material, so `implementation-retrospective.md` is added. The maintainer chose to document and pin the limitation and file a follow-up; recorded in V7, with V6 re-run after the new last production change. The acceptance criteria stay TODO. +- 2026-10-26 16:24 UTC - GitHub Copilot - Review round on #2652 (`review-finding:pr-2652-f1`, `-f2`, `-f3`). This reverses the 12:42 UTC decision to document the fixed-port limitation: da2ce7 re-raised the finding as a Major (`-f2`) and asked for the fix, and measuring the cost showed a small additive registry method was enough. The maintainer chose to fix it in this PR (route R1) with `Registar::deregister`. Opened torrust/torrust-server-lib#2 at 16:04 UTC (CI green, merged 16:19 UTC), published `torrust-server-lib` 0.4.0, bumped it here, and made `stop()` deregister its own binding (D6, AC8), also when a task failed, with a green fixed-port restart test replacing the `should_panic` pin. The earlier independent review entry is corrected in `agent-review-reports.md` (`-f3`). V6 and V7 and the retrospective are rewritten to the final state. A new independent review on the final tree and the audit follow. The acceptance criteria stay TODO. ## Acceptance Criteria @@ -233,12 +254,15 @@ before maintainer review and commit. Sign every commit with GPG. and the drain controller. - [ ] AC3: `stop()` returns an error naming each failing task, after joining both, and keeps its current signature (D1). -- [ ] AC4: A stopped environment can be started again and serves the health - check. +- [ ] AC4: A stopped environment can be started again, on an ephemeral or a + fixed port, and serves the health check. - [ ] AC5: No caller reads the environment's running state directly. - [ ] AC6: The shutdown task inventory reflects the migration. - [ ] AC7: Dropping a running environment without `stop()` releases its binding within the test deadline. +- [ ] AC8: `stop()` removes the environment's own registration from the + `registar`, also when a task failed, and keeps the services of other + owners (D6). - [ ] `linter all` exits with code `0` - [ ] Relevant tests pass - [ ] Manual verification scenarios are executed and documented in issue-local `manual-verification-evidence.md` @@ -281,11 +305,14 @@ Notes: | AC5 | TODO | | | AC6 | TODO | | | AC7 | TODO | | +| AC8 | TODO | | ## Dependencies - Done: SI-13 (#2324) token-aware health-check API lifecycle; SI-16 (#2412) as the reference migration and the bounded drain helper. +- Done: `torrust-server-lib` 0.4.0 with `Registar::deregister` + (torrust/torrust-server-lib#2), which D6 uses. - Best after SI-17 and SI-23: the contract tests also stop UDP and REST API environments, so migrating those first keeps this diff to the health-check environment. @@ -296,15 +323,26 @@ Notes: - **Public API change.** `Running` and the `state` field are public in a non-`testing` module; external users of them break. The module is test support, so the risk is low; SI-19 is the breaking release anyway. +- **Bare drop keeps the registration.** Dropping a running environment without + `stop()` releases the binding but cannot await the registry lock, so the + entry stays in the `registar`. A fixed-port restart after a bare drop still + fails; only `stop()` is restart-safe. Callers that restart must call `stop()`. +- **`deregister` removes by binding.** The registry is keyed by binding only, + so `Registar::deregister` removes whichever registration holds it. The + environment passes only the binding it registered. ## Rollback Revert the environment and field-read commits; the legacy path is still -available. +available. To keep the migration but drop the registry cleanup, revert only the +`stop()` deregistration commit; the `torrust-server-lib` 0.4.0 bump is harmless +(it only adds a method). ## Implementation Completion Review -- Retrospective: not needed; see the 2026-10-26 07:38 progress-log entry +- Retrospective: `implementation-retrospective.md`, added after the review of + #2652 found the fixed-port restart problem (progress-log entry of + 2026-10-26 12:42 UTC and the later entries) - If needed, create `implementation-retrospective.md` from `docs/templates/IMPLEMENTATION-RETROSPECTIVE.md` in this directory; otherwise add a progress-log entry explaining why it was not needed. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md index cc101fdcdf..08c36c6d17 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md @@ -18,16 +18,20 @@ approach; it does not replace acceptance-criteria verification. ## Outcome `Environment` runs the health-check API on the token lifecycle, with private -`state`, one `DropGuard`, a joined `stop()` that names every failing task, and a -`bind_address()` accessor. The evidence is in `manual-verification-evidence.md` -(V0 to V7). One limitation remains: a stop-then-start on a fixed port panics, -because the environment's registration stays in the `registar`. +`state`, one `DropGuard`, a joined `stop()` that names every failing task, a +`bind_address()` accessor, and a `stop()` that removes the environment's own +registration from the `registar`, so a stopped environment starts again also on +a fixed port. The evidence is in `manual-verification-evidence.md` (V0 to V7). +One limitation remains: a bare drop cannot await the registry lock, so only +`stop()` removes the registration. ## What Went Well 1. The #2449 sibling was a complete model, so the design review of the new environment needed no change. 2. Every new test was mutation-proven before review. +3. Two independent reviewers (Copilot and da2ce7) found the same defect, which + no earlier check had covered. ## What Changed During Implementation @@ -35,9 +39,17 @@ Copilot's review of #2652 found that restarting on a fixed port panics with `DuplicateBinding` (`review-finding:pr-2652-f1`). The legacy `server::start` never registered the service, while the token-aware `start_with_cancellation` does, so the migration added a registration that -`stop()` cannot remove: `torrust-server-lib` 0.3.0's `Registar` has no remove -operation. The restart test used `:0`, which hides the problem. The maintainer -chose to document and pin the limitation and file a follow-up; see V7. +`stop()` could not remove: `torrust-server-lib` 0.3.0's `Registar` had no remove +operation. The restart test used `:0`, which hides the problem. + +The first response was a documented limitation plus a pinning test, with a +registry change left for a follow-up. da2ce7 re-raised the finding +(`review-finding:pr-2652-f2`) and asked for the fix, because AC4 promised a +restart without a port condition. A second look found that the registry change was +small, so the fix went into this PR: `Registar::deregister` in +`torrust-server-lib` 0.4.0, then `stop()` deregisters its own binding. The first +decision was reversed, and the pinning test was replaced by a green fixed-port +restart test. See V7. ## Root Cause @@ -45,7 +57,9 @@ The spec compared the start and stop paths but not the side effects of the token-aware start. D4 asked for `RuntimeServiceMetadata` and treated the registration as a given, so no task asked what a restart does to the registry. The restart test used the one configuration, an ephemeral port, that cannot -collide. +collide. The first fix choice then weighed the registry change as large before +its size was measured: counting the `register` call sites and reading +`Registar` showed an additive method was enough. ## Improvements for Future Work @@ -53,15 +67,23 @@ collide. add a task that lists every side effect of `start` (registrations, files, channels) and says how `stop` undoes each. 2. For a restart test, run it on a fixed port as well as on `:0`. +3. Before choosing to document a limitation in place of a fix, measure the cost + of the fix (call sites, API surface) and write it down; an AC that states no + condition is a promise the limitation breaks. ## Avoiding Overcorrection -The evidence does not justify changing the `Registar` inside this PR, or a rule -that every test environment must support a fixed-port restart: no caller restarts -this environment on a fixed port. +The evidence does not justify the receipt-returning `register` (a breaking +change to about eight production call sites for no present need), shutdown-time +deregistration for real services (the maintainer decided shutdown stays decoupled +from registration for now), or a rule that every test environment must support a +restart after a bare drop. ## Evidence -- `manual-verification-evidence.md` V7 (red test, decision, mutation proof) -- `ISSUE.md` progress log -- Commit subject `test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` +- `manual-verification-evidence.md` V7 (red test, both decisions, mutation proofs) +- `ISSUE.md` progress log and D6 +- `torrust/torrust-server-lib#2` (the `Registar::deregister` change) +- Commit subjects + `fix(axum-health-check-api-server): [#2450] deregister the health-check test environment on stop` + and `chore(deps): [#2450] bump torrust-server-lib to 0.4.0` diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md index 75a7665496..5d3da20db5 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -1,7 +1,7 @@ --- doc-type: manual-verification-evidence issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md -last-updated-utc: "2026-10-26 12:42" +last-updated-utc: "2026-10-26 16:23" --- # Manual Verification Evidence @@ -105,41 +105,74 @@ No prose had to be kept beyond the three section markers. ## V6: Automatic checks after the last production change The last production change is the commit +`fix(axum-health-check-api-server): [#2450] deregister the health-check test environment on stop` +(V7). Earlier last changes were `test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` -(V7). It supersedes the earlier last change, `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`, -after which these commands were first run with 11 lib tests. Run on the tree after the last change (rustc 1.99.1): +and, before it, `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`; +the commands below were run again after this one. Toolchain: rustc 1.99.1, with +`torrust-server-lib` 0.4.0 from crates.io (the tree after the commit +`chore(deps): [#2450] bump torrust-server-lib to 0.4.0`). | Command | Result | | ------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -| `cargo test -p torrust-tracker-axum-health-check-api-server` | 12 lib passed (1.00 s), 8 integration passed (3.04 s) | +| `cargo test -p torrust-tracker-axum-health-check-api-server` | 14 lib passed (1.00 s), 8 integration passed (3.04 s) | | `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings` | no warnings | | `cargo check --workspace --all-targets --all-features` | no errors | | `cargo +nightly fmt --check` | clean | -| `linter all` | exit 0 (12:41 UTC) | +| `linter all` | exit 0 (16:23 UTC) | -The pre-commit hook passed on the commit above. +The pre-commit hook passed on each commit. -## V7: Fixed-port restart (`review-finding:pr-2652-f1`) +## V7: Fixed-port restart (`review-finding:pr-2652-f1`, `review-finding:pr-2652-f2`) Copilot's review of #2652 reported that a stop-then-start on a fixed port -panics. A red test reproduced it before any change: -`cargo test -p torrust-tracker-axum-health-check-api-server --lib fixed_port` -failed with `Registration { source: DuplicateBinding(...) }` raised by `start()`. +panics, and da2ce7 re-raised it as `review-finding:pr-2652-f2`, asking for a +fix instead of a documented limitation. -Cause (read from source, not run beyond the red test): the legacy `server::start` +Red test, before any change: a stop-then-start on a fixed port, with a port +picked by binding `127.0.0.1:0` and dropping the listener, failed with +`Registration { source: DuplicateBinding(...) }` raised by `start()`. + +Cause (read from source, confirmed by the red test): the legacy `server::start` never registered the service in the `registar`; `server::start_with_cancellation` -does (spec D4), and `stop()` cannot remove the registration because +does (spec D4), and `stop()` could not remove the registration because `torrust-server-lib` 0.3.0's `Registar` has no remove operation. Restart on an -ephemeral port (`:0`), which the existing restart test covers, binds a new +ephemeral port (`:0`), which the earlier restart test covers, binds a new address and is unaffected. -Decision (the maintainer chose it): document the limitation and pin it, and file -a follow-up to give the `Registar` a removal operation. The commit -`test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation` -documents it on `Environment::start()` and adds -`it_should_not_start_again_on_a_fixed_port_while_the_registar_keeps_the_previous_registration` -(`#[should_panic(expected = "DuplicateBinding")]`). Lib tests rose from 11 to 12. - -Mutation proof: with the test's configuration changed to bind `127.0.0.1:0`, the -test failed with `test did not panic as expected`; the file was restored from -`HEAD` and `cmp` confirmed the restore. +First decision, superseded: the maintainer chose to document the limitation and +pin it with a `should_panic` test, in +`test(axum-health-check-api-server): [#2450] document and pin the fixed-port restart limitation`. +That was made before it was known that the registry could be fixed cheaply, +and da2ce7's re-raise asked for the fix. The final change replaces it. + +Final decision (the maintainer chose it): add an additive +`Registar::deregister(&ServiceBinding)` to `torrust-server-lib` +(torrust/torrust-server-lib#2, merged, published as 0.4.0), bump it in the +tracker, and make `stop()` remove the environment's own binding. Registry +keyed by binding only: it removes only the binding the environment registered, +and keeps the services of other owners. A receipt-returning `register` was +rejected as a breaking change to about eight production call sites in four +packages (counted from `grep -rn "\.register("` over `src` and `packages/*/src`). + +Tests (in `environment::tests`), red before the change and green after: + +- `it_should_serve_requests_after_being_stopped_and_started_again_on_a_fixed_port` + (replaces the `should_panic` test; green restart on a nonzero port). +- `it_should_remove_only_its_own_registration_from_the_registar_when_stopped` + (the registry holds the caller's other service and only that one afterwards). +- `it_should_remove_its_registration_even_when_stopped_with_a_failed_task`. + +Mutation proofs (each restored from a copy and checked with `cmp`): + +| ID | Mutation in `stop()` | Result | +| --- | --------------------------------------------------------- | ------------------------------------------------------- | +| M-A | remove the `deregister` call | 3 failed: the three tests above | +| M-B | deregister only after the join result was checked with `?` | 1 failed: the failed-task test; the other 13 passed | + +In `torrust-server-lib`, the test that keeps the other registrations failed +when the removal cleared the whole map, and passed after the restore (`cmp`). + +Not covered: a bare `drop` of a running environment cannot deregister, because it +cannot await the registry lock; a fixed-port restart after a bare drop still +fails (read from source, not run). The spec states it in "Risks and Trade-offs". From 6c21b1d03ee25c5f56cc30c53f83092bafe1e3fc Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:31:43 +0000 Subject: [PATCH 13/15] docs(issues): [#2450] record the prose-first comparison of the new tests and fix the review findings Completes V5 for the eleven environment tests, corrects the production call-site count from eight to seven, labels V4 as measured at T1, sets related-pr and states the dropped-stop risk, after the independent review of the final tree. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ISSUE.md | 8 ++- .../implementation-retrospective.md | 2 +- .../manual-verification-evidence.md | 50 ++++++++++++++++--- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md index c5fe6900c1..d802ae1b5b 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md @@ -8,8 +8,8 @@ epic: 1488 github-issue: 2450 spec-path: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md branch: "2450-migrate-health-check-api-test-environment" -related-pr: null -last-updated-utc: "2026-10-26 16:23" +related-pr: 2652 +last-updated-utc: "2026-10-26 16:31" semantic-links: skill-links: - create-issue @@ -245,6 +245,7 @@ before maintainer review and commit. Sign every commit with GPG. - 2026-10-26 07:38 UTC - GitHub Copilot - Independent Task Reviewer passed with five non-blocking findings (F1-F5), all resolved and recorded in `agent-review-reports.md`. No retrospective: no discovery changed the design or the spec; the mutation that did not compile is explained in V2. Acceptance criteria stay TODO until the maintainer says to tick them. - 2026-10-26 12:42 UTC - GitHub Copilot - Copilot's review of #2652 (`review-finding:pr-2652-f1`) found that a fixed-port stop-then-start panics, because the token-aware start registers the service and the `Registar` cannot remove it. This corrects the 07:38 entry: the discovery is material, so `implementation-retrospective.md` is added. The maintainer chose to document and pin the limitation and file a follow-up; recorded in V7, with V6 re-run after the new last production change. The acceptance criteria stay TODO. - 2026-10-26 16:24 UTC - GitHub Copilot - Review round on #2652 (`review-finding:pr-2652-f1`, `-f2`, `-f3`). This reverses the 12:42 UTC decision to document the fixed-port limitation: da2ce7 re-raised the finding as a Major (`-f2`) and asked for the fix, and measuring the cost showed a small additive registry method was enough. The maintainer chose to fix it in this PR (route R1) with `Registar::deregister`. Opened torrust/torrust-server-lib#2 at 16:04 UTC (CI green, merged 16:19 UTC), published `torrust-server-lib` 0.4.0, bumped it here, and made `stop()` deregister its own binding (D6, AC8), also when a task failed, with a green fixed-port restart test replacing the `should_panic` pin. The earlier independent review entry is corrected in `agent-review-reports.md` (`-f3`). V6 and V7 and the retrospective are rewritten to the final state. A new independent review on the final tree and the audit follow. The acceptance criteria stay TODO. +- 2026-10-26 16:31 UTC - GitHub Copilot - A new independent Task Reviewer ran on the final tree and returned REVIEW FAILED for one documentation blocker (V5 lacked the prose-first comparison of the three tests added in this round) and six low findings, with no production defect; recorded in `agent-review-reports.md`. Fixed: V5 now covers the eleven environment tests, the production call-site count is corrected from eight to seven, V4 is labelled as measured at T1, `related-pr` is set, and the dropped-`stop()` risk is stated. The acceptance criteria stay TODO. ## Acceptance Criteria @@ -327,6 +328,9 @@ Notes: `stop()` releases the binding but cannot await the registry lock, so the entry stays in the `registar`. A fixed-port restart after a bare drop still fails; only `stop()` is restart-safe. Callers that restart must call `stop()`. + The same holds if the `stop()` future is dropped after it cancelled the token + and before it deregistered, for example by a caller's timeout (read from + source, not run). - **`deregister` removes by binding.** The registry is keyed by binding only, so `Registar::deregister` removes whichever registration holds it. The environment passes only the binding it registered. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md index 08c36c6d17..093cbff13b 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/implementation-retrospective.md @@ -74,7 +74,7 @@ its size was measured: counting the `register` call sites and reading ## Avoiding Overcorrection The evidence does not justify the receipt-returning `register` (a breaking -change to about eight production call sites for no present need), shutdown-time +change to seven production call sites for no present need), shutdown-time deregistration for real services (the maintainer decided shutdown stays decoupled from registration for now), or a rule that every test environment must support a restart after a bare drop. diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md index 5d3da20db5..947b8278d2 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/manual-verification-evidence.md @@ -1,7 +1,7 @@ --- doc-type: manual-verification-evidence issue-spec: docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/ISSUE.md -last-updated-utc: "2026-10-26 16:23" +last-updated-utc: "2026-10-26 16:31" --- # Manual Verification Evidence @@ -66,7 +66,10 @@ Restart address (read from source, not run): the legacy `stop()` also returned the configured `bind_to`, so a restart on a `:0` configuration binds a fresh ephemeral port both before and after this change. The behaviour is unchanged. -## V4: Suite timing (spec M2) +## V4: Suite timing (spec M2), measured at the T1 tree + +Measured once, on the tree after T1 (11 lib tests). Not re-run on the final tree, which +has 14 lib tests; the integration suite is unchanged. Toolchain: rustc 1.99.1 (58cf8f9c3 2026-10-13), warm build. @@ -80,10 +83,15 @@ cold build, so it is not comparable with the warm total. The lib tests rose from 3 to 11 because of the added `environment::tests`; the existing tests are not slower. -## V5: Prose-first Arrange-Act-Assert comparison for the eight new tests +## V5: Prose-first Arrange-Act-Assert comparison for the eleven environment tests Each test's `// Arrange`, `// Act` and `// Assert` sections were written as -prose first, then compared with the code. Result per test: +prose first, then compared with the code. The first eight tests were compared +at T1. The last three were added after the review of #2652 and had no recorded +comparison; the independent review asked for one (finding F1 of the final Task +Reviewer entry in `agent-review-reports.md`), so their prose was written afterwards +from each test's purpose and then compared with the committed code. Result +per test: - Stop without a failure: Arrange starts the environment; Act is `stop_within_deadline(environment)`; Assert is that the result is `Ok`. The @@ -99,6 +107,33 @@ prose first, then compared with the code. Result per test: failing task handles, Act calls `join_owned_tasks` (or `stop()`), Assert reads the returned error text. No assertion is derived through production code. +- Start again on a fixed port: prose is "start an environment on a free + nonzero address, stop it, start it again; it listens on the same address and + answers 200". The code agrees: Arrange picks the address by binding `:0` and + dropping the listener (the only way to get a free nonzero port), then starts + and stops; Act is `start_within_deadline(stopped)`; Assert compares + `bind_address()` with the chosen address and reads the HTTP status. The + expected address and status are literals of the scenario, not derived from + production code. The deadline wrapper is irreducible, as above. +- Remove only its own registration when stopped: prose is "a registry already + holds another owner's service; start an environment on it; stop it; only the + other owner's service remains". The code agrees: Arrange registers a UDP + service and starts the environment; Act is `stop_within_deadline(environment)`; + Assert compares the remaining bindings with the other owner's binding. The + `assert_eq!(len, 2)` between Arrange and Act is a precondition so the test + cannot pass with an environment that never registered. +- Remove its registration even when stopped with a failed task: prose is "an + environment whose server task panicked and whose registration is in the + registry; stop it; stop reports an error, and the registry is empty". The + code agrees: Arrange builds `Running` by struct literal with a panicking + server task (a real server cannot be made to fail on demand) and registers the + same binding; Act is `stop_within_deadline(environment)`; Assert reads + `result.is_err()` and `registar.services()`. +- Release the binding when stopped (changed in + `test(axum-health-check-api-server): [#2450] assert the stop result in the binding-release test`): + Act is `stop_within_deadline(environment).await.expect("stop() should + succeed")`, so a failing stop fails the test with its own message before the + rebind assertion. No prose had to be kept beyond the three section markers. @@ -119,7 +154,7 @@ the commands below were run again after this one. Toolchain: rustc 1.99.1, with | `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings` | no warnings | | `cargo check --workspace --all-targets --all-features` | no errors | | `cargo +nightly fmt --check` | clean | -| `linter all` | exit 0 (16:23 UTC) | +| `linter all` | exit 0 (16:31 UTC) | The pre-commit hook passed on each commit. @@ -152,8 +187,9 @@ Final decision (the maintainer chose it): add an additive tracker, and make `stop()` remove the environment's own binding. Registry keyed by binding only: it removes only the binding the environment registered, and keeps the services of other owners. A receipt-returning `register` was -rejected as a breaking change to about eight production call sites in four -packages (counted from `grep -rn "\.register("` over `src` and `packages/*/src`). +rejected as a breaking change to seven production call sites in four +packages (counted with `grep -rn "\.register(" --include=*.rs src packages/*/src`, excluding +each file's `#[cfg(test)]` module; an earlier count of eight in this record was wrong). Tests (in `environment::tests`), red before the change and green after: From 8ed7da26e7078e876d47cbe82ed3c54588908b2b Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:34:12 +0000 Subject: [PATCH 14/15] docs(issues): [#2450] record the independent review of the final tree Appends the Task Reviewer entry for the tree after the fixed-port fix, with its inputs, evidence, findings with their resolution references, verdict and follow-up actions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../agent-review-reports.md | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md index c579fb12c3..6da38fe93e 100644 --- a/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md +++ b/docs/issues/open/2450-1488-si-24-migrate-health-check-api-test-environment/agent-review-reports.md @@ -67,3 +67,60 @@ This entry corrects the 07:38 UTC entry above, which stays unchanged. - Fix the restart (`Registar::deregister` in `torrust/torrust-server-lib#2`, then `stop()` removes its own registration) and replace the fixed-port test with a green one. - Run a new independent review on the final tree and append it as a new entry. + +### 2026-10-26 16:32 UTC - Task Reviewer (final tree after the fixed-port fix) + +This is the new independent review that the 16:10 UTC correction asked for. + +- Invocation scope: branch `2450-migrate-health-check-api-test-environment` against `torrust/develop` + after the commit `docs(issues): [#2450] record the registry deregistration and update the spec to the final design`: + AC1 to AC8, the health-check environment code and tests, `Cargo.lock` and `Cargo.toml`, the spec, + the evidence file (V0 to V7), the retrospective, the task inventory, stamps and commit-id hygiene. + The reviewer was read-only and ran its mutation checks in a `/tmp` copy of `git archive HEAD`. +- Inputs: `ISSUE.md`, `manual-verification-evidence.md`, `implementation-retrospective.md`, + `agent-review-reports.md`, `task-inventory.md`, `environment.rs`, `server.rs`, `contract.rs`, the + branch diff (15 files) and the published `torrust-server-lib` 0.4.0 source. +- Evidence (commands the reviewer ran, from its report): + - `cargo test -p torrust-tracker-axum-health-check-api-server`: 14 lib tests (3 in `server::tests`, + 11 in `environment::tests`) and 8 integration tests passed. + - `cargo clippy -p torrust-tracker-axum-health-check-api-server --all-targets -- -D warnings`, + `cargo check --workspace --all-targets --all-features` and `cargo +nightly fmt --check`: exit 0. + - `linter all`: exit 0. + - Mutation M-A (remove the `deregister` call): 3 tests failed. M-B (deregister after the join result + is checked with `?`): 1 test failed. Both match V7. + - Production `.register(` call sites counted with grep, excluding each file's test module: 7 in 4 + packages (this corrected the "eight" in V7 and the retrospective). + - `git diff torrust/develop...HEAD -- Cargo.lock` changes only the `torrust-server-lib` version and + checksum; no `[patch]` section remains. + - The commit-id check of the `open-pull-request` skill printed nothing; stamps of the changed files are + at or before their last commits; V-range references are consistent. +- Findings: + - **F1 (blocker, evidence)** - V5 recorded no prose-first comparison for the three tests added in + the review round. Resolved in + the evidence file's V5, by the commit + `docs(issues): [#2450] record the prose-first comparison of the new tests and fix the review findings`. + - **F2 (low, accuracy)** - the production call-site count was seven, not eight. Resolved in the + same commit, in V7 and the retrospective. + - **F3 (low, evidence)** - V4 was measured at the T1 tree but read as final. Resolved in the same + commit: V4 is labelled as measured at T1, not re-run. + - **F4 (low, stamps)** - the 16:23 stamp preceded the 16:24 progress-log entry. Accepted as it was: + the rule is stamp at or before the commit, which held; the stamps were bumped again by the + commit above. + - **F5 (low, metadata)** - `related-pr` was `null` while PR #2652 was open. Resolved in the same + commit (`related-pr: 2652`). `status: planned` follows the sibling specs and is unchanged. + - **F6 (low, risk)** - a dropped `stop()` future also leaves the registration. Resolved in the same + commit, in the "Risks and Trade-offs" section of `ISSUE.md` (read from source, not run). + - **F7 (low, test)** - the fixed-port test picks a free port by binding `:0` and dropping the + listener, so another process could take it first. Accepted: the same pattern is used by + `ServerStartWithDuplicateRegistration` in `server.rs` tests, and the window is a few + microseconds. + - No production-code defect was found in `stop()` or `start()`; the reviewer checked the order of + `deregister` against the join, the failed-task path and every place that builds or pattern-matches + `CancellationRunning`. +- Verdict: REVIEW FAILED on the reviewed tree because of F1 (documentation only). All seven low findings + and the blocker are resolved or accepted as above; AC1 to AC8 are supported by the evidence and stay + TODO until the maintainer says to tick them. The reviewer asked for a re-check of V5 after the + fix; the author re-read V5 against `environment.rs`, and the reviewer was not run again. +- Follow-up actions: + - Optional: a reviewer re-checks V5 against `environment.rs`. + - The maintainer decides when to tick the acceptance criteria. From 6c0d9cd80a294e5d64e5675fc4a62820b35887e5 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 26 Oct 2026 16:44:23 +0000 Subject: [PATCH 15/15] docs(pr-reviews): [#2450] record the review audit of PR 2652 Records Copilot's finding F1 and the maintainer's re-raise F2 and finding F3 with their dispositions, current-tree verification, resolution references and reply URLs. The validator exits 0 with 3 rows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/pr-reviews/pr-2652-review/PR-REVIEW.md | 115 ++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 docs/pr-reviews/pr-2652-review/PR-REVIEW.md diff --git a/docs/pr-reviews/pr-2652-review/PR-REVIEW.md b/docs/pr-reviews/pr-2652-review/PR-REVIEW.md new file mode 100644 index 0000000000..bf3c5b7249 --- /dev/null +++ b/docs/pr-reviews/pr-2652-review/PR-REVIEW.md @@ -0,0 +1,115 @@ +--- +semantic-links: + skill-links: + - process-pr-review + related-artifacts: + - .github/skills/dev/pr-reviews/process-pr-review/SKILL.md +--- + + + +# PR #2652 Review Audit + +Source: pull-request reviews and inline review threads for . + +## Ownership + +The PR author owns this tracked audit record. Reviewers, including repository review agents, +deliver findings through GitHub and have no repository-artifact obligation. + +- Post-merge workflow approval: N/A (pre-merge review) + +## Status Values + +- Relationship: `ORIGINAL`, `RE_RAISE_OF:` +- Disposition: `FIXED`, `NO_ACTION`, `SUPERSEDED`, `FOLLOW_UP` +- Thread state: `OPEN`, `RESOLVED`, `NON_RESOLVABLE`, `SUPERSEDED`. `OPEN` applies prospectively + to audits created or updated for approved follow-up work; historical audits remain valid without + bulk migration. +- Severity: `Blocker`, `Major`, `Minor`, `Nit`, `Suggestion`; append `(inferred)` when derived + from free prose. +- Author class: `Copilot`, `Human`, `Unknown` +- Category: `link-integrity`, `formatting`, `metadata`, `testing`, `correctness`, + `documentation`, `maintainability`, `security`, `other` +- An outdated thread whose concern was fixed is `FIXED`/`RESOLVED`, even when GitHub marks the + original thread outdated after the push. For in-PR feedback, use `NO_ACTION`/`SUPERSEDED` only + for a duplicate, superseded, or no-change concern. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. + +## Findings + +Round 1 has two reviews. Copilot's review `5649072698` (https://github.com/torrust/torrust-tracker/pull/2652#pullrequestreview-5649072698), submitted 2026-10-26 08:15 UTC, has one inline finding, F1. The maintainer da2ce7's review `5650838526` (https://github.com/torrust/torrust-tracker/pull/2652#pullrequestreview-5650838526), submitted 2026-10-26 10:48 UTC with `CHANGES_REQUESTED`, has two inline findings, F2 and F3; its body is a summary with the verdict and its checks and holds no further independently actionable assertion. The review `5652143371` is my own reply on the F1 thread and has no body. The reviewers' own IDs (`F1`, `F2`, `F3`) do not collide, so the audit keeps them. + +| Finding ID | Review finding reference | Author class | Severity | Category | Relationship | Disposition | Thread state | +| ---------- | ------------------------ | ------------ | -------- | -------- | ------------ | ----------- | ------------ | +| F1 | review-finding:pr-2652-f1 | Copilot | Major | correctness | ORIGINAL | FIXED | RESOLVED | +| F2 | review-finding:pr-2652-f2 | Human | Major | correctness | RE_RAISE_OF:F1 | FIXED | RESOLVED | +| F3 | review-finding:pr-2652-f3 | Human | Minor | documentation | ORIGINAL | FIXED | RESOLVED | + +## Finding Details + +### F1 - Keep the environment restartable with a fixed bind port + +- PR number: 2652 +- Source review ID: 5649072698 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4375139248 +- Concern: `start_with_cancellation()` registers the health-check binding in the caller's `registar`, `stop()` kept that registration in the returned environment, and a second `start()` on a nonzero port got `RegistrationError::DuplicateBinding` and panicked. The reviewer asked for a restart-safe registration that keeps caller-owned services, and a fixed-port stop/start regression test. +- Solution: `stop()` now calls `Registar::deregister` with the binding the server registered, after joining both tasks and also when a task failed. `Registar::deregister` was added to `torrust-server-lib` 0.4.0 (torrust/torrust-server-lib#2, merged and published), because the 0.3.0 registry had no remove operation. It removes only that binding, so other owners' services stay. A first reply, at 2026-10-26 12:45 UTC (https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4377335685), said FOLLOW_UP and documented the limitation with a `should_panic` test; that was reversed after F2, and the new reply below corrects it. The `should_panic` test is replaced by a green fixed-port restart test. +- Current-tree verification: `cargo test -p torrust-tracker-axum-health-check-api-server` passed 14 lib tests and 8 integration tests on the pushed tree, including `it_should_serve_requests_after_being_stopped_and_started_again_on_a_fixed_port`, `it_should_remove_only_its_own_registration_from_the_registar_when_stopped` and `it_should_remove_its_registration_even_when_stopped_with_a_failed_task`. Removing the `deregister` call failed those three tests, and removing the registration only after the join result is checked failed the last one (evidence V7). +- Resolution reference: fix(axum-health-check-api-server): [#2450] deregister the health-check test environment on stop +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4379919227 + +### F2 - Remove the stale health-check registration before a fixed-port restart + +- PR number: 2652 +- Source review ID: 5650838526 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4376385862 +- Concern: A re-raise of F1 by the maintainer. The returned environment kept the caller's registry with the stale entry, so a fixed-port restart panicked; the restart test used port 0 and did not establish AC4. He asked for only the environment's own registration to be restart-safe, preserving caller-owned services, with a regression test on a dynamically selected nonzero port, and noted that copying the REST environment's fresh registry would discard caller services. +- Solution: The same change as F1. The fresh-registry approach was rejected for the reason he gave (spec decision D6), and AC4 now says a restart works "on an ephemeral or a fixed port" and AC8 covers the registration; both stay TODO for the maintainer to tick. +- Current-tree verification: the same test run as F1 (14 lib and 8 integration tests passed). `it_should_serve_requests_after_being_stopped_and_started_again_on_a_fixed_port` picks a free port by binding `127.0.0.1:0` and dropping the listener, restarts on it and gets HTTP 200. The registry test asserts that another owner's UDP binding is the only one left after `stop()`. +- Resolution reference: fix(axum-health-check-api-server): [#2450] deregister the health-check test environment on stop +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4379919713 + +### F3 - Append an evidence-backed correction to the completion review + +- PR number: 2652 +- Source review ID: 5650838526 +- Reviewer finding ID: N/A +- Source URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4376385876 +- Concern: The independent-review entry in `agent-review-reports.md` said all seven acceptance criteria were met, which F2 contradicts; it lacked the template's Inputs, Evidence, Verdict and Follow-up actions; and it said every finding was resolved in the commit that recorded it, although the test change was in an earlier commit. The reviewer asked for an appended correction that keeps the earlier entry. +- Solution: Appended a correction entry that withdraws the AC4 conclusion, states the real resolution references and carries the missing template fields; the earlier entry is unchanged. A new independent review of the final tree is a separate, later entry. +- Current-tree verification: `awk` from the 16:10 heading to the end of `agent-review-reports.md` lists `Invocation scope`, `Inputs`, `Findings`, `Verdict` and `Follow-up actions` in both new entries, and the second entry's Evidence heading carries extra wording. The 07:38 entry is byte-for-byte unchanged in the diff (additions only). `linter all` exited 0. +- Resolution reference: docs(issues): [#2450] correct the independent review entry after the fixed-port finding +- Follow-up PR URL: N/A +- Reply URL: https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4379920169 + +## Processing Log + +- 2026-10-26 08:15 UTC - Copilot review `5649072698` submitted with one inline finding (F1). +- 2026-10-26 10:48 UTC - Review `5650838526` submitted by da2ce7 with `CHANGES_REQUESTED` and two inline findings (F2 re-raise of F1, F3). +- 2026-10-26 12:45 UTC - First reply on the F1 thread (https://github.com/torrust/torrust-tracker/pull/2652#discussion_r4377335685), recorded FOLLOW_UP; superseded by the 16:41 reply after the maintainer chose to fix it here. +- 2026-10-26 16:19 UTC - torrust/torrust-server-lib#2 merged (GitHub `merged_at`), then `torrust-server-lib` 0.4.0 was published. +- 2026-10-26 16:41 UTC - Replied on the three threads (reply times 16:41:57, 16:41:59 and 16:42:01 UTC, GitHub); the F3 reply was edited at 16:42:11 UTC to say "all six template fields". +- 2026-10-26 16:42 UTC - Each resolve mutation returned `isResolved: true`, and a GraphQL fetch showed the three threads resolved. +- 2026-10-26 16:43 UTC - Wrote this audit and validated it with `validate-audit-record.py --pr-number 2652 --base torrust/develop`, which exited 0 with 3 rows (command output at 16:43 UTC). + +## Completion Rules + +- Re-derive the reply claim against the current tree before replying or resolving a thread. +- Reply on every resolvable thread before resolving it. +- For an outdated thread whose concern was fixed, record `Disposition=FIXED` and + `Thread state=RESOLVED`, even if GitHub marks the thread outdated after the push. For a + duplicate, superseded, or no-change in-PR thread, reply exactly + `Superseded by : .`, record `Disposition=NO_ACTION` and + `Thread state=SUPERSEDED`, then resolve it. A post-merge `NO_ACTION` requires maintainer + approval to decline the follow-up work. +- A consolidated PR conversation response may cover multiple review rounds only when it names + every review ID and every finding ID with its disposition and resolution reference. Record its + durable URL in each related row. +- Cite a fix by its unique Conventional Commit subject or durable reply URL, never by a branch SHA + that can change after a rebase. +- Refresh review threads using GraphQL and confirm that no unresolved actionable thread remains.