fix: stop merging sub-agent turns into parent session#335
Merged
Conversation
Sub-agent requests (OpenCode explore/general agents) were being merged into the parent session via x-parent-session-id header lookup in identifySession(). This caused the full Lore pipeline to run on the sub-agent's messages using the parent's session state, corrupting gradient state, cache analytics, timing baselines, and model tracking. Sub-agents already carry their own x-session-affinity header with a unique nanoid. By removing the parent-merge priority, they naturally get independent sessions through the normal Tier 1 identification path, benefiting from the full pipeline (LTM, gradient, distillation) on their own state without corrupting the parent. Removes all isSubagentTurn guards from handleConversationTurn() and postResponse() — now dead code since sub-agents are separate sessions.
- Remove extractParentSessionId(), PARENT_SESSION_HEADERS and their tests — no longer used after parent-merge removal - Fix stale doc comments in pipeline.ts, session.ts, and types.ts that still referenced x-parent-session-id or sub-agent merging behavior - Remove unnecessary bare block scope in postResponse() temporal storage
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
x-parent-session-idheader lookup, causing the full Lore pipeline to run on the sub-agent's messages using the parent's session state — corrupting gradient state, cache analytics, timing baselines, and model trackingidentifySession()so sub-agents naturally get independent sessions through their ownx-session-affinityheader, benefiting from the full pipeline (LTM, gradient, distillation, curation) on their own stateisSubagentTurnguards fromhandleConversationTurn(),postResponse(), and the structural compaction dispatchProblem
When OpenCode spawns a sub-agent (e.g. "explore" for file search), the gateway merged it into the parent session, then ran the full pipeline against the parent's state with the sub-agent's completely different system prompt and messages. This caused:
lastRequestBodylastLayer,lastTransformedCountlastRequestBody, poisoning next parent comparisonlastModelfor warmup profilelastRequestTimereset by sub-agent ingetOrCreateSession()Approach
Sub-agents already carry their own
x-session-affinitynanoid. The fix simply removes thex-parent-session-idmerge priority inidentifySession(), letting sub-agents fall through to the normal Tier 1 path where they get independent sessions. Net deletion: -113 lines.Files changed
packages/gateway/src/pipeline.tsidentifySession(), remove allisSubagentTurnlogic, remove structural compaction sub-agent guardpackages/gateway/test/cache-warmer.test.tssimulateGapRecordinghelper, remove 3 obsolete sub-agent tests