Skip to content

fix(crew): backfill an old crewmate thread's record before its hand-off - #23879

Closed
buluoray wants to merge 1 commit into
mainfrom
fix/crewmate-backfill-conductor-record
Closed

buluoray wants to merge 1 commit into
mainfrom
fix/crewmate-backfill-conductor-record

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An old crewmate chat with no memory record hands work to its worker like any other crewmate chat, instead of being refused.

#23678 made session_create refuse a crewmate conductor thread that has no execution record (conductor_record_missing), because without a record the worker had no crewmate and landed on the shared store. Those threads are real: crewmate DM threads from before execution records were written. By the owner's decision (buluoray), such a thread should not be refused; its record should be written on the spot so the hand-off works.

Why it matters

A user with an older crewmate thread sees every hand-off refused and is told to open a new chat. Their long-running crewmate thread, the one with its history, can no longer dispatch work. Writing the record the thread's first turn would have written fixes that without weakening which crewmate or which store the worker gets.

Not a goal

  • Backfilling records for any session other than a crewmate's own DM thread, or at any time other than its hand-off.
  • Dropping the slot-name fallback inside _dispatching_crewmate for its other readers (crewmate: drop the slot-name fallback in _dispatching_crewmate #23834).
  • Any change for a caller that already has a record, or for ordinary (non-crewmate) conductor sessions.

What changed (motivation → approach → change)

Goal → approach → change:

  • src/kiro_crew/dashboard/session_control_parts/session_create.py:create_session: on a crewmate's own-worker hand-off with no caller record, it calls the new _backfill_conductor_record before the worker is built, then continues down the normal own-worker path with the written record, the caller's store and the re-read vouch.
  • _backfill_conductor_record reads the crewmate from the gateway's own state only. All four must hold: the slot is a persistent DM thread; its bound agent (caller_slot.agent, set by the gateway) is a config.agents row on the conductor; that row has a member_id; and the slot key encodes that member_id. The last is the check the thread's first turn makes (turn_context._dm_member_binding_changed). The agent the model passes is never read. The record is the one that first turn writes (resolve_member_execution), published with bind_session_execution(expected=None, vouch=False), so it lands only if the session still has none. Not vouched: the own-store admission re-vouches a member DM key against config itself (revouch_at_verified_admission).
  • Anything unconfirmed keeps conductor_record_missing: no such crewmate, a DM key naming another member, a plain chat bound to the crewmate, a non-persistent chat, or a record written meanwhile. The text now says the crewmate could not be confirmed and to open its chat again from the crew page.

I chose resolving from the slot's bound agent plus the DM key over trusting the slot agent alone, because the agent name is mutable and a renamed or reassigned alias must not hand one member's thread another member's store; the key is the one identity the thread carries that no model or metadata edit can change.

docs/system-specs/modules/session-control.md (the hand-off refusal paragraph) and test/test_execution_context.py (the binder ratchet: the new writer declares vouch=False) are updated.

Backwards compatibility

Compatible: a record-less crewmate thread that was refused now works; every caller with a record takes the same path as before, and every unconfirmed case is still refused with the same code.

Removes nothing: no code, field or function is removed; one refusal becomes a success for confirmed crewmate threads.

Tests

Proof: PROVEN test/test_execution_context.py::test_every_binder_declares_whether_it_vouches, test/test_mate_worker_dispatch.py::test_a_record_less_thread_whose_crewmate_cannot_be_confirmed_stays_refused[member-ada-member], test/test_mate_worker_dispatch.py::test_a_record_less_thread_whose_crewmate_cannot_be_confirmed_stays_refused[chat-7-700-] (head 1b57607)

  • test/test_mate_worker_dispatch.py:
    • test_a_record_less_conductor_thread_is_backfilled_and_opens_its_worker: the record is written as pixel on its own store, and the worker opens with pixel's member id, store and workspace.
    • test_a_second_hand_off_reuses_the_backfilled_record: the backfill runs once; the second hand-off reads the same record.
    • test_a_record_less_thread_whose_crewmate_cannot_be_confirmed_stays_refused (a DM key naming another member; a plain chat bound to the crewmate): refused conductor_record_missing, nothing allocated, nothing written.
    • test_the_model_cannot_pick_which_crewmate_is_backfilled: naming a peer keeps the peer's refused resolution and writes nothing; naming a peer as a template still backfills the slot's own crewmate.
  • test/test_mcp_dashboard_folders_session_create.py::test_a_record_less_conductor_refusal_reaches_the_model_with_its_own_remedy: the new refusal text reaches the tool reply through the MCP decoder.
  • test/test_execution_context.py::test_every_binder_declares_whether_it_vouches: lists the new writer as False.
  • All four test_mate_worker_dispatch.py cases above fail without the fix (prove.py names the subset it pairs per hunk).
  • Ran locally: test_mate_*, test_crewmate_*, test_session_control*, test_mcp_dashboard*, test_member_session_control*, test_execution_context.py and both ratchets (2573 passed before the ratchet entry, then 137 on the three touched files), lint, mypy, semgrep, docs-lint, comment history, and scripts/local-gate.py --base origin/main: backend passed (3090); the frontend half could not start on this host (Cannot find package '@rolldown/plugin-babel': the shared website/node_modules here predates that dependency on main). This diff touches no frontend file; CI runs that half.

Manual verification

N/A — unit coverage sufficient: the backfill and hand-off run through the real create_session, config, transcript and execution-record writer.

Sensitive change review

  • Head commit: 1b57607
  • What rule changed: A crewmate conductor DM thread with no execution record was refused conductor_record_missing at its hand-off. Now session_create._backfill_conductor_record writes its execution record (the crewmate's member identity and private store) when the gateway's own state confirms the crewmate: persistent DM thread, bound agent is a crewmate on the conductor, slot key encodes that crewmate's member_id. Then the worker opens on that identity and store.
  • Before -> after (what was allowed/blocked, now): Before: every record-less crewmate thread was blocked from opening a worker. After: a confirmed one is allowed, on its own crewmate's store; a DM key naming another member, a plain chat, a non-persistent chat, or no such crewmate is still blocked with the same code. The model-supplied agent cannot choose the crewmate or the store.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A thread is bound to the wrong crewmate's private store and its worker reads that crewmate's memory. The key check bounds this: a DM key encodes the member id, so only the member the key names can be written, and a reassigned alias is refused, as at the thread's first turn. A too-strict check only keeps the old refusal.
  • Evidence checked (which sandbox result proves it): test_a_record_less_thread_whose_crewmate_cannot_be_confirmed_stays_refused[member-ada-member] (key names another member: refused, nothing written) and test_the_model_cannot_pick_which_crewmate_is_backfilled pass on this head; test_a_record_less_conductor_thread_is_backfilled_and_opens_its_worker shows the store is the crewmate's own. All fail without the fix.
  • No regression:
    • Tools still work (which tools/commands were run, result): test_mate_*, test_crewmate_*, test_session_control*, test_mcp_dashboard*, test_member_session_control* and both ratchets: 2573 passed; test_execution_context.py with the new binder entry: passed. flake8, isort, black, mypy, semgrep, docs-lint and comment history pass.
    • Backward compatible (old config / old data / old callers still work, how checked): A caller with a record never reaches the backfill; the existing hand-off, peer-refusal and workspace tests in test_mate_worker_dispatch.py pass unchanged. The record written is the same shape resolve_member_execution writes for a fresh crewmate thread.
    • Existing tests (which suites passed on this head): test_execution_context.py, test_mate_worker_dispatch.py, test_mcp_dashboard_folders_session_create.py: 137 passed; the wider run above.
  • How to undo: Revert this commit; the record-less hand-off returns to the conductor_record_missing refusal. Records it already wrote are ordinary member execution records and keep working.

Related Issues

Follow-up to #23678. Related: #23834.

Sibling sweep

Swept: git grep -n "resolve_member_execution(" -- src/kiro_crew/dashboard
Sibling: src/kiro_crew/dashboard/chat_turn/turn_admission.py -- not affected -- the thread's first turn already writes this record and applies the same DM-key check
Sibling: src/kiro_crew/dashboard/chat_api/slot_guards.py -- not affected -- an explicit agent selection writes its own record on the owner's pick

Pattern harvest

Not generalizable: a one-time repair for threads from before execution records; new threads are born with one.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

A crewmate's conductor thread from before execution records was refused
conductor_record_missing when it handed work to its worker, by the
owner's decision that it should work instead. session_create now writes
that thread's record on the spot from the gateway's own state (a
persistent DM thread whose key encodes the bound crewmate's member id,
on the conductor), the record its first turn would write, published only
if the session still has none, and opens the worker as usual. The agent
the model passes never picks the crewmate. A thread that cannot be
confirmed stays refused, with text that says how to recover.
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 24, 2026 23:53
@buluoray
buluoray requested a review from mbriones98 October 24, 2026 23:53
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 1b5760735c0578d8529f2fecfd4424215dfd45fc — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design problem found. The backfill reuses the record the thread's first turn would write, checks the crewmate the same way that turn does, and still refuses anything it cannot confirm.

Notes

  • _backfill_conductor_record imports the private turn_context._dm_member_binding_changed. Two modules now share that check, so moving it to a public helper in members would stop the two from drifting apart.

[DESIGN-REVIEWED] 1b57607

Description read

[DESCRIPTION-READ] 01c3b1a1003dea22fa25afa32a347e98b563e456cf5a0af4a25c352b2c71ef32

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

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

First-Principles-Verdict: BLOCK

_backfill_conductor_record repeats a write turn admission already does. Turn admission writes a missing crewmate DM thread's record at the start of every turn, so a caller in the middle of a turn should never lack one, and the PR never shows one that did.

What this change ships

Inventory (4 items) — 2 justified

Intent: let an old crewmate DM thread with no record hand work to its worker instead of being refused. FIX.

  1. A record-less crewmate thread's hand-off now writes its record and opens the worker. Duplicate of chat_turn/turn_admission.py:552-637.
  2. A refused thread now gets new text: "could not be confirmed… open the crewmate's chat again from the crew page". Justified.
  3. The binder ratchet now lists the new writer as vouch=False. Rides along with item 1.
  4. The session-control spec paragraph is rewritten to describe the backfill. Justified.

Blockers

Second writer of the turn-admission record — duplicate of src/kiro_crew/dashboard/chat_turn/turn_admission.py:562-637
Trigger: when a turn starts with previous_execution is None, admission runs resolve_member_execution, then _dm_member_binding_changed, then bind_session_execution. The backfill runs the same 3 calls again (grepped resolve_member_execution|_dm_member_binding_changed|bind_session_execution: 1 existing writer for this case). The description says it is "the one that first turn writes". The tests only reach a record-less caller by clearing the record by hand and calling _create directly, without running a turn.
Outcome: two copies of the member-binding check that will drift apart. The bug the PR describes has no reproduction you can point at.
Delete _backfill_conductor_record. If a real turn does reach session_create with no record, fix the admission branch that skipped the write.
Clears when: a test that fails on base shows a caller with no record after turn admission ran, with the fix made in that admission path, or the backfill is removed.

[FIRST-PRINCIPLES-REVIEWED] 1b57607

Description read

[DESCRIPTION-READ] 704e9d1c3d51f56b90358d326715f1914306dfea075f54d8513c3504a3628b60

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

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 1b5760735c0578d8529f2fecfd4424215dfd45fc — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 1b57607

Verdict parsed from the review's SHA-scoped output markers for commit 1b5760735c0578d8529f2fecfd4424215dfd45fc.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 1b5760735c0578d8529f2fecfd4424215dfd45fc false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 1b5760735c0578d8529f2fecfd4424215dfd45fc and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1b57607

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 1b5760735c0578d8529f2fecfd4424215dfd45fc false-positive: <reason, 20 to 500 characters>

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

Copy link
Copy Markdown
Contributor Author

Closing as unneeded (maintainer decision, buluoray). Verified on origin/main: turn admission (chat_turn/turn_admission.py) already writes a missing crewmate DM thread's execution record at the start of every turn, before any tool runs, so a real turn of an old conductor thread reaches session_create with a record and its worker opens. _backfill_conductor_record would be a second writer of the same record. The branch is kept; reopen if a real turn is found that reaches the hand-off with no record.

@buluoray buluoray closed this Oct 25, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 25, 2026
@bolichen97
bolichen97 deleted the fix/crewmate-backfill-conductor-record branch November 6, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant