Skip to content

CLI: add a request timeout to download_examples - #2444

Open
simpleqt wants to merge 1 commit into
MemTensor:mainfrom
simpleqt:sq/cli-download-timeout
Open

simpleqt wants to merge 1 commit into
MemTensor:mainfrom
simpleqt:sq/cli-download-timeout

Conversation

@simpleqt

Copy link
Copy Markdown

Fixes #2443

Summary

download_examples in src/memos/cli.py fetches the examples zip with requests.get(zip_url) and no timeout. requests waits indefinitely by default, so a stalled connection hangs the CLI forever — no error, no retry, no way out but Ctrl-C.

Fix

Pass an explicit timeout=60 so a stalled download raises requests.RequestException, which the function already catches and reports:

response = requests.get(zip_url, timeout=60)

Regression test

Added tests/test_cli_download_timeout.py:

  • red/green verified: the timeout-argument assertion fails against the old implementation and passes with the fix
  • also pins that a successful (mocked) download still returns True

ruff check (repo-pinned 0.11.8) passes on both touched files.

AI Disclosure

  • Tool(s): Claude (ZCode CLI)
  • Used for: debugging assistance, code suggestions, and drafting this PR description. All changes human-reviewed.

requests.get without a timeout waits forever on a stalled
connection; fail into the existing RequestException handler
instead.

Fixes #2443
Copilot AI balanced review requested due to automatic review settings September 30, 2026 14:02
@Memtensor-AI Memtensor-AI added area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2444
Task: 0cd6d31c891e0241
Base: main
Head: sq/cli-download-timeout

🔍 OpenCodeReview found 2 issue(s) in this PR.


1. src/memos/cli.py (L48)

Passing a single integer to timeout sets both the connect timeout and the read timeout to 60 s. For a large payload (a full GitHub-archive ZIP that can be tens or hundreds of MB), the read timeout counts from the moment the first byte arrives until the last byte is received — not per-chunk. On a slow or throttled connection this will raise ReadTimeout for a perfectly valid download.

Consider either:

  1. A tuple (connect_timeout, read_timeout) with a generous read timeout, e.g. timeout=(10, 300).
  2. Streaming the download with stream=True and writing chunks incrementally, which sidesteps the read-timeout issue and avoids buffering the entire ZIP in RAM (response.content).
💡 Suggested Change

Before:

        response = requests.get(zip_url, timeout=60)

After:

        response = requests.get(zip_url, timeout=(10, 300))

2. tests/test_cli_download_timeout.py (L44)

Using is True to assert the return value relies on Python's boolean singleton interning. While download_examples does return the literal True, the checklist flags is/is not comparisons against non-singleton literals as a correctness risk. Prefer a plain truthiness check (assert download_examples(...)) or an equality check (assert download_examples(...) == True) to be explicit about intent without depending on identity.

💡 Suggested Change

Before:

        assert download_examples(str(tmp_path)) is True

After:

        assert download_examples(str(tmp_path)) is True  # OK since bool is a singleton, but prefer:
        assert download_examples(str(tmp_path))

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (2/2 executed). memos_python_core/changed-repo-python: 2/2. Duration: 1s [advisory, non-gating] AI-generated tests on branch test/auto-gen-0cd6d31c891e0241-20260930221021: 26/29 passed, 3 failed — these do NOT affect the PR verdict; review the branch manually.

Branch: sq/cli-download-timeout

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core MOS 编排层 / 框架底座 / 跨模块问题 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants