Skip to content

[P1][Queue] A failed queue-row deletion after turn admission can execute the same queued message twice #63230

Open

Description

@dovvnloading

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)

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.

  1. Create an idle, persistent thread and enqueue one user message, e.g. make a single change to a file.
  2. Use a fault-injecting QueueStore implementation/SQLite test double that allows list_page and enqueue, but makes the next delete(thread_id, queued_item_id) return a storage error.
  3. Trigger thread/queue/start or let the idle extension automatically dispatch the item.
  4. Observe that start_turn_if_idle has already admitted a turn, but the durable queue item remains. The explicit RPC reports an internal error even though execution has started.
  5. 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

  1. Introduce a durable claimed/started state with a stable queue-item-to-turn-ID mapping before execution, or implement an equivalent atomic admission/delivery mechanism.
  2. Make admission idempotent for the queue item/client message ID; retries should return/recover the existing turn instead of creating a new one.
  3. Separate the admission result from cleanup/reconciliation errors: once started, report the admitted turn; log and retry row cleanup without re-enabling execution.
  4. On resume/restart, reconcile claimed queue items with persisted turn history before any redelivery.
  5. Keep ordering/dispatch locks and failure reporting consistent across both start and dispatch_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

  1. added
    bug
    app-server
    on Nov 23, 2026
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

    app-serverbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions