Skip to content

fix(state): compression child sessions inherit cwd and repo metadata - #69343

Merged
teknium1 merged 2 commits into
mainfrom
salvage/64731-child-cwd
Jul 22, 2026
Merged

fix(state): compression child sessions inherit cwd and repo metadata#69343
teknium1 merged 2 commits into
mainfrom
salvage/64731-child-cwd

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Compression-rotation child sessions now inherit cwd, git_repo_root, and git_branch from their parent row, so a project's sidebar entry (grouped by cwd) no longer disappears at every compaction boundary. Root cause: the rotation path's create_session(..., parent_session_id=old_session_id) passed no workspace metadata and _insert_session_row never backfilled it — the child row was born NULL (git_repo_root wasn't even in the INSERT column list).

Changes

  • hermes_state.py_insert_session_row: adds git_repo_root to the INSERT/COALESCE-on-conflict column set; when parent_session_id is set, backfills still-NULL cwd/git_repo_root/git_branch from the immediate parent row inside the same write transaction (NULL-only — an explicit child value is never overwritten). Multi-generation chains resolve because each generation backfills from its already-resolved parent.
  • hermes_state.py — belt-and-suspenders for Compression continuations lose gateway origin metadata, breaking /sessions and /resume #59527's crash window: compression forks (parent already ended with end_reason='compression') also inherit the gateway origin columns (user_id/session_key/chat_id/chat_type/thread_id/display_name/origin_json) at DB-level creation. The gateway re-records the peer after rotation (d5b4879), but a hard crash between child creation and that write left the child unrecoverable by find_latest_gateway_session_for_peer. Scoped to compression forks only — delegate/subagent children (parent still live) do NOT inherit routing keys, so peer recovery can never repoint gateway traffic into a subagent's session.
  • tests/test_hermes_state.py — inheritance, no-clobber, multi-generation, git_branch, origin-column, and live-parent-exclusion tests.
  • tests/agent/test_compression_rotation_state.py — behavioral test driving the real _compress_context rotation path and asserting the child row carries workspace + origin metadata.

Validation

Before After
Child row after compression rotation cwd/git_repo_root/git_branch NULL → project drops out of sidebar inherits all three from parent row
Gateway crash between rotation and peer re-record child has no routing columns → /resume mapping unrecoverable compression child inherits origin columns
Delegate/subagent child (parent live) still does NOT inherit routing keys

Targeted tests: 555 passed, 0 failed (tests/test_hermes_state.py, tests/agent/test_compression_rotation_state.py, tests/hermes_state/, tests/gateway/test_session_store_stale_prune.py, tests/gateway/test_session_hygiene.py, tests/gateway/test_compression_concurrent_sessions.py, tests/run_agent/test_compression_boundary_hook.py, rotation-flush suites).

Fixes #64709.

Credit

Salvaged from #64731 by @wesleysimplicio — cherry-picked with authorship preserved; conflicts against the schema-v23 profile_name column resolved to keep both. Follow-up commit adds git_branch + compression-scoped gateway-origin inheritance (residual from #59527).

Infographic

compression child sessions inherit cwd and repo metadata

Simplicio, Wesley (ext) and others added 2 commits July 22, 2026 05:41
_insert_session_row never copied cwd/git_repo_root from a parent row when
parent_session_id was set, and git_repo_root wasn't even in the INSERT's
column list. The compression-fork path (and delegate/subagent spawns,
branch continuations) creates a child session without passing cwd/
git_repo_root at all, so the child's tip is born NULL — and since the
Desktop project sidebar groups sessions by cwd, the whole project silently
drops out of the sidebar every time a long conversation compresses. A
lineage that compresses repeatedly compounds this across generations.

Add git_repo_root to _insert_session_row's INSERT/COALESCE-on-conflict
column set, and backfill both cwd and git_repo_root from the immediate
parent row (single non-recursive hop, matching the existing COALESCE
"never overwrite an explicit value" contract) inside the same write
transaction whenever parent_session_id is set. A multi-generation chain
resolves correctly because each generation's own create_session call
already backfills from its (already-resolved) immediate parent.

Fixes #64709
…n children

Follow-ups on top of #64731's cwd/git_repo_root inheritance:

- git_branch joins the parent-row backfill (same NULL-only COALESCE hop):
  the Desktop sidebar branch chip otherwise vanishes at every compaction
  boundary even though the workspace didn't change.
- Belt-and-suspenders for #59527: compression forks (parent already ended
  with end_reason='compression') also inherit the gateway origin columns
  (user_id/session_key/chat_id/chat_type/thread_id/display_name/
  origin_json) at DB-level child creation. The gateway re-records the peer
  after rotation (d5b4879), but a hard crash in the window between child
  creation and that write left the child unrecoverable by
  find_latest_gateway_session_for_peer. Scoped to compression forks only —
  delegate/subagent children (parent still live) must NOT inherit routing
  keys, or peer recovery could repoint gateway traffic into a subagent's
  session.
- Behavioral test driving the real _compress_context rotation path,
  asserting the child row carries cwd/git_repo_root/git_branch and the
  origin columns.
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

running on 0f99d8e

CI timings

CI timings · View job

Wall time 8m1s vs 7m46s (+3.2%). 9 job(s) slower, 7 faster, 4 unchanged.

  • Python tests / Run tests slice 5/8: -19.0s
  • Python tests / Run tests slice 8/8: -17.0s
  • Python tests / Run tests slice 1/8: -7.0s
  • Build&Test Docker image / build (arm64, ubuntu-24.04-arm, linux/arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope...: +7.0s
  • Python tests / Run tests slice 6/8: +5.0s

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/desktop Electron desktop app (apps/desktop/*) area/sessions Session lifecycle, resume, persistence, history area/compression Context compression and continuation sessions P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 22, 2026
@teknium1
teknium1 merged commit 75099ca into main Jul 22, 2026
41 checks passed
@teknium1
teknium1 deleted the salvage/64731-child-cwd branch July 22, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions area/sessions Session lifecycle, resume, persistence, history comp/cli CLI entry point, hermes_cli/, setup wizard comp/desktop Electron desktop app (apps/desktop/*) P2 Medium — degraded but workaround exists 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.

bug(state): compression-split child sessions lose cwd/git_repo_root, causing project sidebar entry to disappear every compression

2 participants