Skip to content

Bug: steering injection pulls from Queue-immediacy items; DefaultInputQueue should default to Immediate #49

Closed

Description

@JoshuaRowePhantom

Two related bugs

Bug 1 — ToolResultSteeringMiddleware drains Queue-immediacy items it should not touch

ToolResultSteeringMiddleware.InjectQueuedIfToolResult currently calls:

while (this.queueManager.TryDequeueNextImmediateOrQueued(out var item))

TryDequeueNextImmediateOrQueued consumes items from both Immediate and Queue-immediacy queues. Steering injection at a tool-result boundary should only ever pull Immediate items. Queue-immediacy items are semantically "hold this until the current run completes and submit as the next independent turn"; pulling them mid-run via the steering path bypasses that intent.

The correct call is the already-existing method:

while (this.queueManager.TryDequeueNextImmediate(out var item))

Affected file: Phantom.Workspaces.Llm.Core/ToolResultSteeringMiddleware.cs (line 82)


Bug 2 — DefaultInputQueue is created with Immediacy = Queue instead of Immediate

In AgentChatQueueManager:

var defaultQueue = new AgentInputQueue(
    new AgentInputQueue.Parameters
    {
        Priority = int.MaxValue - 1,
        Immediacy = AgentInputQueueImmediacy.Queue,   // ← wrong
    });

Normal user text typed into the chat input goes to DefaultInputQueue (via AgentChat.EnqueueUserMessage → DefaultInputQueue). The expected UX is that a message sent while the agent is in the middle of a tool loop gets injected at the next tool-result boundary as steering — i.e., Immediate semantics. With Queue semantics it would not be consumed by TryDequeueNextImmediate at all (and after fixing Bug 1, it also would not be consumed by steering injection even with the old TryDequeueNextImmediateOrQueued).

Fix: change the default immediacy to Immediate:

Immediacy = AgentInputQueueImmediacy.Immediate,

Users who want to explicitly hold a message until the current run finishes can use a Queue- or Held-immediacy queue explicitly; that should not be the default.


Summary of fix

File Change
Phantom.Workspaces.Llm.Core/ToolResultSteeringMiddleware.cs TryDequeueNextImmediateOrQueued → TryDequeueNextImmediate
Phantom.Workspaces.Llm.Core/AgentChatQueueManager.cs DefaultInputQueue immediacy Queue → Immediate

AgentInputQueueManager.TryDequeueNextImmediate already exists and is the correct method — no new API is needed.

Activity

  1. JoshuaRowePhantom commented on Jun 25, 2026

    @JoshuaRowePhantom
    OwnerAuthor

    Fixed in commit 83187c5: DefaultInputQueue now uses Immediate immediacy; ToolResultSteeringMiddleware.InjectQueuedIfToolResult now calls TryDequeueNextImmediate to only inject Immediate-immediacy items at tool boundaries.

  2. added 2 commits that reference this issue on Jun 25, 2026
    83187c5
    5958463
  3. JoshuaRowePhantom commented on Jun 30, 2026

    @JoshuaRowePhantom
    OwnerAuthor

    Verification passed

    Checked: Commit 83187c5 ("Fix steering queue immediacy bugs") on the \ eatures\ branch, files:

    • \Phantom.Workspaces.Llm.Core/ToolResultSteeringMiddleware.cs\
    • \Phantom.Workspaces.Llm.Core/AgentChatQueueManager.cs\
    • \Phantom.Workspaces.Llm.Core.Tests/ToolResultSteeringMiddlewareTests.cs\
    • \Phantom.Workspaces.Llm.Core.Tests/AgentChatTests.cs\

    Result: Implementation found, all verification criteria satisfied, tests present and green.

    Bug 1 — \ToolResultSteeringMiddleware.InjectQueuedIfToolResult\ now calls \TryDequeueNextImmediate\ (not \TryDequeueNextImmediateOrQueued), so Queue-immediacy items are not consumed at tool-result boundaries. Covered by new test \QueueImmediacy_ItemsNotInjected_AtToolBoundary.

    Bug 2 — \DefaultInputQueue\ is now created with \Immediacy = AgentInputQueueImmediacy.Immediate. Covered by updated test \Constructor_DefaultQueueStartsImmediate_AndImmediateQueueStartsImmediate\ in \AgentChatTests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingverifiedIssue has been verified

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions