Skip to content

[Fix] Websocket and Log Viewer - #107

Merged
antonio-amjr merged 5 commits into
project-chip:v2.15.1-cli-developfrom
antonio-amjr:fix/websocket_and_log_viewer
Aug 14, 2026
Merged

[Fix] Websocket and Log Viewer#107
antonio-amjr merged 5 commits into
project-chip:v2.15.1-cli-developfrom
antonio-amjr:fix/websocket_and_log_viewer

Conversation

@antonio-amjr

@antonio-amjr antonio-amjr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fix: project-chip/certification-tool#1072
Depends on Backends: project-chip/certification-tool-backend#347

Description

Companion fix to the backend PR for #1072. Two independent problems remained on the CLI side even after the backend stopped stalling and truncating logs:

  1. The CLI could silently disconnect from the backend's WebSocket the instant it saw the "run finished" signal, before a final trailing batch of log messages had arrived — losing the last few lines of a run.
  2. The browser-based real-time log viewer (--log-streaming) would freeze during large runs: it received log lines faster than it could render them, so its internal queue grew into a multi-minute backlog. The view looked "stuck," even though the connection was healthy — it was just always showing stale content instead of what was happening right now. Since this viewer is the only place users can see SDK trace output live (used to decide how to answer test prompts), a stale view is effectively as broken as no view.

Changes

  • Don't disconnect immediately on run-completion. The WebSocket loop now keeps draining for a short grace period after seeing the terminal state, instead of closing the instant that message arrives, so any trailing log batch the backend
    is still sending isn't dropped.
  • Process log batches without blocking the connection. Large incoming batches are now processed with periodic yields back to the event loop, instead of one big synchronous loop, so the connection stays responsive even under a heavy burst.
  • Cap the live viewer's pending queue. If incoming log lines arrive faster than the browser can render them, the oldest unrendered entries are now dropped so the view stays within a few seconds of real time — instead of accumulating an
    ever-growing backlog that only "catches up" long after the test has already finished. This does not affect the saved log file or the full downloadable log, only what's shown live. (An earlier version of this fix hid raw SDK trace content from
    the live view entirely to solve the freeze — that broke the actual reason the live viewer exists, since it's the only place to read trace context while answering a test prompt. This version keeps everything live and fixes the actual backlog
    instead.)
  • "Download Logs" now points at the backend's own log endpoint instead of the CLI's own process. The previous implementation served the file from the CLI's local, short-lived HTTP server — which shuts down the moment the run finishes, i.e. right when someone would naturally want to click "download." Rather than trying to keep that ephemeral server alive or fall back to an incomplete in-memory reconstruction, the button now links directly to the backend's existing, durable
    log-download endpoint (the same one the web UI's download has always used successfully). This is the standard fix for this kind of problem — never serve a "download" from a transient process; point at wherever the artifact durably lives.

Verified

Watched the live viewer through two full TC-ACE-2.4 runs: content stays current throughout (brief freezes), and the CLI's saved log matches the backend's copy.

Also, the websocket closure was postponed for when inactive and now yields to the event loop every 200 records intead of whole batch
@antonio-amjr antonio-amjr self-assigned this Aug 11, 2026
@antonio-amjr
antonio-amjr requested review from oxesoft and rquidute and removed request for oxesoft August 11, 2026 16:49
@mergify

mergify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@KishokG KishokG moved this to In Progress in CSG issue tracking Aug 13, 2026
Comment thread th_cli/test_run/log_viewer.html
@rquidute

Copy link
Copy Markdown
Contributor

/gemini review

@oxesoft

oxesoft commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review full

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

@oxesoft I will perform a complete review of PR #107.

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

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: CHILL

Plan: Pro Plus

Run ID: 907f50fb-518b-4499-851a-b94d7a7ec671

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43267653-0238-4c62-bf43-423a8ec2acc6

📥 Commits

Reviewing files that changed from the base of the PR and between 0f00720 and 0717968.

📒 Files selected for processing (7)
  • tests/test_run/test_websocket_socket.py
  • th_cli/commands/run_tests.py
  • th_cli/test_run/log_stream_handler.py
  • th_cli/test_run/log_viewer.html
  • th_cli/test_run/logging.py
  • th_cli/test_run/logs_http_server.py
  • th_cli/test_run/websocket.py

📝 Walkthrough

Walkthrough

The websocket now marks completed runs, drains trailing messages, and yields during large log batches. The logging subsystem propagates the created run ID to the HTTP server and connected viewers through SSE. The viewer creates backend download links and limits queued and retained logs. The HTTP server removes its log-download endpoint and file-path handling. Tests cover completion state, handler calls, and log-record forwarding.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the WebSocket and log viewer fixes covered by the changes.
Description check ✅ Passed The description directly explains the CLI WebSocket, live viewer, and log download changes.
Linked Issues check ✅ Passed The changes address issue [#1072] by preserving trailing WebSocket logs and maintaining responsive CLI log processing.
Out of Scope Changes check ✅ Passed The run ID and backend download-link changes support the stated logging and download objectives.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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

This is not related to the issue being fixed.
@antonio-amjr
antonio-amjr merged commit bf49694 into project-chip:v2.15.1-cli-develop Aug 14, 2026
4 of 5 checks passed
@antonio-amjr
antonio-amjr deleted the fix/websocket_and_log_viewer branch August 14, 2026 19:50
@github-project-automation github-project-automation Bot moved this from In Progress to Done in CSG issue tracking Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[MVE] 1.6.1: TC-ACE-2.4 docker-python and CLI run logging difference

5 participants