Repository navigation
fix(native-chat): a subagent's words are presented as that subagent's, never the parent's - #23605
Conversation
…, never the parent's The journal already names the agent that produced every row, but the transcript projection dropped it, so a subagent's prose rendered as the parent's reply, its tool calls folded into the parent's runs, and a settled turn could fold down to a subagent's words as its only visible answer. The transcript message now keeps the row's producer. The fold keeps each agent's calls in that agent's own run, a turn's answer is the session's own agent's last prose, and a subagent's row names the subagent on desktop, mobile and a worker's transcript text.
…ld it now carries
…wn run live Review follow-ups: - the fold is main's adjacency fold plus one condition: a row never folds into another agent's run, so an agent's later call stays below its subagent's work instead of jumping back into its earlier row - each agent has its own live frontier, so a parent still inside its spawn call reads as running while its subagent works below it - mobile names no one on a row whose only content is hidden behind its settled turn - a pending question from a subagent keeps its producer - worker reads serve only the producing agent's id, bounded like the roster key that names it, and drop the provenance fields - the single-message worker formatter is private, so no caller can drop names
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change preserves subagent identity in projected and served transcript messages. Native chat uses that identity to separate agent-specific runs and show subagent labels, captions, and row styling. Worker transcript formatting adds subagent speaker prefixes and uses batch formatting in CLI output and terminal previews. Tests cover attribution, folding, projection, and row layout. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Interleaved tool results can disappear, and some subagent messages can appear without attribution. Fix both before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Helper-agent attribution is improved across the chat experience, but an interleaved tool result may disappear from the visible transcript. No new cross-user access or privilege escalation is evidenced. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 31 files. (7 skipped: 7 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
ℹ️ No critical issues — two non-blocking notes inline (one design question, one wire-contract observation).
Reviewed changes
Carries the journal's producer lineage onto the chat transcript so a subagent's words are never presented as the parent agent's.
- Projection —
NativeChatMessagenow intersectsAgentJournalProducerLinkage;structured-agent-session-projection.tsandstructured-agent-question-projection.tsspread the row's linkage. Absence ofagentIdremains the claim that the session's own agent wrote the row. - Fold —
foldToolMessagesonly absorbs a tool-only message into a preceding assistant written by the same producer, so interleaved agents keep their order and each call lands under the agent that made it. - Turn answer —
nativeChatTurnAnswerRowsnow requiresisRootAgentJournalItem, so a subagent narrating after the parent's last word is no longer the turn's answer. - Slots — per-agent frontier (
trailingRunIndexes), roster-label lookup, and caption height (attributed). - Presentation — desktop
MessageRowand mobileMobileNativeChatMessagecaption a subagent row from the roster label, falling back toSubagent;native-chat-subagent-attribution.tsis the shared label source. - Worker text —
formatWorkerTranscriptMessagestags subagent lines[assistant, subagent <name>];worker-transcript-payload.tsserves only the boundedagentId. - i18n —
subagents.unnamed/writtenByadded to en, fr, ja, ko, zh, es.
I verified the key equality the feature rests on (roster entry id === journal agentId === canonical task/thread id, for both Claude and Codex) and that mobile's structured messages do carry both the roster block and the child agentId, so labels resolve end to end. Changed tests run green here except the mobile suite (expo deps unavailable in this environment).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| (row, index) => | ||
| // Each agent has its own frontier: a subagent working below its parent's run | ||
| // has not moved the parent past it. | ||
| const trailingRunIndexes = new Set<number>() |
There was a problem hiding this comment.
The per-agent frontier never consults the roster's completion state. A subagent that has finished stops emitting rows, so its last qualifying row stays trailingRun: true for the rest of the parent's working turn — and NativeChatToolRun forces live whenever activeTurnIsWorking === true && trailing !== false, so a completed subagent's tool run keeps pulsing until the whole turn settles. The old single findLastIndex frontier let the parent's later row settle it. Is that intended?
Technical details
# A completed subagent's run stays live for the remainder of the turn
## Affected sites
- `native-chat-transcript-slots.ts:121-136` — `trailingRunIndexes` marks one frontier per `agentId` and never reads `agents[].state`; a child agent's frontier can only be superseded by that same agent's later rows, which a completed child never writes.
- `NativeChatTranscriptRow.tsx:59` → `NativeChatMessageRow.tsx:260` → `NativeChatToolRun.tsx:132-136` — `trailing !== false` on a working turn forces `live`, regardless of the call's terminal state.
- `NativeChatMessageList.tsx:161-169` — `turnKeys` are assigned on `user` boundaries only, so a child's rows share the parent turn's key and get `activeTurnIsWorking: true` while the parent works.
## Example interleaving
```
user ask → root prose "delegating" → root spawn call →
child tool run (completed; roster already reads `completed`) →
root prose "continuing" → root tool run
```
trailing = {child row, root row}: the child's run renders `data-native-chat-tool-run-state="live"` while the roster row above reports it `completed`.
## Required outcome
- Either a completed subagent's own run settles once it is done, or the behavior is documented as intended (per-agent liveness overrides roster completion for the duration of the turn).
## Suggested approach (optional)
- When marking a non-root frontier, skip (or do not mark trailing) an agent whose roster entry state is terminal. The roster is on the same message list, so the state is already reachable from `messages`.
## Open questions for the human
- Is a finished subagent's run meant to keep its live mark until the turn ends?| agentId: _agentId, | ||
| parentAgentId: _parentAgentId, | ||
| providerParentRef: _providerParentRef, | ||
| producerKind: _producerKind, | ||
| attempt: _attempt, |
There was a problem hiding this comment.
This destructure removes parentAgentId, providerParentRef, producerKind and attempt from the served payload — fields the old code spread through — not just adds agentId. Per docs/reference/remote-wire-compatibility.md Rule 3, a host that stops populating a field is a wire change even with no codec change. No renderer or mobile consumer reads these today (checked), so it is benign, but the PR description's "new optional fields (Rule 1)" framing doesn't cover the removal.
Technical details
# Worker-read transcript narrows previously-published provenance fields
## Affected sites
- `worker-transcript-payload.ts:115-122` — destructures away `parentAgentId`, `providerParentRef`, `producerKind`, `attempt` (previously served via `...served`).
- `worker-transcript-payload.ts:130` — re-adds only the bounded `agentId`.
## Required outcome
- Confirm no released client reads the removed fields from `orchestration.workerRead` / the released-worker archive, or note the narrowing in the wire section of the PR so a future reader does not treat the payload as purely additive.There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c26cdffc-9cd1-4b62-b5f2-512f4c529e55
📒 Files selected for processing (38)
mobile/src/session/MobileNativeChatMessage.test.tsmobile/src/session/MobileNativeChatMessage.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-native-chat-message-styles.tssrc/cli/handlers/orchestration/worker-output.tssrc/main/runtime/orchestration/worker-transcript-payload.test.tssrc/main/runtime/orchestration/worker-transcript-payload.tssrc/main/runtime/structured-worker-terminal-read.tssrc/renderer/src/components/native-chat/NativeChatMessageList.tsxsrc/renderer/src/components/native-chat/NativeChatMessageRow.test.tsxsrc/renderer/src/components/native-chat/NativeChatMessageRow.tsxsrc/renderer/src/components/native-chat/NativeChatTranscriptRow.tsxsrc/renderer/src/components/native-chat/native-chat-row-height-estimate.tssrc/renderer/src/components/native-chat/native-chat-tool-fold.test.tssrc/renderer/src/components/native-chat/native-chat-transcript-slots.test.tssrc/renderer/src/components/native-chat/native-chat-transcript-slots.tssrc/renderer/src/components/native-chat/structured-agent-question-projection.test.tssrc/renderer/src/components/native-chat/structured-agent-question-projection.tssrc/renderer/src/components/native-chat/use-native-chat-transcript-window.options.test.tsxsrc/renderer/src/i18n/en-runtime-required.jsonsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/agent-session-journal-producer.tssrc/shared/native-chat-subagent-attribution.tssrc/shared/native-chat-tool-fold.tssrc/shared/native-chat-turn-fold.test.tssrc/shared/native-chat-turn-fold.tssrc/shared/native-chat-types.tssrc/shared/structured-agent-session-projection.test.tssrc/shared/structured-agent-session-projection.tssrc/shared/worker-transcript-background-task-text.test.tssrc/shared/worker-transcript-subagent-attribution.test.tssrc/shared/worker-transcript-text-scaling.test.tssrc/shared/worker-transcript-text.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| // A subagent's row sits where it happened but speaks as that subagent, never as | ||
| // the agent the reader is talking to. | ||
| const subagentName = | ||
| agentJournalItemSubagentId(message) === null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Show attribution on notice and provider-frame rows.
If a subagent row contains a notice or provider frame, MessageRow returns at Line 111 or Line 123 before it reaches this caption. The displayed content has no subagent attribution, even though the message retains agentId. Render the caption in those branches as well, or move attribution into a wrapper shared by all non-user row types.
| const foldTarget = | ||
| mutableAssistantIndex >= 0 && | ||
| agentJournalItemSubagentId(output[mutableAssistantIndex]) === | ||
| agentJournalItemSubagentId(message) | ||
| ? mutableAssistantIndex | ||
| : -1 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Preserve tool results when another agent interleaves.
If a child emits a tool call, the parent emits an assistant row, and the child then emits a tool result, foldTarget is -1. The result stays in its own row. dropUnattributableToolResults then removes it because that row has no call. The transcript loses the result and any reported failure. Keep the result in its attributed position, or match it to the child's call without moving it ahead of the parent's row.
| const label = nativeChatSubagentLabel(subagentLabels, message) | ||
| return label === undefined ? `${message.role}, subagent` : `${message.role}, subagent ${label}` |
There was a problem hiding this comment.
🔒 Security & Privacy | 🛡️ Detected with Advanced Tier | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '1,100p' src/shared/worker-transcript-text.ts
sed -n '1,100p' src/shared/native-chat-subagent-attribution.ts
rg -n 'agentPath|agent\.label|subagent.*label' src/main src/shared | head -100Repository: stablyai/orca
Length of output: 19695
🏁 Script executed:
#!/bin/bash
sed -n '1,130p' src/main/codex/codex-subagent-activity.ts
sed -n '1,130p' src/main/codex/codex-subagent-roster.ts
sed -n '1,100p' src/main/codex/codex-subagent-group-body.ts
sed -n '1,100p' src/main/runtime/orchestration/worker-transcript-activity-block-bounds.ts
rg -n -A12 -B8 'boundInlineText\(agent\.label|label:.*agent\.label|replace\(/\\s|trim\(\)' src/main/claude src/main/codex src/main/native-chat src/main/runtimeRepository: stablyai/orca
Length of output: 45715
Injection
Reachability: External
Exploitability: Moderate
CWE: CWE-93
Reachability path
● Entry
src/shared/worker-transcript-background-task-text.test.ts:5
formatWorkerTranscriptMessage
│
▼
● Sink
src/shared/worker-transcript-text.ts
Escape line breaks from Codex roster labels before building speaker prefixes. Codex labels retain embedded line breaks after trimming and length bounding. workerTranscriptSpeaker inserts the label directly, so a label containing \n[assistant] ... can create a forged speaker line in CLI transcript and terminal-read output.
Escape line breaks in the shared formatter
const label = nativeChatSubagentLabel(subagentLabels, message)
- return label === undefined ? `${message.role}, subagent` : `${message.role}, subagent ${label}`
+ const safeLabel = label?.replace(/\r/g, '\\r').replace(/\n/g, '\\n')
+ return safeLabel === undefined
+ ? `${message.role}, subagent`
+ : `${message.role}, subagent ${safeLabel}`📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const label = nativeChatSubagentLabel(subagentLabels, message) | |
| return label === undefined ? `${message.role}, subagent` : `${message.role}, subagent ${label}` | |
| const label = nativeChatSubagentLabel(subagentLabels, message) | |
| const safeLabel = label?.replace(/\r/g, '\\r').replace(/\n/g, '\\n') | |
| return safeLabel === undefined | |
| ? `${message.role}, subagent` | |
| : `${message.role}, subagent ${safeLabel}` |
…-subagent-speech # Conflicts: # src/renderer/src/components/native-chat/NativeChatMessageRow.test.tsx # src/renderer/src/components/native-chat/NativeChatMessageRow.tsx
|
| specifier: ^9.1.7 | ||
| version: 9.1.7 | ||
| i18next-cli: | ||
| specifier: 1.74.1 | ||
| version: 1.74.1(@types/[email protected])([email protected]([email protected]))([email protected])([email protected]) | ||
| specifier: 1.74.2 |
There was a problem hiding this comment.
Inconsistent dependency lockfile The lockfile now resolves
[email protected] and records a patch hash for it, but package.json still pins 1.74.1 and pnpm-workspace.yaml declares no patch for 1.74.2. A frozen install cannot use this configuration as committed, blocking clean installs and CI. Please update the manifest and patch declaration together, or restore the lockfile entry.
…3614) into #23059 Conflicts, resolved to keep main's mechanism and #23059's turn facts: - Codex turn boundaries and translator: main's #23682 wins; the error-driven `fail` end and the oversized-notification settler are gone, and only `turn/completed` ends a turn, a command's turn included. - Codex adapter: the compaction tracker stays deleted; #23618's settlement of sends in an ended turn is kept, and `codexDispatchRejection` is imported from its new home. - Journal reducer: main's per-item creating fence (#23456) moves into the item and submission folds this branch split out of the reducer. - Stale-turn verdict: main's proof-of-death revision; every turn revision states the thread scope. - Failure words: main's retry-control rules (#23608) with this branch's any-command retry step; `commandRefused` drops its retry step beside a Retry, as hostFault does. - Delivery: both the commit wake and main's death-evidence resettle and dispose. - Fold row and transcript slots: both the turn-outcome flag and main's `agentId`. - pr.yml and pnpm-lock.yaml taken from main. Beyond the conflicts, the merged files needed: - use-structured-agent-session: both sides added the same `submissions` key; one kept. - structured-agent-session-projection: the root-item import main still used is unused here. - The desktop message list and the mobile chat view each grew past the line limit from both sides' additions: the turn-membership memo moves into its own hook, and the mobile list footer (live status, then waiting rows) into its own helper.
|
Follow-up: #23752 restructures this PR's transcript half so a subagent's rows live in that subagent's own section, never in the parent's conversation. Review status is in that PR. |

ELI5
When an agent in the chat hands work to a helper agent (a subagent), the helper's words show up in the same chat. Today they look exactly like the main agent talking, so you can read a helper's "The PR is CLEAN" as if the agent you asked had concluded it. This PR keeps every helper line where it happened but labels it as that helper's, and never lets a helper's words stand in as the main agent's reply.
What Changed
Before (mechanism). Every journal row already records which agent wrote it: #22299 added producer linkage (
agentId,parentAgentId,producerKind, …) and scoped the sidebar and status readers by it. But the chat transcript's projection copied only the row's id, time and position onto each chat message, so the linkage stopped there. Everything downstream of the projection could no longer tell the agent from its helpers:orca orchestration worker-readandterminal readon a structured worker printed a helper's lines as[assistant] …, the worker's own.After (mechanism). The projection now carries the row's linkage onto the chat message through the same single spread (
agentJournalLinkageFields) every other linkage carrier uses. Nothing new is stored: the chat message is rebuilt from the journal on every read. With the linkage present, each reader applies one rule, all through the existing single interpretation point for "was this the session's own agent":[assistant, subagent <name>]; the worker-read payload serves only the helper's id, bounded exactly like the roster entry that names it, and not the provenance fields.User-visible after. The chat still shows everything every agent did. A helper's lines read as the helper's. A collapsed turn shows the agent's own answer, with the helpers' narration behind "Worked for N" like the rest of the turn's work.
Why
The failure class. Attribution existed in the durable record and was thrown away at one hop, so every reader downstream had to present rows without knowing whose they were. Patching individual readers would leave the next one wrong; carrying the fact across the hop fixes the class, and each reader keeps only presentation policy.
How often, on real data. On this machine's journals from the last six days, 572 of 2,309 settled turns (about 25%) folded down to a helper's words as the turn's answer. In one real session the "parent's" transcript held 3,584 tool calls and 299 prose lines that were actually its helpers', against 3,353 and 461 of its own.
Why attribute in place, rather than the alternatives.
What stays one rule. Absence of linkage means "the session's own agent", read in one place (
isRootAgentJournalItemand its new siblingagentJournalItemSubagentId). Transcripts with no linkage at all — terminal-backed chats and journals written before #22299 — fold and render exactly as before; there is a test for that.Deviation from common practice, stated plainly. The common approach keeps a helper's own rows out of the parent's timeline: either dropping them, or attaching them beneath the call that spawned the helper. This PR does neither; it attributes them in place. That is a deliberate deviation for the reasons above, not an alignment. Its cost is that a helper-heavy session stays busy to read, and every new reader of chat messages has to consult the producer rather than being safe by construction. The linkage-on-the-message and producer-aware fold introduced here are the foundation a later "attach helper rows beneath their helper" design would build on, so this is not a dead end.
Known weaknesses.
Wire and persistence. No schema bump, no migration, no new persisted fact. The chat message gains optional linkage fields that are copies of what the journal already stores; they reach the
worker-readresult and the released-worker archive as new optional fields (Rule 1 indocs/reference/remote-wire-compatibility.md). An older client ignores them and prints as today; a newer client reading an older host sees no linkage and prints as today. Archives written before this change carry no linkage and read exactly as before.Linked Issue
Linear: STA-8138 — relands the user-visible fix reverted in #22058 on the identity model #22299 introduced, rather than on the reverted boolean.
Scope note: #22299 already relanded the sidebar and status half of #21398. The ticket's acceptance ("a subagent's output is not presented as the parent agent's speech") also covers the chat transcript, which #21398 had deliberately left alone; this PR is that half.
Visual Proof
To be attached by the Electron QA pass.
Testing
New tests, each proven red against the pre-change code and green after (break the fix, watch the named tests fail, restore):
Gates: root typecheck (node, CLI, web) and the mobile typecheck (which root typecheck does not cover, and which caught a real bug in the first draft),
oxlintwith root and mobile configs (with a positive control proving it fails on a real violation), the changed-code quality gate, React Doctor, and all five localization verifiers.Broad regression over
src/shared, the native-chat and sidebar components, the orchestration CLI andsrc/main/runtime: 23,868 passed, 8 failed, and every failure was checked against main's code. Three pass in isolation (load-sensitive), three fail identically with this change reverted (orchestration-task-list-brief×2,orchestration-all-start-versions-migration), one fails 1 run in 3 on both main's code and this branch (repo-ref-maintenance). None is caused by this PR.AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Cross-platform: no platform-specific code. SSH/remote: the change is in shared projection and presentation; remote hosts' journals carry the same linkage, and the wire change is optional-field only. Mobile: same fold and caption as desktop. Performance: one linear pass per message list to collect roster names, memoized on the list; row props stay primitive so memoized rows do not re-render.
Two pre-existing localization issues noticed and deliberately not fixed here: the Spanish catalog has no
subagentssection at all, and the existing Japanese, Korean and Chinese "Kicked off N subagents" strings are mistranslated as "fired", "expelled" and "kicked out".Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)