Skip to content

[Bug]: thread.merge_back succeeds when the parent (or source) thread is deleted or archived, stranding a transfer and navigating into the dead thread #41222

Closed

Description

@gpu004

What I observed

Orchestrator.dispatchThreadMergeBack (apps/server/src/orchestration-v2/Orchestrator.ts:6119-6170) validates lineage, active/queued runs on the target, and fork-transfer presence, but never checks targetProjection.thread.deletedAt !== null, targetProjection.thread.archivedAt !== null, or sourceProjection.thread.deletedAt !== null. (By contrast, dispatchThreadFork right above it explicitly rejects sourceProjection.thread.deletedAt !== null.)

On the client side, resolveMergeBackTargetThreadId (packages/client-runtime/src/state/threadRelationships.ts:37-44) only checks forkedFrom.threadId / lineage.parentThreadId on the fork itself. Because deleting or archiving a parent thread only cascades to side chats (not full forks), the Merge back to source conversation action remains enabled in the fork on web, desktop, and mobile. Clicking it commits a stranded pending merge_back context transfer onto the dead/archived parent, returns Success with no error, and navigates the user straight into the deleted or archived parent thread.

Reproduction

  • Commit: main @ 9d3054a7bb
  • Environment: macOS 27.2.1, Node v26.13.1

UI steps (single user, single device, no race):

  1. Create a thread and complete at least one turn.
  2. Fork the thread (full fork) and complete a turn in the fork.
  3. Archive or delete the parent thread.
  4. Open the fork, open the Lineage panel, and click Merge back to source conversation (also reachable on mobile via ThreadRouteScreen.tsx and via MCP t3_thread_transfer({ action: "merge_back" })).

Programmatic server repro (ThreadManagementService + OrchestratorV2):

  1. Create parentId, finish Turn 1, dispatch thread.fork (parentId -> forkId), finish Turn 1 in forkId.
  2. Dispatch thread.archive on parentId, then dispatch thread.merge_back (forkId -> parentId).
  3. Dispatch thread.delete on parentId, then dispatch thread.merge_back (forkId -> parentId).

Expected behavior

dispatchThreadMergeBack rejects thread.merge_back with OrchestratorDispatchError (emitting 0 events) when the target thread is deleted or archived, or when the source thread is deleted (and clients should disable/hide merge-back when the target thread is no longer active).

Actual behavior

thread.merge_back succeeds against both archived and deleted parent threads, appends a pending context-transfer.created event onto the dead/archived parent, shows no error toast, and navigates the client into the deleted/archived parent (redirecting to home on web or landing on a missing thread on mobile).

Evidence

Observed output from the deterministic Effect/SQLite server repro:

REPRO 4: {"mergeIntoArchived":"Success","mergeIntoDeleted":"Success","parentDeleted":true,"pendingMergeBacks":1}

Additional investigation

  • How found: Stateful property-based testing of OrchestratorV2, minimized to a deterministic non-PBT Vitest/Effect repro.
  • Verified: Confirmed on origin/main (9d3054a7bb) that dispatchThreadMergeBack still has no deletedAt or archivedAt checks.
  • Duplicate check: Searched open and closed issues/PRs for merge_back deleted and merge back archived — no matching issue found.
  • Impact: Minor/moderate — silently creates a stranded transfer on a deleted/archived thread and navigates the user out of their fork with no error message.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions