Stamp the serving semantic cache entry for each file ``partial: True``. The semantic cache is deliberately unversioned and content-hash keyed, so a degraded extraction — e.g. a document chunk that returned only its file-level node — is otherwise replayed as authoritative on every later
(
files: Iterable[str | Path],
root: Path = Path("."),
*,
mode: str | None = None,
prompt: "str | Path | None" = None,
prompt_file: "str | Path | None" = None,
cache_root: "Path | None" = None,
)
| 2422 | |
| 2423 | |
| 2424 | def mark_semantic_cache_partial( |
| 2425 | files: Iterable[str | Path], |
| 2426 | root: Path = Path("."), |
| 2427 | *, |
| 2428 | mode: str | None = None, |
| 2429 | prompt: "str | Path | None" = None, |
| 2430 | prompt_file: "str | Path | None" = None, |
| 2431 | cache_root: "Path | None" = None, |
| 2432 | ) -> list[Path]: |
| 2433 | """Stamp the serving semantic cache entry for each file ``partial: True``. |
| 2434 | |
| 2435 | The semantic cache is deliberately unversioned and content-hash keyed, so a |
| 2436 | degraded extraction — e.g. a document chunk that returned only its |
| 2437 | file-level node — is otherwise replayed as authoritative on every later |
| 2438 | run. The #3203 shrink guard keeps refusing the graph write while the cache |
| 2439 | keeps suppressing the LLM call that could heal it, so the corpus is stuck |
| 2440 | until an operator deletes the entry by hand (#5083). |
| 2441 | |
| 2442 | The guard compares against graph.json, which :func:`save_semantic_cache` |
| 2443 | deliberately does not read (the cache writer does not know the graph), so |
| 2444 | the CLI marks the entry after the fact instead. ``load_cached`` already |
| 2445 | treats ``partial`` as a miss: the next run re-dispatches the file and a |
| 2446 | complete extraction overwrites the same content-hash key with a clean |
| 2447 | entry, which is the self-healing path the ``_partial`` truncation flag |
| 2448 | already uses. |
| 2449 | |
| 2450 | Marks the entry the read path would actually serve — the |
| 2451 | prompt-fingerprint namespace when it exists, else the pre-fingerprint flat |
| 2452 | layout ``load_cached`` falls back to — so a legacy entry cannot keep |
| 2453 | shadowing the marked one. |
| 2454 | |
| 2455 | ``files`` may be absolute, or relative to ``root`` (the shape of the shrink |
| 2456 | guard's canonical ``source_file`` keys). Returns the entry paths actually |
| 2457 | marked. Best-effort: a missing, unreadable or already-partial entry is |
| 2458 | skipped rather than failing the extraction. |
| 2459 | """ |
| 2460 | kind = "semantic" if mode is None else f"semantic-{mode}" |
| 2461 | location = cache_root if cache_root is not None else root |
| 2462 | prompt_fp = _resolve_prompt_fp(prompt, prompt_file) |
| 2463 | marked: list[Path] = [] |
| 2464 | for value in files: |
| 2465 | p = Path(value) |
| 2466 | if not p.is_absolute(): |
| 2467 | p = Path(root) / p |
| 2468 | try: |
| 2469 | h = file_hash(p, root, cache_root=cache_root) |
| 2470 | except (OSError, ValueError): |
| 2471 | continue |
| 2472 | candidates: list[Path] = [] |
| 2473 | if prompt_fp: |
| 2474 | candidates.append(_cache_entry_path(location, kind, h, prompt_fp)) |
| 2475 | candidates.append(_cache_entry_path(location, kind, h)) |
| 2476 | entry = next( |
| 2477 | (c for c in candidates if os.path.isfile(_os_long_path(c))), None |
| 2478 | ) |
| 2479 | if entry is None: |
| 2480 | continue |
| 2481 | # Extended-length form for I/O only: under a deep root the entry path |