Skip to content

fix: preserve desktop workspace cwd across continuations - #49860

Open
kemaldoganay wants to merge 1 commit into
NousResearch:mainfrom
kemaldoganay:fix/desktop-workspace-cwd-drift
Open

fix: preserve desktop workspace cwd across continuations#49860
kemaldoganay wants to merge 1 commit into
NousResearch:mainfrom
kemaldoganay:fix/desktop-workspace-cwd-drift

Conversation

@kemaldoganay

Copy link
Copy Markdown

Summary

  • Preserve the parent session cwd when context compression rotates into a continuation session.
  • Separate declared workspace cwd from execution/runtime cwd in TUI gateway session metadata so legacy/no-workspace sessions do not get grouped under the gateway launch directory.
  • Hydrate live Desktop sidebar payloads from the stored SessionDB row when a resumed/live session has a persisted cwd but no in-memory explicit marker.
  • Sync the Desktop default project dir before resolving cwd for new local sessions and branches.
  • Tighten regression coverage for workspace/no-workspace semantics, DB isolation, compression cwd inheritance, Desktop cwd resolution, and an environment-dependent browser hint test.

Test plan

  • venv/bin/python -m pytest tests/test_tui_gateway_server.py tests/agent/test_compression_logging_session_context.py -q
    • 289 passed, 8 warnings
  • npm --prefix apps/desktop run typecheck
    • passed
  • npm --prefix apps/desktop run test:ui -- src/store/session.test.ts
    • 21 passed

Notes

This fixes a Desktop sidebar drift case where compression continuation sessions could reappear under No workspace after app restart even though their parent session belonged to a concrete workspace.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/tui Terminal UI (ui-tui/ + tui_gateway/) comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #42228 (issue — compressed sessions drift to "No workspace" when continuation cwd is null), #42240 / #42233 (narrower compression-cwd-inheritance fixes in agent/conversation_compression.py), #41678 (Desktop compression session lineage overhaul), #45744 (no-workspace sidebar new sessions).

This PR is the multi-layer fix: it combines the compression-rotation cwd inheritance (agent/conversation_compression.py), the TUI gateway declared-vs-runtime workspace cwd separation (tui_gateway/server.py), and Desktop sidebar hydration from the persisted SessionDB row (apps/desktop/*). Not a duplicate of the single-layer PRs above — it spans the union of those layers.

@alt-glitch alt-glitch added comp/desktop Electron desktop app (apps/desktop/*) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state and removed comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 26, 2026
@rzyns

rzyns commented Jul 10, 2026

Copy link
Copy Markdown

Thanks for working on this. I reproduced the core bug on current main: rotated compression continuations are still supported, compression.in_place still defaults to false, and the continuation create_session(...) path does not carry cwd/git workspace metadata. The root-to-tip projection then replaces valid root metadata with null tip metadata.

We need the narrow fix locally now, but do not want to create an uncoordinated competing PR. I’m preparing a clean, minimal branch from current upstream that will:

  • inherit cwd, git_branch, and git_repo_root when a continuation row is created;
  • preserve nearest non-null lineage workspace metadata when projecting historical rows;
  • add focused regression tests only.

Are you planning to rebase #49860? If so, I’m happy to keep our branch local and share tests/evidence. Otherwise, would you or the maintainers prefer a small superseding PR that credits and references this work plus #42240/#41678?

@teknium1 teknium1 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.

Thanks for pursuing the cross-layer workspace-drift issue. The underlying rotation defect remains on current main, but this branch needs a focused salvage.

Problems

  • The new continuation call copies only cwd (agent/conversation_compression.py:606 in this PR). Current rows also carry git_branch and git_repo_root through SessionDB.update_session_cwd() (hermes_state.py:2126-2162), so workspace metadata remains incomplete after rotation.
  • Current projection replaces root metadata with every tip field, including null cwd, git_branch, and git_repo_root (hermes_state.py:3517-3524). The PR does not change that persisted historical-list path, so existing null-tip continuations can still lose their workspace grouping.

Suggested changes

  • Preserve or recompute the full workspace metadata when creating the continuation, and retain nearest non-null lineage metadata during tip projection.
  • Add focused tests for a null-metadata continuation and a multi-rotation lineage; the current test only covers a non-null tip cwd (tests/test_hermes_state.py:4105-4121).
  • Reapply the gateway/Desktop portion to current deferred-resume/session-action structure before salvage.

Automated hermes-sweeper review.

@@ -598,6 +606,7 @@ def _release_lock() -> None:
model=agent.model,

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.

This preserves only cwd. Current session rows also retain git_branch and git_repo_root (hermes_state.py:2126-2162), while projected sidebar rows replace all three from the continuation (hermes_state.py:3517-3524). Please preserve or recompute the git metadata here as well, and add the null-tip projection fallback.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
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 comp/desktop Electron desktop app (apps/desktop/*) comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants