Skip to content

[Bug] th-cli: don't call GET /api/v1/version on every invocation - #123

Merged
rquidute merged 1 commit into
project-chip:v2.16-cli-developfrom
rquidute:fix/1005-version-check-eager-call-v2.16
Sep 22, 2026
Merged

rquidute merged 1 commit into
project-chip:v2.16-cli-developfrom
rquidute:fix/1005-version-check-eager-call-v2.16

Conversation

@rquidute

Copy link
Copy Markdown
Contributor

Summary

th-cli was calling GET /api/v1/version on every invocation (--help,
subcommands, etc.), not just --version. When the backend is unreachable,
every command hangs until the HTTP client times out.

Root cause

click.version_option(message=get_extended_help()) evaluates message
eagerly, at decoration (i.e. module import) time — so get_extended_help()
(which calls get_versions() and hits the backend) ran on every th-cli
invocation, regardless of which flag/subcommand was used.

Fix

Replace click.version_option with a hand-rolled eager --version option
whose callback only calls get_extended_help() when --version is actually
passed (and is skipped during ctx.resilient_parsing, e.g. shell
completion).

Testing

  • Added tests/test_main.py: --help/no-args never call get_versions();
    --version does call it and still exits 0 with the existing
    "Not able to retrieve versions from server." fallback if the backend call
    raises.
  • Manually verified th-cli --help returns instantly with the backend down,
    and th-cli --version still prints CLI + backend version info as before.
  • mypy, black, isort, flake8 all pass.

Closes #1005

click.version_option's message param is evaluated eagerly at decoration
(i.e. import) time, so get_extended_help() -> get_versions() hit the
backend on every th-cli invocation (--help, subcommands, etc.), not just
--version. When the backend is unreachable, this stalled every command
until the HTTP client timed out.

Replace it with a hand-rolled eager --version option whose callback only
runs get_extended_help() when --version is actually passed.
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b705e9b8-c336-4b6a-b13c-5226fc18dccc

📥 Commits

Reviewing files that changed from the base of the PR and between 7b7483b and 4d0b04e.

📒 Files selected for processing (2)
  • tests/test_main.py
  • th_cli/main.py

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


📝 Walkthrough

Walkthrough

The root CLI now uses an eager --version callback instead of click.version_option. The callback evaluates get_extended_help() only when --version is provided and exits after printing the result. Normal invocations no longer call get_versions. Tests cover --help, no arguments, successful version retrieval, and retrieval exceptions.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix: preventing GET /api/v1/version from running on every th-cli invocation.
Description check ✅ Passed The description accurately explains the root cause, fix, testing, and issue addressed by the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
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.

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.

@mergify

mergify Bot commented Sep 21, 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

@rquidute rquidute self-assigned this Sep 21, 2026
@rquidute
rquidute merged commit f41adf1 into project-chip:v2.16-cli-develop Sep 22, 2026
5 checks passed
@rquidute
rquidute deleted the fix/1005-version-check-eager-call-v2.16 branch September 22, 2026 22:50
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.

3 participants