Repository navigation
Description
Problem
Dewey's serve command performs vault indexing (incremental index + embedding generation) synchronously before starting the MCP server. On repos with 255+ local pages and 689 external pages, this takes ~32 seconds. OpenCode's MCP server startup timeout is ~30 seconds, causing Dewey to be killed before it can accept requests.
Evidence
From .uf/dewey/dewey.log:
13:35:49 INFO serve starting
13:35:49 INFO persistent store opened elapsed=7ms
13:35:49 INFO ollama state elapsed=5ms
13:35:49 INFO embedding model available
... (incremental indexing + embedding generation takes ~30s)
13:36:32 INFO vault indexed elapsed=~30s
13:36:32 INFO external pages loaded pages=689 blocks=4091 elapsed=83ms
13:36:32 INFO file watcher started elapsed=28ms
13:36:32 INFO server ready startup=31.97s <-- too late
The server ready message appears at 32 seconds. OpenCode has already timed out at ~30 seconds.
Root Cause
In main.go:executeServe(), the call chain is:
initObsidianBackend()— callsindexVault()synchronously (line 560)indexVault()— runs incremental index + generates embeddings for changed blocks via Ollama API- External pages loaded (line 574)
- File watcher started (line 586)
- Only then:
runServer()starts accepting MCP requests (line 265)
The bottleneck is step 2 — each embedding generation is a round-trip HTTP call to Ollama. With dozens of changed blocks, this accumulates to ~30 seconds.
Proposed Fix
Start the MCP server immediately after store/backend initialization, then perform indexing in a background goroutine:
- Open store + check Ollama + verify model — fast (~20ms total)
- Create MCP server + start stdio transport — start accepting requests immediately
- Launch
indexVault()+loadExternalPages()+Watch()in a background goroutine - While indexing: search/traverse tools return results from the persistent store (stale but available). Semantic search may return partial results.
- When indexing completes: log it, backlinks rebuilt, watcher active
This means the server is available in <1 second instead of 32 seconds. The tradeoff is that the first few queries after startup may return stale results from the previous session's index — but that's better than timing out completely.
Additional Finding
One block in specs/008-swarm-orchestration/spec (1,410 chars) exceeds granite-embedding:30m's context length:
WARN failed to generate embedding chunkLen=1410 err="the input length exceeds the context length"
This should be handled gracefully (skip the block, log the warning — which it does) but the chunker could also be updated to split blocks that exceed the model's context window.
Environment
- dewey version: dev (built from source)
- MCP SDK: go-sdk v1.2.0
- Index: 255 local pages, 689 external pages, 4,091 blocks
- Ollama model: granite-embedding:30m
- Platform: macOS arm64
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
perf: defer vault indexing to background goroutine for instant MCP st…
perf: defer vault indexing to background goroutine for instant MCP st…