feat: self-refreshing mcp/lsp code index#141
Merged
Merged
Conversation
IndexCache re-checks staleness on every read instead of freezing its in-memory snapshot at first read, so the long-lived mcp:serve / lsp:serve singletons reflect newly created modules and routes without a manual indexer:rebuild or restart. The re-check is scoped to app/ + modules/ (vendor excluded; still fully indexed by build()) and a persisted tracked path-set lets it detect deletions, not just additions and edits. A rebuild fires at most once per change. No TTL/clock needed — the scoped walk is cheap. Also stops teaching the obsolete reflexes that this gap trained: - create-module skill Step 6 no longer tells agents to run composer dump-autoload (app-module autoloading is automatic at runtime) or to treat list_modules as a discovery gate - codeindexer/modularity/troubleshooting/verification-checklist docs rewritten to describe on-read self-refresh; indexer:rebuild reframed as forced/clean rebuild + cold-warm + vendor-change - devai-generated CLAUDE.md guidance gains a "trust your own writes" directive Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two real agent sessions wasted steps because the MCP tooling lied. An agent created a correct
app/module (extra.marko.module: true, psr-4 autoload, a#[Get('/')]controller), butvalidate_module/list_routesreturned "module not found" / "no routes" — until it ranindexer:rebuild. That trained two wrong, Magento-style reflexes: runningcomposer dump-autoloadand reaching for a reindex after scaffolding.Root cause:
IndexCache::ensureLoaded()short-circuited on$this->data !== nulland never re-checked staleness after the first read.mcp:serveandlsp:serveare long-lived processes holdingIndexCacheas a singleton, so they froze their snapshot for the whole process lifetime. The runtime app was never affected (routing + autoloading are live per request) — only the AI tooling's symbol index lagged.Fix
IndexCachere-checks staleness on every read, so the long-lived servers reflect new code withoutindexer:rebuildor a restart.app/+modules/(the dirs an agent edits);vendor/is excluded from the on-read check but still fully indexed bybuild(). New/removed vendor packages surface on the nextindexer:rebuild/devai:installcold-warm.save()stamps the cache mtime). Re-checking every read is simpler and avoids any window where a fresh write is masked.Also stops teaching the obsolete reflexes
composer dump-autoloadand the "verify vialist_modules" gate framing.codeindexer,modularity,troubleshooting,verification-checklist): rewritten to describe on-read self-refresh;indexer:rebuildreframed as forced/clean rebuild + cold-warm + vendor-change, not a routine step.CLAUDE.md: added a "trust your own writes" directive — introspection tools are for discovering pre-existing code, not confirming scaffolding you just wrote.Testing
IndexCacheTestcases (singleton refresh, additions/edits/deletions, vendor-excluded, no rebuild storm, legacy-payload handling, first-load preserved) + 1 newClaudeCodeAgentTestassertion.🤖 Generated with Claude Code