Repository navigation
Description
Summary
The queued-message dispatcher starts a turn before deleting its durable queued record. When turn admission succeeds but deleting the queue row fails (for example, a transient SQLite I/O or write error), the operation returns an error while the original queued submission remains available. At the next idle lifecycle event the dispatcher can start the same queued input again. This violates effectively-once delivery and can duplicate filesystem-changing tasks, tool calls, and model usage.
This is a non-security functional correctness bug affecting queue delivery under recoverable persistence failures.
Source evidence (main @ ae6c0c8ac164bdead234d8cdc794dbcdc5b37d28)
- Explicit
QueuedItemService::startstarts a core turn, then deletes the queue row only afterStarted. Ifdelete_lockedfails,?propagates the failure after the turn is already underway. - Automatic
dispatch_if_idlehas the same start-before-delete sequence, so a failed deletion returns before the durable record can be consumed. on_thread_idlesubsequently re-entersdispatch_if_idle; the surviving row is still the queue head.- The explicit queue-start RPC turns this post-admission deletion failure into an RPC error, even though the turn has already started.
There is no transactional consumed/in-flight marker or durable correspondence between the admitted turn_id and the queue row before executing the message.
Fault-injection reproduction
Source-confirmed; end-to-end runtime fault-injection not run.
- Create an idle, persistent thread and enqueue one user message, e.g.
make a single change to a file. - Use a fault-injecting
QueueStoreimplementation/SQLite test double that allowslist_pageandenqueue, but makes the nextdelete(thread_id, queued_item_id)return a storage error. - Trigger
thread/queue/startor let the idle extension automatically dispatch the item. - Observe that
start_turn_if_idlehas already admitted a turn, but the durable queue item remains. The explicit RPC reports an internal error even though execution has started. - Allow the first turn to complete and trigger the next normal idle callback. The leftover queue record is dispatched again as a second turn.
Actual vs expected
Actual: One queue item can cause multiple turn starts after a transient record-deletion failure; manual callers can also retry a request that falsely appeared to fail.
Expected: Once a queue message has been admitted for execution, a storage error must not make that same message eligible for a second execution. A start response should accurately distinguish admission success from cleanup failure.
Impact / severity
Proposed P1 — duplicate execution / unintended side effects. Queued prompts often request changes to real workspace files or invoke external services. A transient database fault must not turn a single accepted request into multiple executions or double usage. The failure may be especially confusing because the first execution happens despite a reported queue-start error.
Suggested resolution
- Introduce a durable
claimed/startedstate with a stable queue-item-to-turn-ID mapping before execution, or implement an equivalent atomic admission/delivery mechanism. - Make admission idempotent for the queue item/client message ID; retries should return/recover the existing turn instead of creating a new one.
- Separate the admission result from cleanup/reconciliation errors: once started, report the admitted turn; log and retry row cleanup without re-enabling execution.
- On resume/restart, reconcile claimed queue items with persisted turn history before any redelivery.
- Keep ordering/dispatch locks and failure reporting consistent across both
startanddispatch_if_idle.
Regression tests
- Queue delete fails once after
Started→ exactly one turn executes, including after first turn completion. - Same case through
thread/queue/start→ API does not incorrectly report a non-admission. - Repeated retry of the same client message ID → no second turn.
- Crash/restart between admission and cleanup → reconcile once without replaying the action.
- Failures before turn admission still preserve the row for safe future dispatch.
Environment: Source review of the pinned main commit. The described repro requires deliberate queue-storage fault injection; it has not been exercised against a live service.
Activity