Repository navigation
fix(kas): make the Auto-Improvement agent runner wait for the kiro-cli floor verdict - #22784
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change adds a thread-side entry point to the existing bounded floor wait. It returns at once when nothing is armed or when the caller is on the arming loop, so it can only add a short, bounded delay. [DESIGN-REVIEWED] 3f04fb2 Description read[DESCRIPTION-READ] e3ceb679fe04dcb1c455763763a8c33b95e7b99e7b573f30dfc8eb56af7fa325 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 Nothing blocks: the one off-loop spawn path that #22376's gate misses now waits for the verdict, using the existing bounded wait. The defect is tracked as #22414, and a test added here fails on base. What this change shipsInventory (3 items) — 3 justifiedIntent: on an old kiro-cli with no backend chosen, an Auto-Improvement agent step that starts right after a gateway restart should run on kiro-cli instead of failing. FIX.
[FIRST-PRINCIPLES-REVIEWED] 3f04fb2 Description read[DESCRIPTION-READ] 1879db4c68168f3fad749a2692e29eaac578d72a396bd964c63a120fe654c8b9 That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
7322ba0 to
3f04fb2
Compare
|
self-added: yes
|
|
|
Review-ready on 3f04fb2.
Only a maintainer approval remains. This crew did not merge, approve or enable auto-merge. |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: bug fix; an Auto-Improvement agent step on its own thread now waits, bounded, for the kiro-cli floor verdict before resolving its backend, with tests for the wait, the no-gate case and the on-loop case. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/slack-gateway.md.
Problem / Motivation
Goal: On a too-old kiro-cli with no backend chosen, an Auto-Improvement agent step started right after a gateway start runs on kiro-cli instead of failing.
#22376 made every gateway-loop spawn wait for the kiro-cli floor verdict when KAS is the default. The Auto-Improvement
SessionAgentRunnerbuilds its provider withcfg.create_provider_factory()and runs it withasyncio.runon a worker thread. That is a separate event loop, so the gateway-bound gate never holds it. A run resumed right after a restart can start KAS on a kiro-cli that rejects--agent-engine, and that agent step fails once.Why it matters
Auto-Improvement resumes its run after an in-place restart, so on an old kiro-cli with no backend chosen, an agent step started in the first seconds after each restart fails instead of running.
Not a goal
kirocrew chat,kirocrew serve, eval): nothing arms the gate there.What changed (motivation → approach → change)
The runner picks its backend in the provider factory, on its own thread, before the floor's verdict can move the backend off KAS.
So the runner now waits for the verdict from its thread.
kas_floor_wait.wait_kas_floor_verdict_blocking()runs the existing bounded wait (await_kas_floor_verdict) on the loop that armed the gate, withasyncio.run_coroutine_threadsafe, and blocks the calling thread until it returns. It returns at once when nothing is armed, when that loop is not running, or when the caller is on that loop (blocking there would stall the verdict).SessionAgentRunner.runcalls it first, before it loads its config and builds the provider factory: that load resolves the unset backend, so it must run after the verdict. Reusing the one wait keeps the same deadline, role and release rules.Other off-loop spawn paths: none found. The crew-member runner (
MemberSessionRunner) hands its work to the gateway loop and gets its provider fromSessionManager.get_or_create, which is already gated. The othercreate_provider_factory/build_provider_factorycallers are the gatewaySessionManager(gated) or run in processes where nothing arms the gate.agent_sdk/kas_floor_wait.pywait_kas_floor_verdict_blocking: the thread-side waitapps/builtins/auto_improvement/spine/agent_runner.pydocs/system-specs/modules/slack-gateway.mdBackwards compatibility
Compatible: with nothing armed (an explicit backend, the bundle route, any non-gateway process) the new call returns at once, so the runner starts exactly as before.
Removes nothing: the change only adds a bounded wait.
Tests
test/test_kas_cli_floor.py,TestOffLoopRunnerWaitsForTheFloor:test_an_agent_runner_step_before_the_verdict_lands_on_kiro_cli: the gateway loop holds the verdict on an old kiro-cli; aSessionAgentRunner.runon its own thread is held at the gate, then resolves its backend and builds its provider on kiro-cli. It fails with the call removed, and with the call placed after the config load (the factory keeps KAS).test_no_armed_gate_costs_the_runner_no_waitandtest_a_caller_on_the_arming_loop_is_never_blocked: the two return-at-once cases.The verdict and the thread's progress are loop futures; no test sleeps or uses a short fixed timeout. Determinism: all 57 tests in
test/test_kas_cli_floor.pypassed 20 of 20 runs, each in a shuffled order (shufover the collected node ids).test_wait_discipline_ratchet.pyandtest_flake_pattern_ratchet.pypass.Manual verification
N/A — unit coverage sufficient: the race is driven deterministically with a held verdict and a real runner thread; this host's kiro-cli 2.32.0 already supports
--agent-engine, so the old-binary case cannot be reproduced by hand here.Related Issues
Closes #22414
Pattern harvest
Rule candidate: review-prompt
Pattern: a gate bound to one event loop silently misses work that runs
asyncio.runon its own thread; such a gate needs a thread-side entry point.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)