Skip to content

feat(code): point back to the previous thread after a switch - #5172

Merged
Mason Daugherty (mdrxy) merged 5 commits into
mainfrom
open-swe/thread-switch-previous-hint
Jul 31, 2026
Merged

feat(code): point back to the previous thread after a switch#5172
Mason Daugherty (mdrxy) merged 5 commits into
mainfrom
open-swe/thread-switch-previous-hint

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jul 29, 2026

Copy link
Copy Markdown
Member

The REPL now shows a Previous thread: <id> (Resume with /threads -r) hint after switching threads, matching /clear.


Switching threads mid-session (/threads, /threads -r) replaced the transcript with no way back — the outgoing thread's ID scrolled out of reach, unlike /clear, which already mounts a Previous thread: <id> (Resume with /threads -r) hint. The /clear logic is extracted into _mount_previous_thread_hint and reused by the switch path, mounted directly under the Resumed thread: <id> note. Threads with no checkpoint row (i.e. the previous thread was empty) still get no hint, since -r can't resume them.

Made by Open SWE

Switching threads mid-session replaced the transcript without telling the
user how to get back, so the outgoing thread's ID scrolled out of reach.
Reuse the `/clear` hint (extracted into `_mount_previous_thread_hint`) so
a switch away from a non-empty thread mounts "Previous thread: <id>
(Resume with /threads -r)" under the "Resumed thread" note.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@github-actions github-actions Bot added dcode Related to `deepagents-code` feature New feature/enhancement or request for one internal User is a member of the `langchain-ai` GitHub organization open-swe size: S 50-199 LOC labels Jul 29, 2026
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as ready for review July 30, 2026 18:05
Mason Daugherty (mdrxy) and others added 3 commits July 30, 2026 14:05
`/threads -r` previously refused any thread owned by a different agent,
telling the user to switch agents first. It now resolves the thread with
its owner and prompts to switch, then restarts the server against that
agent and resumes the exact thread requested. The saved default agent is
left alone, matching launch-time `-r`; a failed restart rolls back the
thread pointers, approval mode, and cwd.

Also harden the previous-thread hint shared by `/clear`, `/force-clear`,
thread switches, and the new cross-agent resume:

- Guard the mount half. It was best-effort only around the resumability
  lookup, so a mount fault escaped into two callers that wrap the call in
  a rollback -- undoing a completed switch and reporting "Failed to
  switch to thread ..." or "Could not switch to agent ..." after the new
  server was already healthy.
- Suppress the hint when the owning agent is unknown, or when a
  cross-agent thread is paired with a remote server that cannot perform
  the restart `-r` would need.
- Log store failures at `info` rather than `debug`, so the branch is
  visible in the Debug Console ring buffer.
- Cover the error branches, the mount failure, and the mount ordering,
  and anchor the no-checkpoint test so it no longer passes when the hint
  is removed outright.
@github-actions github-actions Bot added size: XL 1000+ LOC and removed size: S 50-199 LOC labels Jul 31, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment thread libs/code/deepagents_code/tui/widgets/thread_agent_switch.py Outdated
A picker swap told the user to quit and relaunch with `-r <thread>` to
reach the thread it left behind. That was the only option when
`/threads -r` refused cross-agent threads, but it now offers a switch, so
the relaunch became the long way around. The swap now tries the in-session
hint first and keeps the relaunch command only as a fallback for sessions
`-r` cannot serve -- chiefly a remote server that cannot restart into the
owning agent. `_mount_previous_thread_hint` reports whether it mounted
anything so callers can make that choice.

Also stop a restored goal review from burying the transcript notes. Both
resume paths deferred to `_load_thread_history` to resolve a pending
review, which mounted the interactive prompt before the "Resumed thread"
and "Previous thread" lines -- leaving an informational note sitting under
a question the user was being asked to answer. Both now pass
`resolve_pending_goal=False` and remount the review last, matching how the
startup sequence already defers it. The deferred remount is guarded at
both sites: it runs inside a rollback handler in one and during exception
propagation in the other, so an unguarded raise would undo a completed
switch or mask the original error.

Finally, let the cross-agent prompt's help line wrap. At 48 columns and
below the 38-cell line needs two rows, and the fixed single row clipped
the `Esc: cancel` half -- hiding how to back out exactly where the dialog
was hardest to read.
@mdrxy
Mason Daugherty (mdrxy) merged commit 4507f9f into main Jul 31, 2026
69 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the open-swe/thread-switch-previous-hint branch July 31, 2026 02:32
Mason Daugherty (mdrxy) pushed a commit that referenced this pull request Jul 31, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. Publish reads the merged CHANGELOG via `release.yml`,
not this PR description — keep them aligned anyway so the PR stays an
accurate historical record for reviewers and anyone returning later._

---


##
[0.1.51](deepagents-code==0.1.50...deepagents-code==0.1.51)
(2026-07-31)

### Features

- The status bar and usage view now show the running session cost.
([#5036](#5036))
- Removed redundant `shell` and `web_search` prompt guidance.
([#5213](#5213))
- After switching threads, Deep Agents now points back to the previous
thread.
([#5172](#5172))
- Leaving `/mcp` with pending toggles now prompts you to reconnect.
([#5211](#5211))
- `dcode config get` now accepts configuration sections.
([#5134](#5134))

### Fixes

- Kept the `/goal` criteria prompt responsive.
([#5142](#5142))
- Improved goal handling so underspecified objectives can be resolved
from conversation context.
([#5201](#5201))
- Released the turn when an interrupted worker never starts.
([#5196](#5196))
- Hid timestamp footers together with their associated rows.
([#5167](#5167))
- Fixed editable SDK detection by scanning and correlating SDK locations
more accurately.
([#5199](#5199))
- Improved `doctor` output to explain why it may not have a
latest-version answer.
([#5209](#5209))

_End release notes preview._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: langchain-oss-automated-triage[bot] <248757908+langchain-oss-automated-triage[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dcode Related to `deepagents-code` feature New feature/enhancement or request for one internal User is a member of the `langchain-ai` GitHub organization open-swe size: XL 1000+ LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant