Skip to content

[bugfix] assistant: bound queued-turn context to the dispatched user message - #519

Draft
yefuyou wants to merge 1 commit into
ThinkFlowLab:mainfrom
yefuyou:fix/queued-turn-context
Draft

yefuyou wants to merge 1 commit into
ThinkFlowLab:mainfrom
yefuyou:fix/queued-turn-context

Conversation

@yefuyou

@yefuyou yefuyou commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #518

Summary

Fix queued Agent turns receiving future queued messages or the active empty assistant placeholder as part of their prompt.

The context boundary is now determined by the identity of the user message being dispatched, rather than by assuming the active streaming placeholder is the final item in the persisted conversation message array.

Root cause

For directly submitted turns, begin() appends the user message and streaming assistant placeholder at the end, so tail-relative slicing happens to work.

For queued turns, dispatch() inserts the placeholder immediately after the selected queued user message while later queued user messages remain after it. The old saved['messages'][:-1] / [:-2] logic and last-message preference attachment therefore used the wrong boundary. In a multi-message queue, the current turn could see a future user message, or an empty assistant placeholder, and attach the current preference instruction to the wrong message.

Change

  • Locate the current dispatched user message by its message ID.
  • Build the context through that message, inclusive.
  • Preserve the existing message order and history without broad filtering or reordering.
  • Ensure the current turn's preference instruction is associated with its own user message.
  • Keep the change limited to context construction; no scheduler or queue-state redesign.

Tests and evidence

  • Added 10 deterministic regression tests in test_assistant_queued_context.py.
  • Tests use event barriers rather than sleeps and assert the actual messages received by the runtime.
  • Three regression tests fail on clean-main baseline 2e5cb380.
  • Fixed tests pass 10/10 across 10 repeated runs.
  • Five mutation variants of the incorrect implementation are each detected.
  • Related assistant/agent tests: 161 passed, 13 skipped.
  • Full CPU suite: 3,021 passed; one intermittent test_creation_storage...[in_place] failure also occurs on clean main and is treated as a pre-existing flaky failure.
  • lint-imports: all four contracts preserved.
  • Independent review: PASS.
  • No paid provider calls.

Scope

This PR fixes queued-turn context boundaries only. It does not change what happens to queued messages after a runtime/persistence failure, or the treatment of queued messages cancelled by Stop; those require separate lifecycle/product decisions.

Related: #379, #502, #509, #476.

This branch has not been deployed

No deployments
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.

[bug] assistant: bound queued-turn context to the dispatched user message

2 participants