Isolate Codex Session notifications by thread - #1740
Open
scottt732 wants to merge 1 commit into
Open
Conversation
scottt732
requested a deployment
to
ok-to-test
September 9, 2026 18:43 — with
GitHub Actions
Waiting
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/sessionruntime/codex.go">
<violation number="1" location="internal/sessionruntime/codex.go:796">
P3: During provider startup the readLoop goroutine starts before openThread/startThread publish `p.threadID`, so for a brief window `threadID == ""`. The new filter then drops any notification carrying a non-empty `threadId`, including a root-thread notification that arrives before the root ID is assigned. Only apply the filter once the root thread ID is known.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| done := p.turnDone | ||
| kind := p.interactionKind | ||
| p.activeMu.Unlock() | ||
| if json.Unmarshal(params, &scope) == nil && scope.ThreadID != "" && scope.ThreadID != threadID { |
There was a problem hiding this comment.
P3: During provider startup the readLoop goroutine starts before openThread/startThread publish p.threadID, so for a brief window threadID == "". The new filter then drops any notification carrying a non-empty threadId, including a root-thread notification that arrives before the root ID is assigned. Only apply the filter once the root thread ID is known.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/sessionruntime/codex.go, line 796:
<comment>During provider startup the readLoop goroutine starts before openThread/startThread publish `p.threadID`, so for a brief window `threadID == ""`. The new filter then drops any notification carrying a non-empty `threadId`, including a root-thread notification that arrives before the root ID is assigned. Only apply the filter once the root thread ID is known.</comment>
<file context>
@@ -777,11 +781,21 @@ func (p *CodexProvider) readLoop(reader io.Reader) {
done := p.turnDone
kind := p.interactionKind
p.activeMu.Unlock()
+ if json.Unmarshal(params, &scope) == nil && scope.ThreadID != "" && scope.ThreadID != threadID {
+ return
+ }
</file context>
Suggested change
| if json.Unmarshal(params, &scope) == nil && scope.ThreadID != "" && scope.ThreadID != threadID { | |
| if threadID != "" && json.Unmarshal(params, &scope) == nil && scope.ThreadID != "" && scope.ThreadID != threadID { |
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.
What type of PR is this?
/kind bug
What this PR does / why we need it:
Codex app-server publishes notifications for native subagent threads as well as the Session's root thread. Kelos currently applies every notification to the root interaction: a child error or completion can terminate the Session request while the root agent continues working, and child output or usage can be attributed to the parent.
Filter thread-scoped notifications to the provider's root thread before changing interaction state or emitting events. Preserve notifications without thread scope, including account-wide rate limits. Synchronize initial thread-ID publication with the notification reader.
Which issue(s) this PR is related to:
N/A
Special notes for your reviewer:
Reproduced with a persistent Codex Session spawning native analysts: one child failed while the root kept working, but the Session client received failure and disconnected. The regression test feeds child startup, text, error and completion notifications and then verifies the parent still emits output and completes normally.
Validation:
go test ./internal/sessionruntime -run TestCodex -count=1 -race -timeout=90spassed. The new regression failed before the fix. Broader coverage is delegated to CI.Does this PR introduce a user-facing change?
Summary by cubic
Filters Codex Session notifications by thread so child subagent events no longer affect the parent session. Previously, a child error or completion could prematurely finish the parent turn or be attributed as parent output.
Written for commit 2e6e9b6. Summary will update on new commits.