Repository navigation
feat(chat): migrate a local session to a remote crew (context-carry v1) - #9703
jeeshofone wants to merge 2 commits into
Conversation
Design Review (Fable 5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Sound reuse of shipped seams with rigorous failure ordering, but archive safety rests on an open, unpinned enumeration of slot-mutation paths. WatchArchive correctness is guard-by-enumeration: Suggestions
[DESIGN-REVIEWED] 1eead9d |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of All claims verified against base: the create-only binding refusal exists ( First-Principles-Verdict: CONCERNS Nothing in the product calls the new endpoint yet, and the per-slot Not justified as shipped
What this change shipsInventory (10 items) — 6 justifiedIntent: let an owner move an already-running local conversation onto a remote crew without re-explaining it — ADDITION (part of #7652).
Capped at 10 (folded: catalog-row projection into 3/4; Watch
Subtractions
[FIRST-PRINCIPLES-REVIEWED] 1eead9d |
GPT 5.6 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)Reviewed Opus 4.8 adjudication downgraded every blocking finding to advisory. Adjudication downgraded all 1 blocking finding(s) to advisory: the remedy each one requires is disproportionate to the harm it prevents. Read them as advice, not as merge conditions. Review detailsBLOCKING -- src/kiro_crew/dashboard/chat_handlers.py:4104 -- Metadata reads block the event loop Adjudication (Opus 4.8) — is blocking on each finding proportionate?Confirmed the mechanism. Harm: a single first-line read, cached by mtime; to stall the loop it needs an "oversized metadata header," but the first line is written by the system with bounded fields (redacted title, tags, folder_id) — no path lets a caller inflate it. Rare, and a watchdog restart clears it → LOW rung. Remedy cost: the flagged reads sit at commit points that structurally cannot [ADJUDICATION] 1eead9d total=1 uphold=0 downgrade=1 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
Round 2 disposition (head
|
785dc20 to
0710586
Compare
Round 3 disposition (head
|
50e9c83 to
36e69ef
Compare
Round 4 disposition (head
|
Round 16 disposition (head
|
CI disposition (head
|
Review disposition — round 17 (head
|
|
Round 18 on F1 — F2 — rollback pops a destination that accepted Also fixed (mine): On Design's two watch items: the reclaim/un-migrate path and mint-after-archive ordering are real design questions rather than defects in this change; I'd rather take a maintainer's steer on both than widen the PR unilaterally at round 18. |
|
|
|
Round on GPT F1 — a reset-conversation inside the peer round-trips slips past the pre-pop check (adjudication FLAGGED it as recoverable; fixed anyway). The observation is correct and it exposes a real gap in the consistency anchor: the check compared the transcript's length and dirty generation, and a reset mutates neither — it clears the resumable sid. The archive would then close a source whose live session was already gone while the peer resumed the pre-reset context. I did not take the suggested fix ("refuse reset while Test: sid goes to Non-blocking |
|
Correction to my previous comment's last paragraph (the Disposition: body corrected to describe the real behaviour. I am not stripping the hint: changing main's transfer contract inside this PR would be scope creep, and "apply only on a name match" is the intended design. |
|
Round on F1 — the mint guard fails open on unreadable metadata (UPHELD-FENCED → fixed). Correct. Tests: unreadable record → chat send, slot create and Non-blocking F2 — refusal ordered after 195 across the migrate/openai/contract/slot-create families, all gates. |
|
Round on F1 — display fields (title/tags/folder) are copied to the destination but not anchored (UPHELD → fixed). Correct: a rename, tag edit or folder move landing in the persist/archive awaits after the copy mutates none of the transcript anchors, so the archive would strand the edit on the read-only source. The display tuple F2 — the resume gate is a hand-rolled copy that fails open (UPHELD → fixed). Also correct, and the more important of the two. The resume handler had two local re-derivations of the migrated check from 198 across the migrate/openai/contract/create/resume families, all gates. A note for the maintainer on the pattern: this is the third consecutive round where the finding is "a guard that cannot see one class of change" (sid, unreadable record, display fields, hand-rolled copy). I have swept the migrate handler for further anchors this PR copies-then-relies-on and found none beyond these; if the lanes turn up another, I'd take that as a sign the anchor set should be a single dataclass snapshot rather than a growing tuple, and would propose that as its own change. |
|
Round on F1 — the migration ignores the peer's reported import fidelity (UPHELD → fixed). Correct, and a different class from the last three rounds. The import already reports Fix: a fidelity gate right after the send. A bundle that carried Non-blocking — rollback pops the destination without publishing (fixed). Verified: Tests: degraded import refused with no mirror minted, then the same bundle at full fidelity succeeds; transcript-only bundle not refused; rollback publishes. 329 across the migrate/transfer/openai/contract/create/resume families, all gates. |
|
Round on F1 — an armed auto-nudge / monitor loop passes every migrate guard and is silently retired by the archive (UPHELD → fixed). Correct. Between cycles a loop leaves Fix: a new arm of Test: armed at entry → 409, the bundle is never sent; armed inside the peer round-trip → 409 at the pre-pop check with the source live and the destination rolled back; unarmed → the same slot migrates. 330 across the affected families, all gates. |
|
Round on F1 — the resume guard's source-key derivation only recognises the Fix: the helper accepts both transport spellings and derives the source key with |
|
Round on F1 — anchors snapshotted after the bundle build (UPHELD → fixed). Correct: F2 — the nudge guard reads an empty registry at the commit point (UPHELD → fixed). Also correct: 510 across the migrate/transfer/session-control/close/openai/contract/create/resume families, all gates. I have also re-read every remaining await in the handler against every anchor and guard for ordering: the display anchor is taken at its copy point (correct — it protects the persist/archive window after the copy), and every other guard is evaluated both at entry and at the commit point. |
|
Round on F1 — an ordinary chat bound to a private V2 memory store passes the mode-only guard (UPHELD → fixed). Correct. The owner-selected member pin writes a private session-store binding on an ordinary Fix: a new arm of Test: bound at entry → 409, nothing sent; unreadable binding → 409, nothing sent; bound inside the peer round-trip → 409 at the commit point, source live; unbound → migrates. Fails on the previous head. 1294 across the migrate/member-memory/transfer/session-control/close/openai/contract/create/resume families, all gates. |
|
Round on F1 — the fidelity gate ignores a sender-side Fix: a sender-side refusal before the send — |
|
Round on F1 — destination identity is not rechecked at the commit point (adjudication: FLAGGED; holding). The observation is right: the pre-pop check re-asserts the source's identity ( The fix would be one line in |
|
|
POST /api/chat/slots/{slot}/migrate-remote opens a new local slot bound
to the chosen crew through the same create-path machinery the crew
picker uses, delivers a digest of the source session's recent
conversation to the PEER's own /context endpoint, and archives the
source read-only with a `migrated` metadata stamp naming the crew and
the new slot.
The delivery target matters: the pending-context drain lives inside
_run_chat, and a remote-bound local slot never runs _run_chat
(relay_remote_turn replaces it), so a digest queued on the local mirror
would sit undelivered forever. send_peer_context posts it to the peer,
where the crew's slot is an ordinary local slot whose next turn drains
the digest into the prompt like any other background context.
Failure ordering is deliberate: nothing destructive happens until the
new slot exists and the delivery succeeded — the source is archived
LAST, so a mid-flight failure leaves the original intact. Resuming a
migrated source is refused (409 resume_migrated) so the conversation
cannot fork into two live copies; the transcript stays readable in
History. Owner-gated with the same two-gate authorization as the create
path's remote binding (app tokens get an oracle-free 404).
Part of kirodotdev#7652.
|
|
|
F1 — pending question card. F2 — channel resume pickers. Three pieces, one predicate:
1976 across the migrate, resume (Teams/Telegram/Discord), history and search families; isort/flake8/mypy, black (baseline-aware), comment-history, brand and ACP-boundary gates green; no |
|
Tests: |
|
F1 — reservation namespace. F3 — empty source tombstone. The empty-window closed save merged only into an existing metadata line, so a source that never persisted one (nothing minted it at birth) and had no messages was archived with no durable 4339 across every test module that touches the slot save path (persistence, close, migrate, resume, transfer, folders, ephemeral sessions, channel pickers); all gates green; no |
|
|
Hardening of the migrate-remote flow across its adversarial and crash-ordering surfaces: - The app-token denial runs FIRST, before the slot lookup and body validation, so an app token probing with an empty body reads the same 404 for existing and absent slots instead of a 400/404 existence oracle. - A migration reserves its slot with a check-and-set flag before the first await, and close_slot's pre-pop hook re-validates the turn state at the last instant before removal: a message landing during the peer round-trips starts a turn the original busy check never saw, and archiving would cancel it uncarried. The refusal is a retryable 409. - Channel-origin and channel-linked sessions are refused: the channel keeps addressing the conversation after the archive (the nudge fire path adopts closed transcripts), so migrating one forks it between the crew and a reanimated local copy. - Assistant rows in the digest pass both standard redactors before the digest leaves the machine for the peer — the same sink discipline as every other non-user egress. The user's own words travel verbatim. - The destination binding is durably persisted (metadata upsert — the empty mirror has no window for a save to merge into) BEFORE the source is archived, so a restart at any point leaves at least one addressable copy. An archive-failure rollback CONFIRMS the destination's closed write before popping it — a best-effort save after the pop would be swallowed on exactly the correlated fault that failed the archive — and keeps the slot live and dirty when confirmation fails, while the abandoned peer session is asked to close best-effort. - The migrated-archive resume refusal runs immediately after the initial metadata read, BEFORE clear_closed durably drops the archive flag; a second copy of the gate runs on the post-await re-read. - The mirror carries no execution settings (agent/workspace/model): the peer runs its own defaults, and it does not opt into the user-session pulse count — migration re-homes an existing conversation. - The digest keeps its final row when that row alone exceeds the character budget, truncating content instead of dropping the tail.
|
|
|
There have already a feature "send a local session to remote" |
|
Agreed that the carry itself already ships — this PR reuses it rather than adding a second one ( Fair pushback though: that is a lot of surface for what is, at its core, send + adopt + close. Two ways I can take this, your call:
If I do not hear back I will take option 2 rather than keep a 3.4k-line PR open against a feature you consider shipped. |
|
Thanks for the thorough work here. We already ship “Send a copy to,” which transfers the full session bundle to a connected remote instance. Users can continue there without re-explaining the conversation. This PR reuses that transfer path. Its main addition is exclusive move semantics: archive the local source and prevent further local use. We do not currently need that added lifecycle complexity. The endpoint also has no frontend consumer. Closing this as overlapping with the existing feature. We can revisit if a clear need emerges for “Move” semantics distinct from copying. |
Problem / Motivation
A chat session can be bound to a remote crew only at CREATION: the slot-create path accepts
remote_slot+instance_id, and the binding gate explicitly refuses an existing slot. A user who starts a conversation locally and later wants a remote crew to carry it on has no path — they must open a fresh crew session and re-explain everything by hand. This is the "move an existing local conversation to a remote crew" half of #7652.Why it matters
Long-lived working sessions accumulate real context (decisions, constraints, artifacts under discussion). Losing that context at the local/remote boundary makes crews awkward to adopt mid-task, which is exactly when they are most useful.
What changed (motivation → approach → change)
Goal: move a session's conversation to a crew without any peer-protocol change.
Approach considered: teleporting the raw transcript to the peer would need a new peer ingestion seam (a v2 concern). Instead, v1 is a context-carry migration composed entirely of existing seams: the create path's remote binding (
create_peer_slot), the pending-context channel (_enqueue_pending_context, drained into the next turn as a framed background block), and the tab-close archive (close_slot).POST /api/chat/slots/{slot}/migrate-remotewith{"instance_id": ...}:build_transfer_bundle_async→InstancesManager.send_session_bundle→ the peer's/api/chat/slots/import— the same bundle path the instances "send session" action uses (at bundle v2 it even carries the kiro-cli context for full-fidelity resume). The peer imports the real conversation and returns its new slot key; the mirror binds to it. The bundle is also the migration's consistency anchor: the transcript length is captured at bundle time and re-checked before the archive.migrated: {instance_id, remote_key}metadata stamp, persisted and rehydrated so the pointer survives restarts. Failure ordering is deliberate: a peer-bind failure costs nothing; a peer context-delivery failure rolls back the new slot and leaves the source live; an archive failure rolls back the new slot and clears the speculative stamp. A duplicate crew slot is cheap; a lost original is not.resume_migrated, naming the crew) so the conversation cannot fork into two live copies; the transcript stays readable in History.Tests
test/test_chat_slot_migrate_remote.py(25 tests): every guard refusal (unknown slot, missing instance, app token — with the same 404 for existing and absent slots, non-owner, already-remote, non-plain modes, channel-origin and Slack-linked sessions, running turn, queued prompts, concurrent migration); a peer transfer refusal leaves the source intact with no orphaned slot; success path (binding fields, the full conversation sent throughsend_session_bundle, source archived with themigratedstamp in persisted metadata, source origin preserved on the mirror); destination durably persisted before the archive; failure ordering (archive failure keeps the destination retryable — confirmed-closed-then-pop, live+dirty when the closed write cannot be confirmed); consistency anchor (a turn that completes inside the tunnel send aborts the archive; a replacement slot under the same name aborts the archive); migrated-source resume refused 409 BEFOREclear_closedso the archive flag survives.Local runs: migrate suite 25 passed;
test_remote_crew_execution.py190 passed; body-guard / session-pulse / error-code contracts passed; black/flake8/isort/mypy/comment-history gates clean.Manual verification
A live two-gateway migration has not been run in this branch; the carry leg IS the shipped session-transfer path that the instances "send session" action already exercises in production, stubbed here only at the tunnel boundary (
send_session_bundle), with the real bundle builder contract pinned bysession_transfer's own suite.Related Issues
Part of #7652 (v1 does not complete the issue — see follow-ups).
Follow-ups (out of scope here)
migratedmeta is already persisted for it).