Skip to content

fix(libsy): client disconnect logging - #555

Open
messiaen wants to merge 1 commit into
mainfrom
grclark/switch-1218
Open

fix(libsy): client disconnect logging#555
messiaen wants to merge 1 commit into
mainfrom
grclark/switch-1218

Conversation

@messiaen

@messiaen messiaen commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What

Emit client disconnect metric and ensure processing stops on client disconnect.

This was only reproducible on macOS

Why

The motivation — what problem does this solve, or which ticket does it close?

Closes SWITCH-1218

How tested

  • uv run ruff check . clean
  • uv run mypy switchyard clean
  • uv run pytest tests/ green
  • Manual smoke (describe what was run)

Checklist

  • One class per file; filename = snake_case of the primary class.
  • New public symbols exported from switchyard/__init__.py.__all__ if intended for downstream use.
  • Unit tests added for new components / bug fixes.
  • README / --help updated if customer-facing surface changed.
  • Commits signed off (Signed-off-by: Your Name <email>) per the DCO.

Notes for reviewers

Anything reviewers should pay extra attention to — risky paths, follow-up tickets, intentional trade-offs.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of client disconnections during in-progress requests.
    • Cancelled requests are now logged with a clear disconnect status and warning.
    • Prevented completed requests from being logged more than once.
  • Monitoring

    • Added client-disconnect outcomes to request metrics for improved visibility into interrupted requests.

Signed-off-by: Greg Clark <grclark@nvidia.com>
@messiaen
messiaen requested a review from a team as a code owner August 26, 2026 18:54
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f43614cd-7658-48da-89af-f015dc1af31e

📥 Commits

Reviewing files that changed from the base of the PR and between 21f6951 and 635ecb2.

📒 Files selected for processing (2)
  • crates/switchyard-server/src/lib.rs
  • crates/switchyard-server/src/metrics.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The server now detects buffered handler cancellation after client disconnects. It emits a terminal warning event with status 499, records a dedicated Prometheus outcome, and prevents duplicate events after normal response logging. Tests cover these paths.

Changes

Client disconnect accounting

Layer / File(s) Summary
Disconnect metric outcome
crates/switchyard-server/src/metrics.rs, crates/switchyard-server/src/lib.rs
The metrics module defines and records the client_disconnected outcome. Request logging uses status 499 for client disconnects.
Request cancellation logging
crates/switchyard-server/src/lib.rs
RequestLogGuard emits a warning cancellation event when a handler future is dropped before a response. Normal response logging disarms the guard. Tests cover cancellation and duplicate-event suppression.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 635ec

No actionable merge-blocking risk remains based on the supplied evidence; the PR is merge-ready after normal checks and review.

Poem

A rabbit guards the request stream,

Drops leave footprints in the log,
Five-four-nine marks the disconnect,
Metrics count the vanished hop,
One bright event, then no more noise.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies client disconnect logging, which is a central part of the changes. It is concise and specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

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.

2 participants