google-gemini/gemini-cli · error · Error

Agent executor not found in context.

Error message

Agent executor not found in context.

What it means

Thrown by InitCommand.handleSubmitPromptResult when context.agentExecutor is falsy. The /init command's submit_prompt branch needs to drive the full agent loop (agentExecutor.execute) to generate GEMINI.md, so it requires a CoderAgentExecutor in the CommandContext. Without it the command cannot run.

Source

Thrown at packages/a2a-server/src/commands/init.ts:86

    eventBus.publish(event);
    return {
      name: this.name,
      data: result,
    };
  }

  private async handleSubmitPromptResult(
    result: { content: unknown },
    context: CommandContext,
    geminiMdPath: string,
    eventBus: ExecutionEventBus,
    taskId: string,
    contextId: string,
  ): Promise<CommandExecutionResponse> {
    fs.writeFileSync(geminiMdPath, '', 'utf8');

    if (!context.agentExecutor) {
      throw new Error('Agent executor not found in context.');
    }
    // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
    const agentExecutor = context.agentExecutor as CoderAgentExecutor;

    const agentSettings: AgentSettings = {
      kind: CoderAgentEvent.StateAgentSettingsEvent,
      workspacePath: process.env['CODER_AGENT_WORKSPACE_PATH']!,
      autoExecute: true,
    };

    if (typeof result.content !== 'string') {
      throw new Error('Init command content must be a string.');
    }
    const promptText = result.content;

    const requestContext: RequestContext = {
      userMessage: {
        kind: 'message',

View on GitHub (pinned to 5024443c72)

Solutions

  1. Ensure the CommandContext passed to InitCommand.execute has agentExecutor set to a CoderAgentExecutor instance before invocation.
  2. If running in a context where agentic generation is unavailable, route to the 'message' branch instead of submit_prompt (e.g. pre-create GEMINI.md so performInit returns a message).
  3. In tests, populate context.agentExecutor with a mock executor that implements execute().
  4. Gate the /init command behind a check that the server is fully bootstrapped.

Example fix

// before
if (!context.agentExecutor) {
  throw new Error('Agent executor not found in context.');
}

// after (fail fast at command registration)
execute(context) {
  if (!context.agentExecutor) {
    return { name: this.name, data: 'Init unavailable: agent executor not initialized.' };
  }
  ...
}
Defensive patterns

Strategy: validation

Validate before calling

function canRunInit(context: CommandContext): boolean {
  return !!context.agentExecutor;
}
if (!canRunInit(context)) {
  return { name: 'init', data: 'Agent executor unavailable; cannot generate GEMINI.md.' };
}

Type guard

function hasAgentExecutor(c: CommandContext): c is CommandContext & { agentExecutor: NonNullable<CommandContext['agentExecutor']> } {
  return !!c.agentExecutor;
}

Prevention

When it happens

Trigger: Invoking the /init command via a code path that constructs CommandContext without populating agentExecutor - e.g. a test harness, an alternative command dispatcher, or a miswired server bootstrap that omits the executor.

Common situations: Running InitCommand.execute from a unit test with a stub context; refactoring the server to add a second command router that forgets to inject agentExecutor; calling /init before the CoderAgentExecutor is initialized.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/f79f2306d7cf73f2. Report an issue: GitHub.