Conversation
…rch#116322) Red-team review of NousResearch#116377 found the exclusion clause covered only the _delegate_from marker while the same defect class reproduces through the /branch path: tui_gateway._persist_branch builds the child row with model_config={"_branched_from": parent_key} and parent_session_id, passing no routing columns, so the inheritance gate is the only source of its session_key/chat_id — the same two-live-rows-one-key shape as the delegate case (NousResearch#92859). Add the symmetric IS NULL clause for _branched_from (sibling _NON_CONTINUATION_CHILD_FILTER_SQL already classifies both markers, and 52a293f recently extended that class to _reset_from). _reset_from stays inheriting on purpose: a reset fork continues the user's own conversation, so its routing requirement differs from delegate/branch children. Tests: the delegate invariant is now parametrized over both markers (delegate/branch); compression-fork recovery stays green. RED verified on the previous head (branch param failed with "inherited session_key"), GREEN with the clause, and a mutation removing only the branch clause is killed by the branch param.
teknium1
added a commit
that referenced
this pull request
Sep 20, 2026
…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>
Collaborator
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.
Fixes #116322
_INHERIT_PARENT_ROUTING_SQL(hermes_state_sessions.py:239-249) copies the parent session's gateway routing columns (source/session_key/chat_id/chat_type/user_id) into any child whose parent ended withend_reason='compression'— including delegate/subagent children marked bymodel_config._delegate_from. After a peer failure/recovery, such a child can silently repoint real user traffic into the subagent's session.The code base already states the intended contract three times; only the inheritance SQL misses it:
_INHERIT_PARENT_ROUTING_SQLdocstring: "routing columns are inherited ONLY by compression forks" (:277);:440-446,:478) both explicitly exclude_delegate_fromchildren;Change
One focus: add
AND _delegate_from IS NULLto the inheritance SQL, via the existingjson_valid-guarded_sql_json_extracthelper (malformedmodel_configfalls back safely), mirroring the sibling queries' shape. Compression forks keep inheriting; real delegate children stop inheriting. Nothing else changes.Tests
Two invariant tests (per the 1-2 test norm):
test_delegate_child_does_not_inherit_gateway_routing_columns— delegate child (model_config._delegate_from) getssession_key/chat_id/chat_type/user_id = NULL(RED before the fix, GREEN after);test_compression_fork_still_inherits_gateway_routing_columns— compression fork keeps inheriting all four routing columns (GREEN before and after; guards against over-narrowing).Mutation self-check: replaying the pre-fix logic turns test 1 red (exit=1), restoring the fix turns it green (exit=0). Full
tests/hermes_state/test_hermes_state.py: 283 passed / 2 skipped (skips pre-existing); sibling suites (delegate_cascade / compression_lineage_guard / profile_stamp / orphan_gateway_repair): 43 passed.Test plan
pytest tests/hermes_state/test_hermes_state.py— 283 passed, 2 skipped (pre-existing skips)