Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
4830852
refactor(axum-health-check-api-server): [#2450] migrate the health-ch…
josecelano Oct 26, 2026
a381a86
docs(issues): [#2450] record T0 baseline, T1 mutation proofs and M1/M…
josecelano Oct 26, 2026
6cf6534
docs(shutdown-process): [#2450] record the health-check test environm…
josecelano Oct 26, 2026
8a09fe5
docs(issues): [#2450] record the prose-first comparison and the post-…
josecelano Oct 26, 2026
aa28b3f
test(axum-health-check-api-server): [#2450] assert the stop result in…
josecelano Oct 26, 2026
f0656bc
docs(issues): [#2450] record the independent review, resolve its find…
josecelano Oct 26, 2026
e810655
test(axum-health-check-api-server): [#2450] document and pin the fixe…
josecelano Oct 26, 2026
be0acb8
docs(issues): [#2450] record the fixed-port restart limitation and it…
josecelano Oct 26, 2026
70b2141
docs(issues): [#2450] correct the independent review entry after the …
josecelano Oct 26, 2026
c554b24
chore(deps): [#2450] bump torrust-server-lib to 0.4.0
josecelano Oct 26, 2026
cb8c34f
fix(axum-health-check-api-server): [#2450] deregister the health-chec…
josecelano Oct 26, 2026
0042a18
docs(issues): [#2450] record the registry deregistration and update t…
josecelano Oct 26, 2026
6c21b1d
docs(issues): [#2450] record the prose-first comparison of the new te…
josecelano Oct 26, 2026
8ed7da2
docs(issues): [#2450] record the independent review of the final tree
josecelano Oct 26, 2026
6c0d9cd
docs(pr-reviews): [#2450] record the review audit of PR 2652
josecelano Oct 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 6 additions & 6 deletions docs/features/shutdown-process/task-inventory.md
Original file line number Diff line number Diff line change
@@ -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 16:23"
semantic-links:
related-artifacts:
- docs/features/shutdown-process/README.md
Expand Down Expand Up @@ -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, 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.
Expand Down Expand Up @@ -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
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
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.
Comment thread
josecelano marked this conversation as resolved.
Resolved
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`.

### 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.

### 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
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, 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

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()` 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

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. 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

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`.
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 the receipt-returning `register` (a breaking
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.

## Evidence

- `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`
Loading
Loading