Skip to content

fix(kas): make a defaulted-KAS spawn wait for the kiro-cli floor verdict - #22376

Merged
bolichen97 merged 1 commit into
mainfrom
fix/20469-kas-floor-wait
Oct 21, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/20469-kas-floor-wait

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On a too-old kiro-cli with no backend chosen, the first chat after a gateway start runs on kiro-cli instead of failing.

With no agent.acp_backend stored, the backend defaults to KAS (#20359). The kiro-cli floor check (_start_kas_cli_floor) runs in the background with a 15 s acp --help probe. Until it lands, the backend stays kas. A session created in that window (a quick first dashboard chat, a Slack message queued at boot, an overdue cron, the warm pool or the background session) spawns with --agent-engine, which an old kiro-cli rejects. The user sees one failed turn. The floor's log notice also says "KAS is selected" to a user who never chose it.

Why it matters

The KAS default is new, so every user on an older kiro-cli hits this on the first turn after each restart. It looks like Kiro Crew is broken right at the start.

Not a goal

  • Moving the floor probe onto the boot path. Boot still never waits for it.
  • Changing what the floor decides, or the explicit-kas behavior. A user who chose KAS keeps today's timing.
  • A retry-after-failure fallback.

What changed (motivation → approach → change)

A spawn that runs before the floor's verdict picks KAS, because the verdict has not moved the backend yet. Crew-member DMs hit the same race: agent.member_acp_backend also defaults to KAS.

So the spawn waits for the verdict first, but only when its own KAS is a default. When the gateway schedules the floor, it arms a small gate (kas_floor_wait) per role whose resolved backend is KAS, from in-memory config only, so boot reads no file. The floor's background task first reads, off the loop, which roles the user chose (agent.acp_backend, agent.member_acp_backend) and releases those at once; a chosen KAS never waits for the probe. Defaulted roles wait for the verdict. The cold-start path in get_or_create (member role for a member DM key, main otherwise), the warm-pool fill, the background session (both get_bg_session, which background one-liners use, and the persistent start) and the task-run runtime bootstrap (companions.py) await that gate before they pick a backend. A kiro-cli spawn whose role is not armed never waits. The factory then reads whatever the verdict decided. The wait is bounded by the probe's own 15 s timeout, counted from when the gate was armed. It returns at once when nothing is armed, the verdict already landed, or the deadline passed. A failed or timed-out check leaves the backend as configured, as the floor already does.

The floor notice says "KAS is the default backend, but ..." when no KAS role was chosen, and keeps "KAS is selected, but ..." otherwise. It takes that answer from the same off-loop read, so the files are read once.

Part Job
agent_sdk/kas_floor_wait.py the gate: arm, per-role release, bounded await
docs/system-specs/modules/slack-gateway.md, docs/system-specs/modules/session.md the floor-gate contract
slack/gateway_runtime/process_entry.py, slack/gateway.py arm the gate per defaulted role
config/loader_document.py, config/loader.py member_acp_backend_declared()
session_allocation_parts/get_or_create.py, session_allocation_parts/companions.py, session_pool.py, session_background.py await the gate before the factory
platform/bootstrap.py the default-backend notice wording

Backwards compatibility

Compatible: an explicit backend choice, the bundle route, test_mode and non-gateway processes arm no gate, so they spawn exactly as before.

Removes nothing: the change only adds a bounded wait and a second notice wording.

Tests

test/test_kas_cli_floor.py:

  • test_spawn_before_the_verdict_waits_and_lands_on_kiro_cli: the floor reports an old kiro-cli; a chat spawn started before the verdict waits, then lands on kiro-cli. Red without the gate (the spawn picks KAS).
  • test_member_dm_on_a_defaulted_member_backend_waits_and_main_does_not: with kiro stored and the member backend defaulted, a member DM waits and lands on kiro-cli; a main chat does not wait.
  • test_a_task_run_started_before_the_verdict_lands_on_kiro_cli: the task-run bootstrap waits at the gate, then picks kiro-cli.
  • test_shared_runtime_waits_before_backend_selection: a background one-liner made before the verdict waits outside the runtime lock, then starts on kiro-cli.
  • test_explicit_kas_does_not_wait (main and member): a stored kas spawns while the probe is still blocked; the defaulted role keeps waiting.
  • test_declaration_documents_are_read_only_off_loop: boot returns before any config-document read, and the reads run off the loop thread.
  • release and failure tests: releasing one role keeps the deadline and the other role; another floor cannot release this gate; a failed or cancelled verdict releases every waiter.
  • test_a_landed_verdict_costs_no_wait and test_the_wait_is_bounded_by_the_probe_timeout: no wait after the verdict or past the deadline; the bound equals the probe timeout.
  • TestDefaultNoticeWording: both notice wordings.

The verdict is a controllable event or future; no test sleeps or uses a short fixed timeout (test_wait_discipline_ratchet.py passes). TestGatewayBootDoesNotWaitForTheFloor still passes. Determinism: test/test_kas_cli_floor.py passed 20 serial runs, 10 four-worker runs and shuffled orderings.

Manual verification

N/A — unit coverage sufficient: the race is driven deterministically with a held floor verdict, and the real probe path is already covered by the existing floor tests.

Related Issues

Closes #20469

Pattern harvest

Not generalizable: the race is specific to one background check that changes a resolved default after boot.

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 20, 2026 02:54
@iamwhatever
iamwhatever requested a review from CrysisDeu October 20, 2026 02:54
@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from 85fc46c to 11289db Compare October 20, 2026 03:12
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/slack/gateway.py since this head went green (17404da -> b42f19b); CI re-running. The earlier review lanes failed on a GitHub API rate limit (HTTP 403), not on the code.

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

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision d1170cc3a483d46015f60fe2505577a4840416c2 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 20, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns. The gate only arms when KAS is the default and is never declared. Its wait is capped by the probe's own timeout, and boot and explicit choices keep today's timing.

Notes

  • kas_floor_wait._armed is module-global state that every spawn path must remember to await. A future spawn path that skips await_kas_floor_verdict reopens the race without any error. One await inside the provider factory seam would close that, if the factory ever becomes async.

[DESIGN-REVIEWED] d1170cc

Description read

[DESCRIPTION-READ] 6bbdd4ea733a1d223f1e5b056d9a7f08cc8e5e5161edf74cde6888d3dff1aafe

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of d1170cc3a483d46015f60fe2505577a4840416c2 — 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

Every item fixes the race reported in #20469, which test_spawn_before_the_verdict_waits_and_lands_on_kiro_cli reproduces on base. The notice rewording is a declared rider with no premise risk.

What this change ships

Inventory (7 items) — 6 justified

Intent: on an old kiro-cli where nobody chose a backend, the first chat after a restart runs on kiro-cli instead of failing. This is a FIX.

  1. A chat, member DM, warm-pool fill, background session or task run that starts before the floor verdict now waits for it, up to 15 s, when its KAS is only the default — justified
  2. A role whose KAS the user chose is let through as soon as the off-loop read of what the user chose finishes, without waiting for the probe — justified
  3. Crew-member DMs wait only when the member backend is defaulted, and main chats only when the main backend is — justified
  4. The floor warning now says "KAS is the default backend, but …" when KAS was never chosen — rides along
  5. New member_acp_backend_declared() config helper, with 1 consumer (process_entry._kas_floor_gates_spawns) — justified
  6. New kas_defaulted keyword on apply_kas_cli_floor, with 1 non-test caller that passes a computed value — justified
  7. The floor-gate contract is added to the session and slack-gateway specs — justified

[FIRST-PRINCIPLES-REVIEWED] d1170cc

Description read

[DESCRIPTION-READ] 6c2ead58362e403f9053226c37b74e08c6db11f4a6a31ef9da215c81a66929e3

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d1170cc

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

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

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d1170cc

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

@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from 11289db to 4896368 Compare October 20, 2026 03:31
@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=da43228d7395 fixed: the task-run spawn path has no gate

fixed in 4896368: _get_or_bootstrap_run_runtime (session_allocation_parts/companions.py) awaits await_kas_floor_verdict(member=is_member_session_key(parent_session_key)) before the provider factory.
test: TestTaskRunBootstrapWaitsForTheFloor::test_a_task_run_started_before_the_verdict_lands_on_kiro_cli holds the verdict, asserts the factory is not reached, then lands on kiro-cli; it fails with the await removed.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=e27429010476 rebutted: put the await inside the one factory wrapper

the provider factory is synchronous (create_provider_factory._acp) and the issue asks for the wait on the async spawn path, not the sync factory; awaiting inside it is not possible without blocking the loop.
each caller awaits at its own point on purpose: the warm-pool fill outside _pool_fill_lock, the background session before _start_sem, get_or_create before its start permit, so no lock or start permit is held during the wait. One shared seam would sit before all of those and hold them.
the four async factory callers that start a fresh provider are all gated on 4896368.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=f0d1745ecb0c fixed: the task-run bootstrap was not gated

fixed in 4896368: companions.py awaits the gate before its factory call, and test_a_task_run_started_before_the_verdict_lands_on_kiro_cli shows a task-run bootstrap before the verdict lands on kiro-cli.

@iamwhatever

iamwhatever commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=9bafb34e471b rebutted: the gateway re-export of _kas_floor_gates_spawns has a reader

gateway_runtime owner functions run on the kiro_crew.slack.gateway module globals (_facade_compose.compose; see gateway_runtime/init.py), so _start_kas_cli_floor resolves _kas_floor_gates_spawns from the gateway namespace.
checked: gateway._start_kas_cli_floor.__globals__ is vars(gateway) is True and the name is in its co_names; without the re-export the call raises NameError, which test_slack_gateway_composition_contract.py sweeps for.

@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 20, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • confirmed: every boot-window spawn goes through a gated factory call

gateway-process factory calls that start a fresh provider: get_or_create cold start, warm-pool fill, background-session ensure, task-run bootstrap (companions.py). All four await the gate on this head.
the background recycle spawn (session_background.py replacement) runs only after the background session it replaces already started through the gated ensure path, so the verdict has landed or its deadline has passed by then.
subagent runtimes are spawned from a turn of a session that itself started through a gated path. Other factory users (cli_chat, cli_server, eval) run outside the gateway, where nothing is armed.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • confirmed: the recycle spawn needs no gate

the background recycle spawn (session_background.py replacement) only replaces a background session that started through the gated ensure path and has served prompts, so the floor verdict has landed or the wait deadline has passed before it can run. Gating it would add a check that never waits.
the four gated sites (get_or_create, warm pool, background ensure, task-run bootstrap) are every gateway-process factory call that can run at boot.

@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 labels Oct 20, 2026
@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from 4896368 to f2c9d6a Compare October 20, 2026 04:42
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 20, 2026
@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from f2c9d6a to 4c3728d Compare October 20, 2026 05:21
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: boot-time declared-check for the floor gate

  • span=bffbc26c32dd fixed: uncached document reads block gateway startup

fixed in 4c3728d: _start_kas_cli_floor arms the gate from in-memory backend fields only; the declared-check (acp_backend_declared / member_acp_backend_declared) runs inside the floor task via asyncio.to_thread, before the probe, and releases explicitly chosen roles there.
test: test_declaration_documents_are_read_only_off_loop asserts boot returns before any config-document read and that the reads run off the loop thread; test_explicit_kas_does_not_wait (main and member) shows a chosen KAS goes ahead while the probe is still blocked.

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 20, 2026
@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from d643f96 to bdc9a33 Compare October 21, 2026 07:16
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: class autouse reset of the floor gate

  • span=d03cc91d7d22 fixed: keep the autouse reset on the fixture-owned patch stack

fixed in bdc9a33: the class autouse fixture _disarm requests _floor_monkeypatch and resets kas_floor_wait._armed through it, so a test that calls monkeypatch.undo() cannot lift it.
the diff-scoped semgrep rule semgrep.kirocrew.test-autouse-shared-monkeypatch reports 0 findings on bdc9a33.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: notice-wording declared-check

  • span=bb24836e1697 fixed: the floor read the backend declarations twice

fixed in bdc9a33: _kas_was_chosen is removed; apply_kas_cli_floor(cfg, *, kas_defaulted=False) takes the wording from the single off-loop read _kas_floor_gates_spawns already makes in the floor task.
known edge, kept: the loader reports an unreadable or malformed config document as undeclared (_raw_agent_section returns None: 'a corrupt config is not a declaration'), so the notice then says 'KAS is the default backend'. It only changes log wording, never the backend, wait or fallback. Telling unreadable apart from absent would need a new tri-state loader API, outside this fix.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • span=9e3ba52c2a33 rebutted: _backend_choice_declared in the loader forwarded-name list

required by the facade guard: removing it fails test_every_mirrored_facade_manifest_names_what_it_forwards (test/test_facade_mirror_guards.py), which needs kiro_crew.config.loader to list every name its owner modules define.
it is a TYPE_CHECKING import only; it adds no runtime path and no public API.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • answered: the manual run on a real pre-agent-engine kiro-cli

not runnable here: this host has kiro-cli 2.32.0, which already lists --agent-engine in acp --help.
the same race is driven deterministically in test/test_kas_cli_floor.py: a real apply_kas_cli_floor on an old-help kiro-cli, verdict held, a dashboard chat, member DM and task-run spawn each wait and then land on kiro-cli. A maintainer with an older kiro-cli can confirm by starting the gateway with no agent.acp_backend stored and sending one dashboard chat.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/20469-kas-floor-wait branch from bdc9a33 to ba13b2a Compare October 21, 2026 08:11
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=95ff99ff15ec fixed: the background wait missed the shared-runtime path

fixed in ba13b2a: get_bg_session awaits await_kas_floor_verdict() (main role) before _bg_backend_supports_runtime() picks the shared-runtime or provider path, outside _bg_runtime_lock and start admission; the persistent-start wait stays.
test: TestSharedBackgroundWaitsForTheFloor::test_shared_runtime_waits_before_backend_selection holds the verdict, asserts backend selection and AcpRuntime are not reached and the lock is free, then lands on kiro-cli; it fails with the await removed.

@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 labels Oct 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

CI status on ba13b2a:

All review findings on this head are answered; GPT and Opus report no findings, and Design and First Principles pass.

@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/20469-kas-floor-wait branch from ba13b2a to d1170cc Compare October 21, 2026 10:39
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto the #22697 fix: main now carries #22717, which keeps backend-only test shards running (ba13b2a -> d1170cc, base ef0ec3d). Related tests pass locally on the new head; CI re-running.

@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 d1170cc.

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

@bolichen97 bolichen97 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.

Approving on d1170cc. The floor wait is bounded, never cancels the floor task, and sits outside the session lock, cold-start permit and pool fill lock. The held-verdict tests drive the race without sleeps. The ungated Auto-Improvement path is tracked in #22414.

@bolichen97
bolichen97 merged commit 5329769 into main Oct 21, 2026
107 of 108 checks passed
@bolichen97
bolichen97 deleted the fix/20469-kas-floor-wait branch October 21, 2026 13:31
@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.

KAS default: first spawn races the kiro-cli floor check on a too-old kiro-cli

2 participants