Skip to content

server: report WebRTC cleanup failures - #925

Open
yisding wants to merge 2 commits into
agent/ws25-webrtc-route-task-scopefrom
agent/ws25-webrtc-cleanup-finalizers
Open

server: report WebRTC cleanup failures#925
yisding wants to merge 2 commits into
agent/ws25-webrtc-route-task-scopefrom
agent/ws25-webrtc-cleanup-finalizers

Conversation

@yisding

@yisding yisding commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Problem

WebRTC route shutdown spawned forced per-session finalizers with raw asyncio.create_task() and discarded every gather(return_exceptions=True) result. Expected cancellation of peer-close waiters and genuine forced-finalizer failures were indistinguishable, so teardown defects could disappear silently.

Changes

  • run forced cleanup finalizers in a separate named RuntimeTaskScope
  • preserve the hard-timeout behavior and the existing concurrent cleanup fan-out
  • pair gathered results with task handles and names
  • suppress only CancelledError from cleanup waiters explicitly cancelled by shutdown
  • log unexpected exceptions with the exact task identity
  • add regression coverage for both expected cancellation and a failing forced finalizer
  • reduce the reviewed raw-task-spawn inventory from 34 to 33

Why / impact

Normal teardown cancellation stays quiet, while a real cleanup failure is now observable as easycat-webrtc-force-cleanup-<key>. The result policy no longer hides broken Session/capacity finalization.

Root cause

The original shutdown code used return_exceptions=True solely to keep one cleanup failure from short-circuiting siblings, but never inspected the returned exception values.

Checks

  • full capacity-gate/source-inventory slice — 72 passed
  • focused result-policy regression — 2 passed
  • Ruff on changed Python files — passed
  • mypy on webrtc_routes.py — passed
  • pre-commit hooks — passed

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 12f5e0de-db99-4d8e-a061-7668fce8cfba

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@yisding
yisding marked this pull request as ready for review August 7, 2026 02:44

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 616c69a0a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +593 to +594
completed = await _await_with_hard_timeout(cleanup, timeout_s=timeout_s)
results = cleanup.result() if completed else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Report forced-finalizer failures that settle after the timeout

When a forced finalizer resists or defers cancellation past timeout_s and later raises, _await_with_hard_timeout returns False, this assigns None, and _report_cleanup_results is permanently skipped. The task remains scope-owned, but RuntimeTaskScope._on_done logs failures only at DEBUG, so the genuine cleanup failure this change intends to expose is still absent from normal production logs; attach the error-reporting policy to late task completion as well.

Useful? React with 👍 / 👎.

@yisding
yisding force-pushed the agent/ws25-webrtc-route-task-scope branch from cd7a696 to 6419d39 Compare August 7, 2026 03:05
@yisding
yisding force-pushed the agent/ws25-webrtc-cleanup-finalizers branch from 616c69a to fe99c25 Compare August 7, 2026 03:07
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.

1 participant