Repository navigation
perf(acp): answer a re-opened chat without waiting for user MCP servers - #35739
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS The approach depends on undocumented engine behaviour measured on kiro-cli 3.2.1, but the cases it covers are gated on Notes
[DESIGN-REVIEWED] 99c06f0 Description read[DESCRIPTION-READ] b58ccb12bd1a9e1474dddd946e81a0cde672f197305c60c10d40be31df238081 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One rider goes beyond the Goal. It is reversible and it is declared in Backwards compatibility, so it stays a note. Every other item is backed by a measured cost and reuses the start agent that Not checked: whether KAS 0.66.102 really ignores the mode named on a Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: a re-opened chat answers its first message without waiting for the user's own MCP servers. This is an ADDITION (perf).
[FIRST-PRINCIPLES-REVIEWED] 99c06f0 Description read[DESCRIPTION-READ] 82193884c8d73e87572c0150d34bd42390dfeedeff47e7b29cfa259e0c86c4a4 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
6a43634 to
963821c
Compare
0c90a6f to
5616321
Compare
5616321 to
1d308b6
Compare
|
|
963821c to
68b7979
Compare
68b7979 to
fc01a45
Compare
Sensitive Change Review
|
1d308b6 to
a623f41
Compare
9f84207 to
cbf1445
Compare
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own. Approve. When someone is waiting on a re-opened KAS chat (a FOREGROUND claim or the owner refocusing it), the session is first parked in the server-less start agent with three requests (load, set mode, release), so Kiro Crew's MCP servers connect ahead of the user's. Parking is limited to the KAS branch, to that case and to engines that can release a session; every other resume still sends one load, and tests cover each exclusion. Recovery from a cut-off re-open is covered by a table of nine resume states, each run with and without a named agent. An engine refusal holds nothing; a failed parking step falls back to a fresh session with history replay. Specs and the user doc are updated in the same commit. The new switch for a session that comes back in an undefined mode when the caller names no agent is declared in Backwards compatibility. Remaining concerns are edge cases, not blockers: a session id stays marked held after an unconfirmed release, and a cancelled refocus prefetch relies on the engine handling the release after the in-flight load. Backend test shards, E2E and desktop builds were still pending at decision time; the three verdict-issuing AI review lanes passed. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
cbf1445 to
b62c100
Compare
A new chat already starts in a server-less start agent, so Kiro Crew's own MCP servers connect first and the first prompt does not wait for the user's. A re-opened chat did not: the engine resumes a session in the mode it stored, its own agent, so that agent's servers queued ahead of Kiro Crew's and the first prompt waited behind all of them. A re-open a person is waiting on now parks the stored session in the start agent first (a load with nothing to start, a mode switch, a release), then loads it as before. The load resumes in the start agent, Kiro Crew's servers connect first, and the switch to the session's own agent queues the user's servers behind them. The first prompt is then held for Kiro Crew's servers only, as on a new chat. Only a session stored in its own agent is parked: one that was switched to another agent is left in it and loaded as every other resume. One predicate decides both, mcp_start_wait.person_waits: a start that claimed FOREGROUND, or the dashboard owner's return to a saved chat (the focus resume prefetch, which keeps its BACKGROUND place in the start queues). Every other resume sends the one load it always sent and keeps its wait. A re-open cut off between the two steps leaves the start agent as the stored mode, so every load on this engine registers the start agent. A load whose caller named no agent switches the session to its own agent when the engine brought it back in the start agent, or in a mode the load sent no definition for (the engine's default, where a stored start agent resumes when the batch does not carry it), and is refused when that agent is not advertised. A session the engine or another client left in one of the engine's built-in agents is put back the same way: the engine answers that load as it answers the first, and Kiro Crew itself offers no way into a built-in. The step runs only on an engine that can free a session and keep its record. The parking step's switch to the start agent is the one session/set_mode sent outside the bracketed activation helper: the start agent is Kiro Crew's own entry, with no spec to load, and a failed switch there keeps the re-open's old order where the helper would end the session. The pin test names that one exception and holds it to the start agent's id.
b62c100 to
99c06f0
Compare
buluoray
left a comment
There was a problem hiding this comment.
Approve on 99c06f0. This change makes a re-opened KAS chat answer its first message before the user's own MCP servers have connected, as a new chat and kiro-cli already do. Since the last review only tests changed. The shared load-test helper now expects the start agent in a load batch as well as in a new session, and checks that a load names no mode. The signature and source pins now carry the new focus_resume keyword, and the new parking test patches the pooled-stub hop through the runtime facade. Product code and docs are identical to the last reviewed head. I found no data loss and no security gap. The Code change approver asks for a person to decide, so the owner should make the call once the backend test shards on this head are green. Decisive lines: test/test_acp_runtime.py:197-208, test/test_chat_runner_base_surface.py:701,711,716, test/test_session_allocation_bindings.py:69,117, test/test_session_bindings.py:253, test/test_kas_reopen_parking.py:27,89
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved at the owner's request. The deep review of this head is still running, and anything it finds will be posted here as a follow-up.
Problem / Motivation
Goal: A chat that is re-opened answers its first message without waiting for the user's own MCP servers, as a new chat already does.
A new chat starts in a server-less start agent, so Kiro Crew's own MCP servers connect first and the first prompt is not held for the user's. A re-opened chat (a saved session loaded again, for example after a restart) did not get that. The engine resumes a session in the mode it stored, which is the session's own agent, so that agent's servers queue ahead of Kiro Crew's. The first prompt then waits for Kiro Crew's servers, which are last in the queue, and so in practice for every server the user has.
Measured with 30 MCP servers (n=3, kiro-cli 3.2.1, KAS 0.66.102): a re-opened chat's first token came after 22.4 s, and 15.8 s of that was the session load. Kiro CLI on the same servers answered in 6.8 s.
Why it matters
Every chat that is re-opened pays it: after a restart or an update, and for a chat whose session was put away. With this change the same re-open answers in 9.7 s at 30 servers (12.7 s sooner) and in 10.2 s instead of 11.6 s at 10 servers.
Not a goal
session_reloadverb, a Bot's spec or harness change, the image repair, an app token's request, a cron run, a bulk Resume and a sub-agent. Each sends the one load it always sent and keeps its wait.BACKGROUNDplace in every start queue.session/loadis unchanged.What changed (motivation → approach → change)
A re-opened chat now answers its first message without waiting for the user's own MCP servers, because Kiro Crew's own servers connect first, as they do on a new chat.
Why this shape:
session/loadignores a mode named on it and resumes in the mode it stored, but it does take the agent definitions re-sent with the load over the ones it kept. So the stored mode is the only lever.src/kiro_crew/acp/runtime_session_load.py,_park_in_start_agent). Before the load, three requests that start no server: asession/loadin which the session's own agent declares no server and the session sends none (src/kiro_crew/acp/kas_start_agent.py,parking_load), asession/set_modeto the start agent, and the release that frees that copy and keeps the record. Only a session stored in its own agent is parked; one that was switched to another agent is freed and left in it. The load that follows resumes in the start agent, queues Kiro Crew's servers alone, and the switch to the session's own agent queues the user's servers behind them.src/kiro_crew/acp/mcp_start_wait.py,person_waits). A person is waiting when the start claimedFOREGROUND, or when it is the dashboard owner's return to a saved chat: the focus resume prefetch, marked by its origin insrc/kiro_crew/dashboard/ws.pyand carried throughsrc/kiro_crew/dashboard/chat_turn/eager_spawn.py,src/kiro_crew/session_parts/claims.py,src/kiro_crew/session_allocation_parts/get_or_create.py,src/kiro_crew/providers/base.pyandsrc/kiro_crew/providers/acp_runtime_start.py. The same predicate decides the parking step and the first-prompt wait. A message typed while that prefetch is in flight joins it and is released when Kiro Crew's servers are ready. The servers the load skipped are left to the first turn, as on a new chat (left_to_first_turnreads the same predicate): its prompt names the ones still starting, or holds for them for at most 5 s.session/loadon this engine now registers the start agent (src/kiro_crew/acp/harness/kas.py), because a stored mode the batch does not carry resumes in the engine's own default mode;load_sessionswitches a session that came back in the start agent, or in a mode the load sent no definition for, to its own agent, whoever resumes it, and refuses the load when that agent is not advertised; and a parked copy the engine did not confirm freeing fails the re-open instead of loading over it (src/kiro_crew/acp/runtime_class.py,_parked_copies). A parking load the engine refused holds nothing, so the retry past a stale session lock still works. The session is parked only in the entry Kiro Crew appended, never in another entry that carries its id.changed)unchanged)unchanged, from the PR this follows)session/loadon another harness or an older engineunchanged)added)Legend: added, changed, removed, unchanged.
Specs updated in the same commit:
docs/system-specs/modules/acp-client.md,docs/system-specs/modules/session.md,docs/system-specs/modules/harness-parity.md,docs/system-specs/modules/learn-cron-dashboard.md(theslot_focusedparagraph spells the call),docs/architecture/mcp.md. User doc:src/kiro_crew/docs/troubleshooting.md(the section on a first message whose server tools are not there yet now names a re-opened chat too).Merge order: #35722 owns the first-prompt wait rule, the
[MCP SERVERS]block andmcp_server_wait, and has merged. This PR extends that one rule to a re-open.Backwards compatibility
Compatible:
load_session,_load_session_with_retry,get_or_create,schedule_eager_spawn,first_prompt_brief_waitand_wait_managed_mcpgain an optionalfocus_resumekeyword that defaults to the old behaviour, andLLMProvider.focus_resumedefaults toFalse.Changed on purpose: a
session/loadon this engine carries one more agent in its batch, the start agent, under the same refusals a new session applies (left out when the agent mounts the sub-agent tool or the batch is full). A person's first prompt after a re-open can go out before the user's servers have connected, as on a new chat. Asession/loadwhose caller names no agent, and that the engine brings back in a mode the load sent no definition for, is switched to the session's own agent, or refused when that agent is not advertised; before, such a session ran in the mode the engine brought it back in. A session the engine or another client left in one of the engine's built-in agents is put back in its own agent on such a re-open; Kiro Crew itself has no way to put a session in a built-in. A load the engine brings back in the session's own agent, or in another agent the batch carries, sends the requests it always sent.Removes nothing: no payload key, public function, validator or record is removed or renamed.
Tests
test/test_kas_reopen_parking.py(new): the predicate, for the start's wait and for what is left to the first turn; the parking step (load, set mode, free; a session already parked; a session switched to another agent, which is left in it; an engine that did not register the start agent; a refused mode switch; a load the engine refused, which holds nothing; a load with no readable answer, which may still be held; a copy that was not freed); a re-open after a typed message and after the owner's return parks first, waits for Kiro Crew's servers only, and leaves the user's servers to its first turn; a background resume, an engine without the release verb, an agent with no servers and another harness are not parked; a session left in the start agent ends in its own agent or is refused, whatever the next load's batch carries and whether or not its caller names an agent (a table of nine states, each for both callers: the start agent registered again; the agent lost its servers, gained the sub-agent tool, or its batch is full, so the engine brought the session back in its own default mode; another agent carrying the start agent's id; the session's own agent not advertised, which is refused; a session never parked and one running another agent of the batch, which a caller that names no agent leaves as stored); only the owner's focus frame marks a start as the owner's return (one site in the package).test/test_kas_start_agent.py: a load registers the start agent and names no mode; the parking load; a target the user named like the start agent is not parked in.test/test_eager_spawn_resume_prefetch.py,test/test_eager_spawn_slot_frames.py,test/test_session_resume_prefetch_join.py: the owner's return reaches the allocation and the provider, keeps itsBACKGROUNDplace, and a typed message joins that same session; a reload's respawn does not carry the mark.test/test_acp_runtime_load_session.py,test/test_acp_bindings.py,test/test_runtime_bindings.py,test/test_acp_runtime.py,test/test_chat_runner_base_surface.py,test/test_session_allocation_bindings.py,test/test_session_bindings.py: the existing pins, updated for the start agent on a load (the batch is the projection plus exactly that one entry, and a load names no mode) and the new keyword.test/test_worker_agent_load_bracket.py: the pin that everysession/set_modegoes through the one bracketed helper names the parking step as its one exception and holds it to the start agent's id.test_no_kiro_crew_entry_point_switches_a_running_sessionpins why a built-in a session was left in may be replaced: nothing in Kiro Crew switches a running session's mode.Determinism, on
1ab90c0097ad: the 92 new or changed tests passed 20 of 20 runs at-n0, 10 of 10 at-n 4 --dist loadgroupbeside two co-tenant files, and one shuffled order (seed 8027, at PSI under 1).Manual verification
The tests and checks of this push ran on
1ab90c0097ad, one commit onmainatddf8678ddf17. The pushed head,99c06f088c73, is that commit rebased with no change (git range-diffshows it equal) over four latermaincommits that touch none of its files; the docs lint and ten pin test files (1770 tests) passed again on it.Timed re-open (Linux, one gateway at a time; the gateway is stopped with its data kept and started again, then three prompts are sent on the same chat, typed with no focus frame). A 30-server gateway holds the shared run lock for its whole life. A run taken while memory pressure (
some avg10) was above 10 is left out and re-taken.Before is #35722 at
68b7979afe2c, after is this change (85a67a95a042) on it. Seven rebases followed: onto #35722's fix for more than 64 servers, five times onto its newer heads, and ontomainonce it had merged. None changed what this commit does for a 30-server re-open; the last push also changed how a cut-off re-open is resumed (above), which this timing does not exercise.30 servers. Seconds, median (each run). Engine: before KiroCLI/3.2.1 KAS/0.66.102; after KiroCLI/3.2.1 KAS/0.66.102; kiro-cli KiroCLI/3.2.1 KAS/0.66.102.
before: n=3, load 1m 11.3 to 17.8, PSI some avg10 0 to 0.54.
after: n=3, load 1m 11.3 to 17.1, PSI some avg10 0.24 to 1.16.
kiro-cli: n=3, load 1m 12.2 to 13.3, PSI some avg10 not recorded.
On the first heads this PR was measured on (#35722 at
9ae6ab2f35, this change on it). The Goal's numbers above are from these; the mechanism is the same, the base's own load got faster since:30 servers. Seconds, median (each run). Engine: before KiroCLI/3.2.1 KAS/0.66.102; after KiroCLI/3.2.1 KAS/0.66.102; kiro-cli KiroCLI/3.2.1 KAS/0.66.102.
before: n=3, load 1m 11.2 to 14.8, PSI some avg10 0.52 to 1.65.
after: n=3, load 1m 9.9 to 11.7, PSI some avg10 0.25 to 1.41.
kiro-cli: n=3, load 1m 12.2 to 13.3, PSI some avg10 not recorded.
10 servers. Seconds, median (each run). Engine: before KiroCLI/3.2.1 KAS/0.66.102; after KiroCLI/3.2.1 KAS/0.66.102 (not recorded for its first two runs, same install); kiro-cli KiroCLI/3.2.1 KAS/0.66.102.
before: n=3, load 1m 8.3 to 12, PSI some avg10 0.6 to 1.39.
after: n=5, load 1m 10.1 to 18.1, PSI some avg10 0.15 to 2.76.
kiro-cli: n=3, load 1m 7.1 to 8.2, PSI some avg10 0.11 to 1.47.
Left out: one after run (its three prompts), taken at PSI 73.21; that cell was re-taken in full.
A real re-open, end to end (Linux, kiro-cli 3.3.0, before is
mainat97b6c1d26607, which holds #35722, after is this commit,1ab90c0097ad; one fast server and eight servers that take 4 s each; one tool call, the gateway restarted on its data, then four more turns on the same chat):mcp_server_wait), then called it; no holdIn the focus column the times count from the focus frame, and the message was typed about 3 s after it. Across the earlier runs of this check the parking step took 559 to 773 ms; one run on an earlier head of #35722 took 1642 ms, with Kiro Crew's servers at 4.2 to 4.5 s, and a re-take there took 607 ms. Memory pressure (
some avg10) was under 2 at the start, at the re-open and at the end of each run. The parking step replays the stored turns once more, so it grows with the length of the chat. The Kiro CLI pick runs on the same engine path; it was run on an earlier head pair (6a43634e13aband this change on it) with the same verdicts and Kiro Crew's servers at 19.6 to 20.3 s before and 3.7 to 4.1 s after.Engine behaviour this rests on (kiro-cli 3.2.0 and 3.2.1, driven directly): a load ignores a mode named on it; it takes the agent definitions re-sent with it; a stored mode the batch does not carry resumes in the engine's default mode; the release of a session the engine does not hold answers success.
MCP smoke test (cases 1, 2, 8 and 12, Linux, before and after, both harness picks): before is commit
fc01a4588a25, after is this change ata623f41ba046on it, kiro-cli 3.2.1, engine 3.2.1. That is six rebases before the pushed head. The rebases after it changed no source logic of this commit; the pushed head's fix for a cut-off re-open changes only a load whose caller names no agent and that the engine brings back in a mode the load sent no definition for, which no case of this script does.Case 8 of that script closes a chat and opens a new one of the same name, which starts a new session; the table above this one is the same proof for a stored session that is loaded again. Cases 3 to 7 and 9 to 11 were not run for this change, which touches only a re-open; #35722 carries them. macOS and Windows were not run.
Related Issues
Part of #35261
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.