Repository navigation
Description
Summary
When a queued Agent turn fails, the execution chain correctly stops and leaves later queued messages pending for explicit retry. However, a newly submitted message can start a fresh turn and execute ahead of those older queued messages. The execution order can therefore diverge from the persisted submission order.
This is a FIFO/admission consistency bug, not a request to automatically continue a failed chain.
Existing queue semantics
Issue #379 explicitly defines the intended behavior:
- A failed turn stops the chain and keeps the queue intact for an explicit retry.
- Automatic continuation after an error is not allowed.
- After process restart, queued messages remain persisted and are offered for continuation rather than replayed automatically.
- Stop is different: it cancels the running chain's queued messages and exposes them for resend.
This issue should preserve those semantics.
Reproduction
A deterministic probe on clean upstream main reproduced:
- Start message
一. - While it is running, queue
二. - Make the first turn fail.
- Submit a new direct message
三. - Observe that
三executes before the older queued message二.
Observed execution order: 一、三、二.
Persisted submission order: 一、二、三.
The older queued message remains pending after the failed chain, but a later direct submission can bypass it. The same stranded-queue condition can follow a finish-persistence failure that leaves the turn interrupted, as covered by #502.
Expected behavior
- Preserve [feat] assistant: accept a follow-up message while a turn is still running / 运行中插入补充消息 #379's failure semantics: a failed turn stops the chain; older queued messages are retained for explicit retry, not silently cancelled or automatically executed.
- A newer direct message must not execute ahead of an older pending queued message.
- The system must make the pending-queue state explicit and provide a consistent admission behavior: either require the user to resolve/resume/cancel the older queue before a new direct turn, or append new input behind the pending queue while keeping execution paused until explicit continuation.
- Explicit retry resumes messages in original submission order.
- Process restart must not silently replay pending work.
- Stop cancellation and resend semantics remain unchanged.
- Preserve message idempotency, admission-lock guarantees, and single-run execution.
The implementation should follow existing #379 contracts and avoid introducing an implicit auto-retry or automatic side-effect replay.
Suggested regression tests
- A failed first turn with one queued message, followed by a new direct submission: the new message must not execute first.
- Multiple queued messages followed by a later submission: order remains FIFO after explicit continuation.
- Explicit retry dispatches pending messages in original order.
- Restart with pending messages does not automatically execute them.
- Stop/cancel behavior remains distinct from failure retention.
- Duplicate message IDs remain idempotent.
- Persistence failure/interrupted finish follows the same pending-queue ordering rules.
Scope
This issue covers queue admission and ordering after a failed chain. It does not change the context-boundary fix in #518 / PR #519.
Related: #379 (queue contract), #502 (failed finish persistence), #509 (empty-dispatch lease), #518 (queued-turn context boundary).
Activity