Repository navigation
feat: reply threads on crewmate chat messages (api) - #12797
Conversation
|
Intent: Let the user discuss one message of a crewmate's chat in its own reply thread, stored beside the chat and answered by the crewmate, without anything landing in the main chat. |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Export and transfer silently strand primary, non-regenerable user data — thread replies stay behind with no user-visible warning. WatchThe spec itself says replies "are primary data that cannot regenerate," yet "a fork, a transfer and an export copy the transcript and leave the sidecar behind." Cause: sidecar excluded from the copy paths → mechanism: a user transfers or exports a chat believing it complete → consequence: their thread discussions vanish with nothing telling them, discovered only after the original is gone. Disclosure to reviewers ("recorded decision") is not disclosure to the user. Suggestions
[DESIGN-REVIEWED] 4744ba7 |
UX Review (Fable 5) — ✅ PASSUX-level review of UX-Verdict: PASS Backend-only: verify frontend PR #12815 supplies the screenshots and blind read for these thread strings — nothing in this diff renders. [UX-REVIEWED] 4744ba7 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Frontend PR #12815 is the sole consumer of the three routes and What this change shipsInventory (10 items) — 10 justifiedIntent: let a user discuss one message of a crewmate's chat in its own reply thread, Slack-style (backend half of RFC screen 07) — ADDITION, covered by
[FIRST-PRINCIPLES-REVIEWED] 4744ba7 |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsNothing blocks; one advisory finding on the re-send envelope. FINDING — src/kiro_crew/dashboard/chat_threads.py:337 — [OPUS-REVIEWED] 4744ba7 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
bed2558 to
d4e834a
Compare
|
|
|
|
|
|
|
GPT 5.6 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 5.6 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/history.py:2009 -- The per-thread cap leaves the sidecar globally unbounded Adjudication (Opus 4.8) — is blocking on each finding proportionate?F1 — HARM: LOW. Each sidecar map entry requires a real transcript message — [ADJUDICATION] d4e834a total=1 uphold=0 downgrade=1 False positive or not applicable? A repository writer can comment: |
d4e834a to
59aabde
Compare
a10eddd to
32484ff
Compare
32484ff to
0777a84
Compare
0777a84 to
7815783
Compare
GPT 5.6 Review —
|
GPT 5.6 Review —
|
GPT 5.6 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 5.6 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/dashboard/chat_threads.py:633 -- Row-only reservation ignores the sidecar byte ceiling (origin: validation) Adjudication (Opus 4.8) — is blocking on each finding proportionate?I've examined the code path. F1 concerns Evidence record (F1): (a) Conditions:
(b) Recovery: (c) Harm rung: LOW. The required condition is a single chat's reply-thread sidecar within ~64KB of a 64 MiB ceiling — the extreme boundary of a per-chat cap. The consequence is the loss of one generated assistant answer (not user-entered data), with a visible error at the time; the user's question is preserved. Near any hard byte ceiling the last admitted turn loses its answer regardless — the proposed fix merely moves the refusal from the assistant row to user-reply admission. The remedy (reserve byte headroom, thread a new byte-reservation parameter through False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — 🔴 changes requested (blocking)GPT 5.6 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/history_projection.py:1282 -- Linked |
GPT 5.6 Review —
|
GPT 5.6 Review — 🔴 changes requested (blocking)GPT 5.6 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/session_storage.py:1444 -- Directory swap strands restored thread data |
GPT 5.6 Review —
|
A thread is the set of replies attached to one message of a crewmate's chat, addressed by that message's durable meta.mid. Replies live in a sidecar beside the slot's transcript (.threads/<key>.json) and never enter slot.messages, so the main chat keeps showing only what the crewmate says to the user. Three routes: a per-slot summary (reply counts, last reply, who took part) for the footer under a bubble, one thread's parent + replies, and a reply POST that stores the user's reply, answers 202 and runs the crewmate's turn in an isolated thread:<slot>:<mid> session. The turn carries the parent, the chat just before it and the thread so far, runs under the side chat's read-only tool posture (no approval card in a thread panel), and lands its answer in the thread over an owner-only chat.thread_reply WS event.
Problem / Motivation
A crewmate's chat is one flat list. When the user wants to ask about ONE thing the crewmate said ("what about the other 8?"), the question and its answers land in the main chat, between everything else. There is no way to discuss one message on its own, the way a Slack thread does.
Implements the accepted RFC:
docs/request-for-change/rfc-crewmates-launch.md(screen 07, reply threads).The CrewMates launch review decided screen 07: any bubble, yours or the crewmate's, can carry a reply thread that opens in the right side panel while the main chat stays visible. This PR is the backend half. The panel and the footer under a bubble come in a frontend PR on top of it.
Why it matters
Without threads, every follow-up question pushes the crewmate's real findings up and out of view. The main chat is meant to show only what the crewmate says to you; side questions do not belong in it.
What changed (motivation → approach → change)
dashboard/chat_threads.py.threads/<key>.jsonsidecarchat.thread_replyWS eventthread:<slot>:<mid>sessionA thread is the replies on one message of a crewmate's chat, addressed by its durable
meta.mid. Replies live in a sidecar beside the transcript (ConversationLog.read_threads/append_thread_reply,history.py): the write runs under the lock, refuses a transcript that is gone or replaced under the same key (created_atcaptured at admission) and a parent row not yet on disk; a damaged sidecar is refused, never overwritten; a row is read back as the four reply fields only, held to the writer's shape and bounds (opened once, no link followed, 64 MiB ceiling the writer also stops at;id/role/tsand them-+16-hex key in the writer's formats or the row is dropped; 64 KiB content, 500 rows per thread, 5 000 per file),history_projection.pydeletes it with the transcript all-or-nothing (moved aside under a fresh name, never over a leftover);session_storage.pysizes, moves, restores and purges it with the transcript (a sidecar it cannot stat, or a linked.threads, stops the scan and the delete; the age scan judges each sidecar alone, an unstat-able one reads as fresh; restore publishes and rolls it back under the transcript's lock and refuses a sidecar whose chat was recreated; a linked.threadsleaves the batch staged). Writer,delete_sessionand restore refuse a linked.threadsand work on its pinned descriptor; the publish links the staged leaf itself, never a link's target. Nothing entersslot.messages.Three routes in
routes/chat.py:GET /api/chat/threads?slot=gives reply counts per message;GET /api/chat/threads/{mid}the parent and its replies;POST /api/chat/threads/{mid}/replystores the reply, answers 202 and runs the crewmate's turn; a clientreply_idmakes it idempotent: a re-send after a lost response gets the stored row back, not a second (its turn re-runs if it sits unanswered, or behind only the "send it again" row). The turn is the side chat's shape without its steer/queue ledger: the slot's agent, an isolatedthread:<slot>:<mid>session destroyed per reply (session.py,sel.py,messaging/link.py), an envelope with the parent, six messages of context and the thread so far (newest 40 replies plus a count; crewmate rows redacted before the cut), and the read-only posture. The answer is redacted, clipped at 64 000 characters, stored as anassistantreply (a user reply is admitted one seat below each cap) and streamed byws.py;ws_event_scope.pyandwebsite/src/app-sdk/index.tslist the event as slot-scoped;security_posture.pythe redaction sink. One reply at a time per thread: reserved before any await, released in onefinally. The store write is shielded from cancellation; a committed reply gets a "not answered" row. Every failure sends a plain final frame; a crewmate that no longer resolves gets no substitute answer (the main chat's rule); a refused read-only spec is audited as a denied SEL access; a turn cancelled mid-stream keeps the partial answer under an interruption marker unless the final write committed; both notices say "Kiro Crew stopped". Threads do not travel with a fork, transfer or export (recorded decision).The frontend half is #12815.
Spec:
docs/system-specs/modules/history.md; athread:note insession.md.Backwards compatibility
Compatible: only new routes, a new sidecar file, a new WS event and a new session-key prefix. No existing route, file or event changes shape.
Tests
test/test_chat_threads.py: the summary shape; the sidecar lives beside the transcript and goes with it on delete; the store refuses to write beside a missing transcript or into a replacement chat; a delete takes the sidecar with the transcript or neither; a parent only disk holds is found; a damaged sidecar is refused and never overwritten, a row is read back as the four reply fields and nothing else, a row whose id, role, ts or key is not the writer's shape is dropped, content and counts are bounded at the read, an oversized or linked sidecar is refused on its descriptor and the writer refuses past the same ceiling, and every route answers 503 on it; slot/mid validation and the 400/404/409/413 codes (a lone surrogate in the text is a 400, not a 500); a user reply is refused when only the answer's seat is left; app callers get the anti-enumeration 404; a reply is stored, broadcast on the thread channel only and starts the turn with the parent and the chat before it; a second reply during a turn is refused; a re-sent reply id returns the stored reply (running the turn again only when it sits unanswered, or behind the not-answered row, with none active), a malformed one is a 400; a linked.threadsor a sidecar that cannot be stat'ed refuses the delete, a leftover staged sidecar is never written over, and a failed staging closes its descriptor; a credential straddling the envelope's line cap is scrubbed, not cut; a nested-past-depth document is unreadable, not a 500; a link swapped in under the restore lock is refused, a planted link is never published as its target, a sidecar alone is not restored onto a recreated chat, one vanished sidecar costs no other session its freshness; a map of empty keys retains nothing; two replies racing through the store write run one turn; a full thread, a full sidecar, a chat before its first flush, a chat replaced between the parent lookup and the store write, a parent not yet flushed, and a store error no outcome names (OSError, answered 503) are refused and release the reservation; a handler cancelled mid-write drains the commit and writes the not-answered row; a caller with no identity is held to the parent's mid; the envelope, and a long thread travels as its tail plus a count; a sidecar that cannot be stat'ed stops the reclaim scan while an absent one is skipped; a linked.threadsdirectory gets no write and a linked leaf is refused;test_session_storage.py: the sidecar appears only once the transcript lock is held, a lost race rolls it back under the lock, a link where.threadsshould be leaves the batch staged; thethread:key is a stateless, labelled dashboard surface; the turn runs read-only in its own session and lands in the thread while the main chat is untouched; the no-tools harness getsREJECT_ALL; an empty answer becomes the visible boundary line; a long answer is clipped before storage; a reply the store refuses is published as a failure; a refused spec sends a plain error and persists nothing, even when the audit itself raises; a crewmate that no longer resolves gets a plain error and no turn; a cancel landing on the committed answer writes no interruption row; a signed-out harness says so. The body-cap register, the warm-call-site label ratchet and the redaction-sink list each gain the module's row.Manual verification
N/A — API-only; the frontend PR carries the screenshots of the footer and the open thread panel.
Screenshots / video
Why no screenshot: backend routes and store only; the one frontend line adds an event name to the app-sdk's slot-scoped list and renders nothing.
Related Issues
no linked issue: CrewMates launch screen 07 (reply threads), backend half; the frontend PR follows.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)