Skip to content

feat: self-refreshing mcp/lsp code index#141

Merged
markshust merged 1 commit into
developfrom
feature/index-self-refresh
Jun 25, 2026
Merged

feat: self-refreshing mcp/lsp code index#141
markshust merged 1 commit into
developfrom
feature/index-self-refresh

Conversation

@markshust

Copy link
Copy Markdown
Collaborator

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), but validate_module / list_routes returned "module not found" / "no routes" — until it ran indexer:rebuild. That trained two wrong, Magento-style reflexes: running composer dump-autoload and reaching for a reindex after scaffolding.

Root cause: IndexCache::ensureLoaded() short-circuited on $this->data !== null and never re-checked staleness after the first read. mcp:serve and lsp:serve are long-lived processes holding IndexCache as 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

  • IndexCache re-checks staleness on every read, so the long-lived servers reflect new code without indexer:rebuild or a restart.
  • Scoped to app/ + modules/ (the dirs an agent edits); vendor/ is excluded from the on-read check but still fully indexed by build(). New/removed vendor packages surface on the next indexer:rebuild / devai:install cold-warm.
  • Detects deletions, not just additions/edits, via a persisted tracked path-set compared against the current walk.
  • No TTL/clock — the scoped walk is cheap, and a rebuild fires at most once per change (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

  • create-module skill Step 6: dropped composer dump-autoload and the "verify via list_modules" gate framing.
  • Docs (codeindexer, modularity, troubleshooting, verification-checklist): rewritten to describe on-read self-refresh; indexer:rebuild reframed as forced/clean rebuild + cold-warm + vendor-change, not a routine step.
  • devai-generated CLAUDE.md: added a "trust your own writes" directive — introspection tools are for discovering pre-existing code, not confirming scaffolding you just wrote.

Testing

  • 10 new IndexCacheTest cases (singleton refresh, additions/edits/deletions, vendor-excluded, no rebuild storm, legacy-payload handling, first-load preserved) + 1 new ClaudeCodeAgentTest assertion.
  • Full suite green: 6855 passed.

🤖 Generated with Claude Code

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>
@markshust markshust merged commit 43dc486 into develop Jun 25, 2026
1 check passed
@markshust markshust deleted the feature/index-self-refresh branch June 25, 2026 02:23
@github-actions github-actions Bot added the enhancement New feature or request label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant