Repository navigation
fix(native-chat): stop a subagent's output speaking for the agent that spawned it - #21398
Conversation
…mechanism Re-baselined against origin/main (one unrelated commit; no drift in any cited file). Confirmed the two unverified items at source, found a third reader with the same defect and a fourth append path a naive fix would miss, and recorded the producer-attribution decision with its field shape, migration behaviour, wire category, tests and implementation order.
…t spawned it One journal is the durable record of one agent session, but a session that runs subagents journals their rows into it too, with nothing on the row saying which agent wrote it. Every "what is this agent doing right now" reader is a backward scan bounded by markers only the root agent writes, so the window is guaranteed to hold foreign rows and, while a subagent runs, the newest row in it is the child's. The sidebar therefore showed a child's prose and a child's running tool on the parent's row. Attribute at the producer instead of guessing at the reader. The Claude translator already parses `parent_tool_use_id` on every envelope and threw it away; it now stamps `producedBySubagent` on every row that envelope produces, including the streamed-text path, which persists from a callback with no envelope in scope and takes the flag from the block identity registry that already scopes itself on that id. The three status readers skip non-root rows through one shared predicate. The transcript is deliberately left unscoped: it shows every agent's output. No schema version bump, no upcaster, no backfill. An unknown `v` makes a row unreadable and latches the host read-only, while an unknown key is ignored, so an older host reads a stamped row and behaves exactly as it does today. Rows written before the flag read as root, which reproduces today's behaviour for that history exactly.
…ent-label # Conflicts: # src/shared/structured-agent-session-projection.ts
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
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 selected for processing (2)
💤 Files with no reviewable changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change adds an optional Priority: ➖ Normal Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, testing, compatibility, and scope. However, the required Linked Issue field is incomplete because it contains only Full details: Docstring CoverageExplanation Docstring coverage is 43.59% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 23 files. (2 skipped: 2 unsupported.) Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Validate producedBySubagent when parsing a journal row. · journal-row-schema.ts:183
src/main/native-chat/agent-session-journal/journal-row-schema.ts:183
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winValidate
producedBySubagentwhen parsing a journal row.
JournalRowBaseandAgentJournalRenderItemboth declareproducedBySubagent?: true, butisJournalRowdoes not validate this field. A persisted item row with"producedBySubagent": "yes"can passparseJournalRowand reachrenderedItemthrough the replay path. The truthy string is then copied into the render item, violating its literal-truecontract. Reject the row unless the field is absent or exactlytrue.Proposed validation
function isJournalRow(record: Record<string, unknown>): record is JournalRow { + if (record.producedBySubagent !== undefined && record.producedBySubagent !== true) { + return false + } if (typeof record.kind !== 'string' || !ROW_KINDS.has(record.kind)) {
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 0e6a38e2-b01a-4de6-91da-13c0e48fecd6
📒 Files selected for processing (23)
ATTRIBUTION-parent-label.mdPR-BODY.mdsrc/main/claude/claude-message-journaling.tssrc/main/claude/claude-streamed-block-identity.tssrc/main/claude/claude-streamed-text-checkpoints.tssrc/main/claude/claude-structured-journal-translation-subagents.test.tssrc/main/claude/claude-structured-journal-translation.tssrc/main/claude/claude-structured-provider-fallback.tssrc/main/native-chat/agent-session-journal/journal-item-appender.tssrc/main/native-chat/agent-session-journal/journal-reducer.test.tssrc/main/native-chat/agent-session-journal/journal-reducer.tssrc/main/native-chat/agent-session-journal/journal-row-builders.tssrc/main/native-chat/agent-session-journal/journal-row-schema.test.tssrc/main/native-chat/agent-session-journal/journal-row-schema.tssrc/main/native-chat/agent-session-journal/journal-store-contracts.tssrc/main/native-chat/agent-session-wire/structured-agent-session-event-sink.tssrc/shared/agent-session-journal-producer.tssrc/shared/agent-session-journal-schemas.tssrc/shared/agent-session-journal-types.tssrc/shared/structured-agent-session-live-turn.test.tssrc/shared/structured-agent-session-live-turn.tssrc/shared/structured-agent-session-projection.test.tssrc/shared/structured-agent-session-projection.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| - **Security.** No new data crosses any boundary; the marker is derived from a field the producer | ||
| already parsed. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the boundary claim.
producedBySubagent crosses the render-item wire surface, as this PR body states at Lines 142-147. State that the change adds no new content or sensitive data, rather than that no new data crosses a boundary.
There was a problem hiding this comment.
Important
The attribution change itself reads correctly and is well covered, but the branch also commits 913 lines of authoring scratch to the repository root. ATTRIBUTION-parent-label.md and PR-BODY.md should not land on main.
Reviewed changes
- Producer marker on journal rows. Optional
producedBySubagent?: trueadded to persisted rows and render items; no schema version bump, becauseparseJournalRowspreads the raw record and ignores unknown keys, so older hosts read a stamped row exactly as before. - Claude producer stamping. The translator stamps the message body, each tool call, each tool result, reasoning, and the unmodeled/fallback rows from
envelope.parentToolUseId; streamed text carries the marker through the streamed-block registry and the checkpoint producer map. - Reader scoping. The newest assistant line, active tool call, thinking indicator, and latest prompt now skip rows another agent produced, through one shared
isRootAgentJournalItempredicate. - Deliberately unscoped readers. Transcript projection and the session-has-content check are left unscoped with their reasons recorded.
ℹ️ Subagent prompt rows are never stamped
ClaudeJournalPrompts writes approval/question rows from the prompt event, which is not a message frame, and passes no producer option. isStructuredAgentSessionThinking inspects exactly those kinds, so an unstamped child prompt row is read as the session's own newest content. This is a scope gap rather than a regression — the discriminant exists (canUseTool receives options.agentID) but Orca never reads it.
Technical details
# Subagent prompt rows are unstamped, so the thinking reader reads them as root
## Affected sites
- `src/main/claude/claude-structured-journal-prompts.ts:73` — question rows appended with no options
- `src/main/claude/claude-structured-journal-prompts.ts:83` — approval rows appended with no options
- `src/main/claude/claude-structured-inbound-control.ts:57-71` — `canUseTool` registers the prompt and drops `options.agentID`
- `src/shared/structured-agent-session-live-turn.ts:75-82` — `approval`/`question` treated as the session's own newest content
## Required outcome
A subagent's `approval`/`question` row must not count as the session's own content for `isStructuredAgentSessionThinking`, or the omission must be recorded as an intentional limit.
## Suggested approach (optional)
Thread a producer bit from `options.agentID` (Claude Agent SDK `sdk.d.ts:250`, "If running within the context of a sub-agent, the sub-agent's ID") through `ClaudePromptRegistration`/`ClaudePendingPrompt`, then pass `{ producedBySubagent: true }` on the appends at `:73`/`:83`.
## Open questions for the human
- Does Orca actually observe a subagent's `can_use_tool` request, or does the CLI surface subagent permission prompts through the parent with no `agentID`? The SDK contract says it can; I did not observe one live.
- Is "the parent is not thinking while a child awaits permission" the intended reading? If so, this is a documented limit, not a bug.ℹ️ Nitpicks
- The sink's
appendLifecycleBatch/tryAppendLifecycleTransitiondropoptions.producedBySubagent, andjournalLifecycleBatchRowBuildernever emits it, so the reducer's lifecycle-batch marker test (journal-reducer.test.ts:697-707) exercises a shape no real write path can produce. Harmless today, but a future stamped batch would silently lose the marker.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ Incremental review of the commits pushed during the prior review — a merge from
mainplus a formatter pass. No new issues.
Reviewed changes since 3ba91cb
- Merge from
main(3061eab). Resolved cleanly.mainhad refactoredlatestStructuredAgentSessionPromptto delegate to a newlatestStructuredAgentSessionUserItem; the resolution moves the root-producer check into that shared helper, so the prompt reader stays scoped. Its two resume/teardown callers (structured-agent-session-working-at-teardown.ts:114,structured-agent-session-restart-resume-host.ts:179) are unaffected in practice, because user-role render items only come from root submissions on the Claude lane. - Formatter (
4053f66). Whitespace only.
Verified at 4053f66: 137 tests pass across the projection, live-turn, subagent-translation, reducer, and restart-resume files. The two findings from the initial review are unchanged by these commits.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
CDP QA — structured native-chat parent-label (worktree only)Hidden Electron launch ( Scenario
This is a seeded structured journal, not a live Claude subagent spawn. The host re-read the journal on reveal ( Identity
CDP Visible evidenceSidebar parent row shows the parent's own last line, Native chat transcript still renders both agents:
Backing status published to
The compact row's accessibility name was ConsoleRenderer: 0 product errors. Warnings: React DevTools hint, Tooltip controlled/uncontrolled, React Grab outdated. One 404 during this run: Main-process log: ScreenshotsLocal copies: UnverifiedLive Claude CLI spawn of a helper mid-turn was not exercised. Codex producer is out of scope for this PR. |
Review status: pass with one fix pushed
Remaining validation gap: the QA used a stamped journal fixture rather than spawning a live Claude helper mid-turn. The Codex producer lane remains outside this PR scope. GitHub checks were still in progress at review time; typecheck and cross-version wire compatibility were green, while the root-directory guard was reported failing without available logs yet. |
There was a problem hiding this comment.
ℹ️ Incremental review of
14080fd1— no new issues in this delta. The previously opened thread about the root-level authoring scratch files is unchanged and is the only thing holding approval.
Reviewed changes since 4053f66
- Resolved-append attribution (
14080fd1). BothtryAppendResolvedItemandtryAppendResolvedItemAndPublishnow forwardproducedBySubagentto the durable append, closing the oneStructuredAgentSessionAppendOptionsentry point that accepted the field and silently dropped it. - Regression test. A new sink test drives both resolved paths with
{ producedBySubagent: true }and asserts the marker reachesappendItem; it fails when the forwarding is removed (verified locally by temporarily neutralising the source lines).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Follow-up: the repository root-directory guard failure was caused by the two review markdown artifacts added at the repository root. They are now preserved under docs/audits/attr-parent-label/ in commit f6e0a13. The local guard passes against origin/main and the PR branch; GitHub checks are rerunning for the updated head. |
There was a problem hiding this comment.
✅ No new issues found. This delta resolves the prior review's only blocking finding.
Reviewed changes since 14080fd1
- Moved the two authoring artifacts under
docs/audits/(f6e0a134). A pure rename with no content change:ATTRIBUTION-parent-label.mdandPR-BODY.mdleave the repository root fordocs/audits/attr-parent-label/, so the root no longer carries 900-plus lines of branch scratch. The prior thread asking for these to be removed or relocated is addressed and resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Review complete: ready after fixes.
No scope-expanding changes were made. |
|
Removed the review-only documentation artifacts from the branch, including |
|
The current red check is unrelated to this PR. |
|
Refreshed the branch against current |
|
CI follow-up: after refreshing onto current |
|
Reran the failed checks (attempt 3). The same |



ELI5
When a chat agent hands part of a job to a helper agent, both of them write into the same
notebook. Nothing in the notebook said who wrote each line. So when the sidebar asked "what is my
agent doing right now?", it read the most recent line — usually the helper's — and showed the
helper's words and the helper's tool on the main agent's row.
Now every line records who wrote it, and the "what is my agent doing" readers only read their own
agent's lines. The full conversation still shows everything both agents wrote.
What Changed
Before. Start a chat session and let the agent spawn a helper agent. While the helper worked,
the parent's sidebar row showed the helper's text as its own secondary line, and showed the
helper's running tool (for example
Grep) as the tool the parent was running. The parent's chatalso showed the "thinking" indicator whenever the helper was reasoning, even though the parent was
not. The parent had produced nothing since handing the work over.
After. The parent's row shows the parent's own last line and the parent's own running tool —
which, while a helper runs, is the call that spawned it. The thinking indicator follows the
parent's own reasoning. The transcript is unchanged: it still shows everything the helper wrote,
and the helper's own rows in the helper list are unchanged.
The mechanism. A session's durable record is one file, but a session that spawns helpers writes
their output into it too, and no field on a row said which agent produced it. Every "what is this
agent doing right now" reader is a scan backwards from the end of the list that stops at a marker
only the top-level agent ever writes. So those scans were correctly bounded at their edges and
completely unscoped in their contents — the window they read was guaranteed to contain another
agent's rows, and during a helper run the newest row in it was almost always the helper's.
The change records the producer where the row is written, and scopes the readers by it:
producedBySubagentmarker, shaped exactly like the existingrecoveredmarker next to it — present or absent, never
false. Absence means the session's own agent.every row that frame produces: the message body, each tool call, each tool result, reasoning, and
the generic fallback row. It also stamps streamed text, which is written from a callback that
has no frame in scope — that path takes the marker from the streamed-block registry, which
already scopes itself on the same parent-call id. A fix that only covered the frame path would
have looked complete and still leaked on every streamed reply.
top-level frame. That is now stated in a comment and pinned by a test.
indicator — now skip rows another agent produced, through one shared predicate that is the only
place absence is interpreted.
transcript renders every agent's output, and the "does this session have any content" check is an
existence test, not an attribution one.
No schema version bump, no upcaster, no backfill. A row from a higher version is treated as
unreadable and puts the host into read-only, whereas an unknown key is simply ignored — so a
version bump for an optional marker would make journals written by a newer build unreadable to an
older one, for a field the older build never reads. Rows written before this change read as the
session's own agent, which reproduces today's behaviour for existing history exactly. The one
bounded consequence: a session that is open across the upgrade can still pick up a helper's line
for at most one turn, because the scans stop at the first turn marker and the first turn opened
after the upgrade is written by the new build.
Why
The alternative was to filter at the reader — infer that a row belongs to a helper because it
follows a still-running spawn call. That is not implementable honestly: a helper's rows are written
under the parent's identity and the parent's session id, so there is no bit in the rendered row to
filter on. Inference also breaks under exactly the cases that already exist and are already tested,
such as a backgrounded helper still emitting after its spawn call has returned, or two helpers in
flight at once. It would have to be written four times over, and it would leave the durable record
permanently ambiguous, so the next reader starts from the same nothing.
Recording the producer where the row is written is also what this subsystem's own reference
document asks for: precedence is decided once, at write time, with provenance on the row, and
readers never re-adjudicate. Producer-side classification of top-level versus helper frames is
already established practice here — it exists in turn opening, in the streamed-block registry, in
the transcript reader, and on the Codex lane. The journal row was the one artifact that did not
carry it.
The marker is a bare
true, not the helper's id. Readers need one bit: "is this mine". Per-helperidentity already has an owner — the helper roster, whose ids survive a task resume through an alias
map — and copying that identity onto rows would create a second copy that disagrees after any
resume. A presence bit also generalises to Codex, where the discriminant is a path rather than a
single id.
Honest scope: this removes the ambiguity, so a reader that wants its own agent's truth can now have
it. It does not make a fifth unscoped scan impossible to write; what discourages one is that the
scoped predicate now lives beside the type and is the obvious thing to reach for.
Material deviation. Orca keeps two writers of one status row apart with publication filters;
this change does not remove that structure. It fixes something narrower and adjacent: one row's
content was being written from another agent's output.
Linked Issue
Fixes #
Visual Proof
Not attached. The user-visible change is one line of text and one tool name on a sidebar row, and
reproducing it needs a live session that spawns a helper agent mid-turn. The behaviour is pinned
instead by tests asserting the exact fields the row reads —
lastAssistantMessage,toolNameandtoolInput— in both directions, each shown to fail without the change.Testing
pnpm tc,pnpm teston the five affected files (108 tests),oxlint, andpnpm run check:code-quality:changedall pass. The cross-version wire suite stays green: the newrender-item field is optional, and no reader requires it.
Every new test was checked against the pre-change behaviour and observed to fail, then pass after:
reddens exactly the streamed test and nothing else.
test, and nothing else.
Two tests fail in a full local run and are unrelated: one drives the real Claude CLI and asserts
against this machine's own command catalogue (it fails identically with the change reverted), and
one is a temporary-directory cleanup race that passes in isolation.
Platforms: logic-only, no platform-specific code paths; exercised on macOS. No change to remote or
SSH behaviour — the same summary reaches every surface through the same store, so no reader-side
divergence is introduced.
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
hosts, older rows read as the session's own agent.
rendered item gains an optional field, which is safe as long as no reader requires it — none does,
because absence is read as top-level. The content of the status summary changes for the duration
of a helper run; this is deliberately not capability-gated, because gating it would mean
continuing to serve older clients the helper's text as the parent's, preserving the defect for them
by design. Old clients read those fields correctly; the fields were simply wrong.
RPC recording carries journal render items, so no re-record is forced.
already parsed.
discriminant available, but whether Codex journals helper output into the parent's record is
unverified and is its own investigation. Absent on Codex rows means top-level, which is exactly
today's behaviour there.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)