@cachly-dev/mcp-server 0.9.13 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9091,6 +9091,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }))
9091
9091
  // session_start/session_end manually.
9092
9092
  let _autoSessionInstanceId = null;
9093
9093
  let _autoSessionStarted = false;
9094
+ let _autoSessionStarting = null; // guard against double-start race
9094
9095
  let _autoSessionToolCount = 0;
9095
9096
  // ── brain_from_git concurrency limiter ────────────────────────────────────────
9096
9097
  // Spawning many `git log` subprocesses in parallel can fork-bomb the host.
@@ -9117,12 +9118,21 @@ function _gitSemRelease() {
9117
9118
  async function autoStartSession(instanceId) {
9118
9119
  if (_autoSessionStarted)
9119
9120
  return;
9120
- _autoSessionStarted = true;
9121
- _autoSessionInstanceId = instanceId;
9122
- try {
9123
- await handleTool('session_start', { instance_id: instanceId, focus: 'auto (MCP session)' });
9121
+ // If another call already started the session, await it instead of double-starting.
9122
+ if (_autoSessionStarting) {
9123
+ await _autoSessionStarting;
9124
+ return;
9124
9125
  }
9125
- catch { /* non-fatal — session tracking is a best-effort feature */ }
9126
+ _autoSessionStarting = (async () => {
9127
+ _autoSessionStarted = true;
9128
+ _autoSessionInstanceId = instanceId;
9129
+ try {
9130
+ await handleTool('session_start', { instance_id: instanceId, focus: 'auto (MCP session)' });
9131
+ }
9132
+ catch { /* non-fatal — session tracking is a best-effort feature */ }
9133
+ _autoSessionStarting = null;
9134
+ })();
9135
+ await _autoSessionStarting;
9126
9136
  // Auto-index the project if it hasn't been indexed in the last 24h.
9127
9137
  // This is the main lever for growing token savings: more indexed code →
9128
9138
  // more semantic cache hits → fewer LLM calls for repeated questions.
@@ -9167,12 +9177,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
9167
9177
  // Auto-start brain session on first tool call that has an instance_id.
9168
9178
  // Skip session management tools to avoid recursion.
9169
9179
  const sessionTools = new Set(['session_start', 'session_end', 'auto_learn_session']);
9170
- if (!sessionTools.has(name) && !_autoSessionStarted) {
9180
+ if (!sessionTools.has(name) && !_autoSessionStarted && !_autoSessionStarting) {
9171
9181
  const instanceId = args?.instance_id;
9172
9182
  if (instanceId) {
9173
9183
  await autoStartSession(instanceId).catch(() => undefined);
9174
9184
  }
9175
9185
  }
9186
+ else if (_autoSessionStarting) {
9187
+ // Another concurrent call is mid-start — wait for it before proceeding.
9188
+ await _autoSessionStarting.catch(() => undefined);
9189
+ }
9176
9190
  if (!sessionTools.has(name))
9177
9191
  _autoSessionToolCount++;
9178
9192
  try {