Skip to content

CLI: give project logs a longer timeout and report a timeout accurately (#1231) - #153

Closed
rquidute wants to merge 3 commits into
project-chip:v2.17-cli-developfrom
rquidute:fix/1232-project-logs-timeout-v2.17
Closed

rquidute wants to merge 3 commits into
project-chip:v2.17-cli-developfrom
rquidute:fix/1232-project-logs-timeout-v2.17

Conversation

@rquidute

@rquidute rquidute commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1231

th-cli project logs failed after 5.8 s with ReadTimeout on a project with 12 executions (36 MB of logs), although the backend was running and served the same download correctly. The command used httpx's default 5 s read timeout, and the backend builds the whole archive before it sends the first byte, so the wait grows with the project.

Changes

  • th_cli/commands/project.py
    • New PROJECT_LOGS_TIMEOUT (300 s read, 10 s connect), passed to get_client() through a new optional timeout argument of get_sync_apis(). Only project logs uses it; every other project command keeps the default.
    • A ReadTimeout while downloading is now reported as "Timed out waiting for the logs of project N: no data received for 300s. The backend accepted the connection; building the archive of a project with many or large executions can take longer than that." The previous text ("Is the backend running? Try th-cli doctor") was wrong for this case: a read timeout means the connection was made. The wording is phase-neutral on purpose: httpx's read timeout applies between chunks, so it does not say whether the first byte ever arrived. Other transport errors, including connect, write and pool timeouts, keep the generic handler and the backend hint, and no partial file is written.
  • tests/test_project_commands.py: new TestProjectLogsTimeout (5 tests): the extended timeout is requested, other commands keep the default, a read timeout gives the new message without the backend hint and writes no file, a refused connection keeps the hint, and connect, write and pool timeouts are not reported as a slow archive.

The 300 s is a judgement call. A single execution's log download gets 120 s (TEST_RUN_EXECUTION_IO_TIMEOUT) and a project is the sum of its executions. It is a constant, easy to adjust once there are timings from larger projects.

Not in this PR

The backend still builds the whole archive before it responds and stores it uncompressed (36.1 MB compressed and uncompressed in the case above). Streaming the archive while it is built, and compressing it, would remove the dependency on a timeout altogether; that is a separate backend change.

Testing

  • tests/test_project_commands.py: 71 passed (66 before, plus the 5 new tests).
  • Whole CLI suite: the same 47 tests fail on v2.17-cli-develop without this change and with it (all in other test files, such as test_run_tests.py and test_tc_params_mapping.py, which do not touch this code); 5 more pass with it, the new ones. I did not investigate those 47.
  • isort and flake8 are clean for the changed files; black leaves th_cli/commands/project.py unchanged.
  • On the TH host where it failed, th-cli project logs on the project with 12 executions no longer times out.

th-cli project logs failed after 5.8s with ReadTimeout on a project with 12 executions (36 MB of logs): the
command used httpx's default 5s read timeout, but the backend builds the whole archive before it sends the
first byte, so the wait grows with the project. Other long-running commands already set their own timeout.

- PROJECT_LOGS_TIMEOUT (300s read, 10s connect) for project logs only, passed through get_sync_apis(timeout=).
- A timeout is no longer reported as 'Is the backend running?': the connection worked, the backend is just still
  building the archive. Other transport errors keep the backend hint.

Refs project-chip/certification-tool#1232
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The project logs command now uses a dedicated client timeout of 300 seconds for reads and writes, and 10 seconds for connections. Other project commands retain the default timeout. When a log download fails because of a timeout, the CLI reports that the backend is reachable but has not started sending the archive. Other transport errors retain their existing handling.

Possibly related PRs

Suggested reviewers: oxesoft

Severity of issue fixed: Medium

Merge Risk: Low · up to 0b310

The longer log-download timeout works as intended, but some timeout errors will give a misleading explanation of what went wrong. This is a small diagnostic issue and is worth fixing before merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#1231] Verified at head in th_cli/commands/project.py: PROJECT_LOGS_TIMEOUT = Timeout(300.0, connect=10.0) is defined; get_sync_apis(operation, timeout=None) forwards the timeout to get_client(timeou… Provide a readable view of _download_project_logs in th_cli/commands/project.py at head (or a diff of that hunk) to confirm that a TimeoutException wrapped in ResponseHandlingException raises the reachable-but-slow CLIError without the back…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the two changes in this PR: a longer timeout for project logs and accurate reporting of timeouts. The raw summary confirms both: PROJECT_LOGS_TIMEOUT is added, and a timeout raises…
Out of Scope Changes check Passed The changes visible at head fall within the scope of [#1231]. The timeout constant and its forwarding through get_sync_apis() affect only the project logs command. The project logs error message chang…
Description check Passed The description states the problem (ReadTimeout on th-cli project logs with 12 executions), the changes to th_cli/commands/project.py (PROJECT_LOGS_TIMEOUT, optional timeout argument of get_sync_apis,…
Full details: Title check

Explanation

The title names the two changes in this PR: a longer timeout for project logs and accurate reporting of timeouts. The raw summary confirms both: PROJECT_LOGS_TIMEOUT is added, and a timeout raises a specific CLIError message. The title is specific and matches the main change.

Full details: Out of Scope Changes check

Explanation

The changes visible at head fall within the scope of [#1231]. The timeout constant and its forwarding through get_sync_apis() affect only the project logs command. The project logs error message change is the requested fix. The PR summary and the AI-generated summary report no change to backend code, and the visible changed files are th_cli/commands/project.py and tests/test_project_commands.py. The issue excludes backend archive changes, and none are reported. The unread part of _download_project_logs is not assessed here; its scope is covered by the linked-issue assessment.

Full details: Description check

Explanation

The description states the problem (ReadTimeout on th-cli project logs with 12 executions), the changes to th_cli/commands/project.py (PROJECT_LOGS_TIMEOUT, optional timeout argument of get_sync_apis, revised read-timeout message), the new TestProjectLogsTimeout tests, and the testing performed. It is specific and clearly related to the changeset, so it passes.

Full details: Linked Issues check

Explanation

[#1231] Verified at head in th_cli/commands/project.py: PROJECT_LOGS_TIMEOUT = Timeout(300.0, connect=10.0) is defined; get_sync_apis(operation, timeout=None) forwards the timeout to get_client(timeout=...); the logs command passes PROJECT_LOGS_TIMEOUT; other commands call get_sync_apis without a timeout and keep the default. th_cli/client.py at head already accepts timeout in get_client(), so the forwarding is valid. Not verified: the body of _download_project_logs, which the file read truncated. The acceptance criterion that a read timeout reports a reachable-but-slow backend and that a refused connection keeps the backend hint depends on that function. The PR summary and the AI-generated summary describe this behavior, and the 5 new tests reportedly cover it, but neither is source evidence. The diff tool returned no output for th_cli/commands/project.py and tests/test_project_commands.py, so the test file was not read. Timeout extension and default preservation are supported. The message behavior is unconfirmed.

Resolution

Provide a readable view of _download_project_logs in th_cli/commands/project.py at head (or a diff of that hunk) to confirm that a TimeoutException wrapped in ResponseHandlingException raises the reachable-but-slow CLIError without the backend hint, that other transport errors keep the hint, and that no partial file is written. Provide the TestProjectLogsTimeout tests in tests/test_project_commands.py to confirm they assert these behaviors.

  • 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

@mergify

mergify Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@rquidute rquidute self-assigned this Dec 3, 2026
@rquidute
rquidute requested a review from antonio-amjr December 3, 2026 13:12
@rquidute rquidute changed the title CLI: give project logs a longer timeout and report a timeout accurately (#1232) CLI: give project logs a longer timeout and report a timeout accurately (#1231) Dec 3, 2026

@coderabbitai coderabbitai 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.

Actionable comments

Minor 2
  1. Do not infer that transmission never started from a read timeout.
  2. Do not classify connection timeouts as slow archive generation.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 345579bd-92fd-4805-9d9c-ff713b201f50
Commits

Reviewing files that changed from the base of the PR and between 034130a and 0b3102e.

Files selected for processing: 2

  • tests/test_project_commands.py
  • th_cli/commands/project.py

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

Comment thread th_cli/commands/project.py Outdated
id=id, grouped=grouped
)
except ResponseHandlingException as e:
if isinstance(e.error, TimeoutException):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Do not classify connection timeouts as slow archive generation.

If connection establishment times out after 10 seconds, ConnectTimeout passes this guard because it inherits TimeoutException. The command then claims that the backend is reachable and that it waited 300 seconds. HTTPX does not establish either fact in this case. (raw.githubusercontent.com)

Restrict this branch to ReadTimeout. Let other timeout types reach the existing transport-error handler. Update the test that requires the archive-start message for WriteTimeout and PoolTimeout; those failures also do not establish archive generation. (raw.githubusercontent.com)

Comment thread th_cli/commands/project.py Outdated
Comment on lines +753 to +754
f"The backend did not start sending the logs of project {id} within {PROJECT_LOGS_TIMEOUT.read:.0f}s. "
"It is reachable, but building the archive of a project with many or large executions takes longer."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Do not infer that transmission never started from a read timeout.

If the backend sends part of the archive and then stops sending for 300 seconds, HTTPX raises ReadTimeout while buffering the remaining body. Its read timeout applies between chunks, not only before the first byte. This message incorrectly attributes that failure to archive generation. Restricting the exception type does not fix this case. (raw.githubusercontent.com)

Use phase-neutral wording, such as “Timed out waiting for project logs data after 300 seconds without receiving data.” Describe archive generation as a possible cause, not an established fact.

@rquidute

rquidute commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Both points addressed in 72baf82 (87a25de plus a line-wrap fix). The handler now catches only ReadTimeout; connect, write and pool timeouts reach the generic transport-error handler. The message no longer claims the first byte never arrived: "Timed out waiting for the logs of project N: no data received for 300s. The backend accepted the connection; building the archive ... can take longer than that." The test that required the archive message for write and pool timeouts now asserts the opposite, and a ConnectTimeout case is added.

@greens

greens commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

I think I mostly did the backend work here: project-chip/certification-tool-backend#419 that should have resolved this.

And it got cherry-picked to 2.17 here: project-chip/certification-tool-backend#424

Did the backend image you were running have those changes?

@rquidute

rquidute commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing this. @greens was right: the failure came from a backend without the streaming change..
I re-tested on a clean install of v2.16+winter2026, whose backend includes #419, with the CLI exactly as pinned there (default timeouts, none of this PR's changes)

@rquidute rquidute closed this Dec 4, 2026
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