Skip to content

fix(llm): register LlmChatRunner in LLMAgent worker DI - #391

Merged
ModerRAS merged 1 commit into
masterfrom
fix/agent-worker-llmchatrunner-di
Sep 16, 2026
Merged

ModerRAS merged 1 commit into
masterfrom
fix/agent-worker-llmchatrunner-di

Conversation

@ModerRAS

@ModerRAS ModerRAS commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Symptom

Production log (2026-09-16) shows the agent worker process dying as soon as it picked up a task:

09:59:38 INF  主进程:LLMAgent <chat_id> <pid>已启动
09:59:46 DBG  ChunkPollingService: tracking task <task_id>...
09:59:48 INF  [主进程:LLMAgent <chat_id> <pid>] exited with code -532462766   # 0xE0434352 = unhandled CLR exception
10:00:50 WRN  Recovering LLM agent session for chat <chat_id>: heartbeat timeout

Every LLM chat in agent-process mode was dead until recovery, and recovery could not succeed either.

Root cause

The Phase 4.5 rewrite replaced the five provider services with LlmChatRunner, and LlmServiceProxy was updated to resolve it:

// TelegramSearchBot.LLMAgent/Service/LlmServiceProxy.cs
_chatRunner = serviceProvider.GetRequiredService<LlmChatRunner>();

The worker builds its own DI container manually (LLMAgentProgram.BuildServices) and was only updated for the renamed provider-API classes (OpenAiModelApi …), not for the newly introduced LlmChatRunner / LlmProviderRegistry. Constructing the executor therefore throws

InvalidOperationException: No service for type 'TelegramSearchBot.Service.AI.LLM.LlmChatRunner' has been registered.

and because AgentLoopService.ProcessTaskAsync resolves the executor outside its try, the exception escapes RunAsync and kills the worker process.

CI stayed green because the only worker-DI test asserted that ResponsesModelApi still resolves.

Fix

  • Register LlmProviderRegistry and LlmChatRunner (singletons, matching the main-process DI scan lifetimes) in LLMAgentProgram.BuildServices.
  • Add regression test BuildServices_RegistersAgentTaskExecutor, which resolves IAgentTaskExecutor (constructs LlmServiceProxy → LlmChatRunner). Fails before the fix, passes after.

Validation

  • dotnet build TelegramSearchBot.sln -c Release → 0 errors
  • dotnet test TelegramSearchBot.LLM.Test → 267/267 passed
  • dotnet test TelegramSearchBot.Test → 445 passed, 1 skipped (pre-existing skip)

LlmServiceProxy resolves LlmChatRunner in its constructor, but the worker's
manual DI list was not updated when the five provider services were deleted
in the LLM rewrite. Every agent task therefore killed the worker process
with an unhandled InvalidOperationException (exit code 0xE0434352) and the
chat session stalled until heartbeat-timeout recovery.

- Add LlmProviderRegistry + LlmChatRunner (singleton, same as the main
  process DI scan) to LLMAgentProgram.BuildServices
- Add regression test resolving IAgentTaskExecutor, which constructs
  LlmServiceProxy and would have caught the missing registration
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 16999324-f1e4-4835-b336-121efc400839


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

PR Check Report

Summary

Test Results

Platform Status Details
Ubuntu Passed Tests passed, artifacts uploaded
Windows Passed Tests passed, artifacts uploaded

Code Quality

  • Code formatting check
  • Security vulnerability scan
  • Dependency analysis
  • Code coverage collection

Test Artifacts

  • Test results artifacts count: 2
  • Code coverage uploaded to Codecov

Links


This report is auto-generated by GitHub Actions

@ModerRAS
ModerRAS merged commit 40f7417 into master Sep 16, 2026
5 checks passed
@ModerRAS
ModerRAS deleted the fix/agent-worker-llmchatrunner-di branch September 16, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant