Skip to content

fix(udp-server): [#2345] keep the request kind in the UDP error-response event - #2354

Merged
josecelano merged 6 commits into
torrust:developfrom
josecelano:2345-keep-request-kind-in-udp-error-response-event
Sep 28, 2026
Merged

josecelano merged 6 commits into
torrust:developfrom
josecelano:2345-keep-request-kind-in-udp-error-response-event

Conversation

@josecelano

@josecelano josecelano commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Closes #2345

Summary

When the UDP tracker answered a parsed request with an error response, Processor::send_response hard-coded opt_req_kind: None in the published Event::UdpResponseSent, dropping the request kind that handlers::handle_packet had already resolved. This contradicted the documented UdpResponseKind::Error contract. The fix passes the value through: UdpResponseKind::Error { opt_req_kind }.

No current metric changes: the statistics consumer ignores the request kind for error responses.

Changes

  • packages/udp-server/src/server/processor.rs: the one-line fix, plus two unit tests at the processor's event-publication seam:
    • it_should_keep_the_request_kind_in_the_error_response_event_when_a_parsed_request_fails: a scrape with ConnectionId::new(0) under strict validation expects Error { opt_req_kind: Some(UdpRequestKind::Scrape) }. Red before the fix, green after.
    • it_should_publish_an_error_response_event_without_a_request_kind_when_the_payload_is_unparsable: a 3-byte payload keeps Error { opt_req_kind: None }.
    • Both read events until UdpResponseSent under one absolute deadline (tokio::time::timeout_at).
  • docs/issues/open/2345-keep-request-kind-in-udp-error-response-event/: spec progress, red/green output and post-fix rechecks in manual-verification-evidence.md, and the Task Reviewer reports in agent-review-reports.md.

Commits

  1. docs(issues): start implementation of #2345
  2. test(udp-server): [#2345] cover the request kind in the UDP error-response event (red on its own, by design, to record the failing regression test)
  3. fix(udp-server): [#2345] keep the request kind in the UDP error-response event
  4. test(udp-server): [#2345] use expect for the client address in the new tests
  5. docs(issues): record the #2345 task review and completion review
  6. docs(issues): link #2345 spec to implementation PR #2354

Validation

  • cargo test -p torrust-tracker-udp-server --lib server::processor::tests: parsed-request test failed before the fix with left: Error { opt_req_kind: None }, passes after.
  • cargo test -p torrust-tracker-udp-server: 173 library, 11 integration, 1 doc test passed.
  • Post-fix recheck: the strict-mode loopback integration test should_ban_the_client_ip_if_it_sends_more_than_10_requests_with_a_cookie_value_not_normal still produces eleven error responses and passes.
  • Pre-commit gate for every commit; pre-push hook (nightly checks, nightly docs, full stable test suite) passed.
  • Independent Task Reviewer: first review failed on a missing completion-review record; re-review passed after remediation.

The pre-fix reproduction used a temporary test that is not included; the maintained regression test replaces it.

Related to #2283 (processor test coverage work paused on this fix).

Copilot AI lite review requested due to automatic review settings September 27, 2026 18:10
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Sep 27, 2026
Record the implementation PR and the passed pre-push verification.
@josecelano josecelano self-assigned this Sep 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: None

What changed in this PR

Fixes #2345 by ensuring UDP error-response events preserve the resolved request kind (when available), aligning UdpResponseKind::Error with its documented contract.

Changes:

  • Pass through opt_req_kind in Processor::send_response for Response::Error.
  • Add processor-level unit tests to assert request-kind preservation for parsed-but-invalid requests and None for unparsable payloads.
  • Update issue-spec documentation with red/green evidence and reviewer reports.
File Description
packages/​udp-server/​src/​server/​processor.rs Fixes error event kind propagation and adds regression coverage at the event-publication seam.
docs/​issues/​open/​2345-keep-request-kind-in-udp-error-response-event/​manual-verification-evidence.md Records before/after regression outputs and post-fix rechecks.
docs/​issues/​open/​2345-keep-request-kind-in-udp-error-response-event/​agent-review-reports.md Adds independent review entries documenting verification and follow-ups.
docs/​issues/​open/​2345-keep-request-kind-in-udp-error-response-event/​ISSUE.md Updates spec status, checklists, progress log, and acceptance-criteria evidence.

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

Record the merged spec-only PR torrust#2346, switch the spec to the implementation branch, and mark it in progress.
…ror-response event

Add a processor test for a parsed scrape with an invalid connection ID, which is red until the fix: the published UdpResponseSent event reports Error { opt_req_kind: None } instead of Some(Scrape). Add a complementary test that keeps None for an unparsable payload. Record the red output and the prose-first review.
…r-response event

Processor::send_response hard-coded opt_req_kind to None for every error response, dropping the request kind that handle_packet had already resolved for parsed requests. Pass it through, as the UdpResponseKind::Error contract documents. The parsed-request regression test is now green, and the post-fix rechecks are recorded.
… the new tests

Match the module's convention of expect messages over bare unwrap, as the Task Reviewer suggested.
Add the Task Reviewer reports (failed on the missing completion review, then passed after remediation), record the completion review, the M3 counting command and toolchain, and tick the verified checkpoints and acceptance criteria.
Record the implementation PR and the passed pre-push verification.
@josecelano
josecelano force-pushed the 2345-keep-request-kind-in-udp-error-response-event branch from acf57fb to 7dc3fd1 Compare September 27, 2026 19:56
@josecelano

Copy link
Copy Markdown
Member Author

ACK 7dc3fd1

@josecelano
josecelano merged commit e1b0fa7 into torrust:develop Sep 28, 2026
20 checks passed
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Sep 28, 2026
…closed

PR torrust#2354 merged and GitHub closed torrust#2345. Move the folder-style specification and its evidence into the closed archive, update lifecycle metadata, and retain historical Markdown heading styles.
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Sep 28, 2026
…closed

PR torrust#2354 merged and GitHub closed torrust#2345. Move the folder-style specification and its evidence into the closed archive, update lifecycle metadata, and retain historical Markdown heading styles.
josecelano added a commit that referenced this pull request Sep 28, 2026
…ssues/closed

87ae27a docs(issues): link the #2345 archival review report (Jose Celano)
2108743 chore(issues): archive closed issue #2345 spec to docs/issues/closed (Jose Celano)

Pull request description:

  Archives the completed specification for #2345 from `docs/issues/open/` to `docs/issues/closed/`.

  - Verified #2345 is `CLOSED` on GitHub after PR #2354 merged.
  - Preserved the folder and its verification and review artifacts with Git renames.
  - Updated the primary spec to `status: done`, repaired issue-local frontmatter paths, recorded the archival action, and completed the closure checkpoints.
  - Retained the one historical #2346 review-audit reference to the former open path.

  Validation: `linter all`, the pre-commit gate, and the pre-push suite (nightly checks, nightly documentation build, full stable test suite) passed.

ACKs for top commit:
  josecelano:
    ACK 87ae27a

Tree-SHA512: 4aaca53ea54b7f4f6e637df9933ec362e238719fffc7edbb74317238efe68acd1cb12c7704387c1449230f2bf2b40398938c27425cefb0d5b47e3a88c1ee8392
josecelano added a commit that referenced this pull request Sep 30, 2026
…verage

b0c1fdc test(udp-server): bound scrape event assertions (Jose Celano)
d5cb1c2 docs(issues): correct udp dispatcher coverage figure (Jose Celano)
f7e14be docs(issues): complete udp server coverage review (Jose Celano)
3f364a3 docs(issues): record final udp server coverage (Jose Celano)
62dde21 docs(issues): reconcile udp server coverage records (Jose Celano)
451389d docs(issues): record udp server mutation evidence (Jose Celano)
f991963 docs(issues): close udp server file review (Jose Celano)
d031b21 test(udp-server): cover validation policy mapping (Jose Celano)
986a093 docs(issues): record testing module review (Jose Celano)
1f54167 test(udp-server): clarify response sent metric tests (Jose Celano)
0623fe5 test(udp-server): deduplicate aborted request metric test (Jose Celano)
4816eb8 test(udp-server): deduplicate banned request metric test (Jose Celano)
bccbafa docs(issues): record discarded request metric review (Jose Celano)
f37f730 test(udp-server): clarify accepted request metric tests (Jose Celano)
b462277 test(udp-server): clarify received request metric test (Jose Celano)
d2af884 test(udp-server): clarify statistics error metric test (Jose Celano)
9902512 docs(issues): record statistics event dispatcher test review (Jose Celano)
84b45c1 docs(issues): record statistics event listener test review (Jose Celano)
0b74e6e docs(issues): record statistics event module test review (Jose Celano)
deb522e test(udp-server): clarify statistics service aggregation (Jose Celano)
6313ff7 test(udp-server): cover statistics repository snapshots (Jose Celano)
0a8d986 docs(issues): record udp server statistics metrics test review (Jose Celano)
4456808 docs(issues): record udp server statistics module test review (Jose Celano)
677a029 docs(issues): record udp server banning listener test review (Jose Celano)
9b2b2d4 docs(issues): record udp server banning handler test review (Jose Celano)
2a28d3d docs(issues): record udp server banning event module wiring review (Jose Celano)
e450661 docs(issues): reconcile udp server per-file coverage results (Jose Celano)
7afd3f6 docs(issues): record udp server banning module wiring review (Jose Celano)
6e26912 docs(issues): record udp server states test review (Jose Celano)
897ddf2 docs(issues): plan udp server states test review (Jose Celano)
78df17d docs(issues): record udp request buffer test review (Jose Celano)
4328717 test(udp-server): cover processor response events (Jose Celano)
61c43cf docs(issues): plan processor tests and pause on bug (Jose Celano)
9936f4d docs(issues): record udp server receiver test review (Jose Celano)
b751c69 test(udp-server): clarify launcher admission scenarios (Jose Celano)
2cb3ef6 docs(issues): plan launcher test readability (Jose Celano)
043895b test(udp-server): cover launcher request admission (Jose Celano)
c01bb10 docs(issues): record udp server spawner test review (Jose Celano)
852dfd8 test(udp-server): cover bound socket ipv6 and bind errors (Jose Celano)
e5256e1 test(udp-server): remove tokio-owned barrier test (Jose Celano)
a23e832 fix(udp-server): correct server start/stop error message (Jose Celano)
3cea878 test(udp-server): cover error handler classification (Jose Celano)
0f6af0e docs(issues): record scrape refactor coverage (Jose Celano)
5d60a9c test(udp-server): cover disabled scrape validation (Jose Celano)
940630c test(udp-server): clarify scrape handler scenarios (Jose Celano)
4499dd5 docs(issues): plan scrape test improvements (Jose Celano)
c3e447d test(udp-server): cover scrape error routing (Jose Celano)
5927378 test(udp-server): cover announce error routing (Jose Celano)
c309be7 test(udp-server): simplify connect handler tests (Jose Celano)
3e23962 test(udp-server): cover handler dispatch (Jose Celano)
4d68cdd test(udp-server): cover event error classification (Jose Celano)
a165ad3 docs(issues): record udp server container test review (Jose Celano)
b81afef docs(issues): record udp server lib test review (Jose Celano)
4a76e42 docs(issues): define per-file test workflow for udp server (Jose Celano)
598ac2b docs(issues): track udp server refactor plans (Jose Celano)
5f80f4a test(udp-server): cover error adapters (Jose Celano)

Pull request description:

  Closes #2283

  Part of EPIC #1347.

  ## Summary

  Systematic unit-test coverage work for the `torrust-tracker-udp-server` package. Every one of the 37 source files was processed through its own file test plan (review/refactor existing tests, add focused unit tests where a package-owned contract exists, consider real UDP integration only where it is clearer), with maintainer approval of each plan and completed file.

  - 23 test commits under `packages/udp-server/src/`: new focused unit contracts (error adapters, event classification, handler dispatch, announce/scrape/error routing, bound socket, launcher admission, processor response events, repository snapshots, validation-policy mapping) plus refactors that clarify or deduplicate existing tests.
  - One production change: a typo fix in the server start/stop error message ("sever" → "server").
  - One Tokio-owned barrier test removed from `server/mod.rs` (it tested Tokio, not the package).
  - No new real UDP integration tests: per-file review found no case where loopback was clearer than the direct unit contract.
  - Behaviour intentionally left uncovered is documented per file with its owner, mainly lifecycle/shutdown policy owned by #1488.

  ## Files and Packages Touched

  - `packages/udp-server/src/` — 20 Rust files (tests, plus the one-line error-message fix).
  - `docs/issues/open/2283-1347-increase-udp-server-package-coverage/` — issue spec, 37 file test plans, coverage, mutation, and manual-verification evidence.
  - `docs/issues/open/1347-overhaul-packages-testing/EPIC.md` — final #2283 coverage figures.

  ## Unit-Test Coverage Changes

  Unit-only (`cargo llvm-cov -p torrust-tracker-udp-server --all-features --lib`) line coverage, filtered to `packages/udp-server/src/`. Baseline: `cfb93157` (before any #2283 change). Final: implementation head, 2026-09-30 (`cargo-llvm-cov 0.6.16`, Rust 1.98.1).

  ### Package Totals

  | Metric | Before | After |
  | --- | ---: | ---: |
  | Lines | 5,471 / 5,688 (96.18%) | 6,314 / 6,431 (98.18%) |
  | Regions | 7,183 / 7,534 (95.34%) | 8,267 / 8,519 (97.04%) |
  | Functions | 562 / 592 (94.93%) | 680 / 696 (97.70%) |
  | Uncovered lines | 217 | 117 |

  Aggregate: 97.86% → 98.58% lines. Integration-only: 76.11% → 75.90% lines (real UDP loopback tests unchanged; the denominator grew).

  ### Per-File Line Coverage

  Denominators include in-file `#[cfg(test)]` code, so adding or removing tests changes them. Files marked † also changed through already-merged `develop` PRs (#2351 for #2342, #2354 for #2345), so their deltas are not solely from this issue.

  | File | Before | After | Δ |
  | --- | ---: | ---: | ---: |
  | `error.rs` | 52 / 62 (83.87%) | 92 / 92 (100.00%) | +16.13 |
  | `server/processor.rs` † | 72 / 85 (84.71%) | 180 / 180 (100.00%) | +15.29 |
  | `handlers/error.rs` | 155 / 178 (87.08%) | 218 / 218 (100.00%) | +12.92 |
  | `handlers/mod.rs` | 184 / 214 (85.98%) | 241 / 250 (96.40%) | +10.42 |
  | `server/bound_socket.rs` | 55 / 65 (84.62%) | 77 / 86 (89.53%) | +4.91 |
  | `event.rs` | 125 / 131 (95.42%) | 190 / 190 (100.00%) | +4.58 |
  | `server/launcher.rs` † | 278 / 290 (95.86%) | 463 / 467 (99.14%) | +3.28 |
  | `handlers/announce.rs` | 781 / 800 (97.63%) | 903 / 905 (99.78%) | +2.15 |
  | `testing/environment.rs` | 168 / 184 (91.30%) | 185 / 200 (92.50%) | +1.20 |
  | `statistics/repository.rs` | 547 / 549 (99.64%) | 523 / 523 (100.00%) | +0.36 |
  | `handlers/scrape.rs` † | 319 / 321 (99.38%) | 506 / 508 (99.61%) | +0.23 |
  | `handlers/connect.rs` | 251 / 251 (100.00%) | 212 / 212 (100.00%) | 0.00 (duplicate test code removed) |
  | `server/states.rs` † | 72 / 77 (93.51%) | 84 / 90 (93.33%) | −0.18 |
  | `server/mod.rs` † | 176 / 177 (99.44%) | 250 / 252 (99.21%) | −0.23 |
  | `statistics/event/handler/request_aborted.rs` | 56 / 57 (98.25%) | 33 / 34 (97.06%) | −1.19 (duplicate test removed; same single uncovered line) |
  | `statistics/event/handler/request_banned.rs` | 56 / 57 (98.25%) | 33 / 34 (97.06%) | −1.19 (duplicate test removed; same single uncovered line) |
  | `banning/event/handler.rs` | 81 / 82 (98.78%) | 81 / 82 (98.78%) | 0.00 |
  | `banning/event/listener.rs` | 147 / 150 (98.00%) | 147 / 150 (98.00%) | 0.00 |
  | `container.rs` | 59 / 59 (100.00%) | 59 / 59 (100.00%) | 0.00 |
  | `lib.rs` | 28 / 29 (96.55%) | 28 / 29 (96.55%) | 0.00 |
  | `server/receiver.rs` | 55 / 56 (98.21%) | 55 / 56 (98.21%) | 0.00 |
  | `server/request_buffer.rs` | 162 / 174 (93.10%) | 162 / 174 (93.10%) | 0.00 |
  | `server/spawner.rs` | 17 / 17 (100.00%) | 17 / 17 (100.00%) | 0.00 |
  | `statistics/event/handler/error.rs` | 131 / 151 (86.75%) | 131 / 151 (86.75%) | 0.00 |
  | `statistics/event/handler/mod.rs` | 19 / 21 (90.48%) | 19 / 21 (90.48%) | 0.00 |
  | `statistics/event/handler/request_accepted.rs` | 162 / 163 (99.39%) | 162 / 163 (99.39%) | 0.00 |
  | `statistics/event/handler/request_discarded.rs` | 33 / 34 (97.06%) | 33 / 34 (97.06%) | 0.00 |
  | `statistics/event/handler/request_received.rs` | 33 / 34 (97.06%) | 33 / 34 (97.06%) | 0.00 |
  | `statistics/event/handler/response_sent.rs` | 122 / 130 (93.85%) | 122 / 130 (93.85%) | 0.00 |
  | `statistics/event/listener.rs` | 164 / 172 (95.35%) | 164 / 172 (95.35%) | 0.00 |
  | `statistics/metrics.rs` | 827 / 834 (99.16%) | 827 / 834 (99.16%) | 0.00 |
  | `statistics/mod.rs` | 52 / 52 (100.00%) | 52 / 52 (100.00%) | 0.00 |
  | `statistics/services.rs` | 32 / 32 (100.00%) | 32 / 32 (100.00%) | 0.00 |

  Declaration-only modules with no executable lines: `banning/mod.rs`, `banning/event/mod.rs`, `statistics/event/mod.rs`, `testing/mod.rs`.

  Remaining uncovered lines are mostly lifecycle, shutdown, or task-management paths owned by #1488. The rest need OS-level socket fault injection, are logging-only failure branches, or are owned by collaborator crates. Per-file reasons are in `coverage-evidence.md`.

  ## Validation

  - Pre-commit gate passed (all 9 steps, including `linter all`, `cargo machete`, `cargo deny check bans`, and doc tests).
  - Pre-push gate passed on the rebased head (nightly format, nightly check, nightly docs, full stable test suite).
  - Package tests: 199 unit tests, 11 integration tests, 1 doc test passed.
  - Mutation sample (`cargo-mutants 27.0.0`, bounded to `handlers::handle_packet`): the viable mutation was caught; no survivors. See `mutation-evidence.md`.
  - Manual verification: built tracker run locally on `127.0.0.1:16969` from an isolated, git-ignored config; the unified `tracker_client` performed a real UDP announce and scrape successfully. See `manual-verification-evidence.md`. No local-only patches were used.

  After merge, the issue spec will be moved to `docs/issues/closed/` in a follow-up archive PR.

ACKs for top commit:
  josecelano:
    ACK b0c1fdc

Tree-SHA512: 16171149e0e49ff72bce62240e588ce05b13ed7ddb3a0ef80c31314510338f4167d50c615a519b0097a60048837219671d2c1f29b057ad0b9b9293ad6ac7737f

This branch was previously deployed

1 inactive deployment
coverage — 7dc3fd13 Deployed Sep 27, 2026 by josecelano via Generate Coverage Report #2338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the request kind in the UDP error-response event

2 participants