Conversation
…on-blocking-fetch test Addresses the actionable subset of the PR #316 whole-branch review follow-ups (item #327): - 404/bad package name now returns invalid_params instead of internal_error. FetchError gains a structured Status(u16) variant (ureq::Error::Status was previously flattened into a string), and a ClientError trait lets blocking_fetch discriminate 4xx (caller's fault) from 5xx/transport/timeout (ours). npm's NoTypes counts as caller-caused too. - search limit is capped at 50, enforced inside DocsStore::search so the MCP tool and the CLI both inherit it rather than each guarding separately. - the non-2xx re-check in UreqFetcher::fetch is documented as deliberate rather than dead: ureq only auto-errors on >= 400, so 1xx/3xx still arrive as Ok. It now returns the same structured Status variant. - committed regression test for the spawn_blocking fix (83f76ad), which was previously only proven by an ad-hoc uncommitted script. Verified it fails ("only 0 ticks elapsed") when the fetch is made inline. Two of the six findings needed no change: the zstd output cap already landed (MAX_DECOMPRESSED_BYTES + read_capped), and CLI `get` now has its own cache-checking arm, so its "or read from cache" help text is accurate.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughFetch failures now preserve HTTP status codes and classify 4xx errors for MCP responses. npm fallback handling uses status 404, while documentation searches and MCP lists cap results at 50 with updated CLI and schema metadata. ChangesFetch error classification
Search result cap
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mcp_server/flare_docs.rs`:
- Around line 175-180: Update the error-message construction in the visible
error-handling branch so eco.other_ecosystem_hint(package) is not appended for
NpmError::Npm(NpmFetchError::NoTypes(_)). Restrict the cross-ecosystem hint to
genuine package-not-found errors, while preserving the existing
invalid_params/internal_error classification and messages for other failures.
In `@src/mcp_server/types.rs`:
- Around line 445-447: The limit field description incorrectly claims
enforcement for list operations. Update the schemars description on the limit
field in the request type to document only the search behavior unless the list
handler is also changed to enforce the limit; preserve the existing default and
maximum wording.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 52b49445-476c-4ba8-ac18-e5d11a810911
📒 Files selected for processing (7)
crates/flare-docs/src/fetch.rscrates/flare-docs/src/lib.rscrates/flare-docs/src/npm/mod.rscrates/flare-docs/src/store.rssrc/cli/docs.rssrc/mcp_server/flare_docs.rssrc/mcp_server/types.rs
…st limit Self-review follow-ups on this branch: - 408 and 429 are 4xx but retryable — the request was well-formed and the caller needs to back off, not fix its arguments. Mapping them to invalid_params told an agent to correct a request that was never wrong. They now stay internal_error. - the `limit` schema documents a ceiling for both search and list, but the list action ignored the field entirely, so the documented cap was a promise the tool did not keep. list still returns every cached document by default; an explicit limit is now honoured and capped. Description reworded to state both behaviours exactly.
CodeRabbit finding on PR #344, and broader than reported: the hint reads "\"X\" was not found on docs.rs/npm", but blocking_fetch appended it to every failure. A 503, a corrupt tarball, a store error, or a package that exists and simply ships no types all produced a message asserting the package does not exist. In the NoTypes case it directly contradicted the sentence it was appended to. ClientError gains is_package_missing(), kept separate from is_client_error() because they answer different questions -- a package with no types is the caller's problem yet is not missing. Only a 404 now earns the hint.
Addresses the actionable subset of the six Minor findings from the PR #316 whole-branch review (agentflare item #327).
Four findings needed code. Two were already fixed by later work and are reported below rather than re-done.
1. A 404 was reported as
internal_errorinstead ofinvalid_paramsRoot cause was structural:
ureq::Error::Statuswas flattened into a string, soblocking_fetchhad no way to tell "you asked for a package that does not exist" from "the registry is down".FetchErrorgains a structured variant carrying the code:and a
ClientErrortrait lets the MCP layer discriminate, implemented per error type because only the error knows which of its variants are caller-caused:4xx and npm's
NoTypesare caller-caused; 5xx, transport errors, timeouts and task panics stayinternal_error.This also subsumes the
FetchError::NotFoundvariant added during #342's review — one variant carrying the status code preserves that timeout-vs-absence distinction and adds 4xx-vs-5xx, so the npm@typesfallback now matchesFetchError::Status(404).2.
limitwas unboundedCapped at 50 in
DocsStore::searchrather than at each caller, since the MCP tool and the CLI both route through it and two separate guards would drift:Schema description and CLI
--limithelp updated to state the cap.5. The non-2xx re-check in
UreqFetcher::fetchis not deadThe review suggested removing it or documenting it. It turns out not to be dead:
ureqonly auto-errors on status >= 400, so a 1xx/3xx response (redirect budget exhausted, or an agent configured not to follow redirects) still arrives asOk. Documented as deliberate and switched to return the same structuredStatusvariant.6. No committed regression test for the
spawn_blockingfixThe "a slow fetch does not freeze the MCP server" property (fixed in 83f76ad) was previously only proven by an ad-hoc uncommitted script. Now covered by a committed test that exercises the property directly through
blocking_fetch, so noFetcher-injection refactor was needed.The test was verified to have teeth: temporarily making the fetch run inline fails it with
runtime was blocked during the fetch: only 0 ticks elapsed. The mutation was then reverted.Findings that needed no change
MAX_COMPRESSED_BYTES/MAX_DECOMPRESSED_BYTES+read_capped, with three tests.get --helpoverpromises caching) — now stale:Gethas its own cache-checking arm viastore.get_by_path, so "Fetch (or read from cache)" is accurate.Verification
cargo fmt --all --checkcleancargo test --workspace: 821 passed, 8 failedThose 8 failures are pre-existing and environmental, not from this change. They reproduce identically on pristine
origin/masterwith the same command in the same setup (819 passed / 8 failed — the 2-test difference is exactly the two tests this PR adds). All 8 are tests that shell out togit, failing with:They only trip under the parallelism of a full
--workspacerun; a filtered run of the same tests passes. Since the shim itself asks for it to be reported, that is worth a separate issue — it is unrelated to this PR.Summary by CodeRabbit