You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No execution deadline on tool calls (and why Promise.race won't work) #2
There is no execution deadline on MCP tool calls. A pathological call has no upper bound on how long it occupies the server.
Why a simple async wrapper does not work
The obvious fix — Promise.race([handler(), timeout]) — cannot work for our handlers, and it is worth recording why so nobody tries it.
Our vault and DB operations are synchronous: fs.readFileSync, better-sqlite3. While a synchronous handler runs, Node's event loop is blocked, so the setTimeout backing the race can never fire. The timeout only resolves after the work completes, which is exactly when it is no longer useful.
Options
Pre-flight bounds (largely done). Size caps, pagination, read windows, walk-depth limits — prevent long operations rather than interrupting them. This is the current defence and covers the known hot paths.
Chunked async. Yield to the event loop periodically (as indexer.rebuild() now does), which makes a deadline enforceable between chunks. Requires rewriting each path individually.
Worker threads. Move vault/DB work off the main thread and kill the worker on timeout. Real isolation, but needs a separate SQLite connection per worker and significant restructuring — likely overkill for a single-user server.
Instrument first. Log per-tool duration and only chunk what actually shows up as slow.
Recommendation
Do (4), then (2) for anything it flags. The remaining synchronous work (listNotes tree walk, resolveAllLinks) measures in milliseconds on a 2,600-note vault, so there is currently no evidence justifying worker threads.
MCP tool calls are request/response: the client blocks on a result, so moving the work to a queue only changes where it waits. Progress notifications report on work in flight; they do not let the server abandon it.
And the deadline is not really blocked by the protocol — it is blocked by our handlers being synchronous (fs.readFileSync, better-sqlite3). While one runs, nothing else in the process executes, including the timer meant to interrupt it. That leaves chunk-and-yield per handler, or worker threads with a killable child, both of which are substantial for a single-user server whose remaining synchronous work measures in milliseconds across 2,600 notes.
Activity
Add latency instrumentation; read_attachment refuses markdown
wiverson commentedon Aug 6, 2026
Closing as won't fix, pending a protocol change.
MCP tool calls are request/response: the client blocks on a result, so moving the work to a queue only changes where it waits. Progress notifications report on work in flight; they do not let the server abandon it.
And the deadline is not really blocked by the protocol — it is blocked by our handlers being synchronous (
fs.readFileSync,better-sqlite3). While one runs, nothing else in the process executes, including the timer meant to interrupt it. That leaves chunk-and-yield per handler, or worker threads with a killable child, both of which are substantial for a single-user server whose remaining synchronous work measures in milliseconds across 2,600 notes.Current defence stays: pre-flight bounds — size caps, pagination, read windows, walk-depth limits.
Reopen if MCP grows an async/callback tool-call shape, or if instrumentation shows a handler that actually runs long.