Repository navigation
Description
What I observed
Orchestrator.dispatchMessage (apps/server/src/orchestration-v2/Orchestrator.ts:7126) never checks projection.thread.deletedAt !== null or projection.thread.archivedAt !== null for normal message.dispatch commands (it only checks them inside four internal continuation branches: steerFollowUpOfRunId, manualContinuationOfRunId, usageLimitContinuationOfRunId, and restartContinuationOfRunId).
Because the WebSocket RPC path (ws.ts → ThreadMessageIntake.dispatchCommand → ThreadManagementService.dispatch → Orchestrator.dispatch) also has no deletedAt or archivedAt check:
- A
message.dispatcharriving for a deleted thread is accepted, commits domain events, leavesdeletedAtnon-null, and enqueuesprovider-turn.start— running a real paid agent turn in the workspace on a deleted, invisible thread that the user has no UI way to see or stop. - A
message.dispatcharriving for an archived thread is accepted, leavesarchivedAtnon-null, and runs a live provider turn. If a second message is queued while that turn runs,startNextQueuedRunOnce(Orchestrator.ts) refuses to start it becausearchivedAt !== null, leaving the second message permanently stranded inqueued.
Reproduction
- Commit:
main @ 9d3054a7bb - Environment: macOS 27.2.1, Node v26.13.1
Reachable real-world triggers:
- Open the same thread on two clients/tabs/devices (e.g., desktop and mobile). Delete or archive the thread on one client, then tap Send (or approve a pending guest message) on the other.
- Client reconnect resending an in-flight
message.dispatch(packages/client-runtime/src/operations/commands.ts:302) after the thread was deleted or archived elsewhere. - TOCTOU race in
ThreadManagementService.sendToThread: it checksdeletedAt/archivedAtbefore runningworktreeRestore.restoreI/O outside the thread lock, then callsdispatchwithout re-checking under the lock.
Minimal server repro (ThreadManagementService + OrchestratorV2 + OrchestrationEffectWorkerV2):
// Case 1: deleted thread
yield* threads.dispatch({ type: "thread.create", commandId: CommandId.make("c-create"), threadId, ... });
yield* threads.dispatch({ type: "thread.delete", commandId: CommandId.make("c-delete"), threadId });
const sendExit = yield* Effect.exit(
threads.dispatch({
type: "message.dispatch",
commandId: CommandId.make("c-send"),
threadId,
messageId: MessageId.make("msg:after-delete"),
text: "Do work on a deleted thread",
attachments: [],
dispatchMode: { type: "start_immediately" },
createdBy: "user",
creationSource: "web",
}),
);
yield* drainEffectWorker();
// Case 2: archived thread + second queued message
// Same setup with thread.archive, then dispatch message 1 (start_immediately),
// dispatch message 2 (queue_after_active), then complete turn 1.Expected behavior
Orchestrator.dispatch rejects message.dispatch with OrchestratorDispatchError (emitting 0 events and starting no provider turn) whenever projection.thread.deletedAt !== null or projection.thread.archivedAt !== null, matching dispatchThreadMutation, queue.resume, queued-message.promote-to-steer, queued-run.start, and ThreadManagementService.sendToThread.
Actual behavior
Both deleted and archived threads accept message.dispatch, commit events, and start a live provider turn while keeping deletedAt / archivedAt non-null. On an archived thread, a second queued message stays stranded in queued with queueHeld: false once the first turn completes.
Evidence
Observed output from the deterministic Effect/SQLite server repro:
REPRO 1 (deleted):
{"outcome":"Success","deletedAt":true,"startedProviderTurns":1,"runs":[{"id":"run:thread:thread%3Arepro-deleted:ordinal:1","status":"running"}],"shellActiveRunId":"run:thread:thread%3Arepro-deleted:ordinal:1"}
REPRO 2 (archived + queued 2nd message after turn 1 completes):
{"archivedAt":true,"startedProviderTurns":1,"runs":[{"id":"run:thread:thread%3Arepro-archived:ordinal:1","status":"completed","queueHeld":false},{"id":"run:thread:thread%3Arepro-archived:ordinal:2","status":"queued","queueHeld":false}]}
Additional investigation
- How found: Stateful property-based testing of
OrchestratorV2, minimized to deterministic non-PBT Vitest/Effect repros. - Verified: Confirmed still unguarded on
origin/main(9d3054a7bb). All other thread-work commands (dispatchThreadMutation,queue.resume,queued-run.start,queued-message.promote-to-steer,startNextQueuedRunOnce) already checkdeletedAt/archivedAt. - Duplicate check: Searched open and closed issues/PRs for
deleted thread message,archived thread message,dispatchMessage deleted, andmessage.dispatch archived— no matching issue found. - Impact: Major — silently spends tokens and mutates workspace files on a deleted/hidden thread with no UI to observe or stop it.
Activity