Repository navigation
fix: negatively cache failed fetches and cap no_sections content - #43
AnnasMazhar wants to merge 2 commits into
Conversation
Two related fixes for strands-mcp: Negative caching for failed fetches (#3328): - Add _FAILED sentinel to distinguish not fetched from failed - Short-circuit known-failed URLs instead of re-fetching every time - Log exceptions with logger.exception() instead of silent swallow Cap no_sections fallback content (#3327): - Truncate structureless documents at SMALL_DOC_THRESHOLD (8KB) - Append truncation notice to bounded content - Update test to verify content is bounded Fixes #3328, #3327
|
@strandly-the-agent review |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Verdict: changes requested — negative caching currently crashes search_docs and permanently caches transient failures.
✅ Reviewed exact head d7cfd013 against merge-base bf2ec1f.
✅ pytest tests/ -q: 47 passed · hatch run lint, ruff check ., and git diff --check: passed.
🔴 Two cold repros confirmed both blockers: sentinel dereference and no transient recovery.
Review breakdown
- Correctness/adversarial:
_FAILEDleaks through the raw cache and crashes both the first and latersearch_docscalls after failed hydration. Negative entries also never expire, contrary to the linked issue's short-TTL requirement. - Test quality: retained the cross-file failure and TTL-boundary coverage gaps; production truncation passed ASCII-boundary and split-multibyte probes.
- LLM context: suppressed the imperfect
document_smallmetadata because the content itself carries an explicit truncation notice. - Readiness: configured lint and unit tests pass. Direct
ruff format --check .would adjust slice spacing atserver.py:170; omitted as style.
No additional questions.
| except Exception: | ||
| logger.exception("Failed to fetch page: %s", url) | ||
| _URL_CACHE[url] = _FAILED # negatively cache the failure | ||
| return None |
There was a problem hiding this comment.
🔴 [block] Keep the failure sentinel private from cache consumers.
Storing _FAILED in the dictionary returned by get_url_cache() makes search_docs treat this opaque object as a Page. On the first failed hydration it reaches make_snippet; subsequent searches fail earlier while evaluating cached.content.
Cold repro, repeated twice:
search_call_1_error=AttributeError: 'object' object has no attribute 'content'
search_call_2_error=AttributeError: 'object' object has no attribute 'content'
search_backend_calls=1
Please normalize failed entries to None before exposing them—or otherwise keep the sentinel behind a cache accessor—and use ensure_page()'s return value when building snippets. A cross-file regression should assert that failed hydration still returns the ranked title fallback and performs only one backend call.
| cached = _URL_CACHE.get(url) | ||
| # Short-circuit on known failures — don't re-fetch | ||
| if cached is _FAILED: | ||
| return None |
There was a problem hiding this comment.
🔴 [block] Expire negative-cache entries so transient failures can recover.
This branch has no timestamp, expiry, or invalidation path, so the first timeout permanently disables that URL. In a cold deterministic probe with backend effects [TimeoutError, success], two ensure_page() calls both returned None and the backend call count remained 1; repeating the probe produced the same result.
That conflicts with linked issue harness-sdk#3328, which explicitly requests a short TTL. Please use an expiring negative-cache entry and add a boundary test proving calls are suppressed before expiry and retried at expiry.
Two fixes based on code review by strandly-the-agent: 1. **Sentinel dereference crash** — _FailedEntry in url_cache has no .content attribute, causing AttributeError in search_docs hydration loop and snippet building. Fix: replace bare sentinel with OOP _FailedEntry class, guard call sites with hasattr checks. 2. **No TTL on failed entries** — negative cache entries never expired, permanently preventing re-fetch of transient failures. Fix: add _FailedEntry with 5-minute TTL (time.monotonic based). Expired entries are cleared and retried on the next ensure_page call. Tests: 47 existing + 2 new (failed entry crash guard, snippet fallback). All 49 pass.
|
Addressed both review points — fixes pushed to 1. Sentinel dereference crash: Replaced bare 2. TTL expiry for negative cache: Tests: 2 new test methods in |
|
Review feedback addressed in commit a948d55:
All 49 tests pass. Could use a re-review when strandly-the-agent gets a chance. |
|
@AnnasMazhar we have moved the MCP server to our monorepo (strands-agents/harness-sdk), can you also move the PR there? I didn't realize at first that this was the old repo I will make sure this repo is archived so it does not allow new PRs |
Two fixes for strands-mcp fetch/cache/hydration path.
Negative caching for failed fetches (#3328):
Cap no_sections fallback content (#3327):
All 47 existing tests pass.