Skip to content

feat(code): suggest compacting large resumed threads - #5318

Merged
Johannes du Plessis (johannes117) merged 9 commits into
mainfrom
johannes117/code/compact-on-resume
Aug 5, 2026
Merged

feat(code): suggest compacting large resumed threads#5318
Johannes du Plessis (johannes117) merged 9 commits into
mainfrom
johannes117/code/compact-on-resume

Conversation

@johannes117

@johannes117 Johannes du Plessis (johannes117) commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Large-context threads now offer compaction before resume, with options to continue without compacting or cancel.


The threshold defaults to 400,000 tokens and is configurable with [threads].compact_on_resume_threshold.

Screenshots

Screenshot 2026-08-05 at 10 21 45 AM

@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 size: M 200-499 LOC labels Aug 4, 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: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

Johannes du Plessis (johannes117) added a commit that referenced this pull request Aug 5, 2026
Related #5318

Runtime-model compaction now preserves configured archive routing by
constructing the summarizer before applying `_ArchiveReadGuard`.

## Before:
<img width="863" height="275" alt="Screenshot 2026-08-05 at 11 52 41 AM"
src="https://github.com/user-attachments/assets/a3836fd1-c414-46d0-881f-02d18db77755"
/>

## After:
<img width="649" height="217" alt="Screenshot 2026-08-05 at 12 04 13 PM"
src="https://github.com/user-attachments/assets/59d53b35-0d7e-4f08-8c05-2f49172a2f61"
/>
@github-actions github-actions Bot added size: L 500-999 LOC and removed size: M 200-499 LOC labels Aug 5, 2026
Resuming a thread sends nothing to the model, so the oversized-context
prompt does not need to block the resume. Ask once the thread is live
instead, via `_maybe_compact_after_resume` called from the three
`SessionStartCause.RESUME` sites, and drop the launch-time cancel path
that only existed because the prompt used to gate the resume.

Removes `_cancel_initial_resume` and its server respawn, the
`compact_on_resume` parameter on `_switch_agent`, the startup history
prefetch, and the `_resume_thread` reordering those required. The
threshold check now reads `_context_tokens`, which the history load
already populates.

Both `/threads -r` branches now run off Textual's message pump; the
same-agent branch previously awaited the cwd modal inline, where it
could never receive the keys that would resolve it.
@github-actions github-actions Bot added size: M 200-499 LOC and removed size: L 500-999 LOC labels Aug 5, 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 2 potential issues.

Open in WebView Open SWE trace

Comment thread libs/code/deepagents_code/app.py
Comment thread libs/code/deepagents_code/app.py
A launch that resumes and passes an initial prompt skips the history
load, so nothing populated `_context_tokens` and the compaction check
always fell through -- on the one path where the cost is immediate,
since the prompt is submitted against the full restored context moments
later. Seed the count from the checkpoint via
`_restore_resumed_context_tokens` before the prompt runs.

Also wrap the detached same-agent `/threads -r` continuation in
`_resume_same_agent_thread`. `_resume_thread` reports its own failures
once the switch is under way, but its pre-switch phase runs outside that
boundary, and `_schedule_off_message_pump` only logs -- so a failure
there ended the command with no visible outcome.
@johannes117
Johannes du Plessis (johannes117) merged commit cb2329d into main Aug 5, 2026
57 checks passed
@johannes117
Johannes du Plessis (johannes117) deleted the johannes117/code/compact-on-resume branch August 5, 2026 23:58
Mason Daugherty (mdrxy) pushed a commit that referenced this pull request Aug 6, 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.53](deepagents-code==0.1.52...deepagents-code==0.1.53)
(2026-08-06)

### Features

- Added pricing coverage with Baseten built-in overrides and local
fallback overrides when `genai-prices` is missing data
([#5312](#5312),
[#5304](#5304)).
- Suggest compacting large resumed threads
([#5318](#5318)).
- Added terminal program trace metadata
([#5329](#5329)).

### Bug Fixes

- Preserved runtime offload archive routing
([#5328](#5328)).
- Always restart after a successful startup auto-update
([#5317](#5317)).
- Fixed leaked turn coroutines and SQLite handles
([#5218](#5218)).
- Keep MCP shutdown-race tracebacks from appearing in the terminal
([#5325](#5325)).
- Open the `/auto model` selector immediately while connecting
([#5341](#5341)).
- Route failures to `PostToolUseFailure`
([#5315](#5315)).
- Use dismissed copy for ask-user prompts
([#5331](#5331)).

_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 size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants