Skip to content

fix(chat): cut the reply at a permission request only where a row lands - #23919

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/codex-fragmented-messages
Oct 26, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/codex-fragmented-messages

Conversation

@Pearcekieser

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Codex reply is saved and shown as one message, even when the model's sub-agents ask for approvals while it is writing.

One assistant message from a Codex session was saved as several assistant rows with nothing between them. The splits landed mid-sentence, inside bold text and inside a diff hunk. After a reload the last row could show as the reply on its own, starting mid-word. The rows joined back together equal the model's message exactly, so no text was lost.

Why it matters

Anyone running Codex with sub-agents in a mode where Codex asks before running commands, on a YOLO or trusted chat, gets broken replies. Bold and code render wrong across the cut, and the collapsed view shows the tail of the answer without the explanation before it.

Not a goal

  • Changing where a tool call, an approval card or a steer cuts the reply. Those land a row, and the text before them still renders above them.
  • Attributing a Codex sub-agent's approval to its child card. codex-acp sends nothing that names the child thread.
  • Repairing transcripts already saved in fragments.

What changed (motivation → approach → change)

Codex sends a sub-agent's session/request_permission on the parent session while the parent's message is still streaming. A capture of codex-acp 2.2.2 with codex 0.164 showed three of these inside one message, each with a tool call id no tool_call frame announced. _on_permission_request cut the segment before deciding the request. A grant that appends no row (YOLO, session trust, a native crew) still ended the segment, so the text after it became a new row.

The cut is now owed rather than made. _on_permission_request arms it on the slot and runs the decision, now _decide_permission_request. slot.append pays the cut before the first durable row that decision lands, and the interactive card gets it before it is drawn. A request answered with no row drops it, and the reply keeps streaming into the same segment. Any other segment flush, such as a send cutting the reply while the decision waits, clears the owed cut first, so the text is saved once.

Backwards compatibility

Compatible: every permission request that lands a row still cuts before it, and the transcript format is unchanged.

Removes nothing: the change adds one slot field and defers an existing cut; no row, key or path is taken away.

Tests

test/test_permission_cut_owed.py streams a synthetic message with bold text, a bare diff hunk and a JSON string, split at random points over 12 seeds, under YOLO and session trust. Up to three unannounced approval requests are interleaved, some followed by a tool-call update. Each case asserts one saved assistant row equal to the whole message, a reload window holding only that row, and one crew-log copy. Two tests keep the real boundaries: an approval card after prose and a tool call inside the reply still split the reply around their rows. A unit test checks append pays an owed cut before a durable row and never before a chunk row. Another flushes the segment the way a send cut does while a cut is owed and checks the text is saved once, above the send's row.

test_state_parts_facade.py pins the new slot field's default. test_transport_permission_floor.py renames the reviewed approval caller to _decide_permission_request; its six approve_tool calls and their identity gate are unchanged.

Proof: PROVEN test/test_permission_cut_owed.py (head 1fa69f7)

Manual verification

A live capture against codex-acp 2.2.2 over stdio with codex 0.164.0.751, multi-agent, read-only mode, confirmed the frame shape the tests replay. In codex-acp's default agent mode Codex approves commands itself and sends no permission requests, so the split does not occur there.

Related Issues

Closes #23918

Sibling sweep

Swept: git grep -n "_cut_segment(|_steer_segment_cut|_flush_segment(" -- src/kiro_crew/dashboard
Sibling: src/kiro_crew/dashboard/chat_turn/tool_rows.py -- not affected -- the tool-call cut is always followed by the tool row it appends
Sibling: src/kiro_crew/dashboard/chat_turn/stream_chunks.py -- not affected -- it cuts only after a tool group whose rows already sit between the segments
Sibling: src/kiro_crew/dashboard/responsive_chat.py -- not affected -- its cut is followed by the waiting send's user row
Sibling: src/kiro_crew/dashboard/chat_delivery.py -- not affected -- the steer cut is followed by the steer's user row

Pattern harvest

Rule candidate: review-prompt
Pattern: a display cut made before the decision that may add nothing to display

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser
Pearcekieser requested review from a team and KiroCrewCaptain as code owners October 25, 2026 03:57
@Pearcekieser
Pearcekieser requested a review from buluoray October 25, 2026 03:57
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 25, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from 1fa69f7 to a6a934c Compare October 25, 2026 04:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 8e28b19e17886665382f6667b9940be02963c469 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 8e28b19e17886665382f6667b9940be02963c469 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. A cut that waits until a row actually lands goes after the root cause: the old code cut before knowing whether any row would follow. The change is backend-only and easy to revert.

Notes

  • _pay_permission_cut repeats the assistant_text and not open_construct_at_end guard that _on_permission_request checks when it arms the cut. The two checks see different moments, so the pay-time check is the one that counts. Keep only that one, so the two can't drift apart.

[DESIGN-REVIEWED] 8e28b19

Description read

[DESCRIPTION-READ] 735954ecf9cb3f027af1c2627826657588a9fb60c4c0de8054670d461ccbab9a

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 8e28b19e17886665382f6667b9940be02963c469 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix works at the mechanism: the cut now happens where a row actually lands, not before the decision. The author checked all four other cut sites and none has the same defect.

What this change ships

Inventory (5 items) — 5 justified

Intent: a Codex reply stays one saved and displayed message even when sub-agent approvals arrive mid-stream. This is a FIX (#23918).

  1. A permission request granted with no row (YOLO, session trust, native crew) no longer splits the reply into several assistant rows. — justified
  2. A permission request that does land a row (an approval card or a tool row) still cuts the reply's text above that row. — justified
  3. A send or steer flush made while a permission decision is pending clears the owed cut, so the text is saved once. — justified
  4. New slot field _owed_segment_cut, which append pays before the next durable row. It is not a second copy of _steer_segment_cut: that one is called on demand by senders (3 call sites), while this one is paid on the next row. — justified
  5. The decision body is renamed from _on_permission_request to _decide_permission_request. The identity-gate pin is updated, with the count of 6 unchanged. — justified

[FIRST-PRINCIPLES-REVIEWED] 8e28b19

Description read

[DESCRIPTION-READ] c03b841b315e04d20ed2f6b78cbe3c6bec455de606ad4fc682ffd688c934206f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 8e28b19e17886665382f6667b9940be02963c469 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8e28b19

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 8e28b19e17886665382f6667b9940be02963c469 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8e28b19

@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from a6a934c to d82d8ea Compare October 25, 2026 05:13
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

The cut stays deferred until a row lands; tool calls, approval cards, refusals and steers still cut before their rows, and test_permission_cut_owed.py pins both sides.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

The cause is a cut made before the decision knows whether a row follows; the fix moves the cut to the row, and the five shipped items are the smallest set that keeps rows that land in order.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore: d82d8ea fixes the Backend Tests (3.12, 3) red. test_a_name_a_closure_writes_is_never_held_under_its_own_name flagged _pay_permission_cut writing turn._turn_flushed_visible_text directly; it now binds the local and copies it onto the turn, the form every other phase uses. No behaviour change. The plumbing, owed-cut, segment-cut, permission-floor and composition-contract tests pass locally, 323 in all.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from d82d8ea to 84206ce Compare October 25, 2026 11:58
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore: rebased on main as 84206ce, no behaviour change. On d82d8ea the only red was Security Scope Review: its generate job's Checkout base step hung for 35 minutes and the lane posted no verdict (run 40165986368). Main had moved 61 commits in the same directories, so this rebase re-runs CI on today's base. The permission, segment-cut, plumbing, steer and composition-contract tests pass locally on the rebased head, 443 in all.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 25, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note: Backend Tests (3.12, 2) is red again on 741bb44 with test_two_concurrent_releases_each_prune_their_own_view, the main flake tracked in #23965 (assigned, recorded there twice for this PR). This diff touches no skill-projection code and every other check on the head is green. No further retrigger from this side; the PR waits for the #23965 fix and is rebased onto it when it lands.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 25, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from 741bb44 to e3eb78f Compare October 26, 2026 02:57
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore: rebased onto main as e3eb78f, which now carries the #23965 fix (#24142), no behaviour change. The only red on 741bb44 was that flake in Backend Tests (3.12, 2), plus the Coverage Gate that failed because of it. The permission, segment-cut, plumbing, steer and skill-projection tests pass on the rebased head, 463 in all.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 26, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

e3eb78f is a no-behaviour-change rebase onto the #23965 fix; the cut is still owed until a row lands, with one arming site and one paying site, and test_permission_cut_owed.py pins the silent-grant and row-landing cases.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

e3eb78f is a no-behaviour-change rebase onto the #23965 fix; the cut is still owed until a row lands, with one arming site and one paying site, and test_permission_cut_owed.py pins the silent-grant and row-landing cases.

@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from e3eb78f to 5a7955a Compare October 26, 2026 05:57
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore: rebased onto main as 5a7955a, no behaviour change. On e3eb78f, Backend Tests (3.12, 5) failed on test_pruning_removes_from_the_seam_and_leaves_local_files_alone. That test fails 3/3 on that head and passes on main since #24191 pinned its prune clock; this PR touches no memory code. Coverage Gate failed only because shard 5 did, and the Automated Rule Check was cancelled at its 10-minute job timeout, so this push re-runs it. The permission, segment-cut, plumbing, steer and memory-file tests pass on the rebased head, 415 in all.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 26, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/codex-fragmented-messages branch from 5a7955a to 8e28b19 Compare October 26, 2026 07:13
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

chore: 8e28b19 is a same-tree retrigger of 5a7955a, no code change. On that head all eight backend shards passed, but the fork GPT 6.1, Opus 5.5, Internal Content Scan and Security Scope lanes stopped at 06:03Z with 'API rate limit exceeded for installation' in their PR-resolve step (lane run 40277611077), so none produced a verdict. Main has moved in no file this PR touches.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 26, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

8e28b19 is a same-tree retrigger; the cut is still owed until a row lands, with one arming site and one paying site, and test_permission_cut_owed.py pins the silent-grant and row-landing cases.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 26, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): agreed, no change.

The cut waits for a row that actually lands; every row-landing path still cuts first, any other flush clears the owed cut, and test_permission_cut_owed.py pins both.

@iamwhatever iamwhatever 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.

Approve. Reviewed 8e28b19e17886665382f6667b9940be02963c469.

The fix goes after the cause: the permission handler used to cut the reply before knowing whether any row would follow. Now _on_permission_request arms an owed cut. append pays it before the first durable row, the interactive-card path pays it before drawing the card, a silent grant drops it, and any other flush clears it. The decision body is unchanged apart from the moved cut: every approve_tool call, hook, trust read and return value is the same, and the permission-floor pin keeps its count of 6 under the new name. The new tests cover silent grants under YOLO and session trust, plus the boundaries that must still split. AI lanes are PASS or no findings, the Design note is answered, checks are green on this head, and there are no change requests.

— crew-pr-reviewer (r127)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 26, 2026 17:37
@iamwhatever
iamwhatever merged commit 5bd7d56 into kirodotdev:main Oct 26, 2026
104 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex: one assistant message is saved as several rows when a permission request lands mid-message

2 participants