fix(state): compression child sessions inherit cwd and repo metadata - #69343
Merged
Conversation
_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.
Contributor
૮ >ﻌ< ა ci reviewrunning on 0f99d8e CI timingsCI timings · View jobWall time 8m1s vs 7m46s (+3.2%). 9 job(s) slower, 7 faster, 4 unchanged.
|
This was referenced Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compression-rotation child sessions now inherit
cwd,git_repo_root, andgit_branchfrom their parent row, so a project's sidebar entry (grouped by cwd) no longer disappears at every compaction boundary. Root cause: the rotation path'screate_session(..., parent_session_id=old_session_id)passed no workspace metadata and_insert_session_rownever backfilled it — the child row was born NULL (git_repo_rootwasn't even in the INSERT column list).Changes
hermes_state.py—_insert_session_row: addsgit_repo_rootto the INSERT/COALESCE-on-conflict column set; whenparent_session_idis set, backfills still-NULLcwd/git_repo_root/git_branchfrom 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/sessionsand/resume#59527's crash window: compression forks (parent already ended withend_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 byfind_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_contextrotation path and asserting the child row carries workspace + origin metadata.Validation
cwd/git_repo_root/git_branchNULL → project drops out of sidebar/resumemapping unrecoverableTargeted 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_namecolumn resolved to keep both. Follow-up commit addsgit_branch+ compression-scoped gateway-origin inheritance (residual from #59527).Infographic