Skip to content

Commit 6616095

Browse files
DavidDavid
authored andcommitted
fix: ignore subagent rollout activity
1 parent a011860 commit 6616095

7 files changed

Lines changed: 217 additions & 3 deletions

File tree

‎Sources/CodexNotch/Models/SessionActivity.swift‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22

33
enum RolloutEventKind: Equatable, Sendable {
44
case sessionMeta(threadID: String, cwd: String?, originator: String?)
5+
case subagentSessionMeta(threadID: String, cwd: String?, originator: String?)
56
case taskStarted(turnID: String?)
67
case taskCompleted(turnID: String?)
78
case turnAborted(turnID: String?)
@@ -83,18 +84,25 @@ enum ActiveSessionReducer {
8384
var originator: String?
8485
var active: [String: SessionActivity] = [:]
8586
var completed: [SessionActivity] = []
87+
var isSubagentRollout = false
8688

8789
for (index, event) in events.enumerated() {
8890
switch event.kind {
8991
case let .sessionMeta(newThreadID, newCWD, newOriginator):
92+
isSubagentRollout = false
9093
threadID = newThreadID
9194
cwd = newCWD
9295
originator = newOriginator
9396
active = active.mapValues {
9497
$0.updating(threadID: threadID, cwd: cwd, originator: originator)
9598
}
9699

100+
case .subagentSessionMeta:
101+
isSubagentRollout = true
102+
active.removeAll()
103+
97104
case let .taskStarted(turnID):
105+
guard !isSubagentRollout else { continue }
98106
let resolvedTurnID = turnID ?? "anonymous-turn-\(index)"
99107
let timestamp = event.timestamp ?? .distantPast
100108
// A rollout represents one serial Codex conversation. When
@@ -116,6 +124,7 @@ enum ActiveSessionReducer {
116124
)
117125

118126
case let .taskCompleted(turnID), let .turnAborted(turnID):
127+
guard !isSubagentRollout else { continue }
119128
guard let key = matchingKey(for: turnID, active: active),
120129
let item = active.removeValue(forKey: key) else {
121130
continue

‎Sources/CodexNotch/Monitoring/RolloutEventParser.swift‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,23 @@ enum RolloutEventParser {
2929
switch type {
3030
case "session_meta":
3131
guard let threadID = envelope.payload?.id, !threadID.isEmpty else { return nil }
32+
let payload = envelope.payload
33+
if payload?.isSubagent == true {
34+
return RolloutEvent(
35+
timestamp: timestamp,
36+
kind: .subagentSessionMeta(
37+
threadID: threadID,
38+
cwd: payload?.cwd,
39+
originator: payload?.originator
40+
)
41+
)
42+
}
3243
return RolloutEvent(
3344
timestamp: timestamp,
3445
kind: .sessionMeta(
3546
threadID: threadID,
36-
cwd: envelope.payload?.cwd,
37-
originator: envelope.payload?.originator
47+
cwd: payload?.cwd,
48+
originator: payload?.originator
3849
)
3950
)
4051

@@ -70,12 +81,57 @@ private struct PayloadDTO: Decodable {
7081
let turnID: String?
7182
let cwd: String?
7283
let originator: String?
84+
let parentThreadID: String?
85+
let source: SourceDTO?
86+
87+
var isSubagent: Bool {
88+
source?.containsSubagentThreadSpawn == true
89+
|| !(parentThreadID?.isEmpty ?? true)
90+
}
7391

7492
enum CodingKeys: String, CodingKey {
7593
case id
7694
case type
7795
case turnID = "turn_id"
7896
case cwd
7997
case originator
98+
case parentThreadID = "parent_thread_id"
99+
case source
100+
}
101+
}
102+
103+
private struct SourceDTO: Decodable {
104+
let containsSubagentThreadSpawn: Bool
105+
106+
init(from decoder: Decoder) throws {
107+
guard let container = try? decoder.container(keyedBy: CodingKeys.self) else {
108+
containsSubagentThreadSpawn = false
109+
return
110+
}
111+
112+
containsSubagentThreadSpawn =
113+
(try? container.decode(SubagentSourceDTO.self, forKey: .subagent))?.threadSpawn != nil
114+
}
115+
116+
private enum CodingKeys: String, CodingKey {
117+
case subagent
118+
}
119+
}
120+
121+
private struct SubagentSourceDTO: Decodable {
122+
let threadSpawn: ThreadSpawnDTO?
123+
124+
enum CodingKeys: String, CodingKey {
125+
case threadSpawn = "thread_spawn"
126+
}
127+
}
128+
129+
private struct ThreadSpawnDTO: Decodable {
130+
init(from decoder: Decoder) throws {
131+
_ = try decoder.container(keyedBy: EmptyCodingKeys.self)
132+
}
133+
134+
private enum EmptyCodingKeys: String, CodingKey {
135+
case none
80136
}
81137
}

‎Tests/CodexNotchTests/ActiveSessionStoreTests.swift‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,37 @@ final class ActiveSessionStoreTests: XCTestCase {
148148
XCTAssertEqual(snapshot.recentCompletions.first?.session.turnID, "turn-a-new")
149149
}
150150

151+
func testSubagentReductionDoesNotEnterStoreSnapshot() async {
152+
let now = Date(timeIntervalSince1970: 2_000_000_000)
153+
let reduction = ActiveSessionReducer.reduce([
154+
RolloutEvent(
155+
timestamp: now,
156+
kind: .subagentSessionMeta(
157+
threadID: "child-thread",
158+
cwd: "/tmp/project",
159+
originator: "Codex Desktop"
160+
)
161+
),
162+
RolloutEvent(timestamp: now, kind: .taskStarted(turnID: "child-turn")),
163+
RolloutEvent(
164+
timestamp: now.addingTimeInterval(1),
165+
kind: .taskCompleted(turnID: "child-turn")
166+
)
167+
])
168+
let store = ActiveSessionStore()
169+
170+
await store.replace(
171+
rolloutID: "child-rollout",
172+
reduction: reduction,
173+
lastModifiedAt: now
174+
)
175+
176+
let snapshot = await store.snapshot(now: now)
177+
178+
XCTAssertTrue(snapshot.activeSessions.isEmpty)
179+
XCTAssertTrue(snapshot.recentCompletions.isEmpty)
180+
}
181+
151182
func testCompletedHistoryOutlivesActiveSessionStaleness() async {
152183
let now = Date(timeIntervalSince1970: 2_000_000_000)
153184
let eightHoursAgo = now.addingTimeInterval(-(8 * 60 * 60))

‎Tests/CodexNotchTests/RolloutEventParserTests.swift‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,48 @@ final class RolloutEventParserTests: XCTestCase {
6868
XCTAssertNil(result.completed.first?.title)
6969
}
7070

71+
func testSubagentRolloutDoesNotCreateActiveOrCompletedConversation() {
72+
let data = Data(
73+
"""
74+
{"timestamp":"2026-07-16T09:00:00Z","type":"session_meta","payload":{"id":"child-thread","cwd":"/tmp/project","source":{"subagent":{"thread_spawn":{"parent_thread_id":"parent-thread"}}},"parent_thread_id":"parent-thread"}}
75+
{"timestamp":"2026-07-16T09:00:01Z","type":"event_msg","payload":{"type":"task_started","turn_id":"child-turn"}}
76+
{"timestamp":"2026-07-16T09:00:02Z","type":"event_msg","payload":{"type":"task_complete","turn_id":"child-turn"}}
77+
""".utf8
78+
)
79+
80+
let result = ActiveSessionReducer.reduce(RolloutEventParser.parse(data: data))
81+
82+
XCTAssertTrue(result.active.isEmpty)
83+
XCTAssertTrue(result.completed.isEmpty)
84+
}
85+
86+
func testParentThreadMarkerAloneExcludesSubagentRollout() {
87+
let data = Data(
88+
"""
89+
{"timestamp":"2026-07-16T09:00:00Z","type":"session_meta","payload":{"id":"child-thread","cwd":"/tmp/project","parent_thread_id":"parent-thread"}}
90+
{"timestamp":"2026-07-16T09:00:01Z","type":"event_msg","payload":{"type":"task_started","turn_id":"child-turn"}}
91+
""".utf8
92+
)
93+
94+
let result = ActiveSessionReducer.reduce(RolloutEventParser.parse(data: data))
95+
96+
XCTAssertTrue(result.active.isEmpty)
97+
XCTAssertTrue(result.completed.isEmpty)
98+
}
99+
100+
func testDirectVscodeSourceStillCreatesAnActiveConversation() {
101+
let data = Data(
102+
"""
103+
{"timestamp":"2026-07-16T09:00:00Z","type":"session_meta","payload":{"id":"direct-thread","cwd":"/tmp/project","source":"vscode"}}
104+
{"timestamp":"2026-07-16T09:00:01Z","type":"event_msg","payload":{"type":"task_started","turn_id":"direct-turn"}}
105+
""".utf8
106+
)
107+
108+
let result = ActiveSessionReducer.reduce(RolloutEventParser.parse(data: data))
109+
110+
XCTAssertEqual(result.active.map(\.threadID), ["direct-thread"])
111+
}
112+
71113
private func fixtureData(_ name: String) throws -> Data {
72114
let url = URL(fileURLWithPath: #filePath)
73115
.deletingLastPathComponent()

‎docs/contracts/behavior-contracts.yaml‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ contracts:
750750

751751
- id: ACTIVITY-STATE-004
752752
title: Interrupted turns cannot leave the compact notch running
753-
status: active
753+
status: superseded
754754
statement: A rollout records serial turns for one Codex thread. If a later task_started event appears for that thread before an earlier turn has a terminal event, the earlier turn is superseded and must no longer count as active or keep the compact quota indicator moving. A terminal event explicitly naming a superseded or unknown turn is ignored and must not finish the replacement turn. Active turns from separate rollout files retain their normal priority; when no active task remains, the most recent completion still shows the completion checkmark.
755755
rationale: A missing terminal event previously left an orphan active turn in a continuously modified rollout file. Because active staleness used the file modification time, the orphan could hold the compact notch in its running animation for hours after the visible task completed.
756756
source: user-reported-incident
@@ -767,6 +767,40 @@ contracts:
767767
- Tests/CodexNotchTests/NotchPresentationReducerTests.swift
768768
- "manual: complete a real task after an interrupted turn and confirm the compact quota indicator stops"
769769
supersedes: [ACTIVITY-STATE-003]
770+
superseded_by: ACTIVITY-STATE-005
771+
last_verified_commit: null
772+
773+
- id: ACTIVITY-STATE-005
774+
title: Subagent rollouts do not affect notch activity or conversation history
775+
status: active
776+
statement: >-
777+
A rollout whose session metadata identifies a child through
778+
`source.subagent.thread_spawn` or a non-empty `parent_thread_id` is
779+
ignored for notch activity and recent-conversation history. Its
780+
task_started, task_complete, and turn_aborted events cannot create active
781+
or completed records. Top-level rollouts retain the interrupted-turn
782+
supersession rules and the six-hour stale fallback from ACTIVITY-STATE-004;
783+
explicit terminal events still clear the matching top-level turn
784+
immediately.
785+
rationale: >-
786+
Codex writes child-agent work as separate rollout files beside the user's
787+
top-level task. Treating those files as user-facing conversations makes
788+
the notch show internal implementation work and lets an abandoned child
789+
turn keep the parent-facing running cue alive until stale cleanup.
790+
source: user-reported-incident
791+
owner: project-maintainer
792+
risk: medium
793+
scope:
794+
include: [compact-state, expanded-state, recent-conversations, rollout-session-monitoring]
795+
exclude: [task-termination, quota-semantics, physical-notch-geometry]
796+
examples:
797+
positive: "A child rollout with a task_started event and no terminal event contributes neither an active row nor a running count; a completed child rollout is absent from recent conversations; a direct `source: vscode` rollout remains eligible."
798+
negative: "A child-agent nickname appears in the expanded list, a child-only orphan keeps the compact notch in the running state, or decoding a direct string source causes the top-level rollout to disappear."
799+
guards:
800+
- Tests/CodexNotchTests/RolloutEventParserTests.swift
801+
- Tests/CodexNotchTests/ActiveSessionStoreTests.swift
802+
- "manual: run a top-level task with a child agent, close the child unexpectedly, and confirm only the top-level task controls the notch state"
803+
supersedes: [ACTIVITY-STATE-004]
770804
superseded_by: null
771805
last_verified_commit: null
772806

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
status: active
3+
contract_ids: [ACTIVITY-STATE-005, CONVERSATION-TITLE-041]
4+
supersedes: []
5+
superseded_by: null
6+
---
7+
8+
# Ignore Child-Agent Rollouts in the Notch Activity Feed
9+
10+
Codex stores child-agent work as separate rollout JSONL files. Those files are
11+
implementation details of the user's top-level task, not independent
12+
conversations for CodexNotch to show beside the notch.
13+
14+
## Decision
15+
16+
When `session_meta.payload` contains either the structured
17+
`source.subagent.thread_spawn` marker or a non-empty `parent_thread_id`, the
18+
parser emits a child-rollout marker. The activity reducer drops all activity
19+
and completion events for that rollout. A normal string source such as
20+
`"vscode"` remains a top-level rollout.
21+
22+
## Rejected alternatives
23+
24+
- Filter by `cwd`: parent and child agents commonly share the same project
25+
directory, so this cannot distinguish them.
26+
- Filter by `originator`: child rollouts currently use the same `Codex Desktop`
27+
originator as top-level work.
28+
- Display child rows but hide only their titles: the child task would still
29+
incorrectly keep the running state alive.
30+
- Reduce the stale timeout to a short fixed interval: that would hide legitimate
31+
long-running top-level tasks when their rollout has no new line for a while.
32+
33+
## Consequences
34+
35+
- The expanded list and recent-conversation history contain only top-level
36+
Codex conversations.
37+
- An abandoned child rollout cannot keep the compact notch in the running
38+
state; top-level abnormal-exit recovery continues to use its existing stale
39+
fallback.
40+
- The parser reads only metadata needed for classification and still ignores
41+
rollout message bodies.

‎docs/decisions/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Record decisions here only when they affect active behavior contracts, could be
1212
| [008-local-thread-summary-titles](008-local-thread-summary-titles.md) | active | `CONVERSATION-TITLE-041`, `PRIVACY-BOUNDARY-005` | Resolve row labels from Codex's read-only thread summaries rather than rollout messages |
1313
| [009-keep-notch-visible-across-full-screen-apps](009-keep-notch-visible-across-full-screen-apps.md) | active | `NOTCH-VISIBILITY-042` | Keep the requested notch surface available in native and borderless full-screen applications |
1414
| [010-layer-backed-quota-motion](010-layer-backed-quota-motion.md) | active | `QUOTA-SEMANTICS-043` | Keep 8 FPS visual motion while moving persistent ring and wave frames out of SwiftUI |
15+
| [011-ignore-subagent-rollouts](011-ignore-subagent-rollouts.md) | active | `ACTIVITY-STATE-005`, `CONVERSATION-TITLE-041` | Ignore child-agent rollouts in notch activity and conversation history |
1516

1617
New decisions must include `status`, `contract_ids`, rejected alternatives, and consequences. When a decision changes, retain the old document and point to the new one with `superseded_by`.

0 commit comments

Comments
 (0)