Skip to content

feat(threads): a thread is a full session anchored to one message, openable mid-stream - #14928

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
feat/crew-bot-threads-epic
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
feat/crew-bot-threads-epic

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a thread on any chat message becomes a full conversation you can keep talking in, and you can open one on a reply while it is still being written.

A reply thread on a crewmate's chat was a bounded reply list, not a conversation. It stored replies in a sidecar beside the transcript, ran every reply in a throwaway session keyed thread:<slot>:<mid> that could never resume, forced a read-only tool posture because the panel had no approval card to fall back on, injected no memory, and re-seeded its whole envelope every turn because the session was always cold. It refused a second message while the crewmate was replying (409 thread_turn_in_flight). It existed only on the Crewmates page, only behind the dashboard.crewmate_threads developer flag, and only on a message whose turn had already finished: the "Reply in thread" action was withheld while a reply was still streaming, which is exactly the moment a reader wants to ask about it.

Four of those were reproduced live on main on 2026-09-30, and they share one cause. Legacy threads were not sessions. A reply lived in a sidecar beside the parent's transcript and its turn COLD-STARTED a throwaway thread:<slot>:<mid> session every time, handed a rebuilt envelope: the instructions, a clipped copy of the parent's surrounding rows, the parent message and the replies so far. So a thread had no durable context of its own -- what it knew was re-pasted per reply and clipped to fit. In the same session the thread composer did not grow with its content, so a second line hid the first; a turn in a thread could not call a tool; and the composer offered no steer or queue chooser while its own turn ran. D1 fixes all four structurally rather than one at a time: a thread is its own slot with its own durable context, and the pane renders ChatPane -- the real composer and the real transcript row set -- so the thread inherits auto-grow, tool cards and the busy-send chooser by construction. What the thread is told about its parent is a bounded summary its own projector builds at its first turn (see the parent-context projection in docs/system-specs/modules/history.md), never the parent's context and never the reverse. website/src/test/threadInheritsChatSurface.contract.test.ts pins the delegation.

A second, unrelated thread convention had grown up agent-side. A resident manager opened a "thread" with session_create plus a folder naming convention, and the app hung it under the user's message by convention alone. There was no anchor, so nothing connected the two models, and no channel could join either.

Why it matters

You cannot work in a thread you cannot talk in. Every real use of one -- follow up on a single point, change direction, let the agent run a tool and approve it -- needs an ordinary conversation, and the old thread refused all three by construction.

Opening one also cost a wait. The action appeared only after the reply finished, so the moment you wanted to branch off was the one moment you could not.

And a thread could not travel. Slack threads, member DMs and the ordinary chat page each had their own idea of a thread, or none, so the same gesture meant something different on every surface.

Not a goal

  • Threads in a split-view pane on the chat page. Each pane is a different slot and needs its own controller and drawer.
  • An MCP tool to LIST a conversation's threads. thread_open is the only tool on that surface; an agent asking "is one already open here?" reads the footer.
  • Adapters for Telegram, Discord, Teams, Webex, WhatsApp, iMessage or Feishu. The anchor type and the adapter seam are in place for them; this PR ships the dashboard. Slack's anchor recorder is the seam's first other consumer and ships separately (see Other notes).
  • Migrating the stored version 1 reply threads into sessions. Their files are read in place and never rewritten, for the reason under "What changed". Drawing their replies is also not a goal here: the read-only fold ships in a follow-up (see "Other notes"), so the panel says it holds nothing it can draw yet and offers a real thread, while the parent's footer still counts them.
  • Editing session_control.py. open_thread passes that module's refusals through verbatim rather than adding a bypass.
  • Reducing the thread drawer's composer to a subset of the parent's controls. A thread is a full session; see "Other notes".

What changed (motivation -> approach -> change)

A thread is now an ordinary chat session plus an anchor to one message.

The old machinery existed because a thread was not a session. Each limitation traces to that one choice:

symptom root cause change
a second message refused mid-reply a module-global _in_flight lock, because the thread had no session to queue on a real slot, so steer/queue/stop are the ordinary ones. Lock and 409 thread_turn_in_flight deleted
tools read-only in a thread thread: sat in _STATELESS_PREFIXES and _run_thread_turn published a read-only spec, because a bounded panel has no approval card a real surface with a real approval card. _run_thread_turn, the read-only spec and the boundary prompt deleted
the whole envelope re-sent every turn the session cold-started each time a warm session, seeded once
"Reply in thread" withheld while streaming a streaming row has no mid; ids are minted when the row persists, post-turn the anchor resolves to the user message that started the turn, which is already persisted. The UI sends an inflight sentinel and never invents a mid
threads only on the Crewmates page ThreadHooks arrived only when MembersPage passed them one controller, website/src/pages/chat/useThreads.ts, wired by both ChatPage and MembersPage. 409 not_crewmate_chat deleted
Slack has no threads Slack already keyed one session per thread_ts and never recorded it the anchor shape covers it; the recorder that writes it ships separately, so nothing about Slack changes here

The anchor is (surface, conversation, message id): (dashboard, parent slot, mid) and (slack, channel id, thread_ts). Each surface keeps ONE record of it, in the only place that surface can make durable: the dashboard writes a per-parent index, so a parent lists its threads in one read, and the old reply sidecar becomes that index at version 2. Slack has no parent transcript to hang an index off, so its anchor belongs on the thread session's own metadata, which its writer also reads as an idempotency guard -- seam only in this change; that writer ships separately. A second copy on the dashboard side was written for durability, had no reader, and is gone.

Version 1 files are read in place and never rewritten. Their replies came from a cold read-only session with no memory injection and a curated envelope; replaying them as a full session's transcript would assert a history that session never had. The read-only fold that draws them is cut from this PR for the review diff cap and ships in a follow-up: the anchor index still reports kind: "legacy" with its count and last reply time, so the parent's footer names such a thread, and the panel states it cannot draw it yet rather than rendering an empty thread. Nothing on disk is migrated, moved or deleted.

Opening never touches the running turn. No semaphore, not a fourth _handle_busy branch, not a messaging.queue_mode value. It reads a non-consuming snapshot of the parent's partial text: chat_utils._collapse_wire_rows never mutates its input, and purge_chunks rebinds rather than mutates, so a reader that copies first cannot be emptied underneath. Every messaging invariant holds -- one turn per session, exact FIFO, one combined drain turn, the receipt edited and never deleted.

Two openers, one coroutine. POST /api/chat/threads/{mid}/open for a person clicking a message, MCP thread_open for an agent opening one on the message it is answering. open_thread calls create_session directly, so a thread faces the same authorization gate as any session opening another.

The drawer is a pane of the chat row, and the pop-out switches the slot. At 1100px and up the thread is a shrink-0 flex child of the chat surface row, the slot the side panel and the docked search panel already take, so the parent reflows instead of sitting behind the drawer; below that a split leaves neither column readable, so it stays an overlay. The rule and its reasoning live in website/src/pages/chat/threadDrawerLayout.ts. The header's pop-out dispatches the ordinary slot switch rather than pushing /chat?sid=<thread>: on this page a pushed ?sid= reaches nothing, because the session controller honours only a Back/Forward for that param and the activeSlot-to-URL effect then rewrites it back to the slot on screen -- which made the pop-out land on the PARENT.

The ledger is the existing crew log. thread/opened and thread/closed join session/opened, which already carries the parent link. No second store.

Backwards compatibility

The rebase onto origin/main deleted the version-1 crewmate side-chat reply
mechanism wholesale (it is superseded by the session-anchored thread model), so
PR Hygiene's take-away check names its removed public defs. Each had exactly one
reader, all inside that same removed mechanism or its route registration, and
each reader is removed or repointed in this diff:

Reader: src/kiro_crew/dashboard/routes/chat.py:configure_chat_routes -- chat -- the only reader of api_chat_thread_reply was the POST /api/chat/threads/{mid}/reply registration; this diff drops that line and registers the new /open and /close routes instead, so no route resolves the removed handler
Reader: src/kiro_crew/dashboard/chat_threads.py:api_chat_thread_reply -- chat -- thread_session_key, build_thread_message and threads_enabled were called only from api_chat_thread_reply and its helpers in this same file, all removed together in the rewrite, so no caller survives
Reader: src/kiro_crew/session.py:_THREAD_PREFIX -- chat -- the one reference to build_thread_message outside chat_threads.py was a code comment beside the _THREAD_PREFIX session-prefix constant; the comment is updated and nothing imports the removed symbol
Reader: src/kiro_crew/dashboard/chat_threads.py:broadcast_thread_reply -- chat -- broadcast_thread_reply (in ws.py) was imported and called only by the removed reply path in chat_threads.py; the new path broadcasts the chat.thread_anchor frame instead, so the removed def has no reader

Breaking: three contracts narrow. Writer sweep on origin/main @ b5ca357ba8:

  1. dashboard.crewmate_threads is kept, not removed (an earlier revision of this body claimed removal; corrected on the 2026-10-07 rebase). The backend thread routes and the thread_open MCP tool are ungated so a thread is openable from any surface, but the flag still gates the Crewmates page's own thread panel: config/sections.py, config/loader.py, dashboard/handlers/core.py's editable-key map, useCrewmateThreadsFlag.ts, CrewmatesSection.tsx. A stored true/false in an existing config.json keeps its meaning for that surface, so no operator config fails to load. (Making threads always-on on every surface is the open §07 governance decision — see the RFC amendment; it is not asserted as accepted here.)
  2. The chat.thread_reply ws frame is renamed chat.thread_anchor and its payload drops run_id, role and content. Writers: dashboard/ws.py, dashboard/ws_event_scope.py; readers: website/src/hooks/useWebSocket.ts, website/src/app-sdk/index.ts, website/src/state/threadLiveStore.ts. All updated here. No alias is kept: the payload shares no field with the old one, so a client written against the old frame would read every field as absent. A renamed event it does not subscribe to is a frame it ignores, which is the honest failure.
  3. POST /api/chat/threads/{mid}/reply is replaced by POST /api/chat/threads/{mid}/open plus ordinary chat sends on the thread's own slot, and 409 not_crewmate_chat is gone from all three thread routes. The only caller was website/src/api/threads.ts, updated here.

Compatible: stored version 1 sidecars keep reading, and their replies keep rendering.

Tests

test/test_chat_threads.py (48) covers the anchor index at both versions, the open core, both entry points, the close card, and that a thread mints a real session rather than forking the parent's transcript. test/test_mcp_dashboard_registration.py (23), test/test_channel_blocked_tools.py (62), test/test_json_object_body_guard.py and test/test_transcript_derivation_seam.py (85 together), test/test_agent_spec_hardened_reads.py (81) and test/test_config_baseline.py (17) carry the cross-file pins that name the removed route and the removed flag.

website/src/pages/chat/threadDrawerLayout.test.ts (4) pins the drawer's placement: overlay by default, and at the breakpoint an unshrinkable pane that undoes every base rule which would keep it out of the flex row, with the transcript still a shrinkable child of that row. Flex decides the width, so there is no computed value to read back and jsdom lays nothing out; the measured proof is in R3 above. threadInheritsChatSurface.contract.test.ts gained the pop-out case.

Frontend: 52 across ThreadPanel.test.tsx, useThreads.test.ts (new), threads.test.ts, threadHooks.test.ts (new), threadLiveStore.test.ts and ThreadFooter.test.tsx. MembersPage.test.tsx (221) and the renderer suites (241) are unchanged. tsc, eslint, mypy, npm run lint:i18n and npm run i18n:check clean.

Two consequences of "always on" surfaced in the suites and are fixed with the flag: MembersPage.test.tsx's shared threadsSummary spy now resolves by default, because with no flag the footer read goes out on every render and a rejecting default put a thread notice on three cases that assert no alert; and the create-dialog case asserts the ['kirocrewConfig'] cache is invalidated rather than refetched, because the flag hook was the only observer of that query.

Manual verification

Against a pod serving this branch, with real model turns. POST /api/chat/threads/<mid>/open answered 201 while the parent read running: true, and the parent's own reply then finished at 4103 characters rather than being cut short. Six turns ran inside the thread with grep and shell actually executing. A shell call raised a real permission row that POST /api/chat/slots/<thread>/approve granted with 200. A version 1 sidecar and a version 2 anchor were served from one file. A separate 24-check end-to-end run exercised the real routes, the real anchor store, the real create_session and the real delivery verb with only the ACP turn body stubbed.

One measured limitation, not a defect: opening with the inflight sentinel is refused on a brand-new chat's FIRST turn (409 transcript_missing). A transcript row is written after its turn and an anchor is durable only through the row it hangs off, so on a first turn the anchored message exists on screen and not yet on disk. An explicit mid on a busy parent answers 201, which is the case the goal names. The UI says "not yet" rather than reporting a failure.

Screenshots / video

One heading per functional requirement, in the order a reader should meet the feature. Every frame is from a pod serving this branch at 1600x1000 with real model turns; the caption says what that frame proves.

R1 -- Open a thread on any message

The assistant reply's More menu open, with Reply in thread as an item
The action lives on an ordinary crewmate reply, in the row's own More menu.

The user message's More menu open, with Reply in thread as an item
The same action on a user message: either side of the conversation can be anchored.

R2 -- Open while the reply is still streaming

A reply taller than the window, scrolled so its row header is off screen, with the sticky Reply in thread opener and an armed stop control
Bubble measured at 1433px against a 1000px window, the stop control still armed: the opener stays reachable on a reply that is both long and unfinished, so you do not wait for the turn to end.

R3 -- The thread sits beside the parent, not over it

The thread as a right-hand pane at 1600px: the parent transcript reflowed to the remaining width, both transcripts fully readable, both composers visible
Measured in the browser: the parent's scroll container went from 1104px to 584px, losing exactly the 520px the pane takes; its right edge and the pane's left edge both land on 1080px; zero elements overflow the container, and the parent's composer ends at 1057px, inside its own pane. Below 1100px the drawer goes back to an overlay, where a split would leave neither column readable.

R4 -- The thread mirrors the parent's reply as it arrives

The thread pane showing the parent's reply beginning to arrive under a Still being written label
The same pane seconds later, the mirrored reply much longer, the parent still streaming
Two frames seven seconds apart: the mirror grew from 113 to 1487 characters while the parent's turn was still running. It is read-only -- the parent's turn runs in the parent's own process.

R5 -- No seeded reply: the thread starts empty and streams for real

A freshly opened thread beside its parent, saying This thread is empty. Type a message to start it
Nothing is pre-written into a thread. The anchored message is quoted once above; the transcript below is genuinely empty.

The thread mid-turn: the user's own row, then the reply arriving, with the stop control armed in the THREAD composer
A turn inside a thread is an ordinary turn -- its own receipt, its own streaming reply, its own stop.

R6 -- The parent's context arrives by reference, not by pasting

The thread answering what this thread is about, naming the parent's own subject
Asked what it is about, the thread answers from the anchor summary alone.

The thread quoting the anchored text verbatim after a thread_context_read tool call
Asked for the exact wording, it calls thread_context_read and quotes it: the verbatim text is fetched on demand rather than front-loaded into every prompt. Re-probed live on this head with the two parent replies made separable first (0 shared long words between their first numbered points), the thread quoted the SECOND reply, the one it is anchored to, scoring 10/10 on that needle and 0 on the first reply's: "Its first numbered point, quoted verbatim: Record durable state (goal, phase, next step) to a ledger so progress survives context compaction or restarts." The answer names its own coordinates, seq 11/16, and GET /api/chat/threads/context with the thread's own session key returns parent_log_seq 16 -- the second reply's row, so the anchor is right at the layer the tool reads it from and not only in the panel.

R7 -- Tools run inside a thread

A tool call card in the thread, collapsed as 1 tool call, with the listing it returned rendered below
A thread is a real surface, so a tool call renders as the ordinary card and the ordinary rows.

R8 -- Steer and queue work in the thread composer

The thread composer holding unsent text while its reply streams, the send control split into Steer and a send-options chevron
Sending into a busy thread offers the same choice the main composer offers, rather than silently picking one.

R9 -- The thread sees what the parent said after it opened

The thread reporting the parent's two exchanges since the thread opened, both by subject
Asked what the main chat has said since, it names both later exchanges and says how far the parent's log reaches. The window follows the parent instead of freezing at the anchor. Re-probed live on this head with a code word typed only into the parent while the thread was open, the thread retrieved it: "The code word, quoted verbatim: MARIGOLD-8812", with no claim that the parent rows were unreadable. The same read reports last_seq 26, past the row the thread was opened on, which is the reach this requirement needs.

R10 -- The thread never leaks into the parent

The thread discussing its own narrow subject beside the parent
The parent answering an unrelated question cleanly, with no trace of the thread's subject
The parent is asked something unrelated and answers only that. Two sessions, two contexts.

R11 -- The parent shows the thread it carries

The thread footer under the anchored message, naming the thread
The same footer clicked, the thread open again beside the parent
A thread is reachable from the message it hangs off, not only from the menu that made it. A LIVE thread's footer carries no reply count by design: the count is the version-1 fold's, where the replies were the record; a real session's rows are its transcript, and ThreadFooter renders the count only on that older branch.

R12 -- A long anchor stays out of the way

A thread on a long numbered reply: the anchor clamped to a couple of lines behind Show more, the thread's own surface below it
The same anchor expanded behind Show less, the full point visible, the composer still in reach
The quoted anchor is capped so a long parent message cannot push the thread's own conversation off screen.

R13 -- Ending a thread

The card the ending left in the parent: Thread ended, the thread's title, and a Read it link
Ending is recorded where the conversation happened, so the parent still points at what was said.

The ended thread reopened from that link: an Ended badge in the header and the thread's own turn intact
An ended thread stays readable and keeps its history.

The two state transitions a still frame cannot carry, recorded on the live pod:

Anchor quote clamp, then End thread. The drawer opens as a split pane beside the
parent, the anchored 10-point message expands and collapses again on Show more /
Show less, then End thread is pressed with its hint on screen -- and the parent's own
footer flips to Ended with a Thread ended. card written into the transcript. Ending
closes the drawer, which is why the panel's own badge is in the second clip.

thread-transitions.mp4

The panel's side of a finished thread. Reopening it from the same footer draws the
Ended badge in the header, drops the End thread button, keeps the thread's turn and
its tool rows readable, and the composer reads "This thread has ended. You can still
message it, and replies land here." The anchor clamp still works on a closed thread.

ended-panel.mp4

Both recorded from fb2f4da2de4aec6d8967a6f014b416b56fd3206a on a Kiro Crew pod built
from that commit (bundle main-Bjxu8iPi.js), driven through the real UI against a real
session -- no fixtures and no stubbed thread state. Two harness facts, the same ones the
stills disclose: the capture browser holds the pod's own auth cookie, and ONE response is
rewritten, /api/kiro-prerequisite, because a fresh pod is first-run and its sandbox probe
walls the app behind a setup screen. Nothing about threads is touched by that patch and
nothing on the pod was modified.

R14 -- Pop out to a full page

The thread as an ordinary full-page chat, its own turn in place and the drawer gone
The pop-out opens the thread's own session, verified by the landed URL naming the thread slot and the thread's own reply being on the page. The drawer and the full page are two views of one session, so leaving one for the other loses nothing.

R15 -- A version 1 thread says it cannot draw its replies yet

A version 1 anchor on its parent footer, reading 2 replies
A thread written before this change keeps its anchor on the parent's footer, and
the footer still counts the replies: 2 replies.

A version 1 thread opened from its footer: These replies can't be shown yet, with Start a new thread here beside it
Opening it from that footer draws the fold rather than a transcript.

The version 1 fold close up, under the anchor quote and From the main chat
These replies can't be shown yet. with Start a new thread here beside it. It
says the replies exist and cannot be drawn yet, NOT that there are none: the
footer the reader just clicked counts them, so "none" would read as data loss.

R16 -- A tool waiting for approval inside a thread

A pending tool approval inside the thread drawer, reading Approval needed and Waiting for approval
A tool call raised inside a thread waits in that thread: Approval needed, the
command echo hello > note.txt, and Waiting for approval. The parent is not
asked.

The approval card close up, showing the command in both the Formatted and Raw views
The card's own body, legible.

The approval controls while it waits: Allow once, Trust, Reject, and Show this tool call in this thread
The controls are the thread's own, and the jump affordance uses the thread
wording: Show this tool call in this thread. While an approval is pending the
panel keeps its composer dock but holds no writable input -- the card occupies
that area, so the thread's last line is Allow once / Trust / Reject.

R17 -- A thread with nothing in it yet

The drawer of a freshly opened thread, reading This thread is empty. Type a message to start it
A thread opened and not yet used reads This thread is empty. Type a message to start it., with the End thread row above it and a live composer below.

The empty thread close up, with its composer placeholder
The same state legible, beside its composer placeholder Message this thread
(which ends in an ellipsis on screen).

One correction to the review's wording. The request named No replies yet for
this frame. That string is real but belongs to a different state: ChatPane.tsx
renders pages.chat.thread.no_replies_yet only when threadSurface === 'closed',
so it is what an ended thread with zero replies says. A thread that is merely
empty says pages.chat.thread.empty_hint, which is the string above. Two
surfaces, two strings; these frames are captioned with the one actually on screen.

R18 -- The ended thread, re-shot on this revision

The card ending leaves in the parent chat, reading Thread ended with the thread title
Ending is recorded where the conversation happened: Thread ended. followed by
the thread's title.

The same card with its Read it back-link
That card carries the way back into the ended thread.

The ended thread reopened, with an Ended badge in the header and its composer hint
Reopened from Read it: the header carries the Ended badge and no End thread
control, and the composer still works -- its placeholder reads This thread has ended. You can still message it, and replies land here. Ending releases the
anchor, not the session, so the hint says so where the reader is about to type
rather than disabling an input that is still writable from the thread's own page.

The header badge Ended (pages.chat.thread.closed) and the transcript card's
Thread ended. (pages.chat.thread.card_ended) are two different strings; each
caption above names the one in its own frame.

No flag is involved in any of these. This change deletes
website/src/hooks/useCrewmateThreadsFlag.ts outright, so every surface above
appears without a developer flag set.

Recorded runs

Two earlier end-to-end takes were recorded against a pod on this branch (99s and 70s) and are held by the crew alongside the frame-by-frame notes. The frames above supersede them for layout: both takes predate the split-pane change in R3.

Related Issues

no linked issue: this is a new capability tracked outside this repository, so no GitHub issue was filed.

Other notes

Why ending a thread swaps the chip for a card rather than animating one element.
website/AGENTS.md asks for one element animated between two states, and for a
stated reason when it is a swap instead. The reason: these are not one element in
two states. The footer chip is an affordance ON the anchored message -- a way into
a thread that is open -- and the close card is a new transcript ROW recording that
the thread ended, carrying the title and the back-link. They live in different
places in the transcript, so a shared-element flight would animate the way-back-in
away from the message it belongs to and across rows it never belonged to.

Keeping both was the earlier shape and this lane rejected it: the chip-plus-card
stack read as two controls the reader could not tell apart. Suppressing the chip
once the anchor carries closed_at is the answer to that finding, and the way back
in is not lost -- it moves to the row that records the event and names the thread.

  • Follow-up, not in this change: pod_up cannot seed the data home, so a fresh pod is first-run and walled when the diag mask races (pod tooling gap). The images above were taken on such a pod by rewriting ONE response in the capture browser; nothing on the pod was modified.

  • Follow-up, not in this change: legacy version-1 thread sidecars -- their read-only fold lands in a follow-up PR (review diff cap). The sidecar files are untouched on disk and the parent's anchor footer still counts them; the panel says it cannot draw them yet and offers a real thread. Only installs that ran the developer-flagged version-1 feature have any.

  • Follow-up, not in this change: two placement contract tests from threadRowActions.test.tsx move to that same stacked branch, to make room for the redaction fix described under "What changed". Both assert WHERE a control sits -- the thread trigger standing where the copy-link button stood, and Pin keeping its one click while the permalink moves -- which the screenshots above show directly. The two tests in that module asserting SCROLL behaviour stay, because no still can carry them: the action row is sticky, and it sits outside the clipping bubble so sticky can work at all.

  • Follow-up, not in this change: seven regression tests move to the stacked branch with that Slack slice (review diff cap -- the AI lanes refuse a diff over 1 MB and fail closed). They cover the anchor's forward join into the parent log, the window's reach past the row a thread was opened on, and a thread resolving its own parent edge across log sessions. Every behaviour they assert is asserted here too, by the tests that stayed; what moves is the second, probe-derived angle on it. The blocking-fix regression (a cursor rejected at the writer's ceiling publishes nothing) stays in this PR.

  • Follow-up, not in this change: the Slack anchor recorder lands in feat(threads): record a Slack thread's anchor on every dispatch #15410 (review diff cap). A Slack thread keeps its anchor on its own _thread_anchor metadata line, and the recorder that writes it is two one-name imports away from everything else, so it splits cleanly. Slack's native threading is already on main and is unaffected.

  • Known limitation: the Opus review lane warns that this change touches 15,983
    reviewable lines, above its 15,000 advisory threshold for one reliable pass. The diff
    is already split once -- feat(threads): record a Slack thread's anchor on every dispatch #15410 carries the
    Slack anchor recorder, the read-only version 1 fold and several contract tests -- and
    a second split now would discard a verified R1-R14 evidence set and restart five
    reviewers for a warning that is not what any lane failed on. Reviewable-line budget is
    tracked as its own item for the next round.

  • Follow-up, not in this change: a screenshot harness that feeds the approval store the way the gateway does, so the thread's approval card can be captured rather than argued from tests. The one used for these images staged the row by hand and got that field wrong, which is exactly why it is not committed.

  • The thread drawer renders a second full composer dock -- model chip, mic, attach, reasoning chip -- so two of every control sit beside the parent's. Kept deliberately: a thread is a full session, and reducing the dock means deciding which controls a thread may not have, which is the partial-session shape this change removes. If the density is wrong, the fix is to reduce the drawer and reach the rest from the popped-out full page, one click away. That is a product call.

  • Trading Desk's agent-side convention migrates by a patch rather than a commit here, because that tree is outside this repository: five THREAD CLONE sites in its engine/orchestrate.py and five edits to skills/thread-routing/SKILL.md, whose key-shape rule ("am I in a chat-* session?") becomes "am I anchored?". The patch builder asserts each substitution matches exactly one site, so a desk that has moved on fails loudly instead of half-migrating.

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: history.md (new Surfaces section), session.md, crew-mode.md, docs/feature-map/README.md
  • No secrets, credentials, or internal references in the diff

The four still frames that used to sit here were taken on a superseded build and
have been removed: their header read Thread and Thread: Ready. at once, the
thread was announced twice (chip and card), and empty/start it sat beside
ended -- none of which this revision renders, after threadTitle.ts,
messageRenderers.tsx and ChatPane.tsx collapsed those duplicates. Their
replacements are captioned in R15, R16 and R17 below, each re-shot on this head.

One of the four, a thread opened on a reply still streaming, is not replaced.
It was stale like the others, and re-shooting it would evidence a claim no review
asked about; R7 already shows a tool running inside a thread. Said plainly rather
than quietly dropped.

The version-1 fold is evidenced in R15. The read-only view that draws version 1
replies is still cut from this change and ships in the follow-up (see "Other
notes").

This PR no longer touches src/kiro_crew/vector_memory_runtime/lessons.py

An earlier revision carried a one-line F821 fix there -- lessons.py:1206 called
_row_stem_tokens_for_scan unqualified while its two siblings called it as
_text_scoring._row_stem_tokens_for_scan, a runtime NameError that reproduced on a
clean origin/main checkout and redded Backend Lint & Type Check, shard 5 and shard 6.
It is filed as #15762 and has since landed
upstream, so the rebase dropped the hunk and this branch is back to threads-only.

CI fix round (head 8e57711, rebased from 547c7e5)

Rebase-induced backend failures fixed: the session-control strict set is now 16
(main's session_reload + this PR's thread_open), _DASHBOARD_TOOL_CALLS and
the strict-rows invariant updated to match, thread_context_read's schema moved
from MCP_DASHBOARD_SCHEMAS to MCP_CORE_SCHEMAS (it is a core tool, not a
dashboard TABLE row), and the two start_priority cases naming the removed
side-chat _run_thread_turn/api_chat_thread_reply dropped. Semgrep: the two
autouse fixtures in test_chat_threads.py now request _floor_monkeypatch (D11).
Bundle: ChatPane gets its own 546 KB budget (measured 519.6 KB; the thread row
affordances and sticky header are part of the always-loaded chat surface, no new
dependency).

GPT 6.1 (both security-class, FIXED in thread_projection.py):

  • F1 (:863) — a trimmed block now holds the cursor at window.start - 1 on any
    final trim, incomplete folds included, so a trim that cut a summary can never
    retire the row it summarized. Repeating a window is recoverable; a dropped row
    is not.
  • F2 (:1136) — a projection now stamps cursor_source_sid (the parent log its
    cursor counts against); the next turn resets to first-turn when the resolved
    parent log differs, so a reset parent's early rows are read rather than skipped.
    New field declared on thread/context_projected; effective_cursor_for_log
    carries the decision with a unit test.

First Principles (BLOCK) — the two items split:

  • Item 2 (framing contradiction) FIXED in code: the RFC amendment and the
    MembersPage comment no longer claim dashboard.crewmate_threads is "removed"
    or that the routes 404 when it is off. The flag is kept and still gates the
    Crewmates panel; the amendment now describes the real state (ungated API,
    flag-gated Crewmates UI).
  • Item 1 (always-on scope) is a GOVERNANCE decision, not a code defect: making
    threads reachable on every surface by default expands the accepted §07 scope.
    The amendment records the implemented scope but does not assert acceptance —
    this needs a maintainer's RFC acceptance on main or an /ai-review override on
    First Principles. Flagged as the needs-human call, not coded around.

@chenmingwei23
chenmingwei23 requested a review from a team September 29, 2026 05:01
@chenmingwei23
chenmingwei23 requested a review from a team as a code owner September 29, 2026 05:01
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

Design-level review of eecd81a10e325e3dda447b33da4a0c827aca5f19 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Threads now ship on by default on every chat surface, yet the PR's own RFC amendment says no maintainer has accepted that scope.

Watch

  • The default is unaccepted, and the flag is inverted. The amendment says: "making threads reachable on every chat surface by default … does not itself constitute acceptance of that expansion: whether the always-on default ships needs a maintainer's call." Here is how that plays out. ChatPage turns threads on with useThreads(activeSlot, { enabled: !embedded }) and no flag check, and the routes and thread_open no longer check one either. Meanwhile dashboard.crewmate_threads still gates the Crewmates panel, the one surface that was already accepted. So the switch now covers the surface that needed it least, and the wider rollout has no switch at all. Once it ships, users start writing v2 anchor indexes and thread sessions that a later rollback would leave behind.
    Clears when: a maintainer accepts the §07 scope change on the RFC or in docs/decisions/, or the new surfaces sit behind the same flag until they do.
  • Existing v1 thread replies go dark. The description says "the panel says it holds nothing it can draw yet". So anyone who had the flag on loses sight of their stored replies until the follow-up fold lands. Nothing is lost on disk, but nothing records whether the two PRs must ship in the same release.
    Clears when: the description or spec says the v1 read-only fold ships in the same release, or the v1 renderer is kept until it does.
  • I couldn't check backwards compatibility against the author's list. The description is truncated before its ## Backwards compatibility section. These are removed: POST /api/chat/threads/{mid}/reply, the chat.thread_reply WS frame, _THREAD_PREFIX, and the ThreadHooks.onOpen signature (it now accepts undefined). The in-tree readers I found are all updated, but I couldn't compare them against what the author listed.
    Clears when: the Backwards compatibility section lists those take-aways within the captured description.

[DESIGN-REVIEWED] eecd81a

Description read

[DESCRIPTION-READ] f61867c0b7c3d1f85c41abfa57cf6e9dc50b4337e977fcc5d1abb153cffa9f5e

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging 04fcc5f8bd49c162584abd227dde05b2984a2562. 2 of 2 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/dashboard/thread_projection.py:1404 -- Cursor commits before its context is delivered

cursor_seq=projection.cursor_seq,
Gateway exits after an existing thread’s cursor write but before prompt dispatch -> native resume preserves its SID -> read_thread_state and select_window skip the undelivered parent rows while the memory-only block is lost.
Anchor: residual/crash-data-loss-corruption
Fix: Persist a replayable pending projection alongside the cursor and retire it only after prompt delivery.

BLOCKING -- src/kiro_crew/dashboard/thread_projection.py:801 -- Generated summaries bypass output redaction

text = summarize(prompt).strip()
A fold response containing credentials or a token-bearing URL -> build_projection -> render_context_entry -> drain_pending_context sends that text in the thread’s ACP prompt without either redaction pass; scrubbing the summarizer’s input does not scrub its output.
Anchor: backend-security-controls
Fix: Apply redact to the assembled projection before budget truncation.

[BLOCK-MERGE] 04fcc5f
[GPT-REVIEWED] 04fcc5f

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

F1: the cursor is written at src/kiro_crew/dashboard/thread_projection.py:1404. The block it covers is queued only in the slot's in-memory pending list (src/kiro_crew/dashboard/state.py:4944, via _on_settled at thread_projection.py:1393), and it reaches the prompt only when drain_pending_context runs (src/kiro_crew/dashboard/chat_turn/turn_context.py:106). The failure needs the gateway to exit in the short gap between the cursor landing and the next prompt dispatch, and then a native resume that keeps the SID. What is lost is a summary derived from the parent log. The parent rows themselves are never touched. Nothing recovers it automatically, so a human could reasonably accept this rare-crash residual.

F2: every input the summarizer sees is already redacted (thread_projection.py:725,727) or carries only metadata like tool names, statuses and turn numbers (thread_projection.py:728-741). The fallback is those same redacted lines (thread_projection.py:803). For the output at :801 to carry a credential, the model would have to invent one that was never in its input. If a secret did slip past redact, it would already reach the prompt through the digest fallback, so this line adds no new route. The text also only goes into the same operator's own thread prompt.

[ADJUDICATION] 04fcc5f8bd49c162584abd227dde05b2984a2562 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 04fcc5f8bd49c162584abd227dde05b2984a2562

[ADJUDICATION-FENCED] 04fcc5f8bd49c162584abd227dde05b2984a2562 fenced=2 flagged=2
FLAG F1 src/kiro_crew/dashboard/thread_projection.py:1404 -- The loss needs a gateway exit in the short gap between the cursor landing (:1404) and draining the in-memory pending block (turn_context.py:106), and it loses only a regenerable summary while the parent log stays intact.
FLAG F2 src/kiro_crew/dashboard/thread_projection.py:801 -- Every summarizer input is already redacted or metadata-only (:725, :727, :728-741), so the output can only carry a secret the model invents, and anything that got past redact already reaches the prompt through the digest fallback (:803).
[GPT-ADJUDICATED-FENCED] 04fcc5f8bd49c162584abd227dde05b2984a2562

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/dashboard/thread_projection.py:1404 — The loss needs a gateway exit in the short gap between the cursor landing (:1404) and draining the in-memory pending block (turn_context.py:106), and it loses only a regenerable summary while the parent log stays intact.

    /ai-review override gpt 04fcc5f8bd49c162584abd227dde05b2984a2562: The loss needs a gateway exit in the short gap between the cursor landing (:1404) and draining the in-memory pending block (turn_context.py:106), and it loses only a regenerable summary while the parent log stays intact.
    
  • F2 src/kiro_crew/dashboard/thread_projection.py:801 — Every summarizer input is already redacted or metadata-only (:725, :727, :728-741), so the output can only carry a secret the model invents, and anything that got past redact already reaches the prompt through the digest fallback (:803).

    /ai-review override gpt 04fcc5f8bd49c162584abd227dde05b2984a2562: Every summarizer input is already redacted or metadata-only (:725, :727, :728-741), so the output can only carry a secret the model invents, and anything that got past redact already reaches the prompt through the digest fallback (:803).
    

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 04fcc5f8bd49c162584abd227dde05b2984a2562: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — 🔴 BLOCK

UX-level review of eecd81a10e325e3dda447b33da4a0c827aca5f19 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: BLOCK

A thread opened on an older answer shows the main chat's current, unrelated reply under its quote, and the blind reader had "no idea" why.

Blockers

Thread panel shows an unrelated reply as the thread's context

  • Cause: in ThreadPanel.tsx, {parentLive && (...)} shows the parent slot's latest streaming row whenever the main chat is busy. Nothing checks that the stream belongs to the anchored message. leadWithLive only reorders it.
  • What the user sees: a thread on an older answer gets a "Still being written in the main chat" box (parent_streaming) that grows with a different answer.
  • Evidence: in shots 05 and 06 the blind reader wrote: "The thread is about the older answer, but it's showing the new one -> no idea -> it confuses me." Opening a thread mid-stream is the PR's stated goal, so this is on the main path.
  • Severity: high. It happens every time someone opens or keeps a thread while the main chat is replying, which is the moment the PR exists for.
  • Fix: show the mirror only when the anchor is the user message that started the running turn (parentIsUser and that turn is the one streaming). Hide it otherwise.

Watch

  • "End thread" doesn't do what it says. After ending, the thread shows an "Ended" chip but the composer says "This thread has ended. You can still message it, and replies land here." The reader asked "what did 'End thread' actually do?" and hesitated to press it (shot 04). They'll hit this every time they end a thread. Fix: rename the action to what it really does, or turn the composer off once a thread ends.
  • Old threads look lost. The footer promises "2 replies", then the panel says "These replies can't be shown yet." with a "Start a new thread here" button. The reader would not dare press it, fearing it "hides or replaces the 2 replies" (shot 24). Fix: add that the existing replies stay saved, next to the button.
  • Two actions sound the same. "Reply in thread" and "Fork conversation from here" sit next to each other in one menu, and the reader "can't tell them apart" (shots 01 and 02). "Reply in thread" also appears twice in one spot: as a link above the answer and in the menu.
  • The thread panel covers the main chat. Below the 1100px breakpoint the panel sits on top of the chat and cuts off its text; the reader said "it looks broken" (shot 10).

Suggestions

  • thread.closed_composer: say what ending changed (for example, that it stops showing the open-thread marker in the main chat) instead of only saying it is still usable.
  • The legacy panel: replace "These replies can't be shown yet." with "2 earlier replies are saved but can't be shown here yet."

[UX-REVIEWED] eecd81a

Description read

[DESCRIPTION-READ] 74422ab1faebce2b106b05add1991fb3e165114ebfce13326ea09ccbca5ea033

That sha256 names everything this verdict read: the PR description, plus the 36 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 Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of 04fcc5f8bd49c162584abd227dde05b2984a2562 — 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/CONCERNS are advisory.

First-Principles-Verdict: BLOCK

product-shape change without accepted RFC: threads are now on by default on every /chat, with no flag, and the diff's own amendment says that scope is "GOVERNANCE — OPEN".

Not justified as shipped

  • Item 1 — product shape: useThreads(activeSlot || undefined, { enabled: !embedded, … }) turns threads on for ordinary chat by default. The base §07 of rfc-crewmates-launch.md (accepted) covers threads on Crewmates only, and the amendment admits this "does not itself constitute acceptance of that expansion".
  • Item 6 — oversized: End thread plus a summary card posted into the parent (close_thread, _post_close_card, _emit_thread_closed). The Goal only asks to "keep talking in" a thread and open it mid-stream.
    Subtraction: defer close_thread, api_chat_thread_close, ThreadClosedCard and the close crew-log entry to their own PR.
    Clears when: the close path is removed, or a human amends the Goal.
  • Item 8 — rides along: stored version 1 threads can no longer be drawn; the panel says it "cannot draw it yet".

What this change ships

Inventory (9 items) — 6 justified

Intent: let a person keep talking in a thread on any message, and open one while the reply is still streaming. ADDITION.

  1. "Reply in thread" on ordinary /chat, on by default — product shape (no recorded decision)
  2. A thread is a full session: tools, approvals, memory — justified
  3. A thread can be opened on a reply that is still streaming — justified
  4. A second message mid-reply is queued instead of refused with a 409 — justified
  5. New MCP tool thread_open for agents — justified
  6. End thread control and a summary card posted back in the parent — oversized
  7. New core MCP tool thread_context_read — justified
  8. Stored version 1 threads are no longer drawn — rides along
  9. Deep links ?thread=<mid> and a thread opened as a full tab — justified

Blockers

  • product-shape change without accepted RFC: threads on by default on every chat surface. The amendment to rfc-crewmates-launch.md that this diff adds is a proposal, so it reads as draft. The base list carries only §07, which is Crewmates-scoped and flag-gated.
    Clears when: an RFC covering threads on every chat surface by default is merged non-draft on the base, followed by a push or rebase; or a maintainer posts /ai-review override first-principles 04fcc5f8bd49c162584abd227dde05b2984a2562: <decision>.

[FIRST-PRINCIPLES-REVIEWED] 04fcc5f

Description read

[DESCRIPTION-READ] f766cc65d78426f41ddddc252bdc01d6993c4a660fdcd9a2aff4c01ffc69bde6

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.

@chenmingwei23
chenmingwei23 force-pushed the feat/crew-bot-threads-epic branch from 5da7ac7 to ed90f94 Compare September 29, 2026 05:10
@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 Sep 29, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/crew-bot-threads-epic branch from ed90f94 to ffa9a79 Compare September 29, 2026 06:01
@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 Sep 29, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/crew-bot-threads-epic branch from ffa9a79 to 4da0a68 Compare September 29, 2026 06:25
@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 Sep 29, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/crew-bot-threads-epic branch 2 times, most recently from 6e7e659 to 9179dcc Compare September 29, 2026 06:48
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: new route POST /api/chat/threads/{mid}/close registered in dashboard/routes/chat.py; two tests cover the 200 and the 404.

  • span=48ae40af66be fixed -- the close half has a production entry point.

The finding is right that nothing could reach it. The subtraction it offered is
the one thing I did not take: close is required by the design (the thread's
result returns to the parent as a summary card with a back-link) and by the
Trading Desk convention this change unifies with, and the whole lifecycle was
implemented and tested. The defect was the missing entry point, so I registered
the route the feature map already advertised: POST /api/chat/threads/{mid}/close
in src/kiro_crew/dashboard/routes/chat.py, handled by api_chat_thread_close
in chat_threads.py. The feature-map row now names a route that answers.

useThreads.close() shutting the drawer stays correct and separate: closing the
drawer is a view action, ending the thread is a lifecycle action, and one must
not silently do the other.

Head 9179dcc574.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: open_thread takes in_flight: bool; the open route passes raw_mid == "inflight"; two tests pin true and false on the emitted entry.

  • span=299056bbfdfd fixed -- the open route threads its resolution into the entry.

Confirmed by reading: anchor_row is built without the key, and the row it is
written through projects to a fixed field set (_thread_anchor_row in
history.py), so no value put there could survive anyway. Reading the flag off
that row was wrong in kind, not merely unset.

The fix passes it as a parameter instead. open_thread takes in_flight: bool,
the open route supplies raw_mid == "inflight" (the one place that knows, since
by the time the anchor reaches open_thread it is an ordinary mid either way),
and _emit_thread_opened sends that value. Two tests pin it:
test_an_inflight_open_records_in_flight_true_on_its_ledger_entry and
test_an_open_on_a_real_mid_records_in_flight_false -- a flag true for every
open says as little as one that is never true.

The docstring records why the index cannot carry the answer, so a later reader
does not retry the same shape. Entries written before this head stay ambiguous;
the crew log is append-only and that cannot be repaired, which is the cost of
the defect rather than of the fix.

Head 9179dcc574.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: new route POST /api/chat/threads/{mid}/close in dashboard/routes/chat.py, with tests for the 200 and the 404.

  • span=03c4df445bf7 fixed -- a production caller of close_thread is counted.

The item names two ways to clear, and I took the second. Close is not future
surface: the design makes the thread's result return to the parent as a summary
card with a back-link, which is the paradigm this change unifies with, and the
lifecycle was already written and tested. What was missing was the entry point
the feature map claimed, so I registered it rather than deleting a required half
of the feature.

POST /api/chat/threads/{mid}/close -> api_chat_thread_close -> close_thread.
The feature-map row is now true instead of aspirational.

Head 9179dcc574.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: deleted src/kiro_crew/messaging/thread_adapter.py and its tests; ThreadAnchor, record_anchor, anchor_for and SURFACE_DASHBOARD stay.

  • span=0265f06f70da fixed -- the adapter seam is deleted.

Accepted as written. I checked the counts myself before acting: one registrant,
zero production lookups. A seam with a single implementation and no caller is a
guess about channels this change excludes, and the ## Not a goal section says
so in the PR body, so keeping it would have contradicted the description.

Deleted: the ThreadAdapter Protocol, the registry, thread_adapter_for, and
the five uncalled methods. Kept exactly what the item said to keep, because Slack
dispatch uses record_anchor and anchor_for directly and ThreadAnchor is the
neutral anchor type both surfaces share.

When a second channel lands it will need a seam. It will be built against two
real callers instead of one imagined one, which is the cheaper order.

Head 9179dcc574.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: deleted website/kc-shot-threads/ and its ignore line; the five captured screenshots stay attached to the PR body as the evidence.

  • span=25f20c7f22d1 fixed -- the committed harness is deleted.

Accepted. It imported live internals, nothing imported or ran it, and no CI job
would have caught it rotting. I had kept it after finding website/capture and
website/temp-screenshots tracked on main, but precedent for a tracked rig is
not a consumer for this one, and the item is about this directory.

The screenshots it produced are attached to the PR body and remain the manual
verification. Rebuilding the rig is a few hundred lines whenever the next round
of captures is worth taking, which is cheaper than carrying it untested between
rounds.

Head 9179dcc574.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=2f6082500a24

FIXED. The row was accurate when written and stopped being accurate in this same PR: the seed mechanism it described (build_seed, _deliver_seed) was deleted from this branch in favour of the first-turn projection, and the feature-map sentence was not rewritten with it. open_thread injects nothing at open and _deliver_note returns False for an empty note, so a bare dashboard click does open an empty thread, exactly as the finding says.

The row now states the mechanism the code has: a thread opened by a bare click starts EMPTY, nothing is injected at open, and its first turn is given a bounded SUMMARY of the parent conversation -- anchor quote included -- with thread_context_read for the exact wording. An opener carrying a note delivers that note as the thread's first message, which is the one case where anything is delivered at open. The streaming clause is kept and corrected: opening on a reply still being written anchors to the user message that started the turn, and the PROJECTION carries the partial text, not a seed.

Verified against the diff rather than restated: chat_threads.py has no seed builder left, and thread_projection.build_projection is what renders the anchor band and the parent summary.

@chenmingwei23

chenmingwei23 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

span=741fde857d5c

FIXED, not overridden. The fence's own clearance path is a human override and the annotate-only pass pre-drafted one, but the finding names a real invariant the controller was not enforcing, and enforcing it is six lines -- so there is nothing here worth spending an override on.

I verified the adjudicator's reachability analysis independently and it holds: a chat-page session switch rewrites the URL and deletes thread, whose empty value drives threads.close(); the Crewmates host clears on confirmedSlot; every other surface passes embedded, so threads are off and the drawer is not rendered; and a mint in flight is already discarded by the slot half of live() and of stillMine(). The named sequence is not reachable today.

What it does expose is that the invariant lives in the HOSTS. Every piece of state the controller holds -- open, opening, openError, ending, endError -- belongs to one parent slot, and the controller relied on each host remembering to clear it. A host that forgets, or a new host that never knew, leaves a drawer open over the wrong conversation. useThreads now drops all of it when its own slot changes, and bumps openSeqRef so a mint in flight is invalidated by the sequence guard as well as by the slot check.

During render rather than in an effect, which is the part that matters: an effect would let one frame paint the previous parent's drawer over the new one. React re-renders on a render-phase adjustment without committing, and each setter bails out when its value is already correct, so a render where the slot did not move costs nothing -- pinned by a test.

Four tests in website/src/pages/chat/useThreads.test.ts: an open thread is dropped on the switch; a failed open and a failed end are dropped with it so the next parent starts clean; a mint still in flight across the switch installs nothing; and a render where the slot did not move leaves the open thread alone.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=d2196525dad2

FIXED. Upheld and correct, and the adjudicator named the precedent: this is the same persist-before-you-publish hazard as the cursor entry, in the same file, one write earlier. A thread's parent edge lives in session/opened.parent.slot; the emitter hands that append to a buffered writer and returns; project_for_turn reads it back off disk a few hundred lines later in the same turn. On a FIRST turn the read can beat the write, read_thread_state answers with no parent, and the projector reads that as "not a thread" -- so the first reply carries no account of the conversation it was opened on, with no log line saying so, and recovery is a turn late because no cursor is recorded either.

on_session_opened now takes the after hook _submit already supports and passes it through, and _run_chat waits on it before projecting, bounded by LINEAGE_SETTLE_TIMEOUT_S (2s). Two seconds rather than the cursor's five because this wait sits BEFORE any work is done, and the writer's own batch deadline is milliseconds: a wait that long already means the writer is wedged, and the next turn's delta is then the honest recovery rather than a longer stall.

Both of the emitter's early returns call after -- no session id, and the crew log off. That is what makes waiting safe: without it every such turn would wait out the full bound for an entry that was never going to be written. It suspends only that turn; the loop keeps serving everything else, which is the emitter's own never-block-the-loop rule.

Three tests in test/test_thread_projection.py: the hook fires with the log off and with an empty session id; the lineage bound is strictly under the cursor bound and positive; and an unwritten edge does read as no-parent down in read_thread_state, which is why the ordering has to be fixed at the writer rather than guessed at in the projector.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=da0ca1eea756

FIXED to toBe. Upheld and right: against a mock call count, which cannot decrease, toBeGreaterThanOrEqual(configReadsBefore) asserts nothing at all, and it would pass just as happily if an unintended refetch were reintroduced. That is the a-ratchet-may-only-tighten rule's own named case, and this diff is what relaxed it.

Why it was relaxed, and why toBe is the right strictness rather than restoring toBeGreaterThan: this branch removes the reply-threads flag hook, which was the only live observer on ['kirocrewConfig'] on that page. With no observer, React Query marks the entry stale but never refetches it, so toBeGreaterThan became false -- the count genuinely does not move. The assertion that carries the meaning is the line above it, isInvalidated is true, which is what the pencil deep link actually depends on: the crew manager refetches when IT mounts.

So toBe(configReadsBefore) now pins the exact consequence -- no refetch happened here -- instead of a comparison that no longer discriminates. 226 tests in MembersPage.test.tsx pass with it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

span=d2196525dad2

Both findings on this span, one FIXED and one answered as adjudicated.

F2 (chat_threads.py:925, sidecar title bypasses output-boundary redaction) -- FIXED, and it was a real credential-display path. The row BODY redacted and bounded the title one line above while meta.thread_summary.title stored the caller's string raw, and the card a reader actually sees is rendered from that metadata, not from the body -- so a title carrying a credential would have been displayed in ThreadClosedCard with the redacted copy sitting unused beside it. Write-time redaction narrows it but does not close it, and this file already treats re-redaction of this field at the output boundary as mandatory.

The fix is the one the finding names: compute redact(title)[:THREAD_ANCHOR_TITLE_MAX_CHARS] ONCE and use it for both the body and the metadata. That is also the only shape in which the two copies cannot drift -- there is now one string, not two derivations of one input. A test in test/test_chat_threads.py passes a ghp_-shaped secret plus 400 characters of padding as the title and asserts the stored metadata carries no secret, carries the redaction marker, respects the cap, and is byte-identical to what the body shows.

F1 (chat_threads.py:921, close cards publish before their transcript row is durable) -- NOT FIXED, and the adjudicator downgraded it as a disproportionate remedy on its own reading, which matches mine. _ChatSlot.append publishes every dashboard row before it is durable: it marks the slot dirty and queues the row while the chat_message goes out in the same call, and persistence is the shared five-second loop whose stated contract is that a crash loses at most one interval. Making the close card await its own flush would give one decorative row a durability guarantee no other row in the transcript has.

What matters is that the close itself is already durable first and deliberately so: the anchor transition is written before the card, closed_at and the title live on the anchor, and the closed-state UI reads them rather than the card. So a crash inside that window loses a row that renders nothing rather than leaving a dangling link -- the card renders off its own meta, so an absent row yields no card at all.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=d2196525dad2 -- chat_threads.py close-card save and publish order

FIXED (F2, the upheld one). save_slot_off_loop at the close-card flush now
carries expected_history_key=parent_key. The adjudication's reading is the
one I acted on: parent_key is read before the anchor load and three awaits
follow it, one a locked on-disk read, so the rebinding window is wide rather
than microscopic, and the upstream app refusal runs before that window and
cannot see a link installed inside it. Pinned, the save refuses instead of
resolving routing at write time, and this caller already reads a False
return as 'the row did not land' and leaves the pointer unstored. The
existing ordering test now asserts the pin alongside best_effort=False.

F1 on the same span (close cards publish before their transcript row
commits) was DOWNGRADED by adjudication as a disproportionate remedy, and I
agree with its reasoning: the close itself is already durable before the card
is minted, a failed save deliberately leaves the pointer unstored, _dirty
survives so the periodic pass re-serializes the window, and the only loss is
the cosmetic back-link row. Staged-persist would mean pre-minting the mid and
the window-floored ts outside append and a new ordering contract across
three modules serving exactly one row.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=9e04646dc82a -- Item 7, zero consumers: ThreadHandle.parent_turn_id

FIXED by subtraction, as the finding asked. The field is deleted from
ThreadHandle and from to_dict. The count was right: one production
constructor, which omitted it, and one test that passed it. The claim in
history.md that the handle carries a parent turn id is corrected to name
parent log seq, which is the address the handle actually carries and the
one thread_context_read resolves rows by.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=43ae845a0955 -- Item 10, one consumer generalized: ThreadAnchor.surface

DISAGREE, on a base document rather than on intent. surface is not a guess
about a second surface; it is the address shape an accepted-in-progress RFC on
the base branch already specifies. docs/request-for-change/rfc-session-address-model.md
(status: partial, on main) states that the generalized
(surface, conversation_id, thread_id) index 'becomes the only way any
transport can recover an existing conversation'. Dropping the discriminator
here would put this code out of step with that RFC, which is the objection
this lane raises about the other spans on this PR.

On the reader: the check in open_thread is a fail-closed guard on a SHARED
entry point. open_thread serves both POST /api/chat/threads/{mid}/open and
MCP thread_open, so it is the one place a non-dashboard anchor can arrive,
and refusing there with surface_unsupported is what keeps a second surface
from being silently mis-served before its recorder exists.

I did apply this lane's subtraction reasoning where it held: ThreadAnchor.from_dict
and the two id regexes went when the Slack slice moved out, and Item 7's
parent_turn_id is deleted in this revision. This field differs by having a
reader and a base RFC naming it.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=a5926f7863a1 -- Item 1, flag removal without an accepted RFC

ACCEPTED as accurate, and not fixable inside this PR. The finding's own
clearing condition is a two-PR sequence: the section 07 amendment merged
non-draft to the base first, this branch second. That sequence was considered
and declined by the maintainer, so the amendment travels IN this PR instead,
where a reviewer reads it beside the change it licenses.

This is therefore a maintainer decision, not a code defect, and it is recorded
as one: a /ai-review override first-principles is posted on the settled head
once this lane is the sole remaining blocker.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=a879bf9cfe8c -- threads' default mode and scope vs base section 07

ACCEPTED as accurate on the base text, same disposition as span=a5926f7863a1
and the same single cause. Base section 07 decides the bubble, panel and
composer shape; the sentence licensing threads on every chat surface with the
flag removed is the amendment, and the amendment is in this PR rather than
merged ahead of it because the maintainer declined the two-PR sequence.

Recorded by override on the settled head, for the same reason: the objection
is about merge ORDER, which no change to this branch's code can satisfy.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=60a91f75e64b -- Item 2, threads on every surface without an accepted RFC

ACCEPTED as accurate on the base text, and not fixable inside this PR. The
finding's own clearing condition is a two-PR sequence: the section 07 amendment
merged non-draft to the base first, this branch second. That sequence was put to
the maintainer and declined, so the amendment travels IN this PR, where a reviewer
reads it beside the change it licenses.

This is a maintainer decision about merge ORDER, not a code defect, and no change
to this branch can satisfy it. Recorded by /ai-review override first-principles
on this head, which is the remedy the lane's own Blockers section names.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=18b6d224ab7c -- Item 3, the dashboard.crewmate_threads flag removed on the same amendment

ACCEPTED as accurate, same single cause as span=60a91f75e64b and the same
disposition. The flag's removal is licensed by the same section 07 amendment, so it
cannot clear separately from item 2: either the amendment is read in this PR or the
two-PR sequence runs, and the maintainer chose the first.

Worth stating plainly because the lane counts it as a removal: the flag shipped
false by default, so nothing that was on for a user turns off. Recorded by the
same override.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=276d11b68360 -- Item 9, the description claims a fold the diff does not ship

FIXED, and the finding was right. The legacy read-only fold was cut from this PR
for the review diff cap after the description was written, and two sentences were
left asserting the old behaviour. Both are corrected on this head.

"Not a goal" now reads that the version 1 files are read in place and never
rewritten, that drawing their replies is not a goal here, and that the fold ships
in a follow-up. "What changed" now states the cut explicitly: the anchor index
still reports kind: "legacy" with its count and last reply time, so the parent's
footer names such a thread, and the panel says it cannot draw it yet rather than
rendering an empty thread. Nothing on disk is migrated, moved or deleted.

The capability is deferred, not silently removed, and the description now says so.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=99cf1e8ad3bf -- Item 10, one consumer generalized: ThreadAnchor.surface

DISAGREE, on a base document rather than on intent. surface is not a guess about a
second surface; it is the address shape an accepted-in-progress RFC on the base
branch already specifies. docs/request-for-change/rfc-session-address-model.md
(status: partial, on main) states that the generalized
(surface, conversation_id, thread_id) index "becomes the only way any transport
can recover an existing conversation". Deleting the discriminator here would put
this code out of step with a base RFC, which is the objection this lane raises about
the other spans on this PR.

On the reader: the check is a fail-closed guard on a SHARED entry point.
open_thread serves both the HTTP opener and MCP thread_open, so the guard is
what makes an anchor from an unsupported surface a surface_unsupported refusal
instead of a dashboard thread. Dropping the field turns that refusal into an
assumption.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=4fa546450a23 -- Blocker: product-shape change without an accepted RFC (items 2, 3, 9)

SPLIT, because this blocker bundles two different causes and they end differently.

Items 2 and 3 are the sequencing objection: ACCEPTED as accurate and recorded by
/ai-review override first-principles on this head, which is the remedy this
blocker's own "Clears when" names. The maintainer declined the two-PR sequence, so
the amendment is read in this PR.

The part of this blocker that rests on item 9 is FIXED rather than overridden: the
description now declares the fold's deferral instead of claiming the fold ships. See
span=276d11b68360 and span=5dfc42eefa4b.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author
  • span=5dfc42eefa4b -- Blocker: framing contradicted by the diff (item 9)

FIXED by the second of the two clearing conditions this blocker itself offers: a
human corrected the frozen description to declare the removal.

The description now states that the version 1 read-only fold is cut from this PR for
the review diff cap and ships in a follow-up, that the sidecar files are untouched on
disk, that the anchor index still reports kind: "legacy" with its count and last
reply time so the parent's footer names such a thread, and that the panel says it
cannot draw the replies yet and offers a real thread. The capability is deferred with
the deferral named, which is what the lane asked for.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

If this PR's board carries Backend Tests (Windows) (2) red on test_native_skill_projection.py's two alias-lock tests, that red is inherited from main (it arrived with #15150, which merged with the same lane red) and is not this PR's.

Root cause and the fix are on #15651 (comment 5923360639): the orphan alias-lock sweep unlinks while still holding its own descriptor open, and Windows refuses to delete a file with an open handle. #15280 carries the fix -- a Windows-only reordering in _unlink_unheld_lock_file plus a POSIX-runnable pin -- so once that lands a rebase clears the lane. The hunk is on the issue if it is needed sooner.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles 90e5499: Product decision by the owner: a reply thread is a full chat session, on by default on the chat surface, replacing the bounded section 07 reply panel. The RFC amendment in this diff is the record of that decision, not a draft proposal. The crewmate page keeps its flag-gated panel until the stacked follow-up #15410 moves it onto the same controller.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for 90e5499a6226a8923844b3af22df90566e940d4c.

Product decision by the owner: a reply thread is a full chat session, on by default on the chat surface, replacing the bounded section 07 reply panel. The RFC amendment in this diff is the record of that decision, not a draft proposal. The crewmate page keeps its flag-gated panel until the stacked follow-up #15410 moves it onto the same controller.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security_posture.py

  • No approval on 04fcc5f yet.

A human reviewer with write access must approve the CURRENT head and
paste this template into the approval, every field filled
(N/A needs a reason):

## Sensitive change review
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 8e577119c2 (rebased from 547c7e565b).

GPT 6.1 — both security-class findings FIXED in src/kiro_crew/dashboard/thread_projection.py (no override; a reachable finding is fixed, not waved):

  • F1 (:863, trimmed fallback commits a cursor past undelivered rows) — a final trim now holds the cursor at window.start - 1 on every trim, incomplete folds included, so a trim that cut a summary can never retire the row it summarized. Pinned by test_a_stopped_fold_leaves_the_skipped_rows_for_the_next_turn (now asserts the held-back cursor).
  • F2 (:1136, a replacement parent log inherits the previous log's cursor) — each projection now records cursor_source_sid (the parent crew-log the cursor counts against); the next turn resets to first-turn geometry when the resolved parent log differs, so a reset parent's rows 1..N are read, not skipped. New field declared on thread/context_projected; decision carried by effective_cursor_for_log with test_a_cursor_from_a_different_parent_log_resets_to_first_turn.

First Principles — BLOCK, split:

  • Item 2 (framing contradiction) FIXED in code. The RFC amendment (docs/request-for-change/rfc-crewmates-launch.md) and the MembersPage.tsx comment no longer claim dashboard.crewmate_threads is "removed" or that the thread routes 404 when it is off. The flag is kept and still gates the Crewmates page's own panel; the amendment now states the real shape — ungated backend/MCP, flag-gated Crewmates UI — so the flag reads the same in the RFC, the feature map and the code.
  • Item 1 (always-on scope) is a governance decision for a human, not a code defect. Making threads reachable on every surface by default expands the accepted §07 scope. The amendment records the implemented scope but does not assert acceptance of the expansion; shipping the always-on default needs a maintainer's RFC acceptance on main or an /ai-review override first-principles on this head. I have not coded around it.

UX/Design reviews are advisory (CONCERNS); their flag-consistency point is covered by the Item 2 fix above.

A reply thread on a crewmate's chat was a bounded reply list: replies in a
sidecar, every reply in a throwaway `thread:<slot>:<mid>` session that could
never resume, a forced read-only tool posture, no memory, the whole envelope
re-seeded each turn, and a one-reply-in-flight lock. It lived only on the
Crewmates page, only behind the `dashboard.crewmate_threads` flag, and only on
a message whose turn had already finished.

A thread is now an ordinary chat session plus an anchor to one message.

Anchor is (surface, conversation, message id): (dashboard, parent slot, mid) and
(slack, channel id, thread_ts). It is stored on the thread session's own metadata
and in a per-parent index -- the old reply sidecar, at version 2. Version 1 files
are read in place and render as a read-only fold, because their replies came from
a cold read-only session with no memory and replaying them as a full session's
transcript would assert a history that session never had.

Opening never touches the running turn: no semaphore, no `_handle_busy` branch,
no `messaging.queue_mode` value. It reads a non-consuming snapshot of the parent's
partial text, so every messaging invariant holds. A streaming row has no mid, so
the anchor resolves to the user message that started the turn, which is already
persisted.

Two openers, one coroutine: `POST /api/chat/threads/{mid}/open` for a person
clicking a message, and MCP `thread_open` for an agent opening one on the message
it is answering. `open_thread` calls `create_session` directly and lets its
refusals through verbatim rather than adding a bypass.

Slack already keyed one session per thread_ts and never recorded it; that session
is now recorded as anchored, with nothing re-keyed and the 1:1 DM fold and the
dashboard mirror binding untouched.

`thread/opened` and `thread/closed` join `session/opened` in the crew log, so the
ledger is the existing one. `dashboard.crewmate_threads` is removed, not defaulted
on. Retired with it: `thread_session_key`, the `thread:` stateless prefix,
`_run_thread_turn`, `build_thread_message` and its envelope constants, the
read-only spec posture, the per-reply byte caps, and `409 not_crewmate_chat`.

Specs updated alongside: history.md (new Surfaces section), session.md,
slack-gateway.md, crew-mode.md, docs/feature-map/README.md.
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

GPT 6.1 F1 (chat_threads.py:1542, cross-audience parent read) is fixed in code on head 04fcc5f8bd, not overridden. Both the exact thread_context_read route and the automatic project_for_turn injection now apply the owner-DM / mirrored-caller gate (session_control.judge_owner_dm) before any parent read: a thread that reaches a channel audience and is not the owner's own DM is refused the parent's private rows (fail-closed), and an admitted thread records its audience admission from the same verdict. New tests in test_thread_projection.py pin the four branches.

Also addressed this head:

  • Opus thread_projection.py fold-trim and sessions.py:256 false "stopped at budget" message; config/sections.py flag help corrected to match the shipped (flag-gated-Crewmates-only) behaviour.
  • UX BLOCK (ThreadPanel.tsx showing an unrelated running reply on an older-answer thread): the parent-live mirror is now gated on parentIsUser, so an assistant-anchored thread shows no stream.
  • Frontend Tests ChatInput.lexicalUndo is a lazy-chunk timing flake in main's own code (my diff is a label-only inThread prop); verified 3/3 green in the real merge-ref tree.

First Principles Item 1 (threads always-on, governance) and the Sensitive Change approval remain with the maintainer — not overridden.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Closing this after an audit.

As written, this makes reply threads always on at the API for every user. On main the thread feature deliberately sits behind the crewmate_threads flag (default off), and there's no on-repo request or accepted design RFC for turning it on globally. Flipping a gated, default-off feature to always-on for everyone is a default-behaviour change that needs a design discussion first.

The branch (feat/crew-bot-threads-epic) is kept for a future, smaller proposal — ideally one that keeps the work behind the existing flag and lands incrementally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant