Skip to content

feat(chat): backend to merge a fork back into its parent chat - #17165

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
unstablebrainiac:feat/fork-bring-back-backend
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
unstablebrainiac:feat/fork-bring-back-backend

Conversation

@unstablebrainiac

@unstablebrainiac unstablebrainiac commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bring a fork's new results back into the chat it was forked from, merging only what that chat lacks and delivering each summary to its agent exactly once.

A fork is a one-way door today: when it pays off, nothing lands the outcome in the original chat, and its forked_from link is display-only.

This is the backend half of #15957, which is stacked on this PR.

Why it matters

Every fork that pays off now costs a manual copy and paste, and every skipped one leaves the parent without context you already paid for.

Not a goal

  • The dashboard: the session-menu entry, the dialog, and the card's label and link are feat(chat): merge a fork back into its parent chat #15957.
  • Merging raw messages, a three-way merge, or a parent into a fork.
  • Archiving or locking the fork after a merge; it can be merged again.
  • Merge-back for app tokens, agent tools or internal callers.
  • Merging into a closed parent without opening it.
  • Undoing a merge.
  • A fork of a chat whose key is over MAX_FORK_PARENT_KEY_CHARS: it records no parent link, so it is not_a_fork.
  • Fixing main's name-only slot dedup (api_chat_slot_create, api_chat) first, or refusing a parent open in two slots: main opens one transcript twice on purpose (History resume, a create by name, the hooked resume), so a turn takes its session's cards from whichever slot holds them.
  • Delivering the summary as a parent turn, which starts its agent unasked, or a user message, which speaks in the person's name.
  • At-least-once delivery, which can hand the agent the same results twice.

What changed (motivation → approach → change)

This PR has no UI: the routes' only caller is #15957's dialog. The note hold and History resume changes apply to every chat now; the feature map lists the endpoints as API-only until #15957.

Part What it does
Draft POST /api/chat/slots/{slot}/merge-back/draft has the background model summarize the fork messages the parent lacks, as many as it reads in full, and says how many are left and whether the note was cut. It writes nothing
Merge POST /api/chat/slots/{slot}/merge-back writes the text into the parent as a note whose row carries meta.mergedFrom: the merge card

The card goes through the note path, so the parent's agent sees it after a restart: api_chat_slot_note's delivery step is now deliver_note in chat_api/slot_note.py, which merge-back calls. That gives the card the note's visible inject row, its next-turn context, and its durable hold. A merge counts as done once that hold is written, not once the agent reads it, or the next draft would summarize a pending card again. A card is consumed once a turn whose prompt the next session holds has taken its context: kiro-cli kept it (_kiro_cli_kept_the_prompt), and no reset before end_turn, discard or runtime swap dropped it (_native_session_lacks_the_prompt). That turn marks it consumed on disk, so no restore, flush or other slot sends its context again (a crash before the mark sends it once more). The hold keeps its row until a full save writes it or finds it delivered. The hold in slot_buffers.py carries the mergedFrom block and both marks through serialize, restore and flush. A merge card's context reaches the parent's next turn from whichever of its slots runs it, within one slot's queue caps; a turn with no card on its session moves nothing (chat_turn/turn_context.py).

Merges are incremental and keep no fork-side state. chat_merge_back.py reads what the parent has from the parent: the rows the fork copied keep the parent's message ids, and each merge card records the range of fork messages it covered with a fingerprint of them. Only a note row the server delivered, or a held card whose write committed, counts as a card. Everything after the last range that still matches is new.

The merge route re-reads both chats rather than trusting the draft, and refuses a merge another tab made, a fork rewound past the draft's end, credential-shaped text (context_secret_shaped), and a parent whose context queue is full or whose agent has not finished reading earlier merges. Both routes refuse a parent taking turns outside the dashboard: only dashboard turns read a note's context. The draft's fingerprint refuses one whose messages have moved on. A fork records its parent transcript's created_at (chat_fork.py), so a chat later made on a deleted parent's key is not taken for the parent, and a merge whose parent or fork is deleted while its card is written is not acknowledged. The draft passes the active credential policy before the route returns it. Merges into one parent take turns. Both chats are read in full through the transcript derivation fence, with their rotated archives (derive_messages_chained_full_with_keys in history.py, on main's _derive_settled_chain_rows), and checked again as the draft is returned and while the card is written, so an incognito or temporary fork or parent publishes nothing. The module spec and app-kit reference describe it; security_posture_sinks_gateway.py lists the draft as a redaction egress path.

Backwards compatibility

Compatible: two new routes and new optional fields. Main accepts two writes this refuses: a dashboard send setting the server-minted mergedFrom or noteId, and a held /note past the 64 KiB header cap.

Reader: chat_handlers.py:api_chat -- chat -- strips a client mergedFrom and noteId from the row; test_chat_send_client_meta_survival.py.
Reader: chat_api/resume.py:_live_slot_for_resume -- chat (History resume) -- returns the live slot writing the transcript, so an unbound channel tab's slack_<ts> stem returns that tab, not a second slot; test_history_resume_returns_the_live_slot_for_the_same_transcript.
Reader: chat_api/resume.py:_hydrate_slot_from_history -- chat (History resume) -- restores the note hold as a restart does (part of #17025); a plain /note held at close is written by main's close flush and leaves the hold, so the resume writes it no second time; test_a_plain_note_held_at_close_is_written_once_after_history_resume.
Reader: slot_buffers.py note hold -- chat -- refuses a transcript recreated on its key after a delete, as the save already did, and holds 20 plain entries plus 10 merge cards; test_deferred_note_persistence.py.
Reader: slot_lifecycle.py:api_chat_slots_cleanup -- chat -- a closed tab holding notes loads its window off the loop before the flush, then rechecks for a replacement on the same transcript, which takes the tail through the handover drain; that drain also loads each window off the loop before reading it; test_cleanup_recreate_during_note_preload_uses_handover.
Reader: slot_turns.py:has_pending_context_seat -- apps -- counts merge cards a running turn took, so /context and /note find fewer seats; test_an_inflight_merge_card_holds_a_pending_context_seat.
Reader: the first-turn history settle (_turn_settle_debts) -- chat -- calls _kiro_cli_kept_the_prompt, unchanged; test_recovery_l1_chat_runner.py. The three prompt-keeping helpers live in chat_turn/turn_stats.py, and _message_without_merge_cards and _turn_lands are held on the turn (chat_turn/turn_locals.py) because _queue_recovery and the phases main moved out of _run_chat read them.
Reader: a fork made before this version -- chat -- has no parent created_at: it merges only into an older chat on the parent's key, and a missing or zone-less time is parent_unconfirmed; test_chat_merge_back.py.
Reader: an older build after a downgrade -- release -- ignores delivered, consumed and merged_from (a card it replays as a second row counts as one card here; a held card loses its label) and restores only the first 20 held entries; test_a_card_replayed_by_a_downgrade_counts_as_one_card.

Tests

  • test_transcript_derivation_seam.py and test_history_bindings.py: the guarded full-chain read lives in history_derivation.py, bound on ConversationLog; history_schema.py makes forked_from_created_at slot-owned metadata. history_projection.py's metadata_record_for_update is the record the writer saves, and the note hold measures it, with every merge card already marked consumed and delivered, against the 64 KiB header cap the export reads: a note that would cross it is refused with 413 deferred_note_header_full and nothing is evicted (TestEnqueueDurability in test_deferred_note_persistence.py, three boundary tests).
  • Determinism (testing-conventions § Proving a determinism fix), measured on this change over main 5fd96a0f2 with CI's pytest pins: the 247 tests this diff adds or changes, plus the four files where it changes only data (553 node ids), passed 20 runs at -n0, 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 beside test_history.py and test_chat_persistence_composition_contract.py (982 passed each), and one run in a shuffled order (seed 14521). The four close_before_resume calls in test_chat_merge_back.py fix a Windows clock tie: with a throwaway plugin that floors time.time() to the 15.625 ms Windows tick, the file without them failed 7 of 8 runs (13 resume_conflict failures across three tests) and with them passed 8 of 8. Six tests that delete a transcript and make another on its key pin both creation stamps, since two made in one Windows clock tick get the same stamp: with every new transcript and chat stamped with one constant time, the tests without the pins failed all 7 of their cases and with them passed all 7 (measured over main 397f4beef). With one release.set() removed, test_notes_wait_behind_a_durable_write_and_keep_their_order fails in 13 s and its output names the missed release (over main 334335182). The 12 tests the previous push added or changed (13 node ids) passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (442 passed each), and one shuffled run (seed 13646), over main 5dbde278a. test_a_turn_slot_whose_transcript_was_deleted_takes_nothing now pins both creation stamps too: with every stamp forced to one constant it fails without the pins and passes with them, and it passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files, and one shuffled run (seed 16618), over main 65e13d6b2. The tests the last four pushes add or change, with every test that calls a helper they changed (51 node ids), passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (480 passed each), and one shuffled run (seed 22273), over main 67c1304b0. Each test written for a defect these pushes fix fails with that fix reverted. The four TestSidebarRowParent tests passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (433 passed each), and one shuffled run (seed 2431), over main cbf2b3614. Two checked that a merge card's retirement never loaded a tab whose window was still pending; this push removes that scan, and test_consumption_does_not_load_a_pending_sidebar_twin checks the same of consumption. The other two fail with the merge routes' window load removed. TestMerge::test_a_credential_shaped_summary_is_refused_without_a_card and its two queue-full siblings passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (432 passed each), and one shuffled run (seed 30986), over main 2987fc9f9. It fails when a credential-shaped merge only skips its context half, which lands a card with no context; without the credential check in deliver_note, main's /note tests in test_pending_context_secret_refusal.py fail. For main's test: ratchet fixed short waits; add await_until and LoopHop helpers #19248 wait ratchet, test_chat_merge_back.py waits on the events and state it asserts through kiro_crew.testing.wait (await_until, async_wait_until, LoopHop) instead of short fixed timeouts; it passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files, and one shuffled run (seed 5798), over main 395106a39. The 25 tests this push adds or changes passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (468 passed each), and one shuffled run (seed 30409), over main 54b0c64ba. The 36 tests this push adds or changes passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (480 passed each), and one shuffled run (seed 24020), over main b6a7b33fb. With the bounded replay guard's cap, its stamped-first eviction, its survival after the mark, the queued-twin drop, the live-hold mark, the mark's write check or its retry after the turn removed, the test written for that part fails. With the consumed mark's stamp, its restore or drain guard, its flush skip, its union carry, the full save's retirement check, the turn's finally stamp or its _turn_lands read removed, the test written for that part fails. The 51 tests this push changes, or that call a helper it changed (73 node ids), passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (173 passed each), and one shuffled run (seed 466), over main bc72245a35. The draft runs one composed redaction pass: with the exfiltration-URL and credential passes run one after the other instead, test_a_credential_split_by_a_url_end_is_redacted_from_the_note fails on the half of the credential the URL's end leaves. With the draft on the companion-blind security.redact instead of redact_via_context, test_the_active_credential_policy_redacts_the_draft_note fails: a token only a loaded companion's credential policy matches reaches the JSON. It, the other 43 tests in TestDraft and the merge test that reads a card's title (45 node ids) passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (145 passed each), and one shuffled run (seed 490), over main 3d6cda4f3. With the duplicate check where a turn takes cards from its session's other slots, where the prompt is built, or where consumed cards are reported removed, or with an undeliverable turn-slot copy counted as already queued, the test written for that part fails. Those five tests and every test that calls a function they cover (58 node ids) passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (158 passed each), and one shuffled run (seed 518), over main 64576241e. The binding-rebuild test and the nine card-replay tests whose helpers it borrows (10 node ids) passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (116 passed each), and one shuffled run (seed 714), over main c5078a984. That test, the other 44 TestDraft tests and the merge test that reads a card's title (46 node ids) passed 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside the same two files (152 passed each), and one shuffled run (seed 580), over main 988fad008.
  • test/test_chat_merge_back.py, _merge.py, _merge_hold.py and _routes.py (one file split in four for the 2,000-line cap): the planner on head forks, tail forks, a second merge, a rewound fork, another fork's cards, merged ranges that lost messages at their start or in their middle (they stop counting, so the next draft covers what is left), and a card an earlier build stored with a tail key; the block validator, which requires every field and leaves out a key it does not read; a card row written twice, as a downgrade replays it (it counts once); the fingerprint, which follows the messages' text and not only their ids; the held-note round trip; both routes end to end against a real conversation log, including a fork made by the real fork route, a parent mid-turn, a restart, a parent a restart left as a sidebar row (both routes load its window off the event loop), two merges of the same messages, a reply switched to another variant through the real switch-variant route, both before its merge and after it, another merge covering the start of a draft, a busy fork transcript, a credential in the model's note, one cut in two by a URL's end, a draft that covers only what the summarizer reads in full (a long reply whole, a first message over the limit alone, the rest left for the next draft), a draft that never ends on the first of two pre-id rows with the same stamp, role and text, a model note over the limit (it comes back cut and marked trimmed), a message sent while the fork is read, a merge of a fork mid-turn or one that starts a turn while the merge reads or at its source check (refused as running, not as a stale draft), a fork whose rows predate message ids, a fork whose older messages sit in its rotated archive, a parent whose rows sit in its rotated archive, two tabs merging at once while the first card's write fails, a parent rewritten from its first message, a fork or parent made private while its summary is written, a fork or parent made private before its card is written, a restricted or unreadable parent, a parent chain that changes before the draft is returned, a parent that moved on since the draft (the merge still goes through), a merge into a parent open in two slots whose next turn runs in the other one, a plain note on such a parent (the slot it was posted to delivers it, once), a parent's turn ending, or the parent being saved, while the card's write runs, fails, or finds the fork made private, a chat made on a deleted parent's key, the same with a workflow-<run_id> tab of the deleted parent still open (the new chat's first and second turns take none of its cards), a fork made before this version (it merges into its own parent, is refused by a chat made on the key after it, and is refused as unconfirmed, not deleted, when a creation time is missing or has no timezone), a parent deleted and replaced while its card is written (nothing is shown under its key), a parent that cannot be read right after its card is written (the merge is still acknowledged), a turn on one of a parent's two slots taking no more card context than one slot holds, a card's context surviving a save and a restart until a turn takes it (for an idle parent, a parent mid-turn, a rows-only save and a twin parent), a turn whose prompt kiro-cli did not keep (an error before the send, a Stop, an empty-response re-queue: the card goes back to the queue), one that kept it without landing (promise-only with and without its continuation, a leaked tool call, a completed compaction, a backend error after output streamed: the card is marked consumed in a tracked write, is not sent again, and its hold waits for a save that proves its row), a row-less card whose row never committed (its hold survives a failed save, window trimming and the turn) and one whose row did (its delivered mark retires it), and one that completes (its landing save drops the hold; a twin's save, or one whose window predates the row, keeps it marked consumed until a save proves the row, a malformed hold on disk proves nothing, a live copy merged with disk keeps both marks, and consumption loads no pending sidebar twin; no restart, restore while the mark is being written, twin that queued the context first or rows-only handover sends the context again, nor does a failed mark write in the same process or a Stop inside the mark write; a consumed card whose row never committed comes back as its row alone), merges made while a turn reads earlier cards (those cards count toward the limit until that turn ends), a failed turn handing cards back without passing either queue limit, a delivered card rotated out of the live file before a restart, including one a rows-only save wrote (that save marks it delivered too), a card in a channel parent retiring after a restart, after the parent is bound to its thread, and after its context is dropped as another session's, the routes' full-corpus scans running off the event loop, a fork deleted, replaced or given a new chain while its card is written, the fork rewound or a covered reply switched while its card's write holds it (refused as stale, nothing written), a message added after the covered range then (still merged), a running turn's cards keeping their queue seats, a merge refused when the parent's whole context queue is full (no card written), a card whose context the flush cannot queue (the next restore queues it), a user row or an unstamped row claiming a card, the parent's cards, queue or running slot changing while the merge computes its cursor, a denied audit event for every privacy refusal, a parent outside the dashboard (a channel thread, a scheduled job, an unbound channel tab) refused by both routes before anything is read, a parent closed and reopened from History before its next turn (the card's context reaches that turn once and its hold retires, so a restart delivers nothing again), a parent closed while its card is written and then reopened (the card comes back once), a plain note held across a close and a History resume (written once), a History resume of a channel tab's file stem while its colon-form key is live (it returns the live slot), a History resume of a chat a workflow-<run_id> slot holds (it returns that slot), a create naming the chat beside that slot (the card reaches a turn on either, the new chat's first turn included), a hooked resume publishing the chat beside it, a card held through a restart and a failed turn (delivered once), an app token or a claimless internal-secret caller on either route through the real auth middleware (the uniform 404), and every refusal. test_chat_runner_coverage_merge_cards.py pins that a verbatim replay after an empty response, an image failure, a provider reset after the prompt-busy retries, an owed sub-agent completion or any turn that does not land carries the card once, that a completion held for sign-in keeps no card frame and keeps its completion mark, that a failed replay leaves it queued, and that a refusal's fallback replay carries the card once, because the refused turn consumed it. _queue_recovery re-queues a verbatim message without the card's frame: the thinking-binding rebuild passes the turn's message, and test_a_thinking_binding_rebuild_replays_the_card_once, which pins that it carries the card once, fails with that substitution removed. test_recovery_l1_chat_runner.py pins that the first-turn settle and the card's consumption read one _kiro_cli_kept_the_prompt. A process death after output streamed (a typed one and a pipe death) puts the card back on the queue with its hold intact, and the recovery turn sends it once. So does a retained-image recovery that discards the conversation, for a summary over 2,000 characters; a draft taken while a card's write is in flight offers the range again if the write fails, and cannot merge it twice if it commits. A compaction failure after output and a runtime death reported as a stop reason put the card back too, and test_members_dm_thread.py shows a vetoed agent switch on a crewmate thread returning its card.
  • test_transcript_derivation_seam.py covers the guarded full-chain read, including a chain member that joins after validation, and no longer lists merge-back among the plain reads. It also scans the two new publication holds for awaits. test_json_object_body_guard.py and test_slot_running_readers.py register the merge body's cap and the moved running read, and test_no_config_dir_in_async.py covers the coroutine in chat_turn/turn_context.py. test_chat_runner_coverage_merge_cards.py pins which context a turn takes from its session's other slots: merge cards for that session only, never a plain note, never across an app or between two incarnations of the session's transcript (a slot that has not read its transcript yet gets the identity in a worker thread, off the event loop), and no more than one slot's queue holds, expired entries taking no place in it (an expired card on another slot opens no identity read), the rest left in place, and that a turn whose session holds no card drains its own queue and changes no other. It also pins that a card queued twice, on the turn's slot and another slot of its session, on two other slots, or twice in one queue, reaches the prompt once and is reported consumed once, that a copy the turn's slot cannot deliver (one stamped with another session) does not stop the deliverable copy from moving, and that plain context posted twice is delivered twice.
  • test_dashboard_chat_fork.py, test_dashboard_chat_lifecycle.py (the delete witness), test_dashboard_chat_history.py (the resume's metadata read) and test_session_control_create_filing.py: the fork records its parent transcript's created_at (nothing when it is over-long, and no parent link at all when the parent's key is over-long), both saves write it, and every restore path brings it back, while a saved parent link that is not text or is over-long is discarded on every restore path, with only an over-long one's length logged, so both routes answer not_a_fork and slot_projection.py projects no fork link, and a created_at that is not text or is over-long restores empty, as on a legacy fork; the delete witness tells a proven delete from an unreadable transcript, while session_was_deleted still refuses on both; the resume reads the transcript's metadata off the event loop; test_deferred_note_persistence.py pins that a hold never merges into a transcript recreated on its key, that only a note's own write makes it durable while it awaits that write, that notes held behind a card's write keep their order and are delivered however that write settles, that a failed flush keeps a card's context, that a tab restored as a sidebar row settles its hold on its first window load and that a flush on a row still pending settles it first (a committed note keeps one row and a card's context is queued once), and the ceilings: 20 plain entries and 10 more for merge cards only, and that a restored entry keeps a bounded id, cls and session (an over-long id or class is replaced, an over-long session drops the entry). test_flush_exception_safety.py pins that a failed flush puts a note's context back with it, test_slot_metadata_codec.py that a restore at the 30-entry hold ceiling queues every committed card's context, each counted once, and test_chat_send_client_meta_survival.py that /api/chat strips mergedFrom and noteId.

Manual verification

N/A for a person: this PR adds no UI, and its routes have no caller until #15957. test_chat_merge_back.py drives both routes end to end through the real handlers and a real conversation log, with a fork made by the real fork route.

Screenshots / video

N/A: no UI change. The dashboard and its screenshots are in #15957.

Related Issues

Design: #3816 (comment)

Refs #3816. #15957, stacked on this PR, closes it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@unstablebrainiac
unstablebrainiac requested a review from a team as a code owner October 5, 2026 23:12
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of 1631d953bb74d27e46f8eed59ee31d5100fc27c1 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

Nothing blocks. The merge-back routes add a capability alongside the existing ones and change no default. The one cost worth cutting is the machinery that lets a merge card follow its session across twin slots.

Notes

  • Item 6 — oversized: the description says a card "reaches the parent's next turn from whichever of its slots runs it". That one rule adds adopt_alias_note_context, _same_chat_replacement, _hand_off_cards_when_the_turn_ends, and 6 production call sites of hand_merge_cards_to_open_twin (counted with ^\+.*hand_merge_cards_to_open_twin), spread over four close/cleanup paths. Subtraction: when the parent session is open in more than one slot, refuse the merge with a 409, and delete those helpers and the 6 call sites. ## Not a goal rules out that refusal, but it would shrink the change and lose only merges into a session that is open twice. Clears when: the mechanism is removed, or a human amends the Goal.
  • Item 1 — zero consumers: the two routes have no caller in this tree ("the routes' only caller is feat(chat): merge a fork back into its parent chat #15957's dialog"). Even so, every dashboard turn's prompt build and 10 recovery requeue sites are rewired now. Merging this with feat(chat): merge a fork back into its parent chat #15957, or after it, carries the same cost with a consumer.

What this change ships

Inventory (10 items) — 8 justified

Intent: let a person bring a fork's new results back into its parent chat, so the parent's agent receives them once. ADDITION.

  1. New API to draft a summary of fork messages the parent lacks — zero consumers (only caller is stacked feat(chat): merge a fork back into its parent chat #15957)
  2. New API to write the edited summary into the parent as a merge card — justified
  3. Every new fork records its parent transcript's created_at — justified
  4. History resume now restores held notes, like a restart does (dashboard: slot restore paths skip persisted fields that the next full save then clears #17025) — justified
  5. History resume returns the live slot that already writes the same transcript file — justified
  6. Merge cards follow their session to another open slot of it, on close and on turn — oversized: twin hand-off machinery
  7. Merge cards get consume/deliver stamps, a replay guard and a retried stamp task — justified
  8. A held /note over the metadata header ceiling is now refused with 413 — justified
  9. A client send can no longer set mergedFrom/noteId/noteRowFor — justified
  10. Recovery replays leave out merge-card frames; their context goes back to the queue — justified

[FIRST-PRINCIPLES-REVIEWED] 1631d95

Description read

[DESCRIPTION-READ] d5bf9732061e545821860127479d44a46dee898e643e81f6dfaa866595945ddb

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 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

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

Design-Verdict: PASS

No design-level blocker: the take-aways are listed or stripped server-side, nothing renders under website/src/, and the reversed resume pin is the tracked #17025 gap.

Notes

  • The exactly-once consumption bookkeeping (_inflight_merge_contexts, _consumed_merge_cards, _native_session_lacks_the_prompt) runs through every dashboard turn path: recovery, stop, fallback and queue drain. Every future change to the turn pipeline now has to keep these marks correct, which is a lasting cost of turning down at-least-once delivery.
  • The 64 KiB cap on a held /note is stated under Compatible: but names no reader. If an app posts large durable notes, naming it would turn that claim into something a reviewer can check.

[DESIGN-REVIEWED] 1631d95

Description read

[DESCRIPTION-READ] 9f40899ca26789887ba2e6a02573bb532a24d442b862f44c5853c5dd2d7b46b5

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 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)

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

Opus 5.5 adjudication downgraded every blocking finding. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

Review details

BLOCKING -- src/kiro_crew/dashboard/chat_turn/prompt_assembly.py:789 -- Cold-start replay delivers pending merge summaries twice

_ctx_prefix = _turn_context.prefix
Trigger: A committed merge card awaits consumption when the parent's next dashboard turn uses transcript replay, such as a Tool Search resume. _turn_build_prompt calls _session_replay_history, which includes the card's inject row, then prepends the same summary through take_turn_context.
Outcome: The agent receives the summary twice in one prompt—once in conversation history and once as background context—without a crash or failed consumption write.
Anchor: defect
Fix: Exclude the current turn's merge-card rows from both disk and live-window replay while retaining their queued context.

[BLOCK-MERGE-DOWNGRADED] 1631d95
[GPT-REVIEWED] 1631d95

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 is downgraded, so it no longer blocks the merge.

F1 — LOW. The duplicate needs a cold-start turn: replay only runs when _context_is_new and not _provider_has_history (src/kiro_crew/dashboard/chat_turn/prompt_assembly.py:136). The replay also has to include inject rows, which it does: they are in RECALL_ROLES (src/kiro_crew/context_assembly/replay.py:25). The card's summary then shows up as a visible inject row and again in the pending context queue. On base, every flushed note already does this (row at src/kiro_crew/dashboard/slot_buffers.py:904, then the context is promoted). So the merge card inherits an existing behaviour rather than adding a new one.

The result is one prompt carrying the summary twice. Nothing crashes and nothing is lost or corrupted. The drain clears the queue (_drain_pending_frames, slot._pending_context.clear()), and later turns get the card once.

The suggested fix would mean filtering the current turn's note rows out of both build_session_replay's disk replay and the live-window replay. That ties the context-assembly replay code to the note-delivery code by note id, for every note and not only merge cards, which is a lasting cost for a one-turn token duplicate.

[ADJUDICATION] 1631d953bb74d27e46f8eed59ee31d5100fc27c1 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/dashboard/chat_turn/prompt_assembly.py:789 reason=disproportionate-remedy
[GPT-ADJUDICATED] 1631d953bb74d27e46f8eed59ee31d5100fc27c1

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 1631d95

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 6, 2026
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-bring-back-backend branch from 91fe9ae to 481160b Compare October 7, 2026 03:06
@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: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 7, 2026
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-bring-back-backend branch from 481160b to 79547df Compare October 7, 2026 05:14
@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 7, 2026
@unstablebrainiac
unstablebrainiac force-pushed the feat/fork-bring-back-backend branch from 79547df to 1e6f42f Compare October 7, 2026 05:56
@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 7, 2026
@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles inventory item 3, the card's context moves to the slot that runs the next turn: kept span=4e5ef588e263

Main opens one transcript in two slots on purpose (History resume, a create by name, the hooked resume). A card held by one slot would strand when the user continues in the other, so the card's context follows the slot that runs the next turn. ## Not a goal names main's name-only slot dedup as the cause this PR leaves in place.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles item 6, the resume expected_created_at pin has no consumer: removed span=157b1c179e0a

Removed after 0509c76: the resume route's expected_created_at pin and the card's mergedFrom.createdAt are no longer in this PR (no expected_created_at in chat_api/resume.py and no createdAt in the merge-back code at head b55a40b). What remains is the merge's own source_expected_created_at check, which the merge route reads.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles inventory item 6, the resume pin and the card's createdAt: removed span=a445ef7cac09

Removed after 0509c76: the resume route's expected_created_at pin and the card's mergedFrom.createdAt are no longer in this PR (no expected_created_at in chat_api/resume.py and no createdAt in the merge-back code at head b55a40b). What remains is the merge's own source_expected_created_at check, which the merge route reads.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles inventory item 4, History resume writes held notes for every chat: declared span=4c6ae1890db0

A merge card is a held note, so a parent reopened from History would otherwise not get it until the next restart. This is the fix for an earlier GPT BLOCK on this PR (a History resume that restored no held notes or card context). Backwards compatibility lists the reader: chat_api/resume.py:_hydrate_slot_from_history.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles inventory item 5, History resume returns the tab that writes the same transcript: declared span=853742699839

A resume now restores the note hold, so a second slot on the same transcript would write the held notes twice. Backwards compatibility lists the reader: chat_api/resume.py:_live_slot_for_resume returns the live slot that writes the transcript.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • First Principles inventory item 10, cleanup and hand-over load the window off the event loop: declared span=07ee819abf8c

A closed tab that holds notes has to load its window before the flush writes them, and main's flush loads it on the event loop. The recheck hands the tail to a replacement slot on the same transcript instead of writing it twice. It is in the description now, as the slot_lifecycle.py:api_chat_slots_cleanup reader under Backwards compatibility.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author

@iamwhatever On your r112 hold at 0509c76:

  1. The human review of the security_posture.py redaction row and the write_guards.py delete witness stays with you.
  2. So does carrying the PR onto a repository branch for Sensitive Change Review.
  3. The ten dispositions above answer each Design and First Principles item on 0509c76 that the lanes did not mark justified, one per span. The two deferred Design items now have issues: Merge-back: strip merge-card frames in one shared requeue step #23163 (one shared step strips card frames on every requeue path) and Merge-back: limit the merge-card consumption rule to named backends #23164 (the consumption rule limited to backends checked by name).

On the current head, b55a40bc2, Design and First Principles PASS, and GPT and Opus report no findings.

@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at 4b27edb for maintainer review.

The author has answered the Design and First Principles items with one disposition each. The two deferred items are tracked in #23163 and #23164, which describe them. Opus reports no findings, and every check except Sensitive Change Review is green.

What still blocks, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for model-written merge summaries (security_posture_sinks_gateway.py#L846-L854) and turns the delete witness into three states (write_guards.py#L171-L179). A maintainer's review clears it.
  2. Sensitive Change Review is red because a fork PR cannot pass it. A maintainer has to carry the PR onto a branch of this repository and run the gate there.
  3. GPT's cold-start finding has no author reply. On a replayed cold start, the model sees a pending merge card twice in one request (prompt_assembly.py#L701). Adjudication downgraded it to low, matching the accepted trade-off for plain notes. A one-line disposition that accepts or rebuts it clears this.

I did not re-read the full diff on this head or run the tests.

— crew-pr-reviewer (r127)

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author
  • Cold-start turns deliver pending merge summaries twice span=9dd41fe0962a

accepted: on a replayed cold start the model sees the summary twice in one request. Main documents the same trade-off for a plain /note (slot_note.py#L296-L299): the queued copy is kept because the char-budget bounded replay may have trimmed the row.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author

@iamwhatever On your r127 hold at 4b27edb:

  1. The human review of the redaction egress row and the three-state delete witness stays with you.
  2. So does carrying the PR onto a repository branch for Sensitive Change Review.
  3. GPT's cold-start finding now has its disposition (comment): accepted, as the same trade-off main documents for a plain /note.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 2b13715 for maintainer review.

This head is a rebase of 4b27edb with no new logic. The GPT cold-start item from r127 now has an accepted disposition that cites main's documented /note trade-off, and the two deferred items stay tracked in #23163 and #23164.

What still blocks, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for model-written merge summaries (security_posture_sinks_gateway.py#L846-L854) and turns the delete witness into three states (write_guards.py#L171-L200). A maintainer's review clears it.
  2. Sensitive Change Review is red because a fork PR cannot pass it. A maintainer has to carry the PR onto a repository branch and run the gate there.
  3. CI is not finished on this head. GPT 6.1 Review and Backend Lint & Type Check are still running, PR Readiness is pending, and the GPT and Opus lane comments still name 9c519b2.

— crew-pr-reviewer (r133)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at f55949f for maintainer review.

This head is a rebase of 2b13715 onto current main. git range-diff shows only import and context moves and one test-helper line. GPT, Opus, Design and First Principles all pass on this head with no findings. Their notes repeat items already answered on earlier heads, and the deferred items stay tracked in #23163 and #23164.

What still blocks, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for model-written merge summaries in security_posture_sinks_gateway.py, turns the delete witness in slot_persistence/write_guards.py into three states, and adds two merge-back routes. A maintainer's review clears this.
  2. Sensitive Change Review is red because a fork PR cannot pass it. A maintainer has to carry the PR onto a repository branch and run the gate there.
  3. CI is not finished on this head. Backend Tests (3.12) shards 1-8 and the offline E2E run are still queued or running, and PR Readiness is pending.

— crew-pr-reviewer (r135)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 3a312c0 for maintainer review.

This head is more than a rebase of f55949f (r135). It adds new logic to move queued merge cards from a closing tab onto another open tab of the same chat: hand_merge_cards_to_open_twin with a 5-second transcript-identity read (turn_context.py#L649-L760), new calls to it from the close and cleanup paths, and a check that refuses a merge as merge_draft_stale when the parent window lost a card while the merge was being read. I read the new logic in that range-diff and found no definite defect.

What blocks, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for model-written merge summaries (security_posture_sinks_gateway.py#L866), turns the delete witness in slot_persistence/write_guards.py into three states, and adds two merge-back routes. A maintainer's review clears this.
  2. Opus review is incomplete on this head. The Opus 5.5 Review check reports "review incomplete", and the Opus lane comment still names 8f9ab4f. Re-running the lane on this head clears this.
  3. Sensitive Change Review is red because a fork PR cannot pass it. A maintainer has to carry the PR onto a branch of this repository and run the gate there.
  4. CI is not finished. Backend Tests (3.12) shards 1-8, both E2E runs, Integration, the Frontend Tests shards, Build Desktop and New-test stability are still queued or running, and PR Readiness is pending.

AI findings judged non-blocking:

  • GPT 6.1 (downgraded): a parent rewind that lands between the stale-window check and deliver_note can leave a cursor that cannot be reached, so a later merge re-delivers a range that was already acknowledged (chat_merge_back.py#L1379). This needs two tabs racing, and the worst outcome is a summary the agent receives twice. Nothing is lost.
  • First Principles item 7 and the Design notes: the twin-tab hand-off is cost the PR takes on because twin-slot dedup is out of scope (Not a goal), exactly-once delivery could be at-least-once instead, and two cross-chat behaviours could ship separately. These are scope and design-cost notes, not defects.

The deferred items stay tracked in #23163 and #23164. I read the range-diff from the last reviewed head, the AI lane bodies and CI. I did not re-read the whole 14k-line diff or run tests.

— crew-pr-reviewer (r136)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 21fce89, reserved for human review.

This head is a rebase of 3a312c0 (our r136). The range-diff shows only conflict context and one test-helper line (exit_code=None on a mock); I found no new logic and no defect.

What holds it, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for merge-back summaries, makes the delete witness in slot_persistence/write_guards.py three-state, and adds two merge-back routes. A maintainer's review clears this.
  2. AI review is not complete on this head. GPT 6.1 reports 'review incomplete' and Opus is still running; both lane comments still name an older head. A finished run of each lane on this head clears this.
  3. Sensitive Change Review is red on this fork head; a maintainer has to approve it or carry the PR onto a branch.
  4. CI is still running (lint/type check, ratchets, desktop builds) and PR Readiness is not green.

Deferred items stay tracked in #23163 and #23164. I read the range-diff, lane bodies and CI; I did not run tests.

— crew-pr-reviewer (r139)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD (reserved for human review; CI and AI review incomplete) at 47b2d4786793a36da733be353e524af2df91afc3.

This head rebases 21fce89 (our r139) onto newer main. The range-diff shows only conflict adaptations: turn._stop_reason in turn_stats.py, main's return None in history_projection.py, and neighbouring context. I found no new logic.

What holds it, and what clears each:

  1. Reserved for a human. The PR adds a redaction egress row for merge-back summaries, makes the delete witness in slot_persistence/write_guards.py three-state, and adds two merge-back routes. A maintainer's review clears this.
  2. AI review has not run on this head. The fork GPT, Opus, Design and First Principles comments still name 8841c39. A finished run of each lane on this head clears this.
  3. Sensitive Change Review is red on this fork head. A maintainer has to approve it or carry the PR onto a branch of this repository.
  4. CI is still running: lint and type check, ratchets, CloudFormation lint, Security Scope Review and both desktop builds. PR Readiness is not green.

Deferred items stay tracked in #23163 and #23164.

— crew-pr-reviewer (r142)

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

Requesting changes at 5c8efdc for one point.

dashboard/slot_buffers.py adds a regex in product code. This repository asks new product code not to check text with a regex:

_MERGE_DIGEST = re.compile(r"[0-9a-f]{64}")

is_merge_digest uses it with fullmatch to accept a lowercase SHA-256. The same check needs no regex:

  • isinstance(value, str) and len(value) == 64 and all(c in _HEX_LOWER for c in value), with _HEX_LOWER = frozenset("0123456789abcdef").

A test with a valid digest, an uppercase one, a 63- and 65-character value, and a non-hex character would cover it.

Separately, Sensitive Change Review cannot pass from a fork, so it will need a maintainer.

@unstablebrainiac

Copy link
Copy Markdown
Contributor Author

@bolichen97 Done in fee349d. is_merge_digest now checks len(value) == 64 and all(c in _LOWERCASE_HEX_DIGITS for c in value) with no regex. test_a_merge_digest_is_exactly_a_lowercase_sha256 in test/test_chat_merge_back.py covers a valid digest, uppercase, 63 and 65 characters, a non-hex character, a trailing newline and a non-string. The Sensitive Change Review hand-off is noted.

Add the two dashboard routes that draft and commit a fork's merge-back
summary, the merge card note that carries the summary into the parent
chat, the held-note durability the card relies on, and the History
resume changes behind the card's link back to the fork. The dashboard
that calls these routes lands in a separate PR stacked on this one.

Refs kirodotdev#3816

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

Approving at 1631d95. The point from my last review is fixed: is_merge_digest now checks a lowercase SHA-256 with a length test and a fixed hex character set, and the diff adds no regex in product code. All other checks pass. Sensitive Change Review cannot pass from a fork, so it needs a maintainer.

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) readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants