Repository navigation
Description
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
- 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.
- 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([]);
},
);- From packages/db, run:
pnpm exec vitest run test/data/queued-thread-messages.test.ts --maxWorkers=2This 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 insert function does not check archivedAt/deletedAt before insertion.
- Delayed queue admission can arrive with a previously read thread snapshot.
- Explicit queue admission already rereads the thread inside its transaction; the missing guarantee is at the common insert boundary.
- HTTP error handling requires a mapping for any new database refusal.
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 forthread_not_writableusing 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
bb-slop-cop commentedon Nov 26, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads.confirmed-repro.archivedAtordeletedAt, so retirement can be followed by a new queue row and queue-change notification.b0ddaad731. Each run has 2 intended failures and 47 passes, including all 45 existing queue tests. Soft deletion is exercised withmarkThreadDeleted; physical deletion already refuses insertion. No live HTTP race is claimed.Reject queued inserts after a thread is archived or deleted (get-bb#8263
Reject queued inserts after a thread is archived or deleted (get-bb#8263