fix: prepare the extractor under the chunk cache; mask quoted secrets in MCP errors

Closed
GA
6d ago
+181-8

Two bugs found while reviewing the docs in FalkorDB/GraphRAG-SDK#409. Both were already in 1.7.x.

1. update(cache_unchanged_chunks=True) never called prepare()

update() wraps the extractor in CachedChunkExtraction when the chunk cache is on. The wrapper inherited the base no-op prepare() and never called the wrapped strategy's, so on this path:

  • a GLiNER or spaCy model that could not load failed only inside extract(), after step 3 had written the update's chunks;
  • a custom strategy that sets itself up in prepare() reached extract() without that setup.

The wrapper now passes prepare() on, the same way the pipeline calls it (duck-typed, sync or async). Like the pipeline without the cache, it runs even when every chunk turns out to be cached.

2. redact() left a quoted secret after a bare name unmasked

The key=value pattern stopped at a quote, so api_key='...' and password="..." passed through unchanged. That is how a provider error prints keyword arguments, so a key with no sk- prefix (an Azure key, for example) reached the MCP server log and the client. Both name patterns now take a quoted value up to its closing quote, spaces included. The old quoted-key pattern also stopped at the first space, so {"password": "a b"} used to keep b. With no closing quote, the rest of the line is masked.

The value pattern stops at the quote or a line break, and nothing after it can fail, so it does not backtrack. Tests cover 40,000-character values and 10,000 matches in one string, each under 0.5 s.

Tests

  • test_cached_chunk_extraction.py::TestPrepare: the wrapper prepares the inner strategy, passes its error on, and accepts an inner strategy whose prepare() is missing or synchronous.
  • test_model_load_error.py: a broken GLiNER model under CachedChunkExtraction fails the pipeline before upsert_nodes, the same check the existing test makes without the cache.
  • test_mcp_server.py: quoted values after bare and quoted names, values with spaces, a value with no closing quote, password='' and max_tokens='10' left alone, and speed on long quoted values.

On main, 4 of the new cache tests and all 11 new redact cases fail; with this change they pass. Full unit suite on Python 3.12: 3,475 passed, 429 skipped (integration tests and optional extras). ruff check and ruff format --check are clean.

Docs

FalkorDB/GraphRAG-SDK#409 says a quoted value after an unquoted name is not masked. Once this merges, that sentence should drop the password='...' case. Its prepare() text then holds for the cached update() path too.

🤖 Generated with Claude Code


Summary by cubic

Fixes two bugs from the 1.7.x line: the chunk-cache path never called the extractor's prepare(), and MCP redact() left quoted secrets after a bare name unmasked.

  • CachedChunkExtraction now passes prepare() through to the wrapped strategy, so a model that cannot load fails update(cache_unchanged_chunks=True) before step 3 writes chunks, and custom strategies are set up before extract(). It runs even when every chunk is cached.
  • redact() now masks quoted values (api_key='...', password="...") up to the closing quote, spaces and backslash escapes included, after both bare and quoted names. A value with no closing quote masks the rest of the line, stopping at \r or \n.

FalkorDB/GraphRAG-SDK#409 documents the quoted-secret behavior; its example should drop the password='...' case once this merges.

Summary by CodeRabbit

  • Bug Fixes
    • Cached extraction now forwards preparation to its underlying strategy, allowing setup errors to surface before ingestion proceeds and preventing partial graph updates when model loading fails.
    • Secret redaction now masks quoted credential values, including values with spaces or escaped quotes, after bare or quoted secret names. Unclosed quoted values are masked through the end of their line, without affecting subsequent lines. Ordinary unrelated text remains unchanged.