Repository navigation
fix(native-chat): journal rows name the agent that produced them - #22299
Conversation
A journal is the durable record of one agent SESSION, and a session that runs subagents journals their rows into the same timeline with nothing on the row saying which agent wrote it. Add that: a per-row linkage bundle naming the producing agent, its parent, the provider's raw parent reference as provenance, the kind of work, and which run of the agent produced the row. The bundle rides the row BASE, not the body: two nested prompt shapes are strict, so an unknown key on a body makes the whole row parse as malformed. It is deliberately not a schema-version bump either — 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. One reader predicate interprets absence, by presence and not by truthiness: an id that failed to resolve is still an id, and a truthy test would read it as root and put the child's content back on the parent. The parent-facing status scans — thinking, the running tool call, the latest assistant line and the quoted prompt — now skip rows a subagent produced. The transcript is left unscoped on purpose: it shows every agent's output. No producer stamps anything yet; this is the carrier and the reader.
The Claude translator already parsed `parent_tool_use_id` on every envelope and threw it away. It now resolves that reference to the producing agent's canonical task id — never to the reference itself, which names the tool CALL and is re-minted on every resume, so a row stamped with it would split one child into two the moment it resumed. The raw reference is kept beside it as provenance. Resolution is its own module rather than more roster: the roster maintains the spawn-group row a user reads, while this answers, for one frame's parent reference, whether the rows it produces are the session's own agent's, some child's, or nobody's yet. It reads the alias table directly to tell "an announcement named this spawn call" from "this id is simply unknown", which comparing the canonical id against the raw one cannot do when the two match. Where the identity is not final the row waits rather than guessing. A top-level spawn whose `task_started` has not landed is the one case that can still resolve, so its rows are held — bounded at 64, oldest written first — and released when the announcement arrives or when nothing can name the producer any more. Nothing is dropped and nothing is written as the parent's. A release that announces no tasks at all is decided immediately instead of held: nothing stable is ever reachable for its children, and an id that rotates is worse than no id because it is silently wrong rather than visibly absent. Those rows read as the session's own, exactly as they do today. Holding them instead would strand every row that REVISES an earlier one — a tool result would leave its tool row reading "running" for the rest of the turn. The attempt counter moves in exactly one place, the existing reactivation branch where a new spawn alias reopens an entry, and is gated on that observed alias change rather than on the counter, so a late duplicate cannot advance a settled run. The first run carries no attempt at all. The group row keeps its own module's write path, now named there, because it is the one row written from a child's frame that is deliberately the parent's.
…sses first Four harnesses in this area silently discarded the append options they were handed, so every assertion about attribution would have passed against `undefined`. Two are fixed here — the journal double behind the real deferred sink, and the Claude subagent translator's sink — and each records the options beside its existing call log rather than on it, so the assertions about call order stay about call order. The read side is pinned first, because linkage correct in the store and never read by the projection is the way this ships looking finished and fixing nothing. The three defects are asserted through the live-turn and projection readers: a parent no longer reads as thinking because its child is reasoning, no longer shows its child's running tool, and no longer quotes its child's prose or prompt. The opposite direction is pinned too — the transcript still renders the child's output, and a parent's own line is never suppressed. Also covered: a resumed child keeps one identity while its spawn call id rotates; a child row arriving before its announcement is held and then written linked rather than dropped; a held row is written under the raw reference when no announcement ever comes; the buffer's bound writes the oldest row rather than losing it; an unresolvable id reads as a child rather than as the parent; a row with no linkage reads as root; the schema version is unchanged; and a strict prompt shape still parses, with a positive control proving that strictness is real and is why linkage rides the row rather than a body.
Editing inside the object literal re-attributes the pre-existing assertion to changed lines, and the changed-code gate requires a line-specific rationale.
A grandchild's rows carried an agent id but no parent, and under this journal's semantics an absent parent is not silence — it is the claim that the session's own agent spawned the row's producer. For a task spawned from inside another subagent's sidechain that claim was simply false. The frames from such a task carry exactly one handle: the nested call's tool id. That id was journaled once already, as a tool-use block on the row of the child that made the call, so the child is recoverable from it — but only if something remembers which row carried it. The registry that already tracks which tool calls reached the top-level transcript now records the sidechain ones too, against the reference naming their owner, and the resolver follows that reference to name a row's parent. The reference is recorded, not an identity, and it is resolved through the same path the owner's own rows resolve through, so a parent id always matches the agent id the parent's rows carry however either was settled. A row now persists only once BOTH its producer and its parent are final; a grandchild whose child has not been announced yet waits in the same buffer, and leaves it through the same three doors.
…y capturing it The checkpoint harness was fixed to record the append options, and then nothing asserted them: all five of its tests passed unchanged against an implementation that resolves no producer at all, so the lane's attribution was covered by a capture and no claim. These assert it: a block streamed inside a child carries that child's linkage, the session's own carries no keys at all, a checkpoint is held rather than written while the producing agent is provisional, the flush before settlement writes a held block under the raw reference rather than losing it or filing it as the parent's, and a block's producer is resolved once and kept — every checkpoint rewrites the same row, so a producer that moved would file one agent's prose under two identities.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe change adds producer linkage to journal rows and render items. Claude tool origins now distinguish top-level and child-owned calls. Claude subagent linkage resolves parent, child, background, pending, and settled ownership. Rows written before identity resolution receive provisional stamps and can be corrected in place. Streamed text carries parent tool-use scope. Parent-facing activity, prompt, and assistant projections now exclude subagent rows, while transcript projection retains them. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to A high-volume child session can receive inconsistent attribution across its rows; preserve the abandoned producer identity before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 1b9b925e-7b69-4862-84a7-f1d09f20e97e
📒 Files selected for processing (37)
src/main/claude/claude-forwarded-tool-registry.tssrc/main/claude/claude-message-journaling.tssrc/main/claude/claude-pending-child-rows.test.tssrc/main/claude/claude-pending-child-rows.tssrc/main/claude/claude-streamed-block-identity.tssrc/main/claude/claude-streamed-text-checkpoints.test.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/claude/claude-subagent-group-row.tssrc/main/claude/claude-subagent-id-aliases.tssrc/main/claude/claude-subagent-linkage.tssrc/main/claude/claude-subagent-roster-state.tssrc/main/claude/claude-subagent-roster.tssrc/main/claude/claude-tool-origin-registry.tssrc/main/claude/claude-turn-opening.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-render-item.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.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-event-sink.tssrc/main/native-chat/agent-session-wire/structured-agent-session-journal-append-options.tssrc/main/native-chat/agent-session-wire/structured-agent-session-resolved-append.tssrc/shared/agent-session-journal-producer.test.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
💤 Files with no reviewable changes (1)
- src/main/claude/claude-forwarded-tool-registry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| return turn.state === 'running' && newestContentIsReasoning === true | ||
| } | ||
| if (newestContentIsReasoning !== null) { | ||
| if (newestContentIsReasoning !== null || !isRootAgentJournalItem(item)) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Filter child rows before reading turn lifecycle data.
Both scans process readAgentJournalTurn(body) before they check producer linkage. A newer child-linked turn row can therefore terminate the parent scan. It can clear the parent’s active Task call or make the parent’s thinking state depend on the child’s turn state.
Move the root-agent check before readAgentJournalTurn in both loops. Add regression cases with child-linked turn and status lifecycle rows.
Proposed fix
const item = items[index]
const body = item?.body
+ if (!isRootAgentJournalItem(item)) {
+ continue
+ }
const turn = readAgentJournalTurn(body)
if (turn) {
return turn.state === 'running' && newestContentIsReasoning === true
}
- if (newestContentIsReasoning !== null || !isRootAgentJournalItem(item)) {
+ if (newestContentIsReasoning !== null) {
continue
} const item = items[index]
const body = item?.body
+ if (!isRootAgentJournalItem(item)) {
+ continue
+ }
if (readAgentJournalTurn(body)) {
return null
}
- if (body?.kind === 'tool-call' && body.state === 'running' && isRootAgentJournalItem(item)) {
+ if (body?.kind === 'tool-call' && body.state === 'running') {
return body
}Also applies to: 129-129
…eir shape The anti-slop gate rejects "Shape" in a symbol name. These are the linkage fields a render item carries, and the name now matches the sibling helper that builds them.
…s the parent A child's first frames can arrive before the `task_started` that names it, and the resolver treated "this release has announced no task" as a settled fact about the CLI. Before its own first announcement every session looks exactly like that, so the FIRST subagent's pre-announcement rows were written straight out as the session's own — the whole defect, for the first child of every session, persisted with no backfill to repair it. A spawn call the session forwarded at top level is positive evidence that an announcement is still expected, so it now outranks the release check. A release that genuinely announces nothing is unchanged: its rows reach the release verdict at settle and still read as root, just written a little later. Also stops a malformed owner chain that loops back from naming an agent its own parent; the depth guard bounded that walk but could not make its answer mean anything, and absence is the truthful claim.
Every top-level tool call is a forwarded tool id, not just a spawn, so a result frame naming its own call as parent resolved as a child awaiting an announcement that is never coming. The row was parked until the turn settled and the tool sat `running` in the meantime. A frame delivering the result of the very call it names is the caller consuming its own output; only a spawn call ever gets a sidechain. Pins added for that and for the first-subagent hold, and the never-announced case now asserts the row was WRITTEN as root rather than that it carries no agent id, which an absent row also satisfied.
There was a problem hiding this comment.
Important
The message lane's hold works, but the streamed-text lane's equivalent does not: streamedText.flush() resolves a still-provisional producer on every non-stream frame (including the task_started frame itself, one line before it is observed), so a child block that streamed before its announcement is stamped with the rotating spawn tool_use_id and cached there. Detail inline.
Reviewed changes
- Producer linkage on every row — five optional fields (
agentId,parentAgentId,providerParentRef,producerKind,attempt) ride the journal row base; absence means the session's own agent. One presence predicate,isRootAgentJournalItem, is the single interpretation point. - Claude producer resolution —
ClaudeSubagentLinkagemaps a frame'sparent_tool_use_idto linked/pending/root using the canonical task id;ClaudePendingChildRowsholds provisional-identity rows until an announcement, eviction, or teardown writes them;ClaudeToolOriginRegistryalso records which child owned a sidechain tool id so a grandchild can name its real parent. - Plumbing — all four sink append paths and all three reducer upserts share one linkage mapper each (
structured-agent-session-journal-append-options.ts,journal-render-item.ts); linkage rides the row base with novbump, so older hosts ignore the keys. - Readers scoped —
isStructuredAgentSessionThinking,activeStructuredAgentSessionToolCall,latestStructuredAgentSessionAssistantMessage, and the user-item lookup now skip subagent rows; the transcript and session-existence test deliberately do not. - Tests — 57 new tests across 9 files, including presence-vs-truthiness, nested-parent naming, resume identity, buffer doors, and reader scoping.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| producers.set(key, {}) | ||
| return {} | ||
| } | ||
| const verdict = force ? deps.producer.settledLinkageFor(scope) : deps.producer.linkageFor(scope) |
There was a problem hiding this comment.
The force branch resolves a still-provisional producer here and then caches the result, so the rotating spawn tool_use_id can be pinned into the durable row. streamedText.flush() runs at claude-structured-journal-translation.ts:184 on every non-stream event — including the task_started frame itself, which is only observed at :226 — so a child block that streamed before its announcement takes settledLinkageFor and is stamped agentId = <spawn tool_use_id> before ids.alias exists. producers then returns that for every later checkpoint, and only forget/drop at the final assistant frame clears it, so an interrupted stream keeps the rotating id on its row forever.
Technical details
# Streamed checkpoint resolves a provisional producer to the rotating id
## Affected sites
- `src/main/claude/claude-streamed-text-checkpoints.ts:83` — `force` selects `settledLinkageFor`, which never returns `pending`; `:90` caches the fallback.
- `src/main/claude/claude-structured-journal-translation.ts:184` — `streamedText.flush()` (forcing) runs before `subagents.observeSystemFrame` + `pendingChildRows.retry()` at `:226-229`.
- `src/main/claude/claude-subagent-linkage.ts:124-139` — for a forwarded, unannounced top-level spawn, `settled` skips the pending branch and returns `canonical`, which equals the raw tool id until `ids.alias` runs.
## Sequence
1. Deltas: `handleStream` → `append(..., parentToolUseId)` sets `scopes[key] = toolu_1`; `handle` returns before any flush.
2. Coalescer tick: `persist(key, text, false)` → `producerOptions(key, false)` → `linkageFor` → `pending` → held (correct).
3. `task_started`: `handleStream` false → `flush()` at `:184` → `persist(key, text, true)` → `producerOptions(key, true)` → `settledLinkageFor('toolu_1')` → `linked('toolu_1', 'toolu_1', 'agent', ...)`; cached; durable row written with the rotating id.
4. `:226` observes the announcement and aliases `toolu_1 → task-1`, then `pendingChildRows.retry()` — which drains only the message-lane buffer, not `producers`.
## Required outcome
A child block whose producer is still provisional must not be stamped with the rotating spawn id merely because another frame arrived, and the announcement processed on that same event must be able to give it the canonical id. Process announcements before flushing, or do not cache the `settledLinkageFor` fallback so a later real verdict can replace it.
## Suggested approach
Move the `observeSystemFrame`/`retry` handling ahead of `streamedText.flush()` in `handle`, and/or split `flush` into a non-forcing "write what you have" and the forced release door used only on eviction/settle/teardown.
## Open questions for the human
Is the raw-id stamp for an interrupted stream an accepted anti-swallow price for this lane? The message lane pays it only at drain (bound/settle/teardown); this lane pays it on every intervening frame.| return typeof frame.parent_tool_use_id !== 'string' | ||
| } | ||
|
|
||
| /** The parent this frame names, or null on a root frame. Reads the same field |
There was a problem hiding this comment.
The comment says this reads the field "by the same rule" as isRootClaudeFrame, but they disagree on parent_tool_use_id: '': isRootClaudeFrame (:59, typeof !== 'string') treats '' as a child — so a root result frame carrying '' would not settle its turn — while this function treats it as root. Align the rule, or narrow the "nothing can disagree" claim.
… losing the row The reader that scopes a parent's surfaces tests PRESENCE, so `agentId: ''` is present: a row carrying it reads as a subagent's and disappears from its own author's surfaces for good. Neither validator caught it — the wire schema accepted any string, and the persisted-row guard type-checked nothing in the bundle at all, against that file's own stated policy. The wire schema now requires a non-empty id. The persisted side sanitises instead: a bad linkage field is DROPPED and the row is kept. Rejecting there would turn a tightened validator into a whole-store kill switch, and degrading a row to the session's own agent is what every row said before linkage existed.
… agent `selectStructuredAgentTurnActivity` is a "what is this agent doing right now" reader and was not scoped by producer. It builds a label set from every tool-call row in the turn — a subagent's included — and both readers below it use that set to suppress a line that repeats it. So a CHILD's tool label could blank the PARENT's activity line: child data deciding the parent's surface. Live, not latent: the provider-activity branch is populated in this lane, and it consults the label set without ever consulting `providerFrame`, which is what the status fallback loop relies on. Scoped once at the top, so both readers share one interpretation point. Renderer and mobile share this function, so both are covered.
…ations A lifecycle-batch row carries N mutations but stamped linkage at ROW level, so a future mixed-producer batch would silently attribute every mutation to whoever opened it. Both callers are single-producer today, so this was latent. The write path no longer accepts linkage for a batch, which removes the failure mode by construction rather than guarding it. The reducer still READS linkage off a batch row — a row may arrive from a host that writes one — and a genuinely mixed batch would have to stamp per mutation, which nothing needs yet. Chosen over adding a per-mutation field because that would persist a new key forever with no writer and no reader.
… two false claims Completes the write-site audit the PR claims. Prompt rows carry no linkage and CANNOT: a prompt arrives through the SDK's permission callback, whose options carry a request id and the tool awaiting approval and no parent reference of any kind — unattributable at that site, not deliberately root. Turn rows are deliberately root and now say so. Two comments justified decisions by mechanisms this store does not have. The linkage docblock cited compaction dropping a start row and a pagination boundary; there is no compaction, and pagination is complete-or-reset. Per-row repetition is still right, for the reason that is actually true: every reader scans back from the tail and stops at the turn. A test carried the same false framing. `claudeFrameParentRef` claimed to read the field by the same rule as `isRootClaudeFrame`; it is deliberately stricter on the empty string.
There was a problem hiding this comment.
ℹ️ Incremental commits look correct; one informational note below.
Reviewed changes
Delta since the prior pullfrog review (ba6c178 → 5773768, 3 commits):
- Linkage schema rename —
AgentJournalProducerLinkageShape→AgentJournalProducerLinkageFieldsinagent-session-journal-schemas.ts; all references updated. - First-child hold —
ClaudeSubagentLinkage.resolvenow checks!settled && awaitingOwnAnnouncementbefore the!announcesTasks()release check, so the session's first subagent is held for itstask_startedinstead of being filed as the parent. Also omitsparentAgentIdwhen it would equalagentId(malformed self-parent chain). - Tool result as its caller's row —
journalClaudeMessagecomputesproducedByCaller(a result for the very call the frame names as parent) and admits that envelope as root, so ordinary tool output is no longer parked as a child's against an announcement that never comes. - Tests — new pins for the first-child hold and the tool-result case, plus a tightened assertion for the no-announcement release case.
ℹ️ The release fallback now holds, rather than skips, old-release child rows
a37bae5 makes { kind: 'root' } reachable for a forwarded spawn only through settledLinkageFor, because awaitingOwnAnnouncement is true whenever the spawn id is forwarded and not yet announced. On a CLI that never emits task_started, announcesTasks stays false, so a top-level spawn's child rows now wait in ClaudePendingChildRows until the turn settles (or the 64-row bound evicts them) rather than being journaled immediately as root. The rows still end root, so correctness is preserved, but the child's transcript content is no longer live during the turn for those releases, while the PR body still describes old-release behaviour as "exactly as today". Worth updating the accepted-limitations list — and dropping the "startup-ordering assumption" bullet, which this commit resolves.
Technical details
# Old-release forwarded-spawn rows now wait for settle
## Affected sites
- `src/main/claude/claude-subagent-linkage.ts:98-114` — the `!settled && awaitingOwnAnnouncement` pending check now precedes the `!announcesTasks()` root check.
- `src/main/claude/claude-structured-journal-translation.ts:201` / `:258` / `:226-228` — the buffer drains only at turn settle / session end; `retry()` only fires on a `task_started`.
## Required outcome
No code change required if the delayed liveness is intended. Update the PR description: the old-release rows no longer behave "exactly as today" (they are held to turn settle), and the startup-ordering limitation is now resolved for forwarded spawns.
## Open questions for the human
Is a provider release that announces no tasks still supported in practice, or can the `{ kind: 'root' }` compatibility branch be retired?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in the incremental commits; details below.
Reviewed changes
Delta since the prior pullfrog review (5773768 → 1a8aec3, 6 commits):
- Empty/invalid producer ids — the wire schema now requires
.min(1)on every linkage id, and the host'sparseJournalRowstrips an unusable linkage field while keeping the row. This closes the''-is-present hazard without turning a bad metadata field into a whole-row rejection. - Turn-activity reader scoped —
selectStructuredAgentTurnActivitynow filters its window throughisRootAgentJournalItembefore computing tool labels and status lines, so a subagent's running tool can no longer suppress the session's own activity line. This reader was not covered by the initial review and is now handled. - Lifecycle-batch linkage removed — one batch row covers N mutations, so a row-level producer would stamp whoever opened the batch onto every mutation; the builder, input type, and sink no longer carry linkage, while the reducer still reads it defensively for foreign rows.
- Documentation pass —
claudeFrameParentRefnow states it is deliberately stricter thanisRootClaudeFrameand that the two disagree on''; rationale added for the deliberately root turn-lifecycle row and the unattributable prompt path; the row linkage doc comment was rewritten.
These fixes are correct and consistent with the surrounding plumbing. The streamed-text-lane thread from the initial review remains open (no commit has touched claude-streamed-text-checkpoints.ts or the flush() ordering), so this stays a non-approving review.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ibution Four misattribution paths shared one cause: the lane committed to an attribution verdict at write time and could never revise it. That followed from "the journal has no backfill", which is false — re-appending an `itemId` bumps its revision, the reducer rebuilds linkage from the newest row, and it pins `sequence`/`observedAt` so a correction does not move the bubble. This lane already relied on that twice. So the order inverts. A row whose producer is still provisional is written immediately, stamped with the spawn call's own id, and re-attributed in place when the announcement names it. Bookkeeping no longer gates a user's view of what an agent said. The hold buffer is deleted rather than left as a pass-through. Corrections are bounded and die four ways: the announcement, turn settle, teardown, or the bound. Passing the bound gives up on that producer WHOLESALE — correcting some of a child's rows and not the rest splits one child across two ids, which is worse than correcting none. A correction that would change nothing is dropped rather than burning a revision. The streamed lane loses its producer latch, which pinned the first verdict permanently and is why an announcement one frame later could never reach the row. Every checkpoint rewrites the same identity, so there is one row per block and re-resolving can only revise it; the latch was guarding against a split that cannot happen on this path. A block that stops streaming before its announcement is re-attributed explicitly, since nothing else revisits it, and the announcement is now observed BEFORE the forced flush that would otherwise stamp it a line too early. Also narrows the no-announcements-at-all escape so it no longer swallows a forwarded spawn call. That escape now applies only to a sidechain id no spawn call ever forwarded, where there is genuinely no handle to stamp.
Both failed typecheck while passing at runtime, which is what a test double gets to do: vitest never typechecks them. The sink's lifecycle-batch double still read producer linkage off the batch input after that input stopped carrying any, so it had no property in common with the linkage type. The fence is now all it records, which is what the narrowed contract actually forwards — and what the test beside it already asserts. The row-schema helper returned the whole six-arm `JournalRow` union while every caller reads `body`. It now narrows to the item arm it always builds, so the assertions read it directly rather than through a cast.
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: 5827ab4f-a7b0-4394-b018-9f0dd686153f
📒 Files selected for processing (11)
src/main/claude/claude-message-journaling.tssrc/main/claude/claude-provisional-row-corrections.tssrc/main/claude/claude-streamed-text-checkpoints.test.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/claude/claude-subagent-linkage.tssrc/main/native-chat/agent-session-journal/journal-reducer.test.tssrc/main/native-chat/agent-session-journal/journal-row-schema.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-event-sink.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Electron QA — structured Claude subagentTested commit Structured lane was on before the session started: While the subagent was runningThe parent sidebar row stayed on the parent's own spawn call, The parent chat said "I'll delegate this to a single subagent and wait for it." and Working for …. It did not say Thinking. The transcript still had the child's work. Expanding the running Agent tool showed the child's Bash commands and their output. After the subagent finishedThe child row left the sidebar (settled children are not kept as rows). The parent row went to Done and quoted the parent's own summary: "The subagent finished. Here's what it reported." The chat said Worked for 5m 51s and Ran 1 subagent completed, then the parent's writeup. Opening the turn details still shows the child's Bash commands and output. What looked surprising
|
…sion root A nested tool row could end stuck `running` with its result content dropped. Cause was in the result-frame attribution, not in the correction ledger. A frame delivering the result of the call it names as parent is the CALLER consuming its own output — but the code read "the caller" as "the session's own agent", which is only true when the caller is the root. A call a child made is owned by that child. Collapsing it to root both misattributed the row and made the result's write resolve through a different reference than the call's, so the correction owed to that row was left holding the body it had BEFORE the result landed, and re-attribution then reverted the row. The caller is now resolved through the registry that already records which agent journaled a tool call, so both writes to one row resolve through the same reference and the newest body wins. A settled write also supersedes any correction owed to its row. One `itemId` is legitimately written under two references — `claudeToolIdentity` is keyed on the tool id alone — and a settled write already carries a final verdict, so an outstanding correction could only restamp it from a reference that write did not use. Dropped rather than re-bodied for that reason. Adds the ledger's first unit tests, including the invariant this defect broke: a correction changes a row's attribution and never its content.
A correction went out through the plain append, which discards the queue's admission. Under backpressure the write was refused and `retry` had already dropped the entry, so the obligation died with nothing re-deriving it — the failure class this work exists to refuse. It is self-feeding too: a correction costs a commit on the same serialized writer that carries live rows, so the burst that generates many corrections is what builds the backlog that drops them. It now uses the admission-returning path the sink already exposes, keeps the entry outstanding on a refusal, and lets `abandon` try once more. A refusal there ends it: the row keeps the spawn call's own id, which is usable, and an obligation with no exit is worse than one that settles for less. `settle` also reports what actually happened instead of always claiming it wrote, so publish no longer fires for a write nobody accepted. Also records why the live-turn scans may read the turn record before checking the producer. A turn is the session's unit of work and no producer of a turn-bearing body stamps linkage: Claude's turn rows carry none, Codex has no linkage concept, the compact row passes only a fence, and the stale-turn sweep goes through the lifecycle-batch path, which cannot carry linkage by type. The ordering is safe by construction rather than by accident, and the comment says so, so a future producer knows what it would break.
A non-null `parent_tool_use_id` names a child, always. The resolver still had one branch that read such rows as the session's own agent's — a release that had announced no task, where the comment claimed "there is no handle to stamp". There is one: the reference itself. The branch was buying a false attribution to avoid an id nothing joins on, which is the trade already reversed once for forwarded spawn calls, and every reader of this field is a presence test. So the branch goes, and with it the `root` arm of the verdict and the resolver's whole dependency on whether the release announces tasks. Two states remain: linked now, or linked now and owed a correction. The type deleted a stale test double on sight, which is the argument for removing the arm rather than the branch alone. This also closes the severe half of the tool-origin eviction exposure. A spawn id evicted from the bounded top-level set used to flip the release check on and stamp a child's rows as the parent's; with nothing returning root that cannot happen. What remains is a missed correction, which splits one child across two ids — the same end state as passing the correction bound, benign in kind and disclosed. `isForwardedParentTool` stays where it gates PENDINGNESS. It now decides only whether a correction is owed, never whether a row is a child's, so a stale answer costs precision rather than correctness.
Electron QA — nested delegation on 7c9c9f4Tested The four checks, while the helpers were running
After they finishedThe child rows left the sidebar. The parent row went to Done and quoted its own summary: "Both helpers finished. The outer helper made exactly one tool call…" The chat said Worked for 6m 45s. The transcript still has the inner report. Nested delegation rowIt reached a completed state. It did not stay stuck on Running. The roster reads:
The result content is present. The transcript includes the inner helper's report ("How a helper's tool result is attributed"), and the expanded nested Agent tool is followed by the result that begins "I read the three requested targets…". Nothing on screen was left spinning, and the result text was not blank. Backing note, not what the screen showedThe journal keeps the first copy of each Agent call in Not coveredNo run against |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Preserve the abandoned producer identity after its… · claude-provisional-row-corrections.ts:183-184
src/main/claude/claude-provisional-row-corrections.ts:183-184
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winPreserve the abandoned producer identity after its announcement.
If a producer exceeds the correction bound before its announcement,
giveUp()leaves existing rows under the raw reference. After the announcement, new rows use the canonical task ID becausegivenUponly affectsremember().This splits one child across two IDs. For example, 129 provisional rows remain under
toolu_1, while the next row after announcement usestask-1.Store the frozen fallback linkage for each abandoned reference. Use that linkage for all later rows from the same reference. Add a test that writes another row after the announcement.
Also applies to: 208-214
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 57e3624c-3265-4a4e-a78e-f6428e079c5c
📒 Files selected for processing (10)
src/main/claude/claude-message-journaling.tssrc/main/claude/claude-provisional-row-corrections.test.tssrc/main/claude/claude-provisional-row-corrections.tssrc/main/claude/claude-streamed-text-checkpoints.test.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-subagent-linkage.tssrc/main/claude/claude-subagent-roster.tssrc/shared/structured-agent-session-live-turn.ts
💤 Files with no reviewable changes (1)
- src/main/claude/claude-subagent-roster.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/shared/structured-agent-session-live-turn.ts
- src/main/claude/claude-message-journaling.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
|
Run failed. View the logs →
|
Review status — ready to mergeReviewed at OutcomeThe field model this PR opened with was right and survived intact. The mechanism underneath it was replaced. The original design withheld a subagent's journal rows until that agent's identity was announced, justified by the premise that the journal is a durable record with no backfill. That premise is false — re-appending a row under the same So the order is now inverted: write the row immediately, correct the attribution afterwards. Attribution bookkeeping never sits in front of a user-visible write. Defects found and fixedFive paths produced misattribution, four of them the exact defect this PR exists to remove:
Also fixed: ordinary tool results parking forever with their tools stuck running; an empty or malformed producer id passing validation and hiding a row from every parent-scoped reader; a lifecycle batch stamping one producer onto all its mutations; and a self-referential owner chain naming a row its own parent. One resolver branch was deleted rather than guarded: nothing can now resolve a row naming a parent to the session's own agent. Removing the type's arm — not just the branch — immediately surfaced a stale test double asserting a verdict nothing can produce. Validation
Known limitations, disclosed rather than fixedAll share one shape: the worst case is a child's rows carrying the spawn call's reference instead of its canonical id — still that child's rows, never the parent's.
|
…cer #22299 added main at 9ece273 measures 4212 modules against a pin of 4211: the native-chat fix added src/shared/agent-session-journal-producer.ts, which three shared modules on the session route import, and its PR touched nothing under mobile/ so the mobile job never ran. Re-measured on this merged head and the joiner read off the closure list. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…and shown in Troubleshoot (#22321) * feat(mobile): name why a bundle fetch refused what arrived The fetch threw plain errors whose only content was prose naming asset paths and hashes, so a caller could not keep the cause without keeping the prose. Each refusal now carries a code beside the unchanged message. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(mobile): record why a hybrid shell update failed, on the device A release build forwards no console output to logcat, so a refused or failed page update left the fallback banner and nothing else. Every exit from a failed update read now emits a record-update-failure effect: the cause as a closed code (never an error message), the generation offered and the one on disk, and what went on screen instead. The runner stamps host id and time and the generation store appends it to a bounded log in the cache root, five per host and twenty in all, oldest evicted first. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(mobile): forget a removed host's recorded update failures Removal clears the host's entries from the shell's update-failure log after the metadata commit, unawaited and best-effort: it is evidence about a host that is gone and never a reason to hold the removal. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(mobile): show recorded update failures in Troubleshoot A "Workspace updates" section lists the newest recorded failure of each paired host: the reason, the generation offered, and what the shell showed instead. It renders nothing until a failure has been recorded and mounts only where the hybrid shell can run. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): type the update-failure row doubles without casts Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(mobile): forget a host's update failures once a newer generation commits The Troubleshoot row reads "Last update from Host N failed", which stops being true the moment a later update from that host lands. The activated step for the build this flow downloaded now emits forget-update-failures for the host. A cache open, an offline open and a same-build hit activate a build the flow never requested, so they leave the record alone. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): re-pin the session closure for the shared journal producer #22299 added main at 9ece273 measures 4212 modules against a pin of 4211: the native-chat fix added src/shared/agent-session-journal-producer.ts, which three shared modules on the session route import, and its PR touched nothing under mobile/ so the mobile job never ran. Re-measured on this merged head and the joiner read off the closure list. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(mobile): forget update failures on a download's activation, not a build-id match The fetch reads the manifest again and commits the build that read named, so a host that moved between the session's read and the fetch's committed a build other than requestedBuildId, the forget was skipped, and the stale "last update failed" line outlived the update that should clear it. The activating state now says where it came from, download or cache, and the forget follows a download's activation. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Conflict: config/scripts/mobile-web-app-session-terminal-closure.test.mjs. Main's #22299 paragraph (4211 -> 4212, `agent-session-journal-producer.ts`) kept first in landing order; this branch's Retry-decision paragraph re-measured on top of it. Session route closure 4212 -> 4213 modules, local 1026 -> 1027: the one joiner is `src/transport/connection-retry-action.ts`, this branch's only new source file, read off the measured closure list. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb








ELI5
When an agent hands work to a helper agent, everything both of them do lands in one shared transcript. Until now no line said who wrote it, so the parent's sidebar row showed the helper's text, the helper's running tool, and "thinking" while only the helper was thinking. Now every line names its author, and the parent's status reads the parent's own work.
What Changed
Before: while a Claude subagent runs, the parent's sidebar row shows the subagent's newest text and running tool, and the parent's chat shows "thinking" during subagent reasoning (live on main since #22058 reverted the interim fix).
After: the parent's surfaces report only the parent's own activity. The transcript still renders every agent's output, and subagents keep their own indented child rows beneath the parent — so scoping the parent to its own work hides nothing.
Mechanism. Five optional fields ride every journal row's base:
agentId(the producing subagent's canonical, resume-stable task id; absent means the session's own agent),parentAgentId,providerParentRef(the raw provider reference, provenance only — never a join key),producerKind, andattempt. One reader predicate,isRootAgentJournalItem, is a presence test rather than a truthiness test, and it is the single place absence is interpreted. Every "what is this agent doing right now" reader is scoped by it; the transcript deliberately is not.The resolver holds one invariant: a row naming a parent is never the session's own agent. There is no case where a non-null parent reference resolves to the session root, so the misattribution this fixes has no remaining path back in.
A child's first frames can arrive before the
task_startedthat names the child. Rather than withholding those rows, they are written immediately under the reference they already have and re-attributed when the announcement lands, using the row-revision mechanism this journal already provides: re-appending the sameitemIdbumps its revision, the render item takes its linkage from the newest row, andupsertItempinssequenceandobservedAtso a correction refreshes attribution without relocating the bubble. The streamed-prose lane works the same way and already rewrote its row on a widening interval; it now resolves attribution per checkpoint instead of latching the first verdict.A correction never changes a row's body, only its linkage — pinned by a test. A settled write to a row supersedes any correction owed to it. A correction the sink refuses under backpressure stays owed and is retried once at settle rather than being silently dropped.
Why
Attribution must never gate the durable write of user-visible content. An earlier shape of this change held a child's rows until its identity settled, which inverted that: bookkeeping sat in front of the write. That cost content on a hard kill, and past the hold's bound it wrote the held rows as the parent's — manufacturing the very defect this change removes. Writing first and correcting after removes both, and it is what the journal already supports.
The reverted fix stored one boolean ("was this a subagent's?"), which cannot name which subagent, express nesting, or ever attribute usage. Once persisted, a weak field lives in journals forever.
Alternatives considered and rejected: minting our own row identity (needs a durable provider-reference → id map, a second store of one fact that can disagree); re-deriving parentage at read time from neighbouring rows (order-dependent, and there is no read-time alias resolution for producer identity here).
This matches how the rest of the product already behaves. The PTY/hook lane has gated subagent events out of the lead row for some time — any event carrying an agent id is refused the lead turn, child tool events cannot overwrite the parent's caches, and children surface as their own rows. This brings the structured lane to the same discipline rather than inventing a second answer.
Linked Issue
Fixes #22297
Visual Proof
See the attached screenshots from a real Claude session in the structured lane: the parent's row during a subagent run showing the parent's own spawn call, the subagent present as its own child row, the chat reading "Working" rather than "Thinking", and the transcript still containing the child's output — then the settled state with the parent back on its own summary.
Testing
13,433 tests pass; only pre-existing real-binary failures remain, baselined against the branch point.
tc:nodeclean,oxlintclean, anti-slop clean, changed-lines quality gate 0 findings across 41 files.Every pin proven red by scripted ablation with an asserted occurrence count, then restored green. Ablations cover: producer resolution, the correction ledger, the no-op-revision guard, correction supersession, refusal retention, re-attribution and announcement ordering, tool-result caller resolution, and reader scoping (with a control proving de-duplication was narrowed, not disabled). Removing the resolver's root arm turns 10 tests red across the lane.
Two test harnesses that silently discarded append options were fixed before any assertion was written. Several tests that captured behaviour without claiming it, or whose names described conditions this store cannot reach, were replaced or reframed.
Perf measured, nothing shipped: the per-row linkage spread costs ~22ms per million rows against ~565ms for
JSON.parsealone, on session-open rather than per render. A single-allocation rewrite was written, measured at 7.9ms, and discarded as churn with no symptom.Write amplification: extra durable rows equal the number of distinct rows a child touched before its announcement — not the number of writes, since a tool call and its result share one row and streamed prose is one row however many checkpoints it took. Zero when the announcement precedes child output. Each correction is a durable row commit on the same serialized writer that carries live rows.
Validated in the app on macOS: a real Claude session in the structured lane with a real subagent, via hidden CDP screenshots.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Compatibility, per field
Journal schema version stays at 3: every field is optional and additive, so a bump would only make older hosts stop at the first newer row and latch read-only for no gain. A correction is an ordinary item revision whose body is unchanged, so an old client sees exactly what it saw before. No RPC parameter, stream opcode, or frame shape changed, so no capability negotiation is needed.
agentId?: stringparentAgentId?: stringproviderParentRef?: stringproducerKind?attempt?: numberA malformed linkage field arriving from a foreign or corrupted row is dropped without losing the row — a persisted row validator that rejects is a whole-store kill switch.
Review
Accepted limitations, each deliberate and test- or comment-recorded. Note what they all have in common: the worst case is a child's rows carrying the spawn call's reference instead of its canonical task id — still that child's, never the parent's.
attentionstate is deliberately not producer-scoped, because whoever raised the prompt, the user has to answer it.producerKindis written and deliberately unread. Backgrounded work is already excluded from the parent's surfaces by the same presence test. A reader that wants "nested agents only" would need it; no such surface exists yet, and a real surface should drive that, not this change.claude-prompt-journaling.tshas no importers (dead code); left untouched for a separate cleanup.