agent-refactor: shrink Agent, event-driven compaction/interrupt, scope ownership #88

Merged
jasoncouture merged 17 commits from agent-refactor into main 2026-05-17 01:37:52 -04:00
jasoncouture commented 2026-05-17 01:37:46 -04:00 (Migrated from github.com)

Summary

  • Shrink Agent / split responsibilities
    • Drop IAgent.Id, LockAsync/UnlockAsync, RequestCompactionAsync, InterruptAsync — IAgent's public surface is now just StartAsync.
    • Scope owns the agent: IAgent registered scoped, resolved via scope.ServiceProvider.GetRequiredService<IAgent>(), scope disposal cascades through IAsyncDisposable. AgentManager no longer disposes the agent directly.
    • AgentManager ctor sheds unused IProviderFactory and IContextStore.
  • Per-agent locking
    • IAgentLockManager (singleton) hands out per-agent SemaphoreSlim-backed ILockScopes with finalizer-safe release.
    • IAgentLock is a scoped passthrough that reads the agent id from the ambient IDataContextScope.
    • Agent's old SemaphoreSlim _processGate is gone — turn/compaction serialization rides IAgentLock.
  • Inference runner ownership
    • InferenceRunner injects ILanguageModel and ISystemPromptProvider; RunAsync drops model, eventId, correlationId, and emitTurns parameters.
    • PromptOptions carries SystemPromptTemplate (null = skip) and EmitTurns.
    • Runner reads event id / correlation id from the ambient AgentState; system-prompt rendering moves out of Agent and ContextCompactor into the runner.
  • ContextCompactor cleanup
    • CompactAsync drops ILanguageModel and ModelConfiguration parameters; configuration comes from the data scope, language model from the runner.
    • Compactor stops doing its own system-prompt insertion — runner handles it via SystemPromptTemplate: "COMPACTION.md".
  • Event-driven agent control
    • New command:* event source. command:compaction-request:<agentId> (payload AgentCompactionRequest with Force) and command:interrupt-agent:<agentId> (payload AgentInterruptRequest.Instance) replace direct method calls into the agent.
    • CompactionAgentService is a per-agent scoped service that subscribes to both the agent's Idle (normal pass) and CompactionRequest (forced per payload) events and dispatches to IContextCompactor. Agent itself knows nothing about compaction. EagerCompactor deleted.
    • Agent subscribes to command:interrupt-agent and cancels its active turn CTS; the old public InterruptAsync method is gone.
  • Misc API surface
    • LoopbackBearerHandler resolves the calling agent from IDataContextFactory.Current (drops ICurrentAgentAccessor, which is deleted entirely).
    • IAgentService introduced for agent-lifetime services; Agent ctor takes IEnumerable<IAgentService> and orchestrates Start/Stop around its run loop.
    • IAgentDirectory is frozen — RequestCompactionAsync / InterruptAsync are flagged [Obsolete] with migration pointers to the command events; do-not-extend note at the interface level.
  • Hygiene
    • Subscriptions stop interpolating EventType ($"{type}:{id}"); pass EventType with { Id = ... } and rely on the implicit string conversion. Wildcard (:+) is the only remaining exception.
    • AgentLifecycleMarker and AgentCompactionRequest (renamed from AgentCompactionMarker) get singleton Instance/Normal/Forced statics so callers stop allocating.

Test plan

  • dotnet build clean (warnings only on [Obsolete] callers, expected)
  • dotnet test — 519/519 pass
  • Manual: /compact slash command on a loaded agent still forces compaction
  • Manual: /interrupt slash command still cancels the active turn
  • Manual: idle agent eventually compacts on its own once the budget guard trips

🤖 Generated with Claude Code

## Summary - Shrink Agent / split responsibilities - Drop `IAgent.Id`, `LockAsync`/`UnlockAsync`, `RequestCompactionAsync`, `InterruptAsync` — IAgent's public surface is now just `StartAsync`. - Scope owns the agent: `IAgent` registered scoped, resolved via `scope.ServiceProvider.GetRequiredService<IAgent>()`, scope disposal cascades through `IAsyncDisposable`. `AgentManager` no longer disposes the agent directly. - `AgentManager` ctor sheds unused `IProviderFactory` and `IContextStore`. - Per-agent locking - `IAgentLockManager` (singleton) hands out per-agent `SemaphoreSlim`-backed `ILockScope`s with finalizer-safe release. - `IAgentLock` is a scoped passthrough that reads the agent id from the ambient `IDataContextScope`. - Agent's old `SemaphoreSlim` `_processGate` is gone — turn/compaction serialization rides `IAgentLock`. - Inference runner ownership - `InferenceRunner` injects `ILanguageModel` and `ISystemPromptProvider`; `RunAsync` drops `model`, `eventId`, `correlationId`, and `emitTurns` parameters. - `PromptOptions` carries `SystemPromptTemplate` (null = skip) and `EmitTurns`. - Runner reads event id / correlation id from the ambient `AgentState`; system-prompt rendering moves out of Agent and ContextCompactor into the runner. - ContextCompactor cleanup - `CompactAsync` drops `ILanguageModel` and `ModelConfiguration` parameters; configuration comes from the data scope, language model from the runner. - Compactor stops doing its own system-prompt insertion — runner handles it via `SystemPromptTemplate: "COMPACTION.md"`. - Event-driven agent control - New `command:*` event source. `command:compaction-request:<agentId>` (payload `AgentCompactionRequest` with `Force`) and `command:interrupt-agent:<agentId>` (payload `AgentInterruptRequest.Instance`) replace direct method calls into the agent. - `CompactionAgentService` is a per-agent scoped service that subscribes to both the agent's Idle (normal pass) and CompactionRequest (forced per payload) events and dispatches to `IContextCompactor`. Agent itself knows nothing about compaction. `EagerCompactor` deleted. - Agent subscribes to `command:interrupt-agent` and cancels its active turn CTS; the old public `InterruptAsync` method is gone. - Misc API surface - `LoopbackBearerHandler` resolves the calling agent from `IDataContextFactory.Current` (drops `ICurrentAgentAccessor`, which is deleted entirely). - `IAgentService` introduced for agent-lifetime services; Agent ctor takes `IEnumerable<IAgentService>` and orchestrates Start/Stop around its run loop. - `IAgentDirectory` is frozen — `RequestCompactionAsync` / `InterruptAsync` are flagged `[Obsolete]` with migration pointers to the command events; do-not-extend note at the interface level. - Hygiene - Subscriptions stop interpolating `EventType` (`$"{type}:{id}"`); pass `EventType with { Id = ... }` and rely on the implicit `string` conversion. Wildcard (`:+`) is the only remaining exception. - `AgentLifecycleMarker` and `AgentCompactionRequest` (renamed from `AgentCompactionMarker`) get singleton `Instance`/`Normal`/`Forced` statics so callers stop allocating. ## Test plan - [x] `dotnet build` clean (warnings only on `[Obsolete]` callers, expected) - [x] `dotnet test` — 519/519 pass - [ ] Manual: `/compact` slash command on a loaded agent still forces compaction - [ ] Manual: `/interrupt` slash command still cancels the active turn - [ ] Manual: idle agent eventually compacts on its own once the budget guard trips 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-05-17 01:39:29 -04:00 (Migrated from github.com)
Package Line Rate Branch Rate Complexity Health
LlamaShears.Core.Eventing 91% 84% 53
LlamaShears.Core.Abstractions 49% 34% 364
LlamaShears.Api 29% 30% 461
LlamaShears.Provider.Ollama 44% 28% 188
LlamaShears.Core.Eventing.Extensions 100% 100% 1
LlamaShears.Core 45% 41% 1385
LlamaShears.Provider.Onnx.Embeddings 37% 38% 72
LlamaShears.Provider.OpenAI 65% 65% 227
LlamaShears.Api.Web 1% 1% 428
LlamaShears.Hosting 33% 21% 27
LlamaShears.Plugins 0% 100% 1
LlamaShears.Core.Eventing 89% 75% 53
LlamaShears 52% 36% 25
LlamaShears.Plugins.Host 34% 24% 36
LlamaShears.Core.Abstractions 32% 14% 364
LlamaShears.Api 7% 1% 461
LlamaShears.Provider.Ollama 3% 1% 188
LlamaShears.Core.Eventing.Extensions 100% 100% 1
StrangeSoft.Plugins.Host 20% 21% 87
LlamaShears.Core 40% 27% 1385
LlamaShears.Provider.Onnx.Embeddings 3% 0% 72
LlamaShears.Provider.OpenAI 2% 0% 227
LlamaShears.Api.Web 21% 10% 428
LlamaShears.Hosting 26% 8% 27
LlamaShears.Plugins 0% 100% 1
LlamaShears.Core.Eventing 89% 75% 53
LlamaShears 52% 36% 25
LlamaShears.Plugins.Host 34% 24% 36
LlamaShears.Core.Abstractions 32% 14% 364
LlamaShears.IntegrationTests 85% 73% 72
LlamaShears.Api 9% 3% 461
LlamaShears.Provider.Ollama 3% 1% 188
LlamaShears.Core.Eventing.Extensions 100% 100% 1
StrangeSoft.Plugins.Host 20% 21% 87
LlamaShears.Core 41% 27% 1385
LlamaShears.Provider.Onnx.Embeddings 3% 0% 72
LlamaShears.Provider.OpenAI 2% 0% 227
LlamaShears.Api.Web 31% 17% 428
LlamaShears.Hosting 26% 8% 27
LlamaShears.Analyzers.CodeFixes 85% 69% 60
LlamaShears.Analyzers 88% 76% 199
Summary 46% (10652 / 31277) 36% (2314 / 9476) 10247
Package | Line Rate | Branch Rate | Complexity | Health -------- | --------- | ----------- | ---------- | ------ LlamaShears.Core.Eventing | 91% | 84% | 53 | ✔ LlamaShears.Core.Abstractions | 49% | 34% | 364 | ❌ LlamaShears.Api | 29% | 30% | 461 | ❌ LlamaShears.Provider.Ollama | 44% | 28% | 188 | ❌ LlamaShears.Core.Eventing.Extensions | 100% | 100% | 1 | ✔ LlamaShears.Core | 45% | 41% | 1385 | ❌ LlamaShears.Provider.Onnx.Embeddings | 37% | 38% | 72 | ❌ LlamaShears.Provider.OpenAI | 65% | 65% | 227 | ➖ LlamaShears.Api.Web | 1% | 1% | 428 | ❌ LlamaShears.Hosting | 33% | 21% | 27 | ❌ LlamaShears.Plugins | 0% | 100% | 1 | ❌ LlamaShears.Core.Eventing | 89% | 75% | 53 | ✔ LlamaShears | 52% | 36% | 25 | ➖ LlamaShears.Plugins.Host | 34% | 24% | 36 | ❌ LlamaShears.Core.Abstractions | 32% | 14% | 364 | ❌ LlamaShears.Api | 7% | 1% | 461 | ❌ LlamaShears.Provider.Ollama | 3% | 1% | 188 | ❌ LlamaShears.Core.Eventing.Extensions | 100% | 100% | 1 | ✔ StrangeSoft.Plugins.Host | 20% | 21% | 87 | ❌ LlamaShears.Core | 40% | 27% | 1385 | ❌ LlamaShears.Provider.Onnx.Embeddings | 3% | 0% | 72 | ❌ LlamaShears.Provider.OpenAI | 2% | 0% | 227 | ❌ LlamaShears.Api.Web | 21% | 10% | 428 | ❌ LlamaShears.Hosting | 26% | 8% | 27 | ❌ LlamaShears.Plugins | 0% | 100% | 1 | ❌ LlamaShears.Core.Eventing | 89% | 75% | 53 | ✔ LlamaShears | 52% | 36% | 25 | ➖ LlamaShears.Plugins.Host | 34% | 24% | 36 | ❌ LlamaShears.Core.Abstractions | 32% | 14% | 364 | ❌ LlamaShears.IntegrationTests | 85% | 73% | 72 | ✔ LlamaShears.Api | 9% | 3% | 461 | ❌ LlamaShears.Provider.Ollama | 3% | 1% | 188 | ❌ LlamaShears.Core.Eventing.Extensions | 100% | 100% | 1 | ✔ StrangeSoft.Plugins.Host | 20% | 21% | 87 | ❌ LlamaShears.Core | 41% | 27% | 1385 | ❌ LlamaShears.Provider.Onnx.Embeddings | 3% | 0% | 72 | ❌ LlamaShears.Provider.OpenAI | 2% | 0% | 227 | ❌ LlamaShears.Api.Web | 31% | 17% | 428 | ❌ LlamaShears.Hosting | 26% | 8% | 27 | ❌ LlamaShears.Analyzers.CodeFixes | 85% | 69% | 60 | ✔ LlamaShears.Analyzers | 88% | 76% | 199 | ✔ **Summary** | **46%** (10652 / 31277) | **36%** (2314 / 9476) | **10247** | ❌ <!-- Sticky Pull Request Commentcoverage -->
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-05-17 01:42:20 -04:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

This PR refactors agent ownership and control flow by shrinking IAgent, moving compaction/interrupt operations onto command events, and making inference/compaction use scoped dependencies and ambient agent state.

Changes:

  • Replaces direct agent lock/compaction/interrupt APIs with scoped IAgentLock/IAgentLockManager and command:* events.
  • Moves system prompt rendering/model ownership into InferenceRunner and updates compaction accordingly.
  • Updates API docs and tests for the new agent, compaction, event, and prompt option surfaces.

Reviewed changes

Copilot reviewed 58 out of 58 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/LlamaShears.UnitTests/Agent/Core/InferenceRunnerToolDispatchTests.cs Updates runner construction and RunAsync calls.
tests/LlamaShears.UnitTests/Agent/Core/ContextCompactorTests.cs Updates compactor tests for scoped model/config and runner-managed system prompt.
tests/LlamaShears.UnitTests/Agent/Core/CapturingTurnSubscriber.cs Uses typed event IDs for subscriptions.
tests/LlamaShears.UnitTests/Agent/Core/AgentTurnFlowTests.cs Updates agent test construction for new dependencies.
tests/LlamaShears.UnitTests/Agent/Core/AgentLoopTests.cs Updates loop tests for scoped runner/model and locks.
tests/LlamaShears.UnitTests/Agent/Core/AgentLockTests.cs Adds scoped agent lock tests.
tests/LlamaShears.UnitTests/Agent/Core/AgentLockManagerTests.cs Adds per-agent lock manager tests.
tests/LlamaShears.UnitTests/Agent/Core/AgentInterruptTests.cs Converts interrupt tests to command events.
tests/LlamaShears.UnitTests/Agent/Core/AgentInterruptGracefulTests.cs Converts graceful interrupt tests to command events/locks.
tests/LlamaShears.UnitTests/Agent/Core/AgentEventPublishingTests.cs Updates event publishing tests for new agent construction.
tests/LlamaShears.IntegrationTests/Hosting/IsolatedAppFactory.cs Uses typed loaded-event subscription.
src/public/LlamaShears.Core.Abstractions/Provider/PromptOptions.cs Adds turn emission and system prompt options.
src/public/LlamaShears.Core.Abstractions/Provider/IInferenceRunner.cs Simplifies runner API to ambient scoped state.
src/public/LlamaShears.Core.Abstractions/Events/Event.cs Adds command event source and well-known command events.
src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentLifecycleMarker.cs Adds singleton lifecycle marker instance.
src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentInterruptRequest.cs Adds interrupt command payload.
src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentCompactionRequest.cs Adds compaction command/lifecycle payload.
src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentCompactionMarker.cs Removes old compaction marker payload.
src/public/LlamaShears.Core.Abstractions/Context/IContextCompactor.cs Removes model/config parameters from compactor API.
src/public/LlamaShears.Core.Abstractions/Agent/ILockScope.cs Adds disposable lock scope abstraction.
src/public/LlamaShears.Core.Abstractions/Agent/IAgentService.cs Adds agent-lifetime service abstraction.
src/public/LlamaShears.Core.Abstractions/Agent/IAgentLockManager.cs Adds per-agent lock manager abstraction.
src/public/LlamaShears.Core.Abstractions/Agent/IAgentLock.cs Adds scoped agent lock abstraction.
src/public/LlamaShears.Core.Abstractions/Agent/IAgent.cs Shrinks public agent API to StartAsync.
src/LlamaShears.Core/Tools/ModelContextProtocol/LoopbackBearerHandler.cs Resolves agent info from ambient data scope.
src/LlamaShears.Core/Tools/ModelContextProtocol/ICurrentAgentAccessor.cs Removes old current-agent accessor interface.
src/LlamaShears.Core/Tools/ModelContextProtocol/CurrentAgentAccessor.cs Removes old AsyncLocal current-agent accessor.
src/LlamaShears.Core/InferenceRunner.cs Injects model/system prompt/data scope and reads ambient agent state.
src/LlamaShears.Core/EagerCompactor.cs Removes hosted eager compactor.
src/LlamaShears.Core/CoreServiceCollectionExtensions.cs Registers new scoped agent, lock, and compaction services.
src/LlamaShears.Core/ContextCompactor.cs Uses scoped config/model runner and command payloads.
src/LlamaShears.Core/CompactionAgentService.cs Adds per-agent event-driven compaction service.
src/LlamaShears.Core/AgentManager.cs Resolves scoped agent/services and delegates disposal to scope.
src/LlamaShears.Core/AgentLockManager.cs Implements per-agent semaphore lock manager.
src/LlamaShears.Core/AgentLock.cs Implements scoped ambient-agent lock wrapper.
src/LlamaShears.Core/Agent.cs Uses command interrupts, scoped locks, runner prompt options, and lifecycle events.
src/LlamaShears.Api/Web/AgentDirectory.cs Bridges legacy directory methods to command events.
src/LlamaShears.Api.Web/Services/IAgentDirectory.cs Marks legacy command methods obsolete.
src/LlamaShears.Api.Web/Services/ChatSession.cs Updates subscriptions and compaction payload type.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/PromptOptions.md Documents new prompt options.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/index.md Updates provider API index.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/IInferenceRunner.md Documents simplified runner API.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/WellKnown/index.md Adds command event docs link.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/WellKnown/Command.md Adds command event docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/Sources.md Documents command event source.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/index.md Updates agent event payload docs index.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentLifecycleMarker.md Documents lifecycle singleton.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentInterruptRequest.md Adds interrupt request docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentCompactionRequest.md Adds compaction request docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentCompactionMarker.md Removes old compaction marker docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Context/IContextCompactor.md Updates compactor signature docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/index.md Adds new agent lock/service docs links.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/ILockScope.md Adds lock scope docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentService.md Adds agent service docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentLockManager.md Adds lock manager docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentLock.md Adds scoped lock docs.
docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgent.md Updates shrunken agent docs.
docs/api/LlamaShears.Core.Abstractions/index.md Updates generated package index.
Comments suppressed due to low confidence (1)

src/LlamaShears.Core/ContextCompactor.cs:149

  • The compaction-finished event also drops the force value by publishing a default AgentCompactionRequest, so forced compactions are reported as normal completions. Reuse the same payload derived from the method's force argument for both started and finished events.
            await _eventPublisher.PublishAsync(
                Event.WellKnown.Agent.CompactingFinished with { Id = agentContext.AgentId },
                new AgentCompactionRequest(),
                CancellationToken.None);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview This PR refactors agent ownership and control flow by shrinking `IAgent`, moving compaction/interrupt operations onto command events, and making inference/compaction use scoped dependencies and ambient agent state. **Changes:** - Replaces direct agent lock/compaction/interrupt APIs with scoped `IAgentLock`/`IAgentLockManager` and `command:*` events. - Moves system prompt rendering/model ownership into `InferenceRunner` and updates compaction accordingly. - Updates API docs and tests for the new agent, compaction, event, and prompt option surfaces. ### Reviewed changes Copilot reviewed 58 out of 58 changed files in this pull request and generated 2 comments. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | `tests/LlamaShears.UnitTests/Agent/Core/InferenceRunnerToolDispatchTests.cs` | Updates runner construction and `RunAsync` calls. | | `tests/LlamaShears.UnitTests/Agent/Core/ContextCompactorTests.cs` | Updates compactor tests for scoped model/config and runner-managed system prompt. | | `tests/LlamaShears.UnitTests/Agent/Core/CapturingTurnSubscriber.cs` | Uses typed event IDs for subscriptions. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentTurnFlowTests.cs` | Updates agent test construction for new dependencies. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentLoopTests.cs` | Updates loop tests for scoped runner/model and locks. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentLockTests.cs` | Adds scoped agent lock tests. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentLockManagerTests.cs` | Adds per-agent lock manager tests. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentInterruptTests.cs` | Converts interrupt tests to command events. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentInterruptGracefulTests.cs` | Converts graceful interrupt tests to command events/locks. | | `tests/LlamaShears.UnitTests/Agent/Core/AgentEventPublishingTests.cs` | Updates event publishing tests for new agent construction. | | `tests/LlamaShears.IntegrationTests/Hosting/IsolatedAppFactory.cs` | Uses typed loaded-event subscription. | | `src/public/LlamaShears.Core.Abstractions/Provider/PromptOptions.cs` | Adds turn emission and system prompt options. | | `src/public/LlamaShears.Core.Abstractions/Provider/IInferenceRunner.cs` | Simplifies runner API to ambient scoped state. | | `src/public/LlamaShears.Core.Abstractions/Events/Event.cs` | Adds command event source and well-known command events. | | `src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentLifecycleMarker.cs` | Adds singleton lifecycle marker instance. | | `src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentInterruptRequest.cs` | Adds interrupt command payload. | | `src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentCompactionRequest.cs` | Adds compaction command/lifecycle payload. | | `src/public/LlamaShears.Core.Abstractions/Events/Agent/AgentCompactionMarker.cs` | Removes old compaction marker payload. | | `src/public/LlamaShears.Core.Abstractions/Context/IContextCompactor.cs` | Removes model/config parameters from compactor API. | | `src/public/LlamaShears.Core.Abstractions/Agent/ILockScope.cs` | Adds disposable lock scope abstraction. | | `src/public/LlamaShears.Core.Abstractions/Agent/IAgentService.cs` | Adds agent-lifetime service abstraction. | | `src/public/LlamaShears.Core.Abstractions/Agent/IAgentLockManager.cs` | Adds per-agent lock manager abstraction. | | `src/public/LlamaShears.Core.Abstractions/Agent/IAgentLock.cs` | Adds scoped agent lock abstraction. | | `src/public/LlamaShears.Core.Abstractions/Agent/IAgent.cs` | Shrinks public agent API to `StartAsync`. | | `src/LlamaShears.Core/Tools/ModelContextProtocol/LoopbackBearerHandler.cs` | Resolves agent info from ambient data scope. | | `src/LlamaShears.Core/Tools/ModelContextProtocol/ICurrentAgentAccessor.cs` | Removes old current-agent accessor interface. | | `src/LlamaShears.Core/Tools/ModelContextProtocol/CurrentAgentAccessor.cs` | Removes old AsyncLocal current-agent accessor. | | `src/LlamaShears.Core/InferenceRunner.cs` | Injects model/system prompt/data scope and reads ambient agent state. | | `src/LlamaShears.Core/EagerCompactor.cs` | Removes hosted eager compactor. | | `src/LlamaShears.Core/CoreServiceCollectionExtensions.cs` | Registers new scoped agent, lock, and compaction services. | | `src/LlamaShears.Core/ContextCompactor.cs` | Uses scoped config/model runner and command payloads. | | `src/LlamaShears.Core/CompactionAgentService.cs` | Adds per-agent event-driven compaction service. | | `src/LlamaShears.Core/AgentManager.cs` | Resolves scoped agent/services and delegates disposal to scope. | | `src/LlamaShears.Core/AgentLockManager.cs` | Implements per-agent semaphore lock manager. | | `src/LlamaShears.Core/AgentLock.cs` | Implements scoped ambient-agent lock wrapper. | | `src/LlamaShears.Core/Agent.cs` | Uses command interrupts, scoped locks, runner prompt options, and lifecycle events. | | `src/LlamaShears.Api/Web/AgentDirectory.cs` | Bridges legacy directory methods to command events. | | `src/LlamaShears.Api.Web/Services/IAgentDirectory.cs` | Marks legacy command methods obsolete. | | `src/LlamaShears.Api.Web/Services/ChatSession.cs` | Updates subscriptions and compaction payload type. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/PromptOptions.md` | Documents new prompt options. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/index.md` | Updates provider API index. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Provider/IInferenceRunner.md` | Documents simplified runner API. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/WellKnown/index.md` | Adds command event docs link. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/WellKnown/Command.md` | Adds command event docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Event/Sources.md` | Documents command event source. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/index.md` | Updates agent event payload docs index. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentLifecycleMarker.md` | Documents lifecycle singleton. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentInterruptRequest.md` | Adds interrupt request docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentCompactionRequest.md` | Adds compaction request docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Events/Agent/AgentCompactionMarker.md` | Removes old compaction marker docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Context/IContextCompactor.md` | Updates compactor signature docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/index.md` | Adds new agent lock/service docs links. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/ILockScope.md` | Adds lock scope docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentService.md` | Adds agent service docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentLockManager.md` | Adds lock manager docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgentLock.md` | Adds scoped lock docs. | | `docs/api/LlamaShears.Core.Abstractions/LlamaShears/Core/Abstractions/Agent/IAgent.md` | Updates shrunken agent docs. | | `docs/api/LlamaShears.Core.Abstractions/index.md` | Updates generated package index. | </details> <details> <summary>Comments suppressed due to low confidence (1)</summary> **src/LlamaShears.Core/ContextCompactor.cs:149** * The compaction-finished event also drops the `force` value by publishing a default `AgentCompactionRequest`, so forced compactions are reported as normal completions. Reuse the same payload derived from the method's `force` argument for both started and finished events. ``` await _eventPublisher.PublishAsync( Event.WellKnown.Agent.CompactingFinished with { Id = agentContext.AgentId }, new AgentCompactionRequest(), CancellationToken.None); ``` </details> --- 💡 <a href="/jasoncouture/llama-shears/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-05-17 01:42:19 -04:00

After publishing the Busy lifecycle event, isIdle remains true, so the next loop iteration never satisfies !_sessionQueue.HasQueuedMessages() && !isIdle and the Idle event is never emitted. That means CompactionAgentService never receives the normal idle compaction trigger; flip isIdle to false when the agent transitions to busy.

After publishing the Busy lifecycle event, `isIdle` remains `true`, so the next loop iteration never satisfies `!_sessionQueue.HasQueuedMessages() && !isIdle` and the Idle event is never emitted. That means `CompactionAgentService` never receives the normal idle compaction trigger; flip `isIdle` to `false` when the agent transitions to busy.
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-05-17 01:42:20 -04:00

The compaction-started event now uses AgentCompactionRequest as its payload, but this always publishes Force = false even when CompactAsync was invoked with force: true (for example from /compact). Publish the payload derived from the force argument so observers of the lifecycle event receive accurate compaction metadata.

This issue also appears on line 146 of the same file.

The compaction-started event now uses `AgentCompactionRequest` as its payload, but this always publishes `Force = false` even when `CompactAsync` was invoked with `force: true` (for example from `/compact`). Publish the payload derived from the `force` argument so observers of the lifecycle event receive accurate compaction metadata. This issue also appears on line 146 of the same file.
Sign in to join this conversation.
No description provided.