Skip to content

fix(state): delegate and branch children no longer inherit a compressed parent's chat route (#116322, salvage #116377) - #116740

Merged
teknium1 merged 2 commits into
mainfrom
fix/b0919-L05-sessions-statedb-delegate-inherit
Sep 20, 2026
Merged

teknium1 merged 2 commits into
mainfrom
fix/b0919-L05-sessions-statedb-delegate-inherit

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

A delegate or branch child no longer takes over its parent chat's gateway routing (session_key/chat_id/chat_type/thread_id/user_id) when that parent row has already ended on compression — only a genuine compression continuation inherits them.

  • hermes_state_sessions.py::_INHERIT_PARENT_ROUTING_SQL now excludes children whose model_config._delegate_from / _branched_from names the queried parent (matched by VALUE, like _NON_CONTINUATION_CHILD_FILTER_SQL, because a continuation copies model_config verbatim and would otherwise be misclassified).
  • Docstring of _inherit_parent_session_metadata states the rule for both fork kinds.
probe (real SessionDB, temp db; issue's reproduction) before after
create_session("c", source="subagent", parent_session_id="p", model_config={"_delegate_from": "p"}) after end_session("p", "compression") child row carries session_key='agent:main:telegram:dm:42', chat_id='42', user_id='u1' all routing columns NULL
plain continuation create_session("cont", source="telegram", parent_session_id="p") (control) inherits still inherits
continuation of a branch child (marker value ≠ parent id) inherits still inherits

Root cause: the inheritance UPDATE gated only on the parent's end_reason='compression' and never on the new child's fork provenance, so two live rows ended up holding one routing key (the shape behind #92859).

Tests: tests/hermes_state/test_delegate_child_routing_inheritance.py (2 invariants, both fork markers + the branch-continuation control), red on origin/main (2 failed), green here. Focused files: that file + tests/hermes_state/test_compression_lineage_guard.py + tests/hermes_state/test_session_md_export.py.

Fixes #116322
Salvages #116377 (@strzhao) — cherry-picked with authorship; the branch-continuation control test is a follow-up commit.

Dropped hunks

None.

Infographic

infographic

Lei-k and others added 2 commits September 19, 2026 21:50
… parent's gateway routing

_INHERIT_PARENT_ROUTING_SQL copied session_key/chat_id/chat_type/thread_id/user_id/
display_name/origin_json/transport_profile onto ANY child whose parent row ended on
'compression'. A delegate or branch fork of such a parent is not that conversation's
continuation, so it must not take over the route: two live rows holding one routing key
lets peer recovery repoint gateway traffic into a subagent's transcript (#116322).

Exclude children whose `_delegate_from` / `_branched_from` marker names the queried parent
id. Value-match rather than presence: a compression continuation inherits model_config
verbatim (marker included), so a presence check would misclassify it — the same idiom
_NON_CONTINUATION_CHILD_FILTER_SQL already uses.

Cherry-picked from #109699 (Lei-k) minus its unrelated tools/delegate_tool_dispatch.py
nested-dispatch hunk; test relocated to tests/hermes_state/ where the suite now lives.
…its its route

Pins the reason the exclusion matches the marker's VALUE against the parent id instead
of its presence: a continuation copies model_config verbatim, so a `_branched_from`
marker rides along. A presence check (#116377's variant) would leave the continuation
unroutable — exactly the shape this test fails on against that branch.

Salvages #109699 (@Lei-k). Supersedes #116377 (@strzhao).

Co-authored-by: strzhao <strzhao@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

૮ >ﻌ< ა ci review

ran on 945d95f — test(state): a compression continuation of a branch child st

debug info

CI timings

CI timings · View report · View job

Wall time 5m31s vs 6m29s (-14.9%). 5 job(s) slower, 5 faster, 2 unchanged.

  • OS-specific tests / Windows-only tests: -61.0s
  • Check no case-colliding filenames / check-case-collisions: -33.0s
  • Python tests / e2e: +12.0s
  • Python lints / Windows footguns (blocking): +10.0s
  • OS-specific tests / macOS-only tests: -7.0s

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/delegate Subagent delegation area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Sep 20, 2026
@teknium1
teknium1 merged commit df2865f into main Sep 20, 2026
37 checks passed
@teknium1
teknium1 deleted the fix/b0919-L05-sessions-statedb-delegate-inherit branch September 20, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: create_session copies compressed parent routing columns into a marked delegate child

3 participants