Skip to content

feat(chat): let the project chip stage a switch while a response runs - #17729

Merged
iamwhatever merged 2 commits into
mainfrom
fix/project-chip-mid-turn-7263
Oct 14, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
fix/project-chip-mid-turn-7263

Conversation

@buluoray

@buluoray buluoray commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Let a user pick a new project for a chat while the agent is still answering, so the next response starts in that project without waiting for the current one to finish.

Today the composer's project chip is disabled for the whole length of a response ("Stop the current response to switch project"). A user who realises mid-turn that the next step belongs in another repository has to babysit the turn to its end, then pick the project, then prompt again. Issue #7263 asks for steering-style select-now, apply-at-the-next-boundary behaviour for the project, model and crew selectors.

Why it matters

The project is the selector most often changed between steps of a task, and the lock adds a forced wait to every such pivot. The backend already supports staging this change; the only thing in the way is the UI lock, so the user pays a wait for no protective reason.

Not a goal

  • Staging a model or crew switch mid-turn. Their routes answer 409 turn_in_flight while a turn runs, and staging them needs a pending-pick design (owner-picked model, crew rebind of agent/workspace/memory) that is the owner's call. Both chips stay locked in this PR.
  • A "will switch to X after this turn" pending badge. The chip already shows the newly picked project immediately, and the tooltip says when it takes effect.
  • Backend changes beyond the project route taking the turn-preparation lock and the runner retaining the actual turn-project snapshot for prompt/skill expansion, activity and crew logs, provider agent switches, deferred-reset reuse, and WakaTime heartbeats.
  • Pinning the side panel or the running reply's file links to the start-of-turn project. Every reply's links already follow the slot's live project after any switch; the tooltip states the window instead.

What changed (motivation → approach → change)

  • Motivation: the composer refuses a project pick mid-turn that the backend would accept and handle safely.
  • Approach: POST /api/chat/slots/{slot}/project has no busy refusal. It writes slot.project, arms _pending_reset_history_key, and leaves the session reset to chat_runner._consume_pending_reset, which runs at the next turn's start; the eager pre-spawn returns early while slot.running. The running turn keeps its kiro-cli process and CWD. This is the same deferral the agent's own set_project directive already relies on mid-turn (see docs/system-specs/modules/session.md), and the runner already snapshots start-of-turn project state for heartbeats for that reason (_wt_turn_project).
  • Preparation window: chat_runner._run_chat holds slot_switch_session_lock(session_key) from its binding capture (which includes slot.project) to its session registration, and re-checks the binding with _require_current_binding in that span. The route used to write slot.project under slot._lock only, so a pick in the first moments of a reply failed that reply with "conversation binding changed during preparation". api_chat_slot_project (src/kiro_crew/dashboard/chat_handlers.py) now takes slot._lock and then that session lock, the same order the agent/model/workspace switch handlers use, and re-checks the slot after the second await. The dispatch releases the lock once its session is registered and never holds it across the turn, so a pick waits at most for preparation and the in-turn set_project path is not blocked.
  • Running reply: after the dispatch lock is released the project route may write slot.project, so _run_chat now takes _turn_project = selected_binding[1] at the release and reads it, not the live field, for build_message(project=...) (prompt steering, skills, essentials), the @prompt local root (_expand_prompt_mention_off_loop(..., project=...)), the $skill resolution and allow-globs (_expand_dollar_skills(..., project)), the member record_activity project and the crew log's session/opened cwd. _expand_dollar_skills now takes project as a required argument (its one caller passes _turn_project); _expand_prompt_mention_off_loop and _slot_prompt_project take it as optional, because their /prompts get and on-loop callers outside the turn path still read the live slot. The allocation cwd was already read under the lock. - Agent switch in the running reply: its binding re-checks now pass project_may_be_staged=True, which compares every binding field except the project. The switch is recorded with record_provider_agent_switch(..., _turn_project), and the post-switch re-baseline keeps the turn's project. A pick staged mid-reply therefore no longer aborts a /agent swap with "retry the turn". A rebound session key or a closed slot still fails the switch closed and restores the selection, as before.
  • Change: website/src/components/ChatInput.tsx drops disabled={isRunning} from the project chip. While a response runs, its tooltip and accessible name are the normal project/branch title plus a new line, "Your next message runs in the project you pick. This reply finishes in {{project}}." plus, on its own line, "Links in this reply will open in the project you pick." The second sentence states the window: the dashboard reads slot.project live, so the running reply's relative links and the side panel follow the new project at once.
  • Sub-agents attached: the chip stays locked. With children attached, _consume_pending_reset leaves the reset armed (subagents_attached_async), so a pick could not land at the next turn: the next reply would reuse the old-directory process while _turn_project named the pick. selectProjectChipLocked (website/src/store/chat/selectors.ts) is true whenever sub-agents are attached, whether or not a reply streams, and ChatPage passes it as projectLocked. The locked chip's tooltip and accessible name add "The project can't change while sub-agents are running." (new key components.chatInput.project_locked_while_subagents_run, all 11 locales plus en.context.json, en-XA.json regenerated).
  • Deferred reset into the next turn: a pick staged before the turn attached its sub-agents can still leave the reset armed when the next turn starts, and that turn reuses the process spawned in the old directory. _run_chat then takes _turn_project from the claimed provider's cwd (when _pending_reset_history_key still names the session and the claim is not new), so the prompt, @prompt/$skill roots and crew log describe the directory kiro-cli runs in. The reset stays owed and lands once the children detach.
  • Spec: docs/system-specs/modules/learn-cron-dashboard.md gains a "Project switch during a response" entry with the lock order and the link window. The now-unused components.chatInput.stop_the_current_response_to_switch_project key is removed from every catalog. The new components.chatInput.project_switch_applies_next_turn key is added to en.manual.json, all 11 shipped locales and en.context.json, and en-XA.json was regenerated with npm run i18n:pseudo.
  • Evidence harness: website/capture/project-chip-mid-turn.{html,tsx} and website/scripts/capture-project-chip-mid-turn.mjs mount the real ChatInput mid-turn and assert the chip state before writing a frame.

Backwards compatibility

Compatible: the API is unchanged and already accepted this request from any caller; only the UI now sends it during a turn.

Reader: website/src/components/ChatInput.tsx:project chip title -- chat -- the only reader of the removed stop_the_current_response_to_switch_project key (git grep on origin/main outside the catalogs finds no other use); replaced by the new key.

  • Tooltip copy: two keys, components.chatInput.project_switch_applies_next_turn (with {{project}}) and components.chatInput.project_switch_links_follow_pick, in en.manual.json, all 11 shipped locales and en.context.json; en-XA.json regenerated with npm run i18n:pseudo. ChatInput snapshots the project when a response starts and names that one, because the project prop already follows a mid-turn pick.
  • Heartbeat: note_coding_activity reads _turn_project; the older pre-lock _wt_turn_project snapshot is removed, so the turn has one project snapshot.

Tests

  • website/src/test/ChatInput.projectBranch.test.tsx

    • new ChatInput project chip while a response is running suite: the chip is enabled mid-turn, click calls onProjectClick, title and aria-label carry the next-response line; the line is absent when idle; the agent and model chips stay disabled mid-turn.
    • the existing "keeps the branch out of the accessible name while a response is running" test pinned the old disabled state; it is rewritten to the new contract (enabled, names the branch and the next-response line).
  • Mutation check: re-adding disabled={isRunning} reddens both mid-turn tests (2 failed / 14 passed); the file is 16/16 green with the change.

  • test/test_chat_slot_project.py::TestChatSlotProject::test_pick_waits_for_a_preparing_turn: the test holds slot_switch_session_lock("dashboard:test") the way a preparing turn does, posts a pick, waits with kiro_crew.testing.wait.until_parked until the request is parked on that lock, and then asserts the request is still pending with slot.project and _pending_reset_history_key untouched; after release the pick lands and arms the reset. Mutation: removing the route's _slot_switch_session_lock(session_key) acquisition reddens it (assert not pick.done(), 1 failed / 11 passed). The related backend files (test_chat_slot_project, test_chat_slot_switch_atomicity, test_slot_identity_continue_project, test_chat_handlers_composition_contract, test_eager_spawn, test_start_priority, test_json_object_body_guard) pass: 503 passed.

  • test/test_chat_runner_mid_turn_project.py::test_pick_after_registration_does_not_reach_the_running_prompt drives the real _run_chat, writes a new slot.project from inside the session claim (the last await before the lock is released), and asserts build_message got the start-of-turn project and on_session_opened got the start-of-turn cwd while the pick itself stands. Mutations: reverting the build_message read to slot.project reddens it; reverting the crew log cwd read reddens it. The record_activity read is not mutation-covered (it needs a member agent on the slot). Related runner, crew-log and slot tests: 1477 + 1313 passed.

  • Same file: test_pick_after_registration_does_not_reach_prompt_or_skill_expansion drives _run_chat with @local-sop use $local-skill and asserts both expansions get the start-of-turn project after the pick landed; test_explicit_project_overrides_the_live_slot_project and test_dollar_skills_resolve_against_the_explicit_project pin the helpers' new argument. Mutations: dropping project=_turn_project from the prompt call, dropping _turn_project from the skill call, and reverting the helper to slot.project each redden one test. test/test_crew_log_order.py stub updated for the new keyword.

  • test/test_chat_agent_selection.py::test_project_pick_during_a_provider_switch_is_staged_not_fatal: a pick lands as a provider agent switch begins; the turn completes with no "retry the turn" row and no recorded failure, the switch is saved (selection kind template) with the start-of-turn project, and the next turn allocates in the picked project. Mutations: reverting the switch branch's checks to _require_current_binding() reddens it; recording with slot.project instead of _turn_project reddens it. The existing test_interrupted_provider_switch_restores_selection cases (rebound, closed, rollback) still pass.

  • website/src/test/ChatInput.projectBranch.test.tsx::names the project the reply started in after a mid-turn pick: rerenders mid-turn with a new project; the chip shows the new path while the tooltip still names KiroCrew, and the next running turn names the new project. Mutations: naming the live project instead of the snapshot reddens it; not re-snapshotting when a response starts reddens it.

  • test/test_chat_runner_coverage.py::TestRunChatWakaTimeCodingAccounting::test_heartbeat_project_is_the_turn_start_snapshot: a pick lands as the session registers; the heartbeat names the start project. Mutation: passing slot.project to note_coding_activity reddens it.

  • website/src/test/ChatPage.steerWithSubagents.test.tsx::project chip while sub-agents are attached: renders the real page; the chip is locked for sub-agents only and for a streaming reply with sub-agents, and enabled for a streaming reply without them. Mutations: selectProjectChipLocked returning false, and ChatPage passing projectLocked={false}, each redden both locked cases.

  • website/src/test/ChatInput.projectBranch.test.tsx::stays locked when only attached sub-agents keep the composer busy: disabled, no click, and the tooltip carries the locked reason. Mutation: dropping the reason line from title reddens it.

  • New test waits in this PR use ceilings of 30 s, per test/test_wait_discipline_ratchet.py.

  • test/test_chat_runner_mid_turn_project.py::test_deferred_reset_turn_describes_the_reused_process_directory: the slot holds a staged pick with the reset armed and sub-agents attached; the reused process runs in the old directory. build_message and the crew log get the old directory and the reset stays armed. Mutation: dropping the client.cwd override reddens it.

  • website/src/store/chatSlice.{ownership,publicSurface}.test.ts list the new selectProjectChipLocked facade export.

  • src/test/ChatInput.approval.test.tsx fails 3 tests on this host and identically on a detached clean origin/main worktree (cbf2b36); it passed in CI on bb71fc6.

Manual verification

  • The capture script ran against a local Vite server in dark and light themes; every frame asserted OK before it was written (chip enabled, picker opened once, label text, agent and model chips disabled; in the locked frames, chip disabled with the locked reason).
  • Not verified on a live pod: the end-to-end path (pick a project mid-turn, the reply in flight keeps its old directory, the next reply starts in the new one). The preparation window is covered by the unit test above, not by a live run.
  • Windows/macOS: not verified on this Linux host; the change is a lock acquisition, a disabled attribute and a tooltip string, nothing platform-specific.

Screenshots / video

Project chip while a response is running, hovered (the folder chip shows the enabled hover state; the agent and model chips stay dimmed). The text under the composer prints the chip's tooltip, which headless Chromium cannot paint. Re-captured on this head with website/scripts/capture-project-chip-mid-turn.mjs; both frames asserted the shipped label "Your next message runs in the project you pick. This reply finishes in {{project}}." plus, on its own line, "Links in this reply will open in the project you pick."

dark
light

After picking OtherRepo mid-reply: the chip names the picked project while the tooltip still says the running reply finishes in its start project.

after pick, dark
after pick, light

Sub-agents attached: the chip is dimmed and disabled, and its tooltip says why. Both frames asserted the shipped line "The project can't change while sub-agents are running."

locked, dark
locked, light

Related Issues

Part of #7263 (first slice: the project selector only; model and crew stay open in that issue).

Reviewer-requested follow-ups (the parent issue remains open):

Decision for the owner

#7263 asks whether the workspace, model and crew selectors should accept a pick mid-turn and apply it at the next turn boundary. This draft says yes for the project only, because the backend already defers that reset to the next turn safely, and it keeps model and crew locked until their staged-pick and crew-rebind contract is decided rather than letting them answer 409.

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.

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

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check whether it is acceptable that, after a mid-turn pick, the running reply's relative links and the side panel open in the new project rather than the reply's own.

[DESIGN-REVIEWED] dbf7a0f

Description read

[DESCRIPTION-READ] b26aab1c5c30fb35ccb1b04d2d65b18f1bf4576bbe68ef1e81954e0ab10b1a7d

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ human override accepted

@buluoray overrode this lane for dbf7a0fad1b5bac66ccda8a9542d74dc44567e30 via /ai-review override (this commit only).

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of dbf7a0fad1b5bac66ccda8a9542d74dc44567e30 — 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: PASS

Check one thing by hand before merge: three sites slice _current_binding() at index 1 ([:1] + [2:]) on the assumption that index 1 is the project, and no test fails if a field is inserted ahead of it.

What this change ships

Inventory (9 items) — 9 justified

Intent: let a user pick the chat's next project while a reply is still streaming, as issue #7263 asks. This is an ADDITION.

  1. The project chip stays clickable while a reply runs, and a pick takes effect from the next message — justified
  2. While a reply runs, the chip tooltip names the project the reply started in and says links follow the new pick — justified
  3. The chip stays locked while sub-agents are attached, and its tooltip now says why — justified
  4. A pick made while a reply is preparing waits for the session lock instead of failing that reply with "binding changed" — justified
  5. The running reply's prompt, @prompt/$skill roots, activity record, crew log and heartbeat use the project the turn started in — justified
  6. An /agent swap mid-reply survives a staged pick and is recorded under the turn's project — justified
  7. When the old process is reused because the reset is still pending, the turn describes the process's real cwd — justified
  8. The "Stop the current response to switch project" string is removed from all catalogs — justified
  9. The capture harness (project-chip-mid-turn.{html,tsx} plus its script) follows the existing 749-script convention — justified

[FIRST-PRINCIPLES-REVIEWED] dbf7a0f

Description read

[DESCRIPTION-READ] 56da281349173de610d97d92cc682faddbba3e911ebcf8a3a73f380c5b0c44a3

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] dbf7a0f

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

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] dbf7a0f

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

@buluoray

buluoray commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Disposition of the UX Review CONCERNS on 28ba764 (advisory, not acted on in this head):

  • Tooltip wording is vague / hover-only. Agreed that the line can name its object. A sharper candidate is "A new project applies from your next message; this response keeps running where it is." I have not pushed it: it is a copy-only change, and a new head would re-run all ~97 checks during the fleet's CI rate-limit hold. This PR is a draft awaiting the owner's decision on Change workspace, model, and crew mid-conversation (deferred apply at turn boundary) #7263, so the final wording is folded into that decision rather than spent as a CI round now.
  • Hover-only discoverability. Unchanged on purpose: the chip already shows the new project immediately after a pick, which is the visible confirmation; a persistent "pending" badge was listed under Not a goal.

@buluoray
buluoray marked this pull request as ready for review October 11, 2026 02:19
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 11, 2026 02:19
@buluoray
buluoray requested a review from dodgeblaster October 11, 2026 02:19
@buluoray
buluoray enabled auto-merge (squash) October 11, 2026 02:19
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 11, 2026
@buluoray
buluoray force-pushed the fix/project-chip-mid-turn-7263 branch from 28ba764 to c86779a Compare October 11, 2026 03:08
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 11, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes disabled={isRunning} from the composer's project chip (website/src/components/ChatInput.tsx ~L1389) so a project pick made mid-turn applies at the next turn. It relies on the project route arming _pending_reset_history_key. The Opus finding on head c86779a is real, and it has no disposition. I traced it on main. api_chat_slot_project (dashboard/chat_handlers.py ~L8450) writes slot.project under slot._lock only, not under the slot_switch_session_lock that turn dispatch holds while it prepares. _run_chat captures the binding, slot.project included, at chat_runner.py ~L10131. It re-checks it through _require_current_binding at many points up to ~L10430, a window that includes a cold get_or_create spawn. So a project picked in the first seconds after sending fails the message just sent with "memory_unavailable: conversation binding changed during preparation; retry the turn". That contradicts the new tooltip and the PR's claim that the reply in flight finishes in its old directory. The Design lane's watch item is also unanswered: slot.project changes at once, so the running reply's relative file links and the working-tree diff in the side panel resolve against the new repository. Suggested fix: make the route take slot_switch_session_lock(session_key) around the write, or keep the chip disabled until the turn has finished preparing (registered its session). Pin the side panel's projectDir to the turn's start-of-turn project, or state the window in the tooltip. Add a test for a pick that lands during preparation. The owner decision on #7263 (project only, mid-turn) is still open as well. — crew-pr-reviewer (deep re-check)

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 12, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author
  • span=d5541e3ef7af A mid-turn project pick can fail the reply that is still preparing

Disposition: fixed

mechanism: api_chat_slot_project now takes slot._lock and then slot_switch_session_lock(effective_session_key(slot)), the lock _run_chat holds from its binding capture to its session registration, so a pick waits for preparation to finish instead of moving slot.project under _require_current_binding.

Fixed in 53f6112. Test: test/test_chat_slot_project.py::TestChatSlotProject::test_pick_waits_for_a_preparing_turn holds the session lock as a preparing turn does and asserts the pick stays pending with slot.project unchanged. Removing the route's session-lock acquisition reddens it (assert not pick.done()).

@buluoray

Copy link
Copy Markdown
Contributor Author

@iamwhatever thanks for tracing this. Addressed in 53f6112 (one new commit on top of c86779a):

  • Preparation race (Opus finding). Fixed. api_chat_slot_project now takes slot._lock and then slot_switch_session_lock(session_key), the same order the agent, model and workspace handlers use, and re-checks the slot after the second await. A pick made while _run_chat is preparing now waits until the turn registers its session, then writes slot.project and arms the deferred reset for the next turn. The dispatch releases that lock at registration and never holds it across the turn, so a pick waits at most for preparation. New test test_pick_waits_for_a_preparing_turn holds the lock like a preparing turn and asserts the pick stays pending with slot.project untouched; removing the route's lock acquisition reddens it. Disposition: #issuecomment-6116157228.
  • Side panel and file links (Design watch item). I chose to state the window rather than pin. The side panel, FollowUpCard, session-control cwd and relative links all read currentSlot.project live for every reply, not only the running one, so the same re-resolution already happens to earlier replies after any idle switch. Pinning only the running reply would add a per-turn project that nothing else has. The mid-turn tooltip now reads "A new project applies from the next response. File links in this one will open in the new project." (all locales updated), and the PR description says the same.
  • Owner decision on Change workspace, model, and crew mid-conversation (deferred apply at turn boundary) #7263. Still open; it stays in the "Decision for the owner" section.

Also added a spec entry ("Project switch during a response") in docs/system-specs/modules/learn-cron-dashboard.md. Not verified on a live pod; the preparation window is covered by the unit test only.

@buluoray
buluoray requested a review from iamwhatever October 12, 2026 01:31
@buluoray
buluoray force-pushed the fix/project-chip-mid-turn-7263 branch from 53f6112 to 65d2b49 Compare October 12, 2026 01:52
@buluoray

Copy link
Copy Markdown
Contributor Author
  • span=bc140192532d The preparation test waits with a fixed sleep before its absence assertions

Disposition: fixed

mechanism: the sleep loop is replaced by await until_parked(dispatch_lock, timeout=10) from kiro_crew.testing.wait, so the request is observed parked on the session lock before assert not pick.done() runs.

Fixed in 65d2b49. Removing the route's session-lock acquisition now reddens test_pick_waits_for_a_preparing_turn at the barrier itself (no waiter ever parks), independent of runner load.

@buluoray

Copy link
Copy Markdown
Contributor Author
  • span=22557ff5a29d The lock assertion relies on elapsed time

Disposition: fixed

mechanism: the fixed asyncio.sleep(0.01) loop is replaced by await until_parked(dispatch_lock, timeout=10) before the negative assertions.

Fixed in 65d2b49. With the route's _slot_switch_session_lock(session_key) acquisition removed, test/test_chat_slot_project.py::TestChatSlotProject::test_pick_waits_for_a_preparing_turn fails (1 failed).

@buluoray

Copy link
Copy Markdown
Contributor Author
  • span=e48125549479 The running turn reads slot.project live after the dispatch lock is released

Disposition: fixed

mechanism: _run_chat takes _turn_project = selected_binding[1] when it releases the dispatch lock and passes it, not slot.project, to build_message(project=...), record_activity(project=...) and crew_log_emit.on_session_opened(cwd=...).

Fixed in 65d2b49. test/test_chat_runner_mid_turn_project.py::test_pick_after_registration_does_not_reach_the_running_prompt writes a new project from inside the session claim and asserts the prompt and crew log keep the start-of-turn project. Reverting the build_message read reddens it; reverting the crew log cwd read reddens it. The record_activity read is changed the same way but not mutation-covered.

@buluoray

Copy link
Copy Markdown
Contributor Author

@iamwhatever follow-up on 65d2b49, which replaces 53f6112 (still one fix commit on top of c86779a). The review lanes on 53f6112 found two more gaps. Both are fixed:

  • The running reply read the new project after the lock was released. _run_chat now snapshots the project its preparation validated (_turn_project) when it releases the dispatch lock. It uses that snapshot for build_message, the member activity record and the crew log cwd. A pick made mid-reply no longer gives the running prompt the new project's steering and skills. Test: test_pick_after_registration_does_not_reach_the_running_prompt. Reverting either the prompt read or the crew-log read reddens it.
  • Timing-based test. test_pick_waits_for_a_preparing_turn now waits with until_parked until the request is parked on the session lock before asserting it has not landed.

Dispositions: #issuecomment-6116344959, #issuecomment-6116345106, #issuecomment-6116345238. The owner question on #7263 is still open.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 12, 2026
@buluoray
buluoray disabled auto-merge October 13, 2026 18:49
@buluoray
buluoray force-pushed the fix/project-chip-mid-turn-7263 branch from a48deb3 to dfc12e5 Compare October 13, 2026 19:42
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: Rebased onto current main (head dfc12e5). Two adjustments beyond textual conflicts, both inside commit dfc12e5:

  • ChatInput.tsx: main split the prop into projectProp (the chip value) and project (undefined for a session on a peer). The turn-start snapshot now reads projectProp, matching the chip tooltip it extends. For a local session the two are the same value, so behaviour is unchanged.
  • chat_runner.py: main added note_coding_cadence(_wt_turn_project) (feat: emit WakaTime cadence heartbeats at coding-tool dispatch #13177 cadence beats), while this PR replaces _wt_turn_project with the post-registration _turn_project snapshot. The new call now reads _turn_project or None, like the end-of-turn beat in this PR. Without it the four TestRunChatWakaTimeCodingAccounting cadence tests fail with NameError; with it they pass.

Local checks on this head: tsc, eslint on ChatInput.tsx, i18n:check (pseudo regenerated, no diff), 60 vitest tests in the four touched frontend test files, 1492 pytest tests across the touched Python test files plus test_wakatime*, mypy on chat_runner.py, flake-pattern ratchet. No copy changed.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 13, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override ux dfc12e5: owner buluoray ruled the copy final after seven UX rounds that each asked for a different wording; the behaviour is unchanged and GPT/Opus pass. 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]

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

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray marked the ux AI finding as false positive, not applicable, or explicitly accepted for dfc12e565f0fe9e3cfa2514fd01405df03f404e3.

owner buluoray ruled the copy final after seven UX rounds that each asked for a different wording; the behaviour is unchanged and GPT/Opus pass. 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]

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

@CrysisDeu CrysisDeu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head dfc12e5. Code and tests are mergeable quality, and the race from the standing CHANGES_REQUESTED is fixed at head (route takes the session lock; parked test). What is left is mine to decide, so deciding here:

  1. #7263 is needs-human / parked with no maintainer design on record. Decision: the workspace selector alone is an acceptable first slice; model and crew stay 409-locked for now. I will note that on the issue.
  2. Scope: the PR drops the issue's item 3, the pending-state affordance ("will switch to X after this turn"), for a hover tooltip. That is not acceptable as the final shape; a tooltip is not discoverable on touch and the UX lane said so before you self-overrode it. Ship a visible pending state on the chip (label or badge) in this PR or split it as an immediate follow-up with the issue kept open.
  3. ChatInput.tsx:450-459: the "finishes in {{project}}" snapshot is client state seeded from projectProp; a reload mid-reply after a pick names the wrong directory. You acknowledged it. Expose the turn's start project from the server so the snapshot survives reload.
  4. chat_handlers.py:8882: the pick now blocks for the whole preparation window including a cold spawn; the chip shows nothing in flight, so a click during a cold start looks hung. Optimistic label or spinner.
  5. Body: "Not a goal: any backend change beyond the project route" is false, chat_runner.py is +67/-26. Fix the body.

iamwhatever's review is addressed in code but not re-reviewed; I will leave the dismissal to them. Holding at comment until 2 lands.

Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR unlocks the composer's project chip mid-turn so a pick stages for the next turn, and the backend side is now sound. The race from my last review is fixed. api_chat_slot_project takes slot._lock and then _slot_switch_session_lock(session_key), the same order the other switch handlers use, and re-checks the slot after the second await. All 9 _require_current_binding() calls before _release_dispatch_lock() (chat_runner.py:10649-10908) run under that lock. After the release, the turn reads only the _turn_project snapshot (:11052, overridden by client.cwd while a deferred reset stays armed). I found no remaining live slot.project read in the turn. The three in-turn agent-swap re-checks leave out only the project field. test_pick_waits_for_a_preparing_turn and the mid-turn runner tests fail under the mutations the description lists. Lanes all PASS on dfc12e56 (UX by owner override), and the #7263 scope decision is now recorded by CrysisDeu. What blocks approval is the follow-up work CrysisDeu listed on this head, which I agree with. Please open a GitHub issue for each item below and link them in the PR description. (a) A visible pending state on the chip ("will switch to X after this turn"). A tooltip cannot be discovered on touch, and #7263 must stay open for it. (b) website/src/components/ChatInput.tsx:450-459: turnStartProject is client state, so reloading mid-reply after a pick names the wrong directory. The server should expose the turn's start project. (c) chat_handlers.py:8880-8882: the pick now waits for the whole preparation window, a cold spawn included, with no in-flight indicator. One fix in this PR: the frozen "Not a goal" line ("Any backend change beyond the project route…") is false, given chat_runner.py +67/-26. Correct it to name the turn-snapshot changes. — crew-pr-reviewer (deep re-check)

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]:

Addressed the follow-up requests in iamwhatever's review:

The human review explicitly requested correcting the frozen Not-a-goal line. That line now names the project-route preparation lock AND the runner's turn-project snapshots, including prompt/skill roots, activity/crew logs, provider switches, deferred-reset reuse, and heartbeats. The Goal and Why it matters text are unchanged.

Rebased onto eaad034 at head 3c18e76. Range-diff retains both commits and shows only the two upstream context changes in the runner and selector export test. No new feature scope was added. The existing heartbeat naming fix remains in place.

Validation: 1,507 related backend tests and 60 related frontend tests pass; frontend build, formatting, lint, type, comment-history, brand and determinism checks pass. The broad local gate selected 43,062 tests: 42,885 passed, 107 skipped, 70 failed. All 70 failing test IDs were rerun on both the clean eaad034 base and this head; both runs failed the same 70 IDs, with no head-only failure. This is a local baseline limitation, not a claim that the broad gate passed. New-head CI is running.

Re-requesting review without dismissing any review. Auto-merge remains off.

@buluoray

buluoray commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

/ai-review override ux 3c18e76: agent: 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]: Ray authorized retaining the project-only first slice and deferring the same visible-pending-state and wording concerns to the reviewer-requested follow-ups, led by #20350; #7263 remains open.

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]:

This disposition covers only the UX verdict's discoverability/copy findings, not any security or correctness finding. The requested visible pending state is tracked in #20350, reload-stable project text in #20352, and preparation-wait feedback in #20351. Those issues are linked in the PR description as requested by the human reviewer. No code or screenshots were changed to clear this lane.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray marked the ux AI finding as false positive, not applicable, or explicitly accepted for 3c18e76b92376922a522a3f292379d959a3a3e6b.

agent: 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]: Ray authorized retaining the project-only first slice and deferring the same visible-pending-state and wording concerns to the reviewer-requested follow-ups, led by #20350; #7263 remains open.

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

The project route now takes slot_switch_session_lock after slot._lock,
the lock a turn's dispatch holds from its binding capture to its session
registration. A pick made in the first moments of a reply no longer fails
that reply with 'conversation binding changed during preparation'.

After the lock is released the runner reads the turn's own project
snapshot for the prompt context, the member activity record and the crew
log cwd, and resolves @prompt and $skill expansion against the same
snapshot, so a pick that lands mid-reply cannot hand the running prompt
another project's steering, prompts and skills.

A provider agent switch in the running reply compares every binding
field except the staged project and records the switch under the turn's
project, so a mid-turn pick no longer aborts the swap.

The heartbeat project reads the same snapshot.

The mid-turn chip tooltip names the project the running reply started in
and says on its own line that the reply's links open in the picked
project, since the dashboard reads slot.project live.
@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override ux dbf7a0f: agent: 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]: Ray authorized retaining this project-only slice and deferring the same pending-state and copy concerns to #20350, #20351 and #20352; this rebase preserves the previously accepted behavior and #7263 remains open.

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]:

Rebased onto 78d2ae3 at dbf7a0f. The prior head passed CI but gained a merge conflict when #20333 split the chat handlers. That was not merge-ready.

Conflict resolution retains the upstream facade and moves the existing patch to chat_api/agent_switch.py and chat_api/session_relaunch.py. Both affected functions have ASTs identical to the prior head. Every other file retains exactly the same added/deleted patch lines; range-diff shows only the file move and upstream context. The heartbeat snapshot fix remains.

Validation: 1,711 related backend tests (including handler composition and running-state census), 60 related frontend tests, frontend build, formatting, encoding, import order, lint, mypy, comment-history, brand and determinism ratchet pass. The first frontend invocation used the wrong working directory; rerunning in website passed. The broader local-gate selection was inspected but not rerun in this rebase; no full-suite pass is claimed.

The previous head-scoped UX override no longer applies. This renews only the same previously accepted discoverability/copy ruling, not any security or correctness finding. New-head CI remains in flight. No auto-merge, approval or review dismissal.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray marked the ux AI finding as false positive, not applicable, or explicitly accepted for dbf7a0fad1b5bac66ccda8a9542d74dc44567e30.

agent: 🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]: Ray authorized retaining this project-only slice and deferring the same pending-state and copy concerns to #20350, #20351 and #20352; this rebase preserves the previously accepted behavior and #7263 remains open.

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

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]:

Design PASS follow-up, head dbf7a0f: checked the link-window question. The frozen Not-a-goal explicitly excludes pinning the side panel or current reply links to the start-of-turn project. The owning spec and shipped tooltip both state that links follow the selected project. Keeping that behavior preserves this slice rather than silently promising per-reply link roots; no scope change or code push is needed.

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#38930179]:

First Principles PASS follow-up, head dbf7a0f: checked all three binding slices against the implementation. _current_binding() returns (agent, project, workspace, memory_store, history-assignment, effective-session-key, agent-kind), so project is index 1. The two comparison slices omit only project; the provider-switch reconstruction preserves selected_binding[1:2] and adopts the other newly read fields.

The existing test_project_pick_during_a_provider_switch_is_staged_not_fatal uses distinct starting/picked directories, asserts that the switch succeeds, records the starting project and checks the next turn uses the picked directory. That test passed in this rebase batch. This is source inspection plus the unchanged regression test, not a new tuple-reordering mutation proof. No current correctness defect or extra code change is claimed.

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at dbf7a0f.

The items from my last review are done. The three follow-ups each have an open issue linked in the description: #20350 (visible pending state), #20352 (reload-stable running-reply project) and #20351 (in-flight feedback during preparation), and #7263 stays open for model and crew. The Not-a-goal line now names the runner's turn-project snapshot.

The backend change is still sound after the rebase onto the split handlers. api_chat_slot_project takes slot._lock and then the session lock and re-checks the slot after each await (session_relaunch.py:667-683). _turn_project is taken once the dispatch lock is released (chat_runner.py:11291), before any cadence or heartbeat closure can read it, and the [:1] + [2:] slices match project at index 1 of _current_binding (L10734-L10742). The current-head Design and First Principles punchlines have replies, UX has an owner override for this head, Opus and GPT report no findings, and every check on this head is green. I read CI and the test source; I did not run tests locally.

Non-blocking: the description still places api_chat_slot_project in chat_handlers.py; it now lives in chat_api/session_relaunch.py.

— crew-pr-reviewer (r101)

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.

3 participants