Revert "perf(core): correctly parallelize tool discovery dependencies and defer git service"

This commit is contained in:
Sehoon Shon
2026-03-23 21:57:08 -04:00
parent c4fbf12554
commit 9dca02209f
+16 -30
View File
@@ -1288,15 +1288,18 @@ export class Config implements McpContext, AgentLoopContext {
// Initialize centralized FileDiscoveryService
const discoverToolsHandle = startupProfiler.start('discover_tools');
this.getFileService();
if (this.getCheckpointingEnabled()) {
await this.getGitService();
}
this._promptRegistry = new PromptRegistry();
this._resourceRegistry = new ResourceRegistry();
this.agentRegistry = new AgentRegistry(this);
const agentInitPromise = this.agentRegistry.initialize();
await this.agentRegistry.initialize();
coreEvents.on(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed);
this._toolRegistry = await this.createToolRegistry(agentInitPromise);
this._toolRegistry = await this.createToolRegistry();
discoverToolsHandle?.end();
this.mcpClientManager = new McpClientManager(
this.clientVersion,
@@ -3154,33 +3157,13 @@ export class Config implements McpContext, AgentLoopContext {
);
}
async createToolRegistry(
agentInitPromise: Promise<void> = Promise.resolve(),
): Promise<ToolRegistry> {
async createToolRegistry(): Promise<ToolRegistry> {
const registry = new ToolRegistry(
this,
this.messageBus,
/* isMainRegistry= */ true,
);
// 1. Kick off concurrent background checks and external processes
const discoverAllToolsPromise = registry.discoverAllTools();
const useRipgrepPromise = this.getUseRipgrep()
? canUseRipgrep()
.then((res) => ({ useRipgrep: res, errorString: undefined }))
.catch((error: unknown) => ({
useRipgrep: false,
errorString: String(error),
}))
: Promise.resolve({ useRipgrep: false, errorString: undefined });
// 2. Synchronize all heavy operations before registering dependent tools
const [_, rgResult] = await Promise.all([
agentInitPromise,
useRipgrepPromise,
discoverAllToolsPromise,
]);
// helper to create & register core tools that are enabled
const maybeRegister = (
toolClass: { name: string; Name?: string },
@@ -3216,17 +3199,19 @@ export class Config implements McpContext, AgentLoopContext {
);
if (this.getUseRipgrep()) {
if (rgResult.useRipgrep) {
let useRipgrep = false;
let errorString: undefined | string = undefined;
try {
useRipgrep = await canUseRipgrep();
} catch (error: unknown) {
errorString = String(error);
}
if (useRipgrep) {
maybeRegister(RipGrepTool, () =>
registry.registerTool(new RipGrepTool(this, this.messageBus)),
);
} else {
if (rgResult.errorString !== undefined) {
logRipgrepFallback(
this,
new RipgrepFallbackEvent(rgResult.errorString),
);
}
logRipgrepFallback(this, new RipgrepFallbackEvent(errorString));
maybeRegister(GrepTool, () =>
registry.registerTool(new GrepTool(this, this.messageBus)),
);
@@ -3306,6 +3291,7 @@ export class Config implements McpContext, AgentLoopContext {
// Register Subagents as Tools
this.registerSubAgentTools(registry);
await registry.discoverAllTools();
registry.sortTools();
return registry;
}