Skip to content

feat(cli): add timeout options for source imports#269

Open
voidborne-d wants to merge 4 commits intoteng-lin:mainfrom
voidborne-d:fix/source-add-timeout-options
Open

feat(cli): add timeout options for source imports#269
voidborne-d wants to merge 4 commits intoteng-lin:mainfrom
voidborne-d:fix/source-add-timeout-options

Conversation

@voidborne-d
Copy link
Copy Markdown
Contributor

@voidborne-d voidborne-d commented Apr 11, 2026

Summary

  • add --timeout to notebooklm source add so slow remote URL imports can override the default 30s RPC timeout
  • add --timeout to notebooklm source add-research --import-all so import retry budget matches the caller instead of being fixed at the helper default
  • add CLI regression tests for both timeout paths

Why

Two open issues point at the same ergonomics gap around source import timeouts:

This patch keeps the existing defaults, but exposes the knobs where users actually need them.

Testing

  • PYTHONPATH=src python3 -m pytest tests/unit/cli/test_source.py tests/unit/cli/test_notebook.py -k 'source_add_research or source_add'

Summary by CodeRabbit

  • New Features

    • Added a --timeout option to the source add command (default 30s, min 1s) to limit operation duration.
    • Added a --timeout option to the source add-research command (default 1800s, min 1s) to cap import/retry elapsed time when importing all.
  • Tests

    • Added unit tests validating timeout propagation and enforcement (>=1s) and related error behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ea6a6af-55d3-4848-9b7f-b455a1fddb77

📥 Commits

Reviewing files that changed from the base of the PR and between a16a656 and 42759d8.

📒 Files selected for processing (1)
  • src/notebooklm/cli/source.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/notebooklm/cli/source.py

📝 Walkthrough

Walkthrough

Added --timeout CLI options to source add (default 30s) and source add-research (default 1800s); threaded timeout into NotebookLMClient instantiation and into import_with_retry(..., max_elapsed=...); updated function signatures, typing imports, and unit tests.

Changes

Cohort / File(s) Summary
CLI Source Logic
src/notebooklm/cli/source.py
Added --timeout options to source add and source add-research; extended function signatures to accept timeout; pass timeout=float(timeout) to NotebookLMClient and max_elapsed=float(timeout) to import_with_retry; added typing imports/annotations.
CLI Unit Tests
tests/unit/cli/test_source.py
Added tests asserting client constructed with timeout=90.0 and import_with_retry awaited with max_elapsed=90.0; added validation tests for --timeout 0 failing with Click exit code 2 and constraint message; updated expected default max_elapsed=1800.0 assertion.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant CLI as "CLI (source add / add-research)" %%rgba(52,152,219,0.5)
    participant Client as "NotebookLMClient" %%rgba(46,204,113,0.5)
    participant Import as "import_with_retry" %%rgba(241,196,15,0.5)
    participant Remote as "NotebookLM API / Import backend" %%rgba(155,89,182,0.5)

    CLI->>Client: instantiate with timeout=float(timeout)
    CLI->>Remote: send add/import request (async)
    alt import-all requested
      Remote->>Import: trigger import flow
      Import->>Import: retry loop bounded by max_elapsed=float(timeout)
      Import->>Remote: repeated import attempts
      Import-->>CLI: import result / completion
    else not import-all
      Remote-->>CLI: immediate result
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 I nibbled at flags, found a clock in the hay,
I threaded a timeout to keep long imports at bay,
Clients hop out brisk with a timed little beat,
Retries bow out when time and deadline meet,
Hooray — the meadow's no longer a buffet!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(cli): add timeout options for source imports' clearly and concisely describes the main change: adding timeout options to CLI commands for source imports. It accurately reflects the primary objective without being vague or off-topic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces configurable timeout options for the source add and source add-research CLI commands, allowing users to specify HTTP request timeouts and maximum elapsed time for source imports. Corresponding unit tests have been added to ensure these parameters are correctly passed to the underlying client and retry mechanisms. A review comment suggests updating the help text for the research timeout to more accurately describe its coverage.

default=1800,
type=int,
show_default=True,
help="Maximum seconds to keep retrying source import when --import-all is used",
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.

medium

The help text for --timeout in source_add_research is currently limited to the import retry budget. If the timeout is also applied to the research polling phase (as suggested below), this description should be updated to reflect that it covers the entire operation duration.

Suggested change
help="Maximum seconds to keep retrying source import when --import-all is used",
help="Maximum seconds to wait for research and source import to complete",

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/notebooklm/cli/source.py (1)

242-244: Add type hints to the updated command signatures.

The modified function signatures are still untyped. Please annotate the newly added timeout parameter and surrounding arguments to keep mypy coverage aligned for touched code.

As per coding guidelines, src/notebooklm/**/*.py: "Use type hints and ensure type checking passes with mypy for src/notebooklm".

Also applies to: 566-567

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/notebooklm/cli/source.py` around lines 242 - 244, Add proper type
annotations to the updated CLI command signatures (e.g., source_add) so mypy
passes: annotate parameters like ctx, content, notebook_id, source_type, title,
mime_type, timeout, json_output, and client_auth with appropriate types (e.g.,
click.Context or similar for ctx, str for string args, Optional[float|int] or
Union[float,int,None] for timeout, bool for json_output, and the client auth
type used in the codebase), and add return type (likely None). Apply the same
pattern to the other modified signature(s) referenced around lines 566-567 so
all touched functions in src/notebooklm have explicit type hints consistent with
project types and imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/notebooklm/cli/source.py`:
- Around line 233-239: The CLI accepts non-positive integers for the --timeout
option which breaks retry behavior; update the two click.option declarations for
"--timeout" (the one around the add-source flow and the other at lines ~552-558)
to validate and reject non-positive values at parse time — either by using
click.IntRange(min=1) as the type or adding a click callback that raises a
UsageError when value < 1 — so only positive seconds are allowed before command
execution.

---

Nitpick comments:
In `@src/notebooklm/cli/source.py`:
- Around line 242-244: Add proper type annotations to the updated CLI command
signatures (e.g., source_add) so mypy passes: annotate parameters like ctx,
content, notebook_id, source_type, title, mime_type, timeout, json_output, and
client_auth with appropriate types (e.g., click.Context or similar for ctx, str
for string args, Optional[float|int] or Union[float,int,None] for timeout, bool
for json_output, and the client auth type used in the codebase), and add return
type (likely None). Apply the same pattern to the other modified signature(s)
referenced around lines 566-567 so all touched functions in src/notebooklm have
explicit type hints consistent with project types and imports.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bceeba2e-edf3-419c-ad0f-b4bf514913ad

📥 Commits

Reviewing files that changed from the base of the PR and between a997718 and f62713d.

📒 Files selected for processing (2)
  • src/notebooklm/cli/source.py
  • tests/unit/cli/test_source.py

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/notebooklm/cli/source.py (1)

562-568: Clarify --timeout help text scope

Current help text says the timeout covers research + import completion, but the value is only applied to import_with_retry(..., max_elapsed=...) in the --import-all path. Consider making that explicit in the option help.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/notebooklm/cli/source.py` around lines 562 - 568, The --timeout option
help is misleading: the value is only passed into import_with_retry(...,
max_elapsed=...) when running the --import-all path, not for the research step;
update the click.option help string for --timeout to explicitly state it applies
to the import retry (import_with_retry max_elapsed) used by the --import-all
code path (or alternatively wire the same timeout into the research call if you
intend it to cover both). Locate the --timeout click.option and the
import_with_retry call in source.py to either change the help wording to mention
import_with_retry/--import-all or propagate the timeout value into the research
function call so it truly covers both steps.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/notebooklm/cli/source.py`:
- Around line 244-254: The command functions (e.g., source_add) are annotated as
returning None but actually return a coroutine from _run(); update their return
type to an awaitable type such as -> typing.Awaitable[None] (or ->
typing.Coroutine[typing.Any, typing.Any, None]) and add the required import from
typing (Awaitable or Coroutine and Any) at the top of the module; apply the same
change to any other CLI command functions in this file that return _run().

---

Nitpick comments:
In `@src/notebooklm/cli/source.py`:
- Around line 562-568: The --timeout option help is misleading: the value is
only passed into import_with_retry(..., max_elapsed=...) when running the
--import-all path, not for the research step; update the click.option help
string for --timeout to explicitly state it applies to the import retry
(import_with_retry max_elapsed) used by the --import-all code path (or
alternatively wire the same timeout into the research call if you intend it to
cover both). Locate the --timeout click.option and the import_with_retry call in
source.py to either change the help wording to mention
import_with_retry/--import-all or propagate the timeout value into the research
function call so it truly covers both steps.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b0fef19-038c-45bd-8314-4da8343c2a42

📥 Commits

Reviewing files that changed from the base of the PR and between f62713d and 103b520.

📒 Files selected for processing (2)
  • src/notebooklm/cli/source.py
  • tests/unit/cli/test_source.py

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