Skip to content

Fix/repair and cache bugs#23

Merged
michaelalber merged 4 commits intomainfrom
fix/repair-and-cache-bugs
Apr 30, 2026
Merged

Fix/repair and cache bugs#23
michaelalber merged 4 commits intomainfrom
fix/repair-and-cache-bugs

Conversation

@michaelalber
Copy link
Copy Markdown
Owner

Fix cache bug

michaelalber and others added 4 commits April 29, 2026 21:34
The repair_manifest.py CLI uses the user-supplied collection suffix
verbatim as the disk subdir name. This breaks for any collection where
the disk dir uses hyphens but the suffix uses underscores
(e.g. sources/api-design → api_design). The new resolve_explicit_targets
helper must look up the disk subdir from settings.collections.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add resolve_explicit_targets() in manifest_repair so that a user-supplied
collection suffix (e.g. 'api_design') maps to its actual disk subdir
(e.g. 'api-design') by looking up settings.collections, not by assuming
the suffix and the disk subdir are the same string.

The CLI script now uses this helper and exits with a clear error when
an unknown suffix is passed.

Fixes the bug where:
  python scripts/repair_manifest.py api_design

silently did nothing because it looked at sources/api_design/ instead
of sources/api-design/. Affected any collection where the suffix uses
underscores while the disk dir uses hyphens (api_design,
systems_thinking, ui_ux, edge_ai, 4d_legacy, automation).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The MCP server caches the manifest in a module global at startup and
never reloads it. A CLI ingest run while the server is up writes new
entries to manifest.json on disk, but list_sources / list_collections
keep returning the stale cached state until the server restarts.

Adds two tests:
- reload-when-changed: get_manifest reflects post-startup file changes
- cached-when-unchanged: get_manifest returns same object when mtime
  hasn't moved (guards against per-call disk re-read)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The MCP server held a single Manifest instance loaded at startup, so
any CLI ingest run while the server was up was invisible to
list_sources / list_collections / get_source_info until the server was
restarted. Symptoms: source_count: 0 reported by list_collections even
after a successful ingest.

Track _manifest_mtime and call os.stat() on each get_manifest invocation:
- if the file mtime advanced, reload from disk
- if unchanged, return the cached instance (no disk I/O cost beyond stat)
- if the file is missing/unreadable, keep the cache (no-op)

Cost: one st_mtime check per metadata-tool call (admin tools, not hot path).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@michaelalber michaelalber merged commit 980dab4 into main Apr 30, 2026
9 of 10 checks passed
@michaelalber michaelalber deleted the fix/repair-and-cache-bugs branch April 30, 2026 05:12
_manifest_mtime is None or current_mtime > _manifest_mtime
):
_manifest = Manifest.load_or_create(manifest_path)
_manifest_mtime = current_mtime
Comment thread tests/test_server.py
def test_get_manifest_reloads_when_file_changes_on_disk(self, temp_dir: Path) -> None:
"""A manifest write from another process is reflected on the next get_manifest call."""
# Arrange
import grounded_code_mcp.server as server_module
Comment thread tests/test_server.py
def test_get_manifest_returns_cached_when_file_unchanged(self, temp_dir: Path) -> None:
"""When manifest.json has not changed, get_manifest returns the cached object."""
# Arrange
import grounded_code_mcp.server as server_module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants