Skip to content

fix(native-chat): a failed turn ends on its error instead of folding it - #23679

Merged
brennanb2025 merged 227 commits into
mainfrom
brennanb2025/failed-turn-fold
Sep 29, 2026
Merged

brennanb2025 merged 227 commits into
mainfrom
brennanb2025/failed-turn-fold

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

Builds on #23059 (merged); now targets main.

ELI5

When a chat turn failed, it could look as if it had finished normally. On main, the error folds away under "Worked for N". #23059 stops folding errors, but it still shows the agent's last message above the error, so the turn looks answered with an error tacked on. With this PR, a failed turn ends on its error: the error is the one row you see under "Worked for N", and everything before it folds, the same way a normal turn ends on its answer.

What Changed

Before (on #23059)

  • A settled turn keeps one row visible, its "answer": the last message from the agent that shows text. Error rows and compaction reports are never folded.
  • A turn that wrote some text and then failed shows that text and the error below it. The text looks like the answer.
  • A turn that hit an error, recovered and then answered still shows the error above the answer, even though the agent got past it.

After

  • An error row can be the turn's visible end too. The last message or error in the turn is the one that stays visible.
  • A failed turn shows only its error under "Worked for N". The text and tool runs before it fold, and opening the caret shows every row in order.
  • An error the agent recovered from folds behind the answer that came after it.
  • A turn that is nothing but its error shows the error with no caret, as before.
  • Compaction reports, subagent rosters and background tasks keep their never-fold rule.

Mechanism. nativeChatTurnAnswerRows in src/shared/native-chat-turn-fold.ts picks a turn's visible end. It now counts a system row that reports a failure as a candidate as well as an agent message that shows text, and the last candidate wins. Candidates come only from the session's own agent (#23059's rule), so a subagent's error or later text never hides the main agent's answer. The row flag reportsTurnOutcome covered both errors and compaction reports; it is split into reportsFailure and reportsCompaction. Only compaction keeps the never-fold rule. The transcript slot builder sets the two flags from the row's text blocks.

Mobile is unchanged: it does not use this fold (it only hides finished tool runs).

Why

  • The fold's job is to leave the one row that says how the turn ended. For a failed turn, that row is the error. Picking it the same way as an answer puts failure into the single rule for "what is this turn's end". It replaces fix(native-chat): turn facts come from the turn record, and /compact is a message the chat sends #23059's separate never-fold exception for errors rather than adding another rule beside it.
  • Alternatives considered.
    • Keep every error visible (fix(native-chat): turn facts come from the turn record, and /compact is a message the chat sends #23059): the text before the error still reads as the answer, which is the confusion this fixes. It also keeps errors the agent recovered from on screen.
    • Keep the answer visible and show a later error as an extra trailing row: two visible rows per failed turn, and the answer still reads as the outcome.
    • Decide from the turn's recorded result (success or failure): that would be the stronger input, but the result does not reach the transcript on this base. The turn bar only carries timing. See Known limits.

Differences from the common pattern

  • How an error row is recognized. The common pattern marks an error as its own kind of message. Orca has no such kind in the transcript, so this PR reads the error tone on a status row's text. Some rows get that tone without ending a turn. Examples are a Codex stream error that Codex is about to retry ("Reconnecting… n/5") and a Codex Windows folder-permission warning. Such a row becomes a turn's visible end only when nothing the agent said comes after it. That happens, for example, if you press Stop while Codex is reconnecting.
  • An answer followed by a closing error. One common approach keeps a failure after the answer as a trailing row. Another, which this PR follows, makes the last message-or-error the end. Here the answer folds behind the error, one click away. We chose this because the turn bar does not say the turn failed yet, so the error has to be the row you see.

Known limits

  • Retry rows that carry the error tone are addressed by a separate change that turns a run's Codex retry rows into one warning row.
  • Once the "Failed after N" turn bar brings the turn's recorded result into the transcript, an error row should count as the turn's end only when the turn did not succeed. That covers a recorded failure, and a provider crash, which is recorded as an interruption.

Linked Issue

No public issue. This is part of the structured chat turn work stacked on #23059.

Visual Proof

Structured Claude chat on macOS. Each turn is driven by a scripted stand-in for the Claude CLI that speaks the real stream-json protocol, so the rows are the ones the host really writes. Base = #23059 head 436d1771dd6, after = this PR 9685299b1fe.

A turn that wrote text, ran a tool, then the provider stopped. Before: the text reads as the answer, with the error under it. After: the error is the turn's end.

Before (#23059) After
Before: the text before the error stays visible After: only the error is visible under Worked for 3s

Opening the caret shows every row in order: text, the tool run, text, then the error.

After, expanded: every row of the failed turn in order

A turn that ended in an API error.

Before (#23059) After
Before: text and the API error both visible After: only the API error is visible

A turn that hit an error, recovered and answered. Before: the error stays above the answer. After: the error folds behind the answer. Opening the caret shows every row, the error included.

Before (#23059) After
Before: the recovered error stays visible above the answer After: only the answer is visible

After, expanded: the recovered error is still there when opened

Unchanged. A successful turn looks the same in both builds. A turn that died before any output shows its error with no caret in both builds.

Before (#23059) After
Before: successful turn After: successful turn, identical
Before: error-only turn, no caret After: error-only turn, no caret

Testing

  • src/shared/native-chat-turn-fold.test.ts: an error is the answer when nothing the agent said follows it; later text wins over an earlier error; a failed turn folds the work and text before its error; a recovered error folds behind the answer; an error-only turn has no caret; compaction reports still never fold; a subagent's failure after the answer does not replace it.

  • src/renderer/src/components/native-chat/native-chat-transcript-slots.test.ts: the same two shapes end to end through the slot builder (a failed turn's only visible row is its error; a recovered error folds behind the answer).

  • Both files pass (38/38), and so do the neighbouring native-chat transcript tests. tc:web passes, and the changed-lines quality gate and oxlint are clean.

  • Manual: the live before/after run on macOS above (desktop app in the background, isolated profile and homes). Not run manually: a real Claude CLI (the stand-in speaks its protocol), Codex (retry rows are covered by the sibling change), SSH (the change is renderer-only and reads rows the host already sends, so a remote host behaves the same), Linux/Windows (no platform-specific code).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

brennanb2025 and others added 30 commits September 24, 2026 23:36
No client ever called agentSession.requestHandoff or mounted the handoff
chrome. Delete the handoff coordinator, the terminal-owner runtime, the
proof write path and the unmounted UI. Keep agentSession.handoffStatus,
which released desktop clients read for worktree activation, and let
records an older build left mid handoff reconcile through the ordinary
restart and recovery paths.
Eviction now drains delivered events before quit's resume-offer snapshot. An
unbounded wait there sits ahead of the provider stop, so a sink whose journal
write stalls kept the child running until the step deadline aborted the
eviction. The offer is advisory: bound the drain and stop the child regardless.

Co-Authored-By: Claude <noreply@anthropic.com>
`claudeAuthEnvCarriedForward`, `isPathWithinDirectory` and
`queryWindowsProcessRowsFresh` lost their last caller with the handoff. The
fresh-scan tests now go through `queryWindowsProcessDescendants({ fresh: true })`,
the teardown path that still depends on that contract.

Co-Authored-By: Claude <noreply@anthropic.com>
Six comments still named the handoff coordinator, a handoff suspend, or a
terminal-owned session as live participants in the flows they describe.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…ement

The removed restart handoff test pinned this branch; nothing else did.

Co-Authored-By: Claude <noreply@anthropic.com>
The handoff removal dropped the per-session queue from `handoffStatus`, so a
read landing mid-start reported the reservation (no owner) instead of the
settled chat owner, and shipped desktop clients blocked worktree activation on
it. The read is queued again, as it was before the removal.

Co-Authored-By: Claude <noreply@anthropic.com>
The gate only refused a write when a PTY had been bound to a chat session, and the
only code that ever bound one was the terminal handoff this branch removes. With it
gone, every admit/readmit returned "admitted" unconditionally, so the checks on the
renderer write path, the runtime controller backstop, terminal.send, agent prompts,
preview input and orchestration pointers, the refusal fields on terminal.send and
worker-start receipts, the plugin and CLI refusal copy, and the adopted-pane
orchestration routing could no longer run. Ordinary writes take the same path in
the same order as before.

Co-Authored-By: Claude <noreply@anthropic.com>
…alled

appendLegacyTranscriptMessages fed the terminal transcript catch-up and
proveClaudeTranscriptBranch backed the terminal owner's exit proof. Both lost
their last caller with the handoff. Their tests now go through the live entry
points instead: the roster bounds through the legacy import, the pinned-read and
growth tests through the ancestry replay the history window uses, and the marker
rules through the string proof in their own file rather than the session-file
resolver's.

Co-Authored-By: Claude <noreply@anthropic.com>
A send refused because the chat's owner is not settled showed "The session is
mid-handoff (<stage>)." in the composer. With the handoff gone, the stages that
reach it are a chat that is still starting, or one whose previous agent process
has not yet been confirmed stopped. The message now says which of the two it is.
The refusal code is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
With the terminal handoff gone, the module named codex-tui-rollout-proof holds
only the pinned rollout lookup that structured Codex launches use to resume a
thread, so the name described code that no longer exists. Rename the module and
its options type. Also drop a mobile allowlist assertion that pinned the
removed agentSession.requestHandoff method, which no longer exists to allow.
The handoffStatus reply type still listed the terminal handoff's fields and
states (terminal placement, host label, proof retry, queued and waiting phases,
the to-terminal direction). No host writes them any more and the only client
reader parses the reply as unknown, so they described nothing. The reply on the
wire is unchanged.
…t decode

Nothing in this build writes a terminal owner (`runtimeKind: 'tui'`) or the
handoff's `preparing` / `old-owner-stopped` stages, but the in-memory types
still admitted them, so readers across the host kept branches for values no
path produces and the compiler could not point at them.

The store now validates the on-disk shape, which still accepts those values so
an older record is not quarantined, and maps them once while parsing:

- `preparing` and `old-owner-stopped` become `recovering`
- a `tui` lease becomes `native`; when it records a process it also becomes
  `conflicted`, the claim every build probes but never stops. A plain native
  owner would be stopped by restart recovery, here and in older builds.

Revisions are taken over the normalized state on both sides of every compare,
and the mapped record reaches disk with the store's first transaction, the
same way the tab-id backfill does.

The in-memory types narrow to what this build writes, and the branches that
existed only for the removed values go. Structured-worker identity keeps its
verdict for a former terminal owner by refusing a conflicted claim rather
than a non-native kind.
…ation

A reservation only ever names a native owner now, so the request no longer
carries a kind and the reserved lease records `native` directly. The attach
params keep `runtimeKind`: agentSession.ensure and create accept it, and the
operation fingerprint stored in the ledger covers it.
…at changes nothing else

Hiding a tab also committed the visibility index, so the no-op transaction
wrote the file even when its open-time revision was wrong. Committing the index
first leaves the pending rewrite as the only reason to write.
…ration

A write carried the fence of the last frame the pane read, and the host refused it
unless that fence was still current. An idle release and the restart after it each
move the fence, and the release publishes nothing, so a send after a release was
refused "Expected runtime fence 1; the session is at 3", and a Stop queued behind a
cold start was refused as stale.

Every write already names what it acts on: a send its conversation, a cancel its
turn, a prompt answer its item revision, a rewind its epoch; an option is
last-writer-wins. So admission stops comparing the client's fence, and the rebase
that papered over one restart (admitAtResumedFence, resumedFromFence) goes with it.
The writer-lease check stays, and so does the attach's compare-and-swap.

Frames now stamp the fence read when each frame is sent instead of a copy each
subscriber kept, which went stale on the same release.
A journal write and its delivery to open readers were two calls, and some
writers made only the first. A failed start whose lease could not be handed
back, a provider revision with no frame behind it, and eviction's settlement
were all journaled without reaching an open chat.

A journal handle now reports every durable change, and the host's session map
binds that report to the session's readers when the handle is set. Writers no
longer publish what they append; the per-writer publish calls are deleted.
…ackfill cannot supply its rewrite

The seeded record had no surface tab id, so the next open backfilled one and
that rewrite alone made the no-op transaction write. The test passed with the
legacy-lease rewrite signal removed.
The handoff removal deleted it alongside the terminal-owner tests, but it
covers the surfaced-PTY block that still guards resume, including an agent
whose ownership is unknown.
Each commit now delivers itself, so the publish a provider frame still sends
afterwards found every reader caught up but still read rows and rebuilt the
timeline for each one. A caught-up reader now skips the read.
# Conflicts:
#	src/main/native-chat/agent-session-wire/structured-agent-session-subscribers.ts
A send to a chat with no running agent restarted the agent inside the send
call, before the message was recorded, so the client waited for the whole
start and a failed restart refused the message. Claude held prompts sent
during startup, and those could settle as "unconfirmed".

A send is now accepted inside the session's serialized queue: one ledger row
and one submission row marked handoverRecorded, published, answered pending.
A per-session delivery loop exists while a message is queued. It starts the
agent through the same serialized attach a hold uses, waits outside the queue
for a Claude child to prove its start, and hands the oldest queued message
over as its own serialized step, writing dispatch{pending} before the adapter
call. A start it needed and did not get writes one error-tone row and rejects
every queued message with the same words; a start Stop cancelled writes none.

Settlement follows from the rows. A queued message is provably unwritten, so a
close, an eviction or an exit rejects it. A handed-over message stays in doubt.
A queued row at or below the sequence a handle found when it opened was left
by an earlier process and is rejected at open, with no latch. Stop withdraws
queued messages with no writer lease and no fence. An attach failure keeps the
conversation open, and the attach adopts its journal. Owed work counts the
loop and queued rows.

A compaction or rewind found prepared when a conversation opens was started
under a child this process no longer has, so the open settles it rather than
leaving it to refuse every send until a view attaches. The open cursor is
scoped to its epoch, because sequences restart when an epoch is replaced.

Deleted: restart-before-admission, recordFailedRestart, the fence rebase,
Claude's startup gate, the attach's forget on failure and its own crash
boundary. Clients without agent-session.accepted-send.v1 get their reply held
until the handover; the desktop and paired desktop lists advertise it.
A child that proved its start and then exited before its message was handed
over left the message queued: the exit settlement returned early when nothing
else was in flight. Delivery then started another child for it, and a child
that died the same way started another, without end and without a row.

A retried settlement for an earlier generation, run by the attach that
delivery started, did the opposite: with that generation's turn unfinished it
rejected the message queued for the child being attached.

The settlement now takes the rejection for queued messages from its caller.
The unexpected exit and the eviction pass one, and it applies even with no
other work in flight; the retry for an earlier generation passes none.
The compaction tracker files #23116 edited stay deleted; their typed failure
facts move into the command-turn modules:
- a compaction's result row carries `compactionFailed` (with the provider's
  words for a person) or `compactionUnconfirmed`, from both translators;
- a provider refusal at handover rejects the message with its typed fact and
  words its row as the compaction failing;
- a queued command the chat's state refuses at handover is rejected as the new
  `commandRefused` kind, carrying the refusal;
- an older build's prepared /compact replays as `compactionUnconfirmed`.
Rows keep their turn scope and error tone beside #23116's words and facts.
…again

The failure-words context named only /clear as a command to retry, so a
/compact whose agent failed to start read "Send your message to try again."
on its row, its rejected message and the command reply. The context now
carries any conversation command; the host derives it from the oldest
message still waiting on the provider, which is the one a failed start
fails first, and the /compact reply names it directly.
A settled turn folds to its answer: its last assistant prose row. Every
error-toned row was held outside the fold, so an error the agent recovered
from stayed on screen after the answer that followed it.

An error-toned system row now competes with prose to be the turn's answer,
last one wins: a turn that failed shows the error as its visible end with
earlier prose folded, and an error followed by an answer folds behind it.
Compaction reports keep never folding.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: 9685299b1fe

Verdict: no code changes were needed. The PR stays a draft, stacked on #23059.

Review loop. One full review-and-fix pass came back clean with no commits. It traced every shape of a settled turn through the fold and the slot builder:

  • text then an error, an error on its own, tools then an error
  • an error the agent recovered from, then an answer
  • several errors in one turn
  • errors next to compaction reports, subagent rosters and background tasks
  • turns with no turn key, and the live turn

All of them behave as described in the body. Performance is unchanged in practice: one extra pass over each message's blocks. Mobile does not use this fold, so it is unaffected.

Readiness checklist. Start: pass, nothing blocking. End: pass, nothing blocking. The end pass checked every claim in the PR body against the code and found them all accurate.

Architecture. The PR replaces #23059's separate never-fold exception for errors with a single rule for a turn's visible end: the last agent message or error in the turn. It does not add a guard beside the old one. The one input deviation is disclosed in the body: an error row is recognized by the error tone on a status row, because the transcript does not carry the turn's recorded result yet. The follow-up is to gate this on that result once the "Failed after N" turn bar brings it in.

Checks.

  • native-chat-turn-fold.test.ts and native-chat-transcript-slots.test.ts pass 38/38. With the message list tests added, 49/49 pass.
  • tc:web passes at this head.
  • The changed-lines quality gate and oxlint are clean.

Live QA. Passed on macOS. The desktop app ran in the background with an isolated profile and isolated homes, in a structured Claude chat driven by a stand-in that speaks the Claude CLI's stream-json protocol. Base 436d1771dd6, PR 9685299b1fe.

Before (#23059) After
Before: the text before the error stays visible After: the error is the turn's visible end
Recovered error, before Recovered error, after
Before: the recovered error stays above the answer After: the recovered error folds behind the answer

Other scenarios passed too:

  • An API-error turn.
  • Opening the caret shows every row in order.
  • A successful turn looks the same in both builds.
  • A turn that died before any output shows its error with no caret in both builds.

The body has all of the screenshots.

Remaining gaps.

  • Not run live: a real Claude CLI, Codex, SSH, Linux and Windows. The change is renderer-only and reads rows the host already sends.
  • One pre-existing issue, not from this PR: the host's error text for a provider that stops mid-turn includes raw process text (claude stream-json exited (code 1): …). That wording is separate work.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 28, 2026 20:55
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Changes how failed chat turns are displayed and folded.

The PR appears safe to merge; no new actionable issue was identified.

Summary

The PR makes a failed native-chat turn show its error as the visible end, while folding earlier work. A later answer can instead fold an error the agent recovered from. Compaction reports remain visible.

Reviews (4) · Last reviewed commit: "Merge origin/main into brennanb2025/fail..."

Comment thread src/shared/native-chat-turn-fold.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Failure rows can be a turn's answer — nativeChatTurnAnswerRows now treats a system row with rendersFailure-style error tone and rendered prose as an answer candidate beside assistant prose, and the last candidate wins (src/shared/native-chat-turn-fold.ts:48). A failed turn ends on its error; a recovered error folds behind the later answer.
  • reportsTurnOutcome split into reportsFailure / reportsCompaction — only compaction keeps the never-fold rule; errors fold when they are not the turn's end (src/shared/native-chat-turn-fold.ts:88).
  • Slot builder derives the two flags from text blocks — tone === 'error' and presentation === 'compaction' (src/renderer/src/components/native-chat/native-chat-transcript-slots.ts:104).
  • Tests — new unit cases (failure is the answer, recovered error folds, error-only turn has no caret, compaction still never folds) and end-to-end slot cases that would fail on the base behavior.

Borderline checks confirmed clean: no remaining reportsTurnOutcome references or stale docs; nativeChatTurnFold/nativeChatTurnAnswerRows are renderer-only (mobile does not use this fold); and host error rows project to role: 'system', matching the candidate gate. Local runs: 47/47 pass on the changed files plus NativeChatMessageList.turn-membership.test.tsx, and pnpm tc:web passes. (CI is skipped for a branch stacked on a non-default base, so these local runs are the evidence.)

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…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.
…, below Codex's own error row

Since only turn/completed ends a Codex turn, Codex's turn-ending `error` is a row
inside the still-open command turn, and the failed completion that follows it is
the command's end: completed, outcome failure, at the completion's receipt time.
The command's own "Compaction failed" row was written on that completion too, so a
failed /compact read its reason twice.

The command turn now notes when Codex's turn-ending error for the turn it carries
was written as a row, and its end then adds no second row. A retried stream error
ends nothing and is not counted. The flag that let the error end the command and
kept the claim until the completion is gone with the error-driven end.

A test replays the captured failed compaction from the real app-server through a
claimed command turn.
…a dead /compact settles on its recorded exit

Two tests the main merge brought together:
- The crash-turn test from #23456 writes a turn record through the event sink
  without options; every row here states its turn scope, and a turn record's is
  the thread.
- The /compact whose exit settlement could not be written no longer stays running
  until the next start: main now settles an open chat from the exit it recorded, so
  the command reads interrupted before the next message, which is then delivered.
The crash-turn, stale-turn and sink-queue tests main added wrote rows without a
turn scope, which every item write now states. Rows written inside a running
turn name that turn; the sink-queue batch and a send handed over with no live
turn name the thread.
…3700, #22943, #23720, #23793, #23776, #23796) into #23059

#23573 (keep a turn's bar on the prompt that opened it) is ported onto the
turn-record membership instead of kept as a second owner lookup:
- The running turn's bar comes from nativeChatTurnMembership, which now
  returns barTurnKey beside liveTurnKey. Where the host states each row's
  turn they are the same key: the running root turn's anchor, and a
  message handed over mid-turn is already scoped to that turn. Where the
  host states no scope, rows still group by position, so barTurnKey is the
  user entry the running record names (through the same anchors) while
  liveTurnKey keeps the positional live group, as #23573 kept row liveness
  on the newest prompt.
- activeTurnOpenedBy, selectStructuredAgentTurnBars' openedBy and
  selectNativeChatActiveTurnKey are removed; the desktop list, the slot
  builder and both turn-status hooks read barTurnKey.
- The queued-send clock (queuedUntil: a turn counts from the previous
  turn's end when its send waited behind it) is kept, read in the same
  one-pass walk over root turn records that keys timing by anchor.
- Its tests are adapted to pass a journal: each runs on a host that
  states no scope (the original expectations), and the desktop and mobile
  bar tests also run on a scoped host.

#23621 (a message Claude folds into its running turn no longer splits the
turn) is host-only and merged as is: the translator contract carries both
openTurnInLiveProviderCycle and #23059's command-turn members.

Both sides grew the Claude translator past its line budget, so its result
branch moves unchanged into claude-result-journaling.ts, beside
claude-message-journaling.ts (the pre-commit lint refuses the merge
without it).

#23801's Codex child path (no error-driven end) and #23059's Codex /compact
guard (a command turn ends only on turn/completed) both stand.
Brings #23808, which restores the Codex child-turn end on an error Codex
will not retry (the child path has no guaranteed turn/completed), plus a
README badge update. No overlap with #23059's files.
# Conflicts:
#	src/renderer/src/components/native-chat/native-chat-transcript-slots.ts
#	src/shared/native-chat-turn-fold.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the delta since the prior pullfrog review: 6b1b95e796, the merge of #23059's newer head bda9ff153e7 into this branch. The merge reconciled the PR with #23059's root/subagent attribution and the result is sound.

  • Failure candidates now respect root-agent attribution — nativeChatTurnAnswerRows gates every candidate (assistant prose and system failure) on isRootAgentJournalItem(row), so a subagent's failure can no longer replace the session's own answer; it folds instead (src/shared/native-chat-turn-fold.ts:57).
  • New subagent-failure unit test — asserts the session's own prose stays the answer when a subagent's failure follows it (src/shared/native-chat-turn-fold.test.ts:60).
  • Doc comment aligned — now reads "the last prose the session's own agent wrote, or its last system row reporting a failure" (src/shared/native-chat-turn-fold.ts:48).

The remaining churn in native-chat-transcript-slots.ts from the merge (subagentLabel, activeTurnKey, trailingRunIndexes, attributed) is base-authored by #23059, not this PR.

Verified locally at 6b1b95e: the two changed test files plus NativeChatMessageList.turn-membership.test.tsx pass (55/55), and pnpm tc:web is clean.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…3745, #23783, #22971, #22565, #22846, #23724, #23721, #23693, #23810) into #23059

#23671 (group chat rows by the turn that produced them) is ported onto
#23059's turn-scope model, so there is one grouping mechanism, not two:

- A host that states each row's turn scope groups by that scope, as
  before. #23671's journal-order derivation (rows between one turn record
  and the next belong to it) moves from the timing selector into
  src/shared/native-chat-turn-grouping.ts and runs only for a host that
  states no scope, replacing the positional fallback there.
- #23671's anchor rules live in structuredAgentTurnAnchors, which
  membership, settled timing and the live clock all read: a turn whose
  opener key nothing resolves yet takes the send still in flight ahead of
  its record (Codex before its echo), else its own record.
- The live turn is one key again. #23671 made row liveness follow the
  owning turn, so the bar key and the liveness key are always the same;
  nativeChatTurnMembership now returns only liveTurnKey (barTurnKey,
  activeTurnOpenedBy and turnKeysByItemId are gone).
- A turn with no user bubble draws its bar above its first row
  (nativeChatTurnBarRows, desktop and mobile), and a turn's diff rollup
  goes under its last row.
- The Codex full-history restore writes each record ahead of its items;
  that also fixes the derived turn scope on #23059's journal.

#23026 (Stop from the moment a message is sent) is ported onto #23059's
command turns: the cancel paths ask the translator for a command's
provider turn instead of the removed compaction tracker, and a Stop that
names no turn still ends a running /compact through its child.
performCancel moved to structured-agent-session-turns-cancel.ts to keep
the turns module under the line limit.

#22090's awaitingInput replaces showTurnStatus/showLiveTurnActivity; the
waiting-behind-/compact rows are kept.
…'s rows

A message sent while A runs is written to the journal when it is sent.
When the provider queues it (Claude answers it after A), A's remaining
rows - its last tool run and its answer - are written after that
message, and the message's own turn opens only after them. Grouping put
those rows in A's turn, but the transcript still drew them in journal
order, below B's bubble and bar, where A's answer read as B's reply. This
is the residual #23671 left open.

A message that opened a turn now draws after the earlier turns' rows the
journal wrote after it, just before its own turn's rows
(nativeChatTurnDrawOrder, returned by nativeChatTurnMembership as
drawOrder). Desktop and mobile both draw in that order. A steer, and a
message that has opened no turn yet, stay where they were written. It
applies on hosts that state turn scopes and, through journal order, on
older ones.
…urns

Two of #23026's tests call APIs #23059 changed, and failed after the
merge:

- codex-structured-conversation-stop: a compaction now goes through
  adapter.compact with the command run the host wrote (#23059), not a
  bare turn id, and answers with the provider's receipt. With the command
  claimed, a Stop that names no turn while the compaction's provider turn
  has not opened still interrupts nothing.
- main-agent-working-agreement: a provider row states its turn scope
  (#23059's appendItem contract); the retry and subagent rows are
  conversation-scoped.
…inst #23059

A Stop's compaction interrupt reads the narrowed requested turn, and the
restore-grouping test states whether each row reports its turn's outcome.
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/chat-turn-facts-from-record to main September 29, 2026 20:17
# Conflicts:
#	src/main/codex/codex-structured-journal-restore-turn-grouping.test.ts
#	src/renderer/src/components/native-chat/native-chat-transcript-slots.test.ts
#	src/renderer/src/components/native-chat/native-chat-transcript-slots.ts
#	src/shared/native-chat-turn-fold.test.ts
#	src/shared/native-chat-turn-fold.ts
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 66310e76-1f7c-4687-8fdf-adcb678ea7a7

📥 Commits

Reviewing files that changed from the base of the PR and between d60f999 and b2393ed.

📒 Files selected for processing (5)
  • src/main/codex/codex-structured-journal-restore-turn-grouping.test.ts
  • src/renderer/src/components/native-chat/native-chat-transcript-slots.test.ts
  • src/renderer/src/components/native-chat/native-chat-transcript-slots.ts
  • src/shared/native-chat-turn-fold.test.ts
  • src/shared/native-chat-turn-fold.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Turn folding now distinguishes failure reports from compaction reports. Root-agent failure rows can serve as turn answers when no later assistant prose follows. When later prose follows a failure, the prose is selected as the answer. Transcript slot construction sets the separate flags, and tests cover failure visibility, recovery, and compaction behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b2393

No actionable issue remains from this review; the change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b2393

The change affects how chat failures appear in a collapsed turn, not who can act or what the agent can access. The reviewed behavior keeps a terminal error visible and lets readers expand earlier rows. No security issue was established, though coverage is incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Within the examined producer-to-consumer path, the effect is limited to which existing transcript rows are collapsed or drawn; the fold function returns row-index and turn-key sets rather than changing agent execution or permissions.

Trust Boundaries and Controls

  • observed — Message-block attributes supply the failure classification, but the existing root-agent identity check prevents a subagent failure from becoming the parent turn's selected answer.

Resilience and Maintainability Implications

  • inferred — Because failure detection uses raw blocks while answer eligibility requires rendered prose, an error-toned block filtered from visible prose might not become the turn endpoint. The reviewed source does not show that this creates a newly hidden, readable failure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: failed turns now end on their error instead of folding it away.
Description check ✅ Passed The description is detailed and covers the change, rationale, linked work, visual proof, testing, limitations, and scope. Some template sections are omitted, including Review, Notes, and the full Chec…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 5c59a2d into main Sep 29, 2026
26 of 28 checks passed
brennanb2025 added a commit that referenced this pull request Sep 30, 2026
Main now settles a Codex send from the turn it was answered into
(#23618, #23679, #23850): an interrupted or failed turn that never
echoed a send withdraws or refuses it, and a completed turn leaves it
to its echo, which Codex records before turn/completed. That replaces
this branch's own mechanism, so every conflict resolves to main:

- journal-level terminal settlement (ownerEndedClientMessageIds,
  multi-row enqueueMany, terminalTurnFences, canResolveDispatch,
  hasTerminalTurn, turn_settled_before_acknowledgement) and the sink's
  onCommitted/onAbandoned/onDiscarded plumbing
- the dispatch-echo ownership model (start candidates, started
  evidence, terminal snapshots) and the late-settlement retry
- the connection's onResult response observer
- the shared-predicate command admission, which main expresses with
  its own fence and handover rules (#23524)

Codex's turn/steer, the part the host-owned queue still needs, is
re-expressed on main's model in the following commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant