Skip to content

fix(kas): make the Auto-Improvement agent runner wait for the kiro-cli floor verdict - #22784

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/22414-runner-floor-wait
Oct 21, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/22414-runner-floor-wait

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

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 SessionAgentRunner builds its provider with cfg.create_provider_factory() and runs it with asyncio.run on 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

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, with asyncio.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.run calls 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 from SessionManager.get_or_create, which is already gated. The other create_provider_factory / build_provider_factory callers are the gateway SessionManager (gated) or run in processes where nothing arms the gate.

Part Job
agent_sdk/kas_floor_wait.py wait_kas_floor_verdict_blocking: the thread-side wait
apps/builtins/auto_improvement/spine/agent_runner.py call it before building the provider
docs/system-specs/modules/slack-gateway.md the floor-gate contract names the off-loop caller

Backwards 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; a SessionAgentRunner.run on 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_wait and test_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.py passed 20 of 20 runs, each in a shuffled order (shuf over the collected node ids). test_wait_discipline_ratchet.py and test_flake_pattern_ratchet.py pass.

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.run on its own thread; such a gate needs a thread-side entry point.

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

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 21, 2026 14:18
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 3f04fb2f04e6c0007fe5977162ecb513bd91fb95 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 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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 .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 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 3f04fb2f04e6c0007fe5977162ecb513bd91fb95 — 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: 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 ships

Inventory (3 items) — 3 justified

Intent: 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.

  1. An Auto-Improvement agent step started before the floor verdict now waits for it (bounded), then runs on kiro-cli instead of failing on KAS — justified
  2. A new public function, wait_kas_floor_verdict_blocking, lets code on another thread wait for the gateway's floor gate; it has one real consumer, SessionAgentRunner.run — justified
  3. The floor-gate contract in the slack-gateway spec now names the off-loop caller — justified

[FIRST-PRINCIPLES-REVIEWED] 3f04fb2

Description read

[DESCRIPTION-READ] 1879db4c68168f3fad749a2692e29eaac578d72a396bd964c63a120fe654c8b9

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 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 3f04fb2

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

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3f04fb2

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

@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 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/22414-runner-floor-wait branch from 7322ba0 to 3f04fb2 Compare October 21, 2026 14:37
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: member role on the thread-side wait

  • fixed: the new member parameter has no caller that sets it

removed in 3f04fb2: wait_kas_floor_verdict_blocking() takes no arguments and waits for the main role; the docstring says no off-loop caller runs a crew-member DM.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • acknowledged: nothing blocks

the change adds one thread-side entry into the existing bounded floor wait and removes nothing; no change needed for this verdict.

@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready on 3f04fb2.

  • PR Readiness passed (readiness: passed), mergeable, one commit on main. No check failed on this head.
  • GPT and Opus: no findings. Design and First Principles: PASS; each verdict has a disposition comment above.
  • Other off-loop spawn paths: none found (the crew-member runner goes through the gated get_or_create; the other provider-factory callers are gated or run where nothing arms the gate). Details in the PR body.
  • Known reds outside this PR: the repo-wide Dependency License Gate (dependency graph off), and the macOS ledger-sweep flaky test (Flaky: test_a_partial_snapshot_installed_inside_the_locked_write_stops_it fails on unraisable warnings leaked by test_ledger_sweep #22163) when it fires.

Only a maintainer approval remains. This crew did not merge, approve or enable auto-merge.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 21, 2026 17:02

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@KiroCrewCaptain
KiroCrewCaptain merged commit de76d26 into main Oct 21, 2026
105 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/22414-runner-floor-wait branch October 21, 2026 17:03
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 21, 2026
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.

Auto-Improvement agent runner can start KAS before the kiro-cli floor verdict

2 participants