fix: prepare cached extractors and handle CR in MCP redaction

Merged
NA
4d ago
+184-7

Summary

Prepare cached extractors before writing chunks and stop unterminated quoted secrets at carriage returns in MCP error text.

Changes

  • Forward prepare() to the wrapped extraction strategy, including synchronous hooks and strategies without a hook.
  • Preserve the redaction fixes merged in #409 while stopping unterminated quoted values at either \r or \n.
  • Carry over the distinct regression tests from #411 and add coverage for redaction at the log and client boundaries.

Test Plan

  • All existing tests pass (pytest tests/ -q) — not run; focused suites were run instead.
  • New tests added for new functionality (if applicable): cd graphrag_sdk && .venv/bin/python -m pytest tests/test_cached_chunk_extraction.py tests/test_model_load_error.py tests/test_mcp_server.py -q — 212 passed, 5 skipped.
  • Lint passes (ruff check src/): cd graphrag_sdk && .venv/bin/ruff check src/ tests/test_cached_chunk_extraction.py tests/test_model_load_error.py tests/test_mcp_server.py && .venv/bin/ruff format --check src/ tests/test_cached_chunk_extraction.py tests/test_model_load_error.py tests/test_mcp_server.py — passed.

Notes

  • Incorporates #411, including its escaped-quote and CR/LF safeguards.
  • Resolved the overlapping redaction changes after #409 merged.
  • Automated summaries may include changes already on main; this PR changes cached preparation and CR handling in redaction.

Summary by cubic

Prepares the wrapped extraction strategy before cached writes and redacts quoted secrets in MCP error text, stopping unterminated values at a line break.

  • CachedChunkExtraction now forwards prepare() to the strategy it wraps, so a GLiNER or spaCy model that cannot load fails before any write, including when the document is unchanged and every chunk is cached; such an update fails with ModelLoadError. Inner strategies without prepare() still work, synchronous hooks are awaited properly, and an unchanged document with force=False still returns no_op=True without touching the model.
  • MCP redaction masks quoted secret values after a bare name and inside dicts. An unterminated value now stops at \r or \n instead of consuming text past a carriage return; a value that closes is still masked whole, including across a \r inside it. Values with spaces and escaped quotes are covered, and masking stays fast on long quoted runs.

Summary by CodeRabbit

  • Bug Fixes
    • Cached ingestion now prepares the extraction model before checking for unchanged chunks. If the model fails to load, the update stops before writing graph nodes—even when no chunks have changed.
    • Quoted credentials in MCP error messages are now masked up to either a carriage return or a line feed, preventing secret values from extending across line boundaries.