Skip to content

fix(agent): inherit parent session cwd during compression rotation - #42240

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/compression-session-cwd-inherit
Closed

fix(agent): inherit parent session cwd during compression rotation#42240
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/compression-session-cwd-inherit

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Inherits the parent session's cwd (workspace path) into the continuation session created during context compression. Previously, the continuation was created without cwd, causing list_sessions_rich() tip projection to surface cwd=null — moving the conversation into the "No workspace" group in Desktop/TUI.

Related Issue

Fixes #42228

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/conversation_compression.py: Read the old session's cwd via get_session() before ending it, and pass cwd=old_cwd to the continuation create_session() call
  • tests/agent/test_compression_cwd_inheritance.py: 3 regression tests — continuation inherits cwd, null cwd stays null, tip projection preserves cwd

How to Test

  1. Open Desktop/TUI with a workspace selected (e.g., /Users/test/project)
  2. Have a long conversation that triggers context compression
  3. After compression, verify the session still appears under the correct workspace group (not "No workspace")
  4. Run pytest tests/agent/test_compression_cwd_inheritance.py -v — all 3 tests should pass

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: agent/conversation_compression.py (compress_context → create_session call chain)
  • Blast radius: LOW — single parameter addition to existing create_session call; no control flow changes
  • Related patterns: Title propagation (old_title) already follows the same pattern at lines 504/526-531

When a session with an explicit workspace (cwd) is compressed, the
continuation session was created without passing cwd. This caused
list_sessions_rich() tip projection to surface cwd=null, moving the
conversation into the "No workspace" group in Desktop/TUI.

Fix: read the old session's cwd before ending it and pass it to the
continuation create_session() call.

Fixes NousResearch#42228
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Jun 8, 2026
@MatheusBazarinRibeiro

Copy link
Copy Markdown

Independent confirmation from a Windows Desktop profile, with private row data redacted.

I re-ran the read-only state.db audit for the No workspace after compression symptom. Sanitized result shape:

visible sidebar-like rows included No workspace entries
compression chains with root cwd non-empty and continuation/tip cwd NULL: 3

I am intentionally not posting real session ids, workspace paths, titles, prompts, screenshots, or local DB paths. The relevant data shape was:

root: end_reason='compression', cwd=<non-empty workspace path>
tip:  parent_session_id=root, cwd=NULL
list_sessions_rich(project_compression_tips=True): projected row uses tip cwd=NULL
Desktop sidebar: groups projected row under No workspace

That matches this PR's root cause exactly: compress_context() rotates the session and creates the continuation without carrying cwd, then list_sessions_rich() projects the tip over the root.

The old_cwd propagation here should prevent new occurrences.

One follow-up edge case worth covering before merge: existing user DBs can already contain old continuation rows with tip.cwd IS NULL. This PR fixes future compression rotations, but those legacy rows will still project into No workspace unless there is either a defensive projection fallback or a repair/backfill. A minimal regression for that legacy shape would be:

create root with cwd='/tmp/project'
end root with end_reason='compression'
create tip with parent_session_id=root and cwd=NULL
list_sessions_rich(project_compression_tips=True) should either preserve root cwd
or a migration/repair path should backfill tip cwd

If the intended scope is only future rows, it may be worth documenting that existing affected rows need a separate repair. Otherwise, adding a root-cwd fallback in the projection path would make the fix immediately correct for already-affected Desktop profiles too.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this — the diagnosis and fix are correct for the rotation path.

Context on why we're closing it: as of #52658 (#38763), compression.in_place now defaults to True. Compaction keeps ONE durable session id for the conversation's whole life — it no longer ends the session and forks a continuation id. Because there is no continuation session, the conversation keeps its original cwd through compaction — there is no null-cwd continuation row to inherit into.

Rotation now only runs as an explicit opt-out (compression.in_place: false), and the direction is to treat that path as legacy. So this fix hardens a code path that no longer executes by default and that we're not investing further in. Closing as superseded by the in-place default — not a reflection on the code, which was a correct fix for the behavior at the time. Credit preserved in the issue/PR history. Appreciate the contribution.

@teknium1 teknium1 closed this Jun 25, 2026
ruslanvasylev added a commit to ruslanvasylev/hermes-agent that referenced this pull request Jun 30, 2026
Local carry of upstream PR NousResearch#42240 for issue NousResearch#42228 so Desktop/TUI sessions keep their workspace after compression rotation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop/TUI compressed sessions can move into No workspace because continuation cwd is null

4 participants