Skip to content

[Bug]: Thread briefly jumps to the top of the sidebar (out of Working) each time a background subagent finishes #44436

Done

Description

@vakesz

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Sidebar thread sort: "updated_at" (the default).
  2. In a Claude thread, have the agent start one or more background subagents. The parent turn ends while they keep running, and the thread stays in the Working section.
  3. Wait for a subagent to finish.

Expected behavior

The thread stays in the Working section while the parent resumes to handle the subagent's result.

Actual behavior

When a subagent finishes, the thread jumps to the top of the sidebar (out of Working) for a split second, then goes back to Working. With several subagents this happens often, and the list shifts under the cursor, which is the same click-misfire risk described in #40716.

Cause (from reading d838e956)

The tracker in packages/client-runtime/src/state/threadInbox.ts already has a 2 s WORKING_EXIT_GRACE_MS for "an orchestrator run can end moments before its continuation starts". It is skipped in this case by the endedLongAgo check:

const endedAt = toSortableTimestamp(thread.latestRun?.completedAt ?? undefined);
const endedLongAgo = endedAt !== null && endedAt <= at - STALE_EXIT_MS; // 60 s
const deadline = !actual && previous?.working && !actionable && !moved && !excluded && !endedLongAgo ? ... : null;

With background subagents, the parent run completes when its turn ends, and latestRun.completedAt is stamped then. The thread stays in Working only because deriveThreadStructureRuntime (threadExecution.ts) reports runtime.status: "idle" while backgroundWorkHoldsCompletion(...) is true, and isThreadWorking treats idle as working. When the last subagent finishes, the hold drops and the runtime status becomes the completed run's status, so isThreadWorking → false. If the subagent outlived the parent turn by more than 60 s, completedAt is already stale, so the client gets no grace. The thread is moved to Active right away with returnedAt = now (so sortInboxThreadsByReturn puts it at the top). About 300 ms later the continuation run started by the task notification makes it working again.

From the provider event log, the continuation usually starts about 0.3 s after the notification (sometimes a few seconds), mostly within the 2 s grace if it applied:

10:51:11.459  result                     (parent turn ends; subagent still running)
10:52:32.794  system/task_notification   (subagent finished, 81 s later → endedLongAgo)
10:52:37.315  system/init                (continuation, +4.5 s)
...
10:56:47.399  system/task_notification
10:56:47.695  system/init                (+296 ms)

The STALE_EXIT_MS comment ("A run that ended this long ago has no continuation about to start") doesn't hold when background work kept the thread working after the run ended.

Possible fix: measure staleness from when the thread stopped working, not from latestRun.completedAt. For example, skip endedLongAgo when the background-work hold is what just ended, or use the time the hold released / runtime.updatedAt as the end time.

Impact

Minor bug or occasional failure

Version or commit

0.1.14-nightly.20261127.5345

Environment

macOS 27.2, desktop app, local environment, Claude provider

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