Repository navigation
One shared subagent tracker for Claude, Codex and Grok chat rows - #27228
Conversation
… subagent rows Claude, Codex and ACP (Grok) each kept their own subagent roster with drifted rules. They now only report what they observe; one tracker decides grouping, runs, names, state, sweeps, retention, row writes and restart inheritance. The golden row-write tests from the previous commit show each rule change.
…amped in its session-end write Review round 1: a resumed child keeps its one entry and reopens it where it is listed (the chat draws one section per child, anchored at the first row naming it), every lookup is read from the rows, the no-turn row is never released, and ACP's session end stamps its live children inside the session-end write instead of writing rows ahead of it.
… the turn that started it Review round 2: the row no turn owns is recognised from its id (a stored flag was lost when an earlier run's row was first reached through one of its children), and a turn's end settles the foreground runs it started wherever their child is listed.
…when a lookup loads it A read-only lookup could load an earlier run's settled row that retention never saw, so it was never released and a fresh settled row was released in its place.
Review summaryThe problem. Claude, Codex and Grok each had their own code for the "subagent" rows in native chat (the row listing helper agents, their state and run time). The three copies had drifted. Codex listed a helper given follow-up work in a second row with nothing to open, rewrote its "outside any turn" row after a restart, and left a helper whose thread closed early as "status unavailable" even after it reported finishing. What changes for the user. All three agents now follow the same rules from one shared tracker: one entry per subagent (a resumed one reopens where it is), rows that continue after a restart, "status unavailable" that a real result can still correct, and duplicate names that never collide. Claude and Grok look the same as before in normal use. Codex gets the three fixes above. The full list is in the PR body. How it was reviewed.
Fixed during review.
Deferred (all already present on
Verified.
Not verified.
|
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to After a rewind in a live session, an old subagent row that had aged out of history can reappear and be updated by a late event. This edge case affects displayed history rather than core chat function, so the change is mergeable with a small follow-up fix. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
89251955-a6d8-4868-a1a0-98c183fe2130
⛔ Files ignored due to path filters (3)
src/main/acp/__snapshots__/acp-subagent-timeline-characterization.test.ts.snapis excluded by!**/*.snapsrc/main/claude/__snapshots__/claude-subagent-roster-characterization.test.ts.snapis excluded by!**/*.snapsrc/main/codex/__snapshots__/codex-subagent-roster-characterization.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (41)
src/main/acp/acp-structured-host-subagent-stop.test.tssrc/main/acp/acp-structured-session.tssrc/main/acp/acp-subagent-timeline-characterization.test.tssrc/main/acp/acp-subagent-timeline.test.tssrc/main/acp/acp-subagent-timeline.tssrc/main/claude/claude-subagent-group-row.tssrc/main/claude/claude-subagent-journaled-roster.test.tssrc/main/claude/claude-subagent-journaled-roster.tssrc/main/claude/claude-subagent-resume-after-restart.test.tssrc/main/claude/claude-subagent-roster-characterization.test.tssrc/main/claude/claude-subagent-roster-groups.test.tssrc/main/claude/claude-subagent-roster-groups.tssrc/main/claude/claude-subagent-roster-retention.test.tssrc/main/claude/claude-subagent-roster-state.tssrc/main/claude/claude-subagent-roster.test.tssrc/main/claude/claude-subagent-roster.tssrc/main/codex/codex-child-work-evidence.test.tssrc/main/codex/codex-default-mode-subagents.test.tssrc/main/codex/codex-structured-journal-limits.tssrc/main/codex/codex-subagent-execution-projection.test.tssrc/main/codex/codex-subagent-executions.tssrc/main/codex/codex-subagent-roster-characterization.test.tssrc/main/codex/codex-subagent-roster-restart.test.tssrc/main/codex/codex-subagent-roster-state.tssrc/main/codex/codex-subagent-roster.tssrc/main/native-chat/agent-session-journal/journal-subagent-group-body-fallback.test.tssrc/main/native-chat/agent-session-journal/journal-subagent-liveness.tssrc/main/native-chat/agent-session-timeline/provider-timeline-event.tssrc/main/native-chat/agent-session-timeline/provider-timeline-settlement.tssrc/main/native-chat/agent-session-timeline/provider-timeline-turn-decisions.tssrc/main/native-chat/subagent-roster-retention.test.tssrc/main/native-chat/subagent-roster-retention.tssrc/main/native-chat/subagent-row-sink-recorder-test-support.tssrc/main/native-chat/subagent-tracker/journaled-subagent-groups.tssrc/main/native-chat/subagent-tracker/subagent-row-sink-port.tssrc/main/native-chat/subagent-tracker/subagent-row-writes.tssrc/main/native-chat/subagent-tracker/subagent-tracker-entries.tssrc/main/native-chat/subagent-tracker/subagent-tracker-groups.tssrc/main/native-chat/subagent-tracker/subagent-tracker-types.tssrc/main/native-chat/subagent-tracker/subagent-tracker.test.tssrc/main/native-chat/subagent-tracker/subagent-tracker.ts
💤 Files with no reviewable changes (4)
- src/main/claude/claude-subagent-roster-groups.test.ts
- src/main/claude/claude-subagent-roster-state.ts
- src/main/claude/claude-subagent-roster-groups.ts
- src/main/claude/claude-subagent-group-row.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| claimGroup = (groupId: string): JournaledGroup | null => { | ||
| const reading = this.current() | ||
| const row = reading?.rowsByGroup.get(groupId) ?? null | ||
| reading?.rowsByGroup.delete(groupId) | ||
| return row | ||
| } | ||
|
|
||
| /** The extension's reading of the bound journal; null before bind. */ | ||
| extra(): Extra | null { | ||
| return this.current()?.extra ?? null | ||
| } | ||
|
|
||
| private current(): Reading<Extra> | null { | ||
| const journal = this.bound() | ||
| if (!journal) { | ||
| return null | ||
| } | ||
| if (!this.reading || journal !== this.journal || journal.epoch !== this.epoch) { | ||
| this.journal = journal | ||
| this.epoch = journal.epoch | ||
| this.reading = this.read(journal) | ||
| } | ||
| return this.reading | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Find where the journal epoch is assigned or advanced.
rg -nP --type=ts -C3 '\bepoch\s*(=|:)' src/main/native-chat/agent-session-journal | head -80
rg -nP --type=ts -C3 'journalLinkage\s*[:(=]' src/main/native-chat | head -40Repository: stablyai/orca
Length of output: 9794
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- changed file at head ---'
nl -ba src/main/native-chat/subagent-tracker/journaled-subagent-groups.ts
printf '%s\n' '--- PR diff for changed file and tracker callers ---'
git diff --no-ext-diff --unified=80 dab3f6efeb6fc0ddcb6e21b3b6dcfb76659639f2 8f741124a0b3c1bf9b6cb357201493e2db54e7d3 -- \
src/main/native-chat/subagent-tracker \
src/main/native-chat/agent-session-journal \
src/main/native-chat/agent-session-wire | sed -n '1,1200p'
printf '%s\n' '--- tracker references ---'
rg -n -F --glob '*.ts' -- 'claimGroup(' src/main/native-chat
rg -n -F --glob '*.ts' -- 'locate(' src/main/native-chat/subagent-tracker src/main/native-chat | head -120
printf '%s\n' '--- journal epoch lifecycle definitions and references ---'
rg -n -F --glob '*.ts' -- 'publishNewEpoch' src/main/native-chat
rg -n -F --glob '*.ts' -- 'journalEpoch' src/main/native-chat | head -160
rg -n -F --glob '*.ts' -- 'publishJournalSessionEpoch' src/main/native-chat
printf '%s\n' '--- journal binding and write/read APIs ---'
rg -n -F --glob '*.ts' -- 'StructuredAgentSessionLinkageJournal' src/main/native-chat | head -160
rg -n -F --glob '*.ts' -- 'appendLifecycleBatch' src/main/native-chat | head -160
rg -n -F --glob '*.ts' -- 'readJournalRowsAfter' src/main/native-chatRepository: stablyai/orca
Length of output: 42385
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- epoch controller, rollover, replacement ---'
nl -ba src/main/native-chat/agent-session-journal/journal-epoch-controller.ts
nl -ba src/main/native-chat/agent-session-journal/journal-epoch-rollover.ts
nl -ba src/main/native-chat/agent-session-journal/journal-epoch-replacement.ts
printf '%s\n' '--- journal open/store epoch and binding ---'
nl -ba src/main/native-chat/agent-session-journal/journal-open.ts | sed -n '1,230p'
nl -ba src/main/native-chat/agent-session-journal/journal-store.ts | sed -n '280,390p'
nl -ba src/main/native-chat/agent-session-wire/structured-agent-session-event-sink.ts | sed -n '50,330p'
printf '%s\n' '--- tracker implementation and row sink ---'
nl -ba src/main/native-chat/subagent-tracker/subagent-tracker-groups.ts
nl -ba src/main/native-chat/subagent-tracker/subagent-tracker.ts
nl -ba src/main/native-chat/subagent-tracker/subagent-row-sink-port.ts
printf '%s\n' '--- construction and use of JournaledSubagentGroups ---'
rg -n -F --glob '*.ts' -- 'new JournaledSubagentGroups' src/main
rg -n -F --glob '*.ts' -- 'JournaledSubagentGroups<' src/main
rg -n -F --glob '*.ts' -- 'writeSubagentRows' src/main/native-chatRepository: stablyai/orca
Length of output: 42696
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- Claude journaled roster ---'
nl -ba src/main/claude/claude-subagent-journaled-roster.ts
printf '%s\n' '--- Codex roster ---'
nl -ba src/main/codex/codex-subagent-roster.ts
printf '%s\n' '--- tracker groups complete ---'
nl -ba src/main/native-chat/subagent-tracker/subagent-tracker-groups.ts
printf '%s\n' '--- journal state/adoption and epoch mutation ---'
rg -n -F --glob '*.ts' -- 'adopt:' src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire
rg -n -F --glob '*.ts' -- 'onPublished' src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire
rg -n -F --glob '*.ts' -- 'this.epoch' src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire
rg -n -F --glob '*.ts' -- 'journal.epoch' src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire
printf '%s\n' '--- epoch/reread tests and tracker tests ---'
rg -n -F --glob '*.test.ts' -- 'epoch' src/main/native-chat/subagent-tracker src/main/native-chat/agent-session-wire src/main/native-chat/agent-session-journal | head -160
rg -n -F --glob '*.test.ts' -- 'JournaledSubagentGroups' src/main
rg -n -F --glob '*.test.ts' -- 'claimGroup' src/mainRepository: stablyai/orca
Length of output: 42031
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- epoch controller call sites ---'
rg -n -F --glob '*.ts' -- '.epochController' src/main
rg -n -F --glob '*.ts' -- '.roll(' src/main/native-chat src/main | head -120
rg -n -F --glob '*.ts' -- '.replace(' src/main/native-chat src/main | head -120
rg -n -F --glob '*.ts' -- 'epochController' src/main/native-chat src/main | head -160
printf '%s\n' '--- journal adoption and mutable journal state ---'
rg -n -F --glob '*.ts' -- 'onPublished' src/main/native-chat/agent-session-wire src/main/native-chat/agent-session-journal
rg -n -F --glob '*.ts' -- 'adopt(loaded' src/main/native-chat
rg -n -F --glob '*.ts' -- 'adopt:' src/main/native-chat
rg -n -F --glob '*.ts' -- 'this.state =' src/main/native-chat/agent-session-journal
rg -n -F --glob '*.ts' -- 'this.epoch =' src/main/native-chat/agent-session-journal
printf '%s\n' '--- rewind/replacement lifecycle ---'
rg -n -F --glob '*.ts' -- 'replaceJournalEpoch' src/main
rg -n -F --glob '*.ts' -- 'journal.epoch' src/main/native-chat/agent-session-wire | head -120
rg -n -F --glob '*.ts' -- 'new CodexSubagentRoster' src/main
rg -n -F --glob '*.ts' -- 'new ClaudeJournaledRoster' src/mainRepository: stablyai/orca
Length of output: 25683
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- journal store replacement methods and adoption ---'
nl -ba src/main/native-chat/agent-session-journal/journal-store.ts | sed -n '90,155p;365,410p'
nl -ba src/main/native-chat/agent-session-journal/journal-store-collaborators.ts | sed -n '1,145p'
printf '%s\n' '--- rewind callers and journal replacement invocation ---'
rg -n -F --glob '*.ts' -- 'rewind(' src/main/native-chat | head -120
rg -n -F --glob '*.ts' -- '.replace(reason' src/main
rg -n -F --glob '*.ts' -- 'journal.replace' src/main
rg -n -F --glob '*.ts' -- 'replaceEpoch' src/main/native-chat
printf '%s\n' '--- provider translation-writer construction and disposal ---'
nl -ba src/main/codex/codex-structured-journal-translation-writers.ts
nl -ba src/main/claude/claude-structured-journal-translation.ts | sed -n '1,150p'
rg -n -F --glob '*.ts' -- 'dispose()' src/main/codex src/main/claude | head -120
rg -n -F --glob '*.ts' -- 'codexSubagentRoster' src/main/codex src/main/native-chat | head -120Repository: stablyai/orca
Length of output: 41960
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- generic rewind recovery ---'
nl -ba src/main/native-chat/agent-session-wire/structured-rewind-recovery.ts | sed -n '130,195p'
printf '%s\n' '--- Codex rewind lifecycle ---'
nl -ba src/main/codex/codex-structured-rewind.ts | sed -n '110,165p'
printf '%s\n' '--- Claude rewind/session teardown references ---'
rg -n -F --glob '*.ts' -- 'journal.context.rewind' src/main/claude src/main/native-chat
rg -n -F --glob '*.ts' -- 'translator.dispose()' src/main/claude src/main/native-chat | head -80
rg -n -F --glob '*.ts' -- 'createClaudeJournalTranslator' src/main
rg -n -F --glob '*.ts' -- 'replaceEpochItems' src/main/native-chat/agent-session-wire src/main/claude src/main/codexRepository: stablyai/orca
Length of output: 30675
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- complete Codex rewind entry ---'
nl -ba src/main/codex/codex-structured-rewind.ts | sed -n '1,180p'
printf '%s\n' '--- Codex session close and translator ownership ---'
nl -ba src/main/codex/codex-structured-session-close.ts | sed -n '1,100p'
nl -ba src/main/codex/codex-structured-session-acquire.ts | sed -n '230,285p'
printf '%s\n' '--- Claude session journal control ---'
nl -ba src/main/claude/claude-structured-session-journal-control.ts
rg -n -F --glob '*.ts' -- 'rewind' src/main/claude src/main/native-chat/agent-session-wire | head -160Repository: stablyai/orca
Length of output: 42720
Preserve claimed group identities across journal rereads.
A live, idle Codex session can replace the journal epoch while its roster remains alive. current() then rebuilds rowsByGroup, including groups previously claimed and evicted. A late report can inherit that group again, and a later report without a run can rewrite the row.
Suggested fix
private reading: Reading<Extra> | null = null
+ /** Groups handed to the tracker; a re-read must not hand them over again. */
+ private readonly claimed = new Set<string>()
...
claimGroup = (groupId: string): JournaledGroup | null => {
+ if (this.claimed.has(groupId)) {
+ return null
+ }
const reading = this.current()
const row = reading?.rowsByGroup.get(groupId) ?? null
- reading?.rowsByGroup.delete(groupId)
+ if (reading) {
+ this.claimed.add(groupId)
+ reading.rowsByGroup.delete(groupId)
+ }
return row
}Conflict: journal-subagent-liveness.ts. Main (#27228) added `lostAt`, the time a live host saw the session end; this branch added `lost`, which narrows settlement to the entries the ended generation ran. Both now pass as one options object, and each caller names what it supplies. Merge-caused fixes: - roster-provenance test: the Claude group row helpers moved with the shared subagent tracker (#27228). - journal partition receipts (#27559): regenerated with the previous partitioner on this branch's row shape (each item row states its owner generation), which moves three chunk boundaries. - line caps after main's additions: main's hasLoadedProviders (#26473) lives on the conversations map and the host delegates to it; one wire type and two navigation requests written on one line.
) * test(native-chat): pin each agent's subagent row writes before unifying the rosters * refactor(native-chat): one shared subagent tracker owns every agent's subagent rows Claude, Codex and ACP (Grok) each kept their own subagent roster with drifted rules. They now only report what they observe; one tracker decides grouping, runs, names, state, sweeps, retention, row writes and restart inheritance. The golden row-write tests from the previous commit show each rule change. * fix(native-chat): one entry per subagent, derived lookups, ACP end stamped in its session-end write Review round 1: a resumed child keeps its one entry and reopens it where it is listed (the chat draws one section per child, anchored at the first row naming it), every lookup is read from the rows, the no-turn row is never released, and ACP's session end stamps its live children inside the session-end write instead of writing rows ahead of it. * fix(native-chat): derive the no-turn group, end a foreground run with the turn that started it Review round 2: the row no turn owns is recognised from its id (a stored flag was lost when an earlier run's row was first reached through one of its children), and a turn's end settles the foreground runs it started wherever their child is listed. * fix(native-chat): count an inherited subagent row as settled history when a lookup loads it A read-only lookup could load an earlier run's settled row that retention never saw, so it was never released and a fresh settled row was released in its place. (cherry picked from commit 5b228ea)
ELI5
When an agent in native chat starts helper agents ("subagents"), the chat shows a row listing them: their names, whether each is still working or how it ended, and how long it ran. Claude, Codex and Grok each had their own copy of the code that keeps that row up to date, and the three copies had drifted apart. The same situation could look different depending on which agent you used, and each copy had its own bugs. This PR replaces the three copies with one shared tracker that follows one set of rules for every agent.
What Changed
The problem. Three separate subagent rosters existed (Claude, Codex, and the one for Grok and other ACP agents). They disagreed on:
Several of those disagreements were user-visible bugs:
What you see now (the same for Claude, Codex and Grok):
Nothing else about the rows changes. Saved rows from before this change read back exactly as they did, and Claude's rows are written byte-for-byte the same as before outside the cases listed above.
The mechanism.
src/main/native-chat/subagent-tracker/holds oneSubagentTrackerthat owns every decision about the rows:Every lookup is read from the rows themselves, so no second index can drift from them. Each agent's own code now only reads its provider's events and reports what it saw in one shared shape:
claude-subagent-roster.tscodex-subagent-roster.tsacp-subagent-timeline.tsWhat stays per agent, on purpose:
Why
The goal was one set of rules, owned in one place, with each agent only translating its own events. The common pattern is a shared subagent record that every provider adapter emits, plus a shared store that owns lifecycle and settlement. I compared each mechanism to that pattern.
Where common designs differ, I followed what Orca's renderer already draws. That applies to where a resumed subagent appears: one design keeps it under the place that spawned it, the other lists each call separately. Orca draws one section per subagent, so one entry per subagent is the rule that keeps the row and its section in agreement.
I considered a byte-identical move first and changing the rules later, but rejected it. It would have meant temporary per-agent switches that the second PR deletes. Instead, the first commit records golden tests of every row each roster wrote on the unchanged code. The diff to those snapshots in this PR is exactly the list of row changes above, and nothing else.
Differences from the common pattern, labelled:
Linked Issue
N/A (internal refactor; follow-up to #26798).
Visual Proof
Hidden test builds of Orca with scripted stand-in agents (no real Claude or Codex), before =
main, after = this PR. Every screenshot was checked by hand.1. Codex: a follow-up to an earlier helper. Before, the follow-up turn got its own "Ran 1 subagent" row, which has no section to open (the helper's section stays on the first row). After, the helper is listed once, in the row that started it, and that entry reopens.
2. The same after quitting and reopening Orca. The helper started before the restart and followed up after it still appears once. ("Survivor" was still running when the app quit, so after reopening it shows "status unavailable" on both builds.)
3. Codex: the helper's thread closes early, then its turn reports that it finished. Before, it stayed "status unavailable". After, it shows "completed".
4. Claude and Grok resuming a helper: unchanged (listed once, as before).
Testing
*-characterization.test.ts); the snapshot diff is the list of changes above.subagent-tracker.test.ts) and a Codex restart test (codex-subagent-roster-restart.test.ts); existing Claude, Codex and ACP subagent, journal-translation and timeline suites pass (154 files, 1533 tests locally).orca-ci-checkspasses (lint, code quality, localization, typecheck).mainwas one of the intended changes above. One thing behaves the same on both builds and is outside this PR: Stop ends the Claude process, so a Claude background subagent shows "status unavailable" afterwards.Notes
session.endedgains an optional in-process field only.