Skip to content

fix(diagnostics): wait for server close in WebSocket test, cover quiet shutdown, evict LRU - #1838

Merged
devswha merged 1 commit into
mainfrom
fix/connection-diagnostics-followups
Oct 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/connection-diagnostics-followups

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Closes #1414

What it does

Follow-ups from the review of #1356 (connection diagnostics). Nothing changes in what users see; the diagnostics log gets more accurate and the tests now check what they claim to.

  1. server/ws-diagnostics.test.ts waits for Bun's server-side WebSocket close handler before asserting, instead of the client's close event (which sometimes arrives first). The polling loop that followed is gone: the record is written before that handler returns.
  2. New server/core/socket.test.ts: an abnormal close while running writes one websocket.failed record, and a close while the server is stopping writes none. Removing !stopped() && in server/core/socket.ts now fails it.
  3. docs/development.md says websocket.failed covers every close other than 1000/1001, including ones the server starts (device revoke 1008, output stall 4008, a remote PC disconnecting 1012); close_code tells them apart.
  4. ConnectionDiagnostics re-inserts a key on each failure, so the 128-key bound evicts the least recently failed key, not the oldest inserted. New test covers it.
  5. docs/development.md notes that a silent episode (every failure suppressed) keeps its episode_id and start into the next visible failure, so since_first_failure_ms there can include a healthy gap.

Verification

  • bun run check fast passes.
  • The three touched test files: 14 pass, 0 fail, five runs in a row.
  • Mutation checks: removing the LRU re-insert fails the new LRU test; removing !stopped() && fails the new socket test.
  • Reviewed by the omo code reviewer (approve; its two LOW notes, the dead polling loop and the 1012 wording, are fixed here) and Codex (no findings).

…t shutdown, evict LRU

- ws-diagnostics.test.ts waits for Bun's server-side close handler before asserting.
- socket.test.ts covers an abnormal close while running and quiet shutdown.
- ConnectionDiagnostics re-inserts a key on each failure, so eviction drops the
  least recently used key instead of the oldest inserted.
- docs/development.md says websocket.failed also covers server-initiated closes
  (close_code tells them apart) and that a silent episode's ID and start carry into
  the next visible failure.

Closes #1414
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between e68716c and 7777f71.

Files selected for processing: 5
  • docs/development.md
  • server/connection-diagnostics.test.ts
  • server/connection-diagnostics.ts
  • server/core/socket.test.ts
  • server/ws-diagnostics.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Connection diagnostics now retain recently updated peer records when the 128-entry limit is reached, rather than evicting them ahead of less recently used records.
    • WebSocket close diagnostics now distinguish normal and server-stopping closes from failures, while including the close code for failures. Recovery is reported only for visible failure episodes.
    • Failure episode timing can include a healthy gap when all failures in that episode were suppressed.
  • Documentation
    • Clarified how connection failure episodes and WebSocket close codes appear in diagnostics.

The change updates connection-diagnostic peer eviction to use least-recently-used ordering. It adds tests for socket close logging and waits for server-side WebSocket close handling before checking diagnostic records. Documentation clarifies failure episode timing and close-code labeling.

Changes: Connection diagnostics

Layer / File(s) Summary
Peer failure retention
server/connection-diagnostics.ts, server/connection-diagnostics.test.ts
Existing failure keys move to the newest map position. Tests verify that eviction removes the least recently used peer.
WebSocket close diagnostics
docs/development.md, server/core/socket.test.ts, server/ws-diagnostics.test.ts
Documentation describes failure episode timing and close-code labeling. Tests cover close warnings and wait for server-side close handling before checking diagnostic records.

Priority: Low

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: christi4nity

Merge Risk: Minimal · up to 7777f

No actionable issue remains identified in these changes; the PR is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: improved WebSocket test synchronization, shutdown coverage, and LRU eviction.
Description check Passed The description explains the changes, references the issue, and provides detailed validation results. It uses alternate headings instead of the template headings and does not explicitly state contract…
Linked Issues check Passed The pull request meets the coding requirements in open issue #1414. server/ws-diagnostics.test.ts waits for the server-side close handler before assertions. server/core/socket.test.ts covers abn…
Out of Scope Changes check Passed The changes stay within issue #1414. The implementation changes, tests, and documentation directly support the requested WebSocket diagnostics timing, shutdown behavior, event labeling, LRU eviction, …
Full details: Description check

Explanation

The description explains the changes, references the issue, and provides detailed validation results. It uses alternate headings instead of the template headings and does not explicitly state contract-test coverage, but the required change and validation information is substantially present.

Full details: Linked Issues check

Explanation

The pull request meets the coding requirements in open issue #1414. server/ws-diagnostics.test.ts waits for the server-side close handler before assertions. server/core/socket.test.ts covers abnormal close logging during runtime and quiet shutdown. docs/development.md documents server-initiated websocket.failed closes and silent episode timing. ConnectionDiagnostics.failed re-inserts existing keys, and its test verifies least-recently-used eviction.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1414. The implementation changes, tests, and documentation directly support the requested WebSocket diagnostics timing, shutdown behavior, event labeling, LRU eviction, and silent-episode semantics. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED.

Lane Verdict Confidence
Manual QA (4 rows, artifacts kept) PASS -
Gate review (another model; programming and remove-ai-slops applied directly) APPROVE HIGH

Manual QA:

  • The three touched test files pass 5 runs in a row, 14/14 each time, and the typecheck passes.
  • Dropping !stopped() && in server/core/socket.ts fails the new socket test.
  • The LRU change deletes and re-sets an existing key, so the 128-key bound evicts the least recently failed key.
  • git merge-tree is clean against main and with docs(storage): define compatibility rules for structural format changes #1824, which also edits docs/development.md.

Gate:

  • The wait for the server's close is event-driven. It is installed before any connection starts, bounded at 2 s, and doesn't poll.
  • Mutants:
    • Dropping the LRU re-insert gives 129 records instead of 130.
    • Dropping the shutdown guard gives 2 records instead of 1.
  • Close codes: real server-initiated closes were probed for 1000, 1001, 1008, 4008 and 1012. A 4008 close while the server is stopping writes no record, which matches the docs.
  • Silent episodes: a silent episode keeps its id and start into the next visible failure. A synthetic-clock probe confirmed this.

All required checks are green, and no review thread is open.

@devswha
devswha merged commit 5e67b0b into main Oct 24, 2026
17 checks passed
@devswha
devswha deleted the fix/connection-diagnostics-followups branch October 24, 2026 11:43
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.

Connection diagnostics: test and labeling follow-ups from #1356

1 participant