fix(skills): honour overall_timeout and bound ClawHub catalog walk - #38481
Closed
briandevans wants to merge 1 commit into
Closed
fix(skills): honour overall_timeout and bound ClawHub catalog walk#38481briandevans wants to merge 1 commit into
briandevans wants to merge 1 commit into
Conversation
parallel_search_sources accepted an overall_timeout but never honoured it. The ThreadPoolExecutor ran inside a `with ... as pool` block, whose __exit__ calls shutdown(wait=True); even after as_completed() raised TimeoutError on schedule, leaving the block blocked the caller until every worker finished. A single slow source (e.g. ClawHub) therefore stalled the entire browse for minutes. Manage the executor manually and shut it down with wait=False, cancel_futures=True in a finally, so the timeout actually returns and not-yet-started work is dropped. ClawHubSource._load_catalog_index walked up to 750 sequential pages with no wall-clock bound (each request under its own timeout=30, so nothing errored), and wrote the result to the index cache unconditionally — so an interrupted or slow walk poisoned the cache with a partial catalog. Add a CATALOG_WALK_BUDGET_SECONDS deadline that breaks the walk early, and only write the cache when the walk reaches a natural stop (cursor exhausted or page cap), never on a budget-truncated walk. Adds regression tests covering both bugs (timeout honoured + slow source flagged; budget abort does not poison cache) plus their happy-path invariants.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Introduce wall-clock safeguards to prevent long-running ClawHub catalog walks and ensure parallel_search_sources honors overall_timeout without blocking on slow sources.
Changes:
- Add a wall-clock budget to ClawHub catalog walking and avoid caching partial walks.
- Change
parallel_search_sourcesto manually manage the executor andshutdown(wait=False)so timeouts are respected. - Add regression tests covering the catalog budget/caching behavior and timeout honoring in parallel search.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tools/skills_hub.py | Adds catalog walk budget/conditional caching and updates threadpool shutdown to honor overall timeout. |
| tests/tools/test_skills_hub_clawhub.py | Adds tests to ensure partial catalog walks don’t poison the cache and natural termination does cache. |
| tests/tools/test_skills_hub.py | Adds regression tests for parallel_search_sources timeout behavior using fake sources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2191
to
+2197
| deadline = time.monotonic() + self.CATALOG_WALK_BUDGET_SECONDS | ||
| hit_deadline = False | ||
|
|
||
| for _ in range(max_pages): | ||
| if time.monotonic() > deadline: | ||
| hit_deadline = True | ||
| break |
Comment on lines
+2235
to
+2239
| # Only cache a walk that reached a natural stop (cursor exhausted or | ||
| # page cap). A walk truncated by the wall-clock budget is partial, so | ||
| # writing it would poison the cache with incomplete catalog data. | ||
| if not hit_deadline: | ||
| _write_index_cache(cache_key, [_skill_meta_to_dict(s) for s in results]) |
Comment on lines
+3743
to
+3746
| finally: | ||
| # wait=False so a slow source cannot block the caller's return; | ||
| # cancel_futures drops not-yet-started work. | ||
| pool.shutdown(wait=False, cancel_futures=True) |
Comment on lines
+2254
to
+2255
| fast = _FakeSource("fast", sleep=0.0, results=[self._meta("fast")]) | ||
| slow = _FakeSource("slow", sleep=5.0, results=[self._meta("slow")]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes two structural bugs in the Skills Hub search path that let a single slow source stall the entire browse for minutes.
parallel_search_sourcesnever honouredoverall_timeout. TheThreadPoolExecutorran inside awith ... as pool:block. Even thoughas_completed(timeout=overall_timeout)raisedTimeoutErroron schedule, leaving thewithblock invokesThreadPoolExecutor.__exit__→shutdown(wait=True), which blocks until every submitted worker finishes. So a slow source (e.g. ClawHub) kept the caller blocked well past the budget. The executor is now managed manually and shut down withwait=False, cancel_futures=Truein afinally, so the timeout returns promptly and not-yet-started work is dropped.ClawHub's catalog walk was unbounded in wall-clock and poisoned its cache on truncation.
_load_catalog_indexwalked up to 750 sequential pages (each request under its owntimeout=30, so nothing errored) and wrote the result to the index cache unconditionally. An interrupted or slow walk therefore cached a partial catalog. ACATALOG_WALK_BUDGET_SECONDSdeadline now breaks the walk early, and the cache is written only when the walk reaches a natural stop (cursor exhausted or page cap) — never on a budget-truncated walk.Related Issue
Fixes #38459
Type of Change
Changes Made
tools/skills_hub.py—parallel_search_sources: replace thewith ThreadPoolExecutor(...)context manager with a manual executor +try/finallythat callsshutdown(wait=False, cancel_futures=True).tools/skills_hub.py—ClawHubSource: addCATALOG_WALK_BUDGET_SECONDS = 12; in_load_catalog_index, add atime.monotonic()deadline that breaks the walk and only writes the cache when the walk was not truncated by the budget.tests/tools/test_skills_hub.py— regression + happy-path tests for the timeout.tests/tools/test_skills_hub_clawhub.py— regression + happy-path tests for the walk budget and cache-poisoning guard.How to Test
uv run --with pytest --with pytest-xdist --with pytest-asyncio python3 -m pytest tests/tools/test_skills_hub.py tests/tools/test_skills_hub_clawhub.py -v— 155 pass.parallel_search_sourceshunk →test_slow_source_does_not_block_callerblocks ~5s and fails; restore → returns in <2s with the slow source intimed_out_ids.test_catalog_walk_aborts_on_budget_and_does_not_poison_cachefails (no budget/guard, cache written on a truncated walk); restore → passes.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AContract Protected
Invariant:
parallel_search_sourcesreturns within roughlyoverall_timeout, and the ClawHub catalog cache only ever holds a complete walk.search()blocks far pastoverall_timeout(5s sleep vs 0.3s budget) — the call now returns in <2s and flags the source intimed_out_idsinstead of blocking onshutdown(wait=True).nextCursor(would otherwise walk all 750 pages) — the wall-clock budget breaks the walk early._write_index_cacheis not called, so a partial catalog never poisons the cache.timed_out_ids, and a walk that exhausts its cursor within budget still writes the cache exactly once.