Skip to content

Turn finalized prematurely while agent waits on a background task (WaitFor) — final assistant message silently dropped from thread history #8479

Backlog

Description

@ilya1211-bit

Turn finalized prematurely while agent was inside WaitFor for a background task — tail of the turn (final assistant message, file writes) silently dropped from thread history

bb version: 0.50.1 (CLI), Linux
Provider: acp-kimi-code (Kimi Code CLI via ACP)
Date observed: 2026-12-01, ~15:26–15:29 UTC

Summary

A turn was closed with turn/completed (status completed) ~1.5 s after a WaitFor tool call returned (the waited-on background task had just finished). The provider session, however, kept running: it read the task output, executed four file writes, and produced the turn's final assistant message. All of that arrived after turn/completed and was recorded only as provider/unhandled events (for the file writes) or not recorded at all (for the final assistant message). The user never saw the final message; the agent's own session context still contains it, so on the next turn the agent believed the user had read it. In our case this caused the agent to interpret the user's next message ("continue") as consent to a proposal the user had never seen.

Expected behavior

The turn stays open until the agent actually finishes (stop reason from the provider), and the final assistant message plus all tool calls are persisted to the thread log and shown in the UI.

Actual behavior

turn/completed is emitted immediately after the WaitFor tool call resolves (right when the background task it was waiting on completes). Everything the agent does afterwards in the same provider session is orphaned: file writes show up as provider/unhandled (acp/fs/write), and the final assistant message is lost entirely — it is absent from bb thread log --format json and from the UI.

Evidence (from bb thread log <id> --format json --all, 571 events)

Event type counts include turn/started: 5 but turn/completed: 4 (the currently running turn aside, the anomaly is inside turn 1, which does have a turn/completed — see below).

Turn 1 timeline (seq = event sequence number in the thread log):

seq time (UTC) event
504 15:26:48.162 item/started — toolCall (the agent's WaitFor on background task bash-liz154j3)
505–507 15:26:48.162–.763 item/toolCall/progress; background commandExecution completes; item/completed for the WaitFor tool call
509 15:26:50.229 turn/completed {"status": "completed"} — turn closed
511 15:27:55.722 provider/unhandled acp/fs/write → <workspace>/servers/<host-id>/README.md
512 15:28:16.349 provider/unhandled acp/fs/write → <workspace>/servers/<host-id>/audit-2026-12-01.md
513 15:28:22.842 provider/unhandled acp/fs/write → <workspace>/README.md
514 15:28:33.735 provider/unhandled acp/fs/write → <workspace>/servers/<host-id>/README.md
515 15:28:41.467 client/turn/requested — the user's next message ("continue")
516 15:28:41.727 turn/started (turn 2)

Additional facts:

  • The last agentMessage item persisted for turn 1 is a mid-turn progress note (seq 345–347). No agentMessage item exists after seq 347 for turn 1, even though the provider session demonstrably kept producing output (the file writes above, and the final message the agent later quoted verbatim from its own context).
  • The four acp/fs/write calls and the final message correspond to real work: the written files exist on disk with the expected content, so the tool calls executed — they were only dropped from the thread record.
  • The UI showed the turn as finished with "1 background task still running" attached to it.
  • Side symptom: the thread's TODO extension state (thread/extensionState/updated, only 2 events in the whole log) is stale — updates made after the premature close were lost too; bb status still shows the mid-turn todo list.
  • Subsequent turns (2–5) on the same thread ran and completed normally.

Hypothesis

Race in the turn lifecycle handling of acp-kimi-code provider events: completion of a background task while the agent is blocked in the WaitFor tool resolves the tool call and then finalizes the turn (as if the agent had emitted its stop reason), instead of waiting for the provider's actual end-of-turn. Events the provider session emits afterwards are treated as unhandled because the turn (and possibly the event-routing scope) is already closed.

The exact trigger condition is our reconstruction; the premature turn/completed at seq 509 and the orphaned post-close events are directly proven by the log above.

Impact

Silent loss of the turn's final assistant message. The agent's session context and the thread history diverge: the agent believes the user saw its last message, the user never did. Any user reply is then interpreted against a message that was never delivered — in our case the agent performed configuration changes on a production server treating "continue" as approval of a proposal the user had never seen.

Reproduction sketch (not minimal, from the incident)

  1. Provider: acp-kimi-code. During a turn, start a long-running background task (Bash with run_in_background=true).
  2. Call the WaitFor tool on that background task so the task completes while the agent is inside WaitFor.
  3. Observe: turn/completed is emitted right after the WaitFor tool result; the agent's subsequent output (final message, further tool calls) lands as provider/unhandled or is dropped.

We did not attempt a controlled reproduction; the analysis above is from the incident's event log.

Attachments available on request

  • Full JSON event log of the affected thread (571 events; we can share it with personal paths/hosts redacted).

Activity

  1. added theissue type on Dec 1, 2026
  2. added
    providers
    threads
    provider-acp
    partial-repro
    on Dec 1, 2026
  3. bb-slop-cop commented on Dec 1, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Medium. Applied missing classifications and providers, threads, provider-acp; reproduction label: partial-repro.
    • Report: https://get-bb.github.io/reports/issues/8479.html
    • Verdict: PARTIALLY REPRODUCED. Confidence is low for the incident's root cause, high for the filesystem-history subset.
    • Verified cause: filesystem requests made while no turn is open execute, but their file-change items fall back to provider/unhandled. Two clean trusted-main checkouts reproduce four such writes after an explicitly simulated provider stop. The held-prompt control stays open after task completion; final messages survive both cases. The report embeds the repeatable diagnostic and its expected failure. All 642 existing owner tests pass.
    • No PR: the reported premature completion and missing final reply were not reproduced, so an incident fix would be speculative. A redacted ACP wire trace around the prompt response and late output is the next useful evidence.

    AGENT GENERATED

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

    partial-reproprovider-acpprovidersthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions