Skip to content

Queue insertion accepts messages after a thread is archived or deleted #8262

Description

@mistakeknot

Summary

The database queue insert accepts a message for a thread that has already been archived or soft-deleted. A caller holding an earlier thread snapshot can therefore persist new queued work after retirement. The queue insert should reject it atomically, and an API caller should receive a conflict response.

Versions and environment

From source at b0ddaad. Linux 6.8, Node v22.23.4, pnpm 9.15.0. This is a unit-level reproduction using a migrated database fixture; no provider session or provider CLI is started. No desktop or live HTTP race reproduction is claimed.

Steps to reproduce

  1. In a dependency-equipped source checkout at the commit above, open packages/db/test/data/queued-thread-messages.test.ts. Add archiveThread and deleteThread to the existing import from ../../src/data/threads.js.
  2. Add this test inside the existing describe block, reusing setup, queueTurnEndMessage and defaultInput already defined in that file:
it.each([archiveThread, deleteThread])(
  "does not insert after thread retirement",
  (retire) => {
    const { db, thread } = setup();
    retire(db, noopNotifier, thread.id);
    expect(() => queueTurnEndMessage(db, thread.id, defaultInput)).toThrow();
    expect(listQueuedThreadMessages(db, thread.id)).toEqual([]);
  },
);
  1. From packages/db, run:
pnpm exec vitest run test/data/queued-thread-messages.test.ts --maxWorkers=2

This isolates the final queue-write boundary; it does not require racing a UI action or relying on a provider timeout.

Expected vs actual

Expected: both retired states reject insertion and leave no queued row or queue-change notification. If a delayed API send reaches this refusal, return 409 thread_not_writable rather than an internal server error.

Observed on plain base with the equivalent two regression cases: 2 failed, 45 passed, exit 1. The insertion did not throw. With the proposed fence: all 47 database tests pass. Two HTTP error-handler cases also pass, verifying the archived/deleted error becomes 409 and is not logged as an unhandled server error. The proposed error type does not exist on base; the baseline test compares its expected name as a string instead of importing the new type.

Evidence

The counts above come from focused Vitest runs with isolated HOME/TMPDIR.

What was ruled out

  • Searched open issues and closed issues for queue archived deleted, plus all issues for thread_not_writable using repository-scoped GitHub search.
  • Found mode:start can queue after the thread becomes active while its host is suspended #3987, which concerns stale idle-versus-active admission while a host is suspended. This report concerns archived/deleted lifecycle state at the database insert boundary, including callers outside that specific mode:start path.
  • This still reproduces on main at the source commit above; the existing explicit-queue transaction check does not protect every queue-insert caller.
  • No provider failure, attachment resolution failure or host disconnection is required by the unit reproduction. Missing-thread handling is protected by the patch but not a separately reproduced case here.

AGENT GENERATED

Activity

  1. added theissue type on Nov 26, 2026
  2. added
    threads
    confirmed-repro
    on Nov 26, 2026
  3. bb-slop-cop commented on Nov 26, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low · threads.
    • Report: Reproduction and root-cause report.
    • Verdict: REPRODUCED · high root-cause confidence · confirmed-repro.
    • Root cause: The shared transactional queue insert does not validate the thread’s current archivedAt or deletedAt, so retirement can be followed by a new queue row and queue-change notification.
    • Reproduction: A newly authored lifecycle test repeats the failure in two clean checkouts of trusted main at b0ddaad731. Each run has 2 intended failures and 47 passes, including all 45 existing queue tests. Soft deletion is exercised with markThreadDeleted; physical deletion already refuses insertion. No live HTTP race is claimed.
    • No new PR: Existing open PR #8263 already links this issue; creating another would duplicate it. Its diff was reviewed statically, not executed.
  4. added a commit that references this issue on Nov 30, 2026
    cd8cbf4
  5. added a commit that references this issue on Dec 1, 2026
    58d9b43
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

    confirmed-reprothreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions