Repository navigation
fix(session): check the Kiro account before every session acquire - #19752
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The 60-second recorded-result path is a second sharing mechanism. It sits on top of in-flight sharing and adds clock, run-tracking and holder-guard state. No measured cost backs it. Notes
What this change shipsInventory (10 items) — 9 justifiedIntent: after a Kiro account switch or logout, make sure no unattended turn reuses a session still signed in as the old account (#3390, #19651). This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] bf6b2e1 Description read[DESCRIPTION-READ] fe583a56bfca5ea08a08cd84a033e9de931a46a2b89b5b0f0a0e20499fa108a2 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: moving the check into the session manager's acquire wrapper is what #19651 asked for, and every Notes
[DESIGN-REVIEWED] bf6b2e1 Description read[DESCRIPTION-READ] 235ce4ee9e590d46b73d7d68ac2cb5ba4e1b094f9c580b6543235748aeca10b9 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
2e96113 to
8b1d57b
Compare
8b1d57b to
75319d8
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
This PR moves the Kiro account check into the session manager (identity_check_before_acquire, installed by install_acquire_identity_check), so every get_or_create, open_task_session and try_acquire retires a session left on a previous account. That fixes #3390 at the root for task steps, workflows, channel turns, hooks and sub-agent completions, and the _ACQUIRING_TASK re-entry guard, the try_acquire eviction of a flagged session and the per-channel model-switch replies look correct. The defect is the one the Opus and Design lanes both raised on 75319d8, which has no disposition. In _retire_sessions_on_identity_change (chat_runner.py ~L3290), an unchanged baseline with a non-empty pending_identity_sweep_fingerprint still runs retire_kiro_identity_sessions. That function takes _identity_sweep_lock, waits on _start_sem.drain() for every cold-start permit, marks a new identity epoch and calls _retire_kiro_warm_pool (session_lifecycle.py ~L2134/L2482). A sweep stays pending for as long as one channel member keeps its lifecycle lease after an account switch, which can be hours. Before this PR, only dashboard turns and cron fires paid that cost. Now every unattended acquire pays it, so a workflow fan-out or heartbeat traffic cold-starts one session at a time and throws away the warm pool on every acquire. Suggested fix: when the installed unattended check sees changed == False and only the pending fingerprint would trigger a sweep, run just flag_identity_stamp_mismatches(live) (flagged sessions are already evicted at claim and now at try_acquire) and leave the full re-sweep to the attended and cron callers as before. Alternatively, let a waiter queued behind a sweep in progress take that sweep's result. Either way, add a test that N concurrent unattended acquires with a pending sweep drain the start permits at most once. — crew-pr-reviewer (deep re-check)
75319d8 to
63e86d7
Compare
|
@iamwhatever Fixed in 63e86d7 with your second option: concurrent acquires share one check. I did not take the first option, because flagging alone leaves a gap on a sign-out. The sweep skips a busy companion or background runtime and leaves it registered ( |
|
|
|
HOLD at afa876b, reserved for human review. The head is unchanged since r120. Both lane notes r120 listed now have replies on this head. Design note 1 (the shared check would wait on itself if the sweep ever acquired a session) is answered: nothing the sweep runs acquires a session today, and a guard for code that does not exist yet is left to the human reviewer (disposition). First Principles item 6 (the shared check is oversized) is rebutted with the drain-count test and code references (disposition). I accept both. What clears the hold: a person reviews the identity changes. The account check now gates every session acquire (claims.py#L152-L198), and CI is green on this head. I read CI results only and ran no PR code locally. Reviewed head: afa876b — crew-pr-reviewer (r121) |
|
HOLD at e01c455, reserved for human review. This head adds the account check to two long-lived lease holders. A dashboard channel member checks before each message and restarts a flagged session (channel.py#L1077-L1091). A warm workflow worker checks before each reused task and takes the hard reset (agent_pool.py#L195-L198). I found no defect in either, and CI is green. Blockers:
What clears it: a target=design reply for notes 1 and 3 on this head, and a human approval of the identity changes. Our earlier change request on 75319d8 is addressed by the shared check and its drain-count test, so it can be dismissed. Auto-merge is armed, so those approvals are the remaining gate. — crew-pr-reviewer (r123) |
|
|
|
HOLD at cda31db, reserved for human review. This head adds What blocks:
What clears it: a reply per item on this head and a human approval. Auto-merge is armed, so those are the remaining gate. No PR code was run locally. — crew-pr-reviewer (r126) |
|
|
|
|
HOLD at cda31db, reserved for human review. Thanks for the replies. The three lane items r126 listed now each have a reply on this head, and they hold: no cold-start permit holder acquires a session, the session layer imports nothing from What still blocks: the PR changes which Kiro account a reused session is trusted under and when sessions are retired, for every acquire (claims.py#L194-L230). A maintainer must review and approve it. Our older change request from 75319d8 is resolved and can be dismissed when they do. — crew-pr-reviewer (r127) |
|
HOLD at a4850fa, reserved for human review. This head rebases cda31db onto main. Comparing the two patches, the only changes are main's and a move of the Telegram What still blocks: the PR changes which Kiro account a reused session is trusted under and when sessions are retired, for every acquire (claims.py#L193-L227). A maintainer must review and approve it. Our older change request from 75319d8 is resolved and can be dismissed when they do. — crew-pr-reviewer (r130) |
|
HOLD at e8b8b67, reserved for human review. Since our r130 hold on a4850fa, only tests changed. AI findings judged non-blocking:
What still blocks:
I read the source and CI; I did not run any PR code. — crew-pr-reviewer (r134) |
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]:
Reviewed at c8e80ff. This head is a rebase of e8b8b67 onto newer main; the account-check logic is unchanged. No blocking findings.
The change request from 75319d8 is addressed. Concurrent unattended acquires now share one in-flight check (src/kiro_crew/dashboard/chat_turn/account_identity.py:291-333), so a pending sweep no longer drains the cold-start permits once per acquire. With that sharing loop disabled locally, test/test_acquire_identity_check.py::test_concurrent_acquires_with_a_pending_sweep_drain_the_start_permits_once fails with assert 5 == 1.
What I checked:
_acquire_after_identity_check(src/kiro_crew/session_parts/claims.py:195-228) wrapsget_or_create,open_task_session(src/kiro_crew/session_parts/runtimes.py:203) andtry_acquire. With theawait check()atclaims.py:223disabled, 48 tests intest/test_acquire_identity_check.pyandtest/test_cron_identity_gate.pyfail.- The dashboard chat turn passes
identity_checked=True(src/kiro_crew/dashboard/chat_turn/turn_admission.py:952). The cron fire's separate call is gone (src/kiro_crew/slack/gateway_runtime/cron_fire.py:891). Both boot paths install the check (src/kiro_crew/dashboard/server.py:884,src/kiro_crew/dashboard/server_runtime/api_entrypoint.py:236). try_acquirerefuses a flagged session without evicting it (src/kiro_crew/session_allocation.py:717). Every channel/compactand model-picker caller oftry_acquirealso checksis_retiring: Slack, Telegram, Discord, Teams, Webex, iMessage, WhatsApp, WeCom, Feishu and Weixin. The dashboard pick landing (src/kiro_crew/dashboard/session_control_parts/model_switch.py:933) leaves the pick deferred, which is the right outcome there.- Sessions that keep their lease across tasks re-check and restart: the workflow worker (
src/kiro_crew/workflows/agent_pool.py:244-249) and the channel member (src/kiro_crew/channel.py:1087-1101). - The Design lane asked whether anything holds a cold-start permit while it waits on another task's acquire, which would deadlock against the sweep's drain. I found none. The permit holders (
src/kiro_crew/session_allocation_parts/get_or_create.py:294,src/kiro_crew/session_background.py:403and:1117,src/kiro_crew/session_pool.py:441) await only identity reads, the provider start and stamping. The sweep itself makes no acquire.
Non-blocking:
- The First Principles lane's point about the 60 s reuse window (
account_identity.py:208) is a simplification question, not a defect. The sign-out holdout case you described is a fair reason to keep it. - The Security Scope comment that reports BLOCK refers to an old head (24395b2); the current-head check passes.
The targeted tests (test/test_acquire_identity_check.py, test/test_cron_identity_gate.py, test/test_external_logout_detection_baseline.py, test/test_channel_prompt_busy.py, test/test_workflows_agent_pool.py, test/test_telegram_account_check.py) pass locally on this head.
|
HOLD at c8e80ff, reserved for human review. This head rebases e8b8b67 (our r134) onto newer main. In a range-diff the only differences are main's context: cron docs, imports in AI findings judged non-blocking
What still blocks: the PR changes which Kiro account a reused session is trusted under, and when sessions are retired, for every acquire (claims.py#L194-L230). A maintainer must approve it. @buluoray's review is a COMMENT, not an approval, and branch protection needs one approving review, so auto-merge waits for that. Our older change request from 75319d8 is resolved and can be dismissed at that point. One point for the human reviewer: a check that raises is logged and the acquire goes ahead (fail-open), which matches the behaviour before this PR. I read the source and CI; I did not run any PR code. — crew-pr-reviewer (r143) |
|
HOLD at This head rebases What still blocks: the PR changes which Kiro account a reused session is trusted under, and when sessions are retired, for every acquire (claims.py#L195-L229). A maintainer must approve it. @buluoray's review on I read the source and CI; I did not run any PR code. — crew-pr-reviewer (r145) |
|
@iamwhatever the defect from your change request at 75319d8 looks addressed at 6581822. Could you re-review? Your point: with an unchanged baseline and a pending sweep fingerprint, every unattended acquire re-ran the full At this head, the unattended check in
The tests you asked for are in All checks pass on this head (94 ok, 0 red, 0 pending). |
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]:
Reviewed at 6581822. Our last review was on c8e80ff. This head is that commit rebased from 1dd2be3 onto 0a0f9aa, plus one real change: the dashboard's model-pick landing after a channel turn now checks again after try_acquire returns. The account-check code itself (dashboard/chat_turn/account_identity.py, session_parts/claims.py, session_allocation.py) is byte-identical to c8e80ff. No blocking findings.
What changed
src/kiro_crew/dashboard/session_control_parts/model_switch.py:937-950:try_acquirenow waits for the account check before it takes the lease, so the slot can be rebound, or the session lock taken, during that wait. The landing now re-reads both after acquiring. If either changed, it releases the lease withwake_queue=Trueand returns before adding itself to_LANDING_LEASES(:951). Releasing first means the release observer (dashboard/state_parts/session_events.py:484-495) can schedule another attempt. That retry returns at:930for as long as the lock stays held. The lock holder is a dashboard switch or turn start, and it lands the pick itself. I see no retry loop and no lost pick:_deferred_model_switch_keyis left set on both early returns.- New tests in
test/test_channel_turn_model_pick.py, reasoned from source rather than run:test_a_lock_taken_during_the_acquire_hands_the_lease_back: without the lock re-check,apply_deferred_model_switchwaits for the lock the test holds while it awaits the landing, sowait_fortimes out and the test fails.test_a_slot_rebound_during_the_acquire_returns_the_original_lease: without the rebind re-check,apply_deferred_model_switchfollows the slot to the rebound session (model_switch.py:545-552) and callsset_modelonrebound_provider, which the test asserts never happens.
- The rest of the range-diff is rebase fallout: the
slack/handler_runtime/commands.pydirect-send baseline goes from 75 to 76 to keep up with main, and one composition-contract list was re-merged.
Earlier findings
- Our earlier review had no blocking findings. The non-blocking points still apply unchanged, because the code they cover did not change: the 60 s reuse window (
account_identity.py:208) and the stale Security Scope BLOCK comment, which still names 24395b2. - In our last review we called the dashboard pick landing's deferral correct. That was the outcome of a refused
try_acquire. The race this head closes is a different case, atry_acquirethat succeeds after the slot or lock changed during the check. We missed it last time, and it is fixed now.
Maintainer change request (75319d8)
The request said that a pending sweep re-ran on every unattended acquire, draining every cold-start permit and the warm pool each time, and it asked for a test. At this head:
- Concurrent acquires share the in-flight check (
account_identity.py:291-333). - Sequential acquires re-run a pending sweep at most once per
_PENDING_SWEEP_RETRY_SECS(:208,:309-313). test/test_acquire_identity_check.py:744(test_concurrent_acquires_with_a_pending_sweep_drain_the_start_permits_once),:1063and:1107pin this.
The request is addressed. The CHANGES_REQUESTED review still stands on GitHub, and only its author can clear it.
Lanes on this head
- Passing: GPT 6.1, Opus 5.5, Design and First Principles.
- Skipped: UX (no user-facing surface).
- Design's note that the check before every acquire has no timeout (
session_parts/claims.py:222-225catches only exceptions) is a fair hardening idea, but it doesn't gate this PR: dashboard chat turns and crons already wait on the same check without a bound. - First Principles' subtraction of the 60 s path is the same simplification question as before.
- On this head 74 check-runs succeeded and 18 were skipped, with none failing.
This is a comment, not an approval.
|
HOLD at b7a02da, reserved for human review. This head rebases 6581822 (our r145) onto newer main and moves the channel member's per-message account check into AI findings judged non-blocking (unchanged since r143):
What still blocks: the PR changes which Kiro account a reused session is trusted under, and when sessions are retired, for every acquire (claims.py#L162-L234). A maintainer must approve it; @buluoray's reviews are comments, not approvals. One point for that reviewer: a check that raises is logged and the acquire goes ahead (fail-open), which matches the behaviour before this PR. Our change request from 75319d8 is addressed and can be dismissed at that point. I read the source and CI; I did not run any PR code. — crew-pr-reviewer (r146) |
|
🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: Reviewed at b7a02da. Our last review was on 6581822. This head is that commit rebased onto 942ab8b, plus one move: the channel member's per-message account check now lives in What changed
What I checked
Lane notes on this head
Non-blocking follow-ups
Not run: an end-to-end account switch on a live gateway, and the reply mutations for the nine other transports (Slack was spot-checked). |
|
Hold at 232263b, reserved for human review. This head rebases b7a02da (my r146 hold) onto newer main. The only change in the PR's own patch is one call-site baseline in What blocks: the PR changes which Kiro account a reused session is trusted under, and when sessions are retired, for every acquire (claims.py#L201). A maintainer must review and approve it. Our older change request from 75319d8 is resolved and can be dismissed when they do. Auto-merge is armed, so that maintainer review is the remaining gate. — crew-pr-reviewer (r148) |
bolichen97
left a comment
There was a problem hiding this comment.
Maintainer decision: accepted. Checking the signed-in Kiro account before every session acquire, and retiring a reused child when that account changed or logged out, is the behavior we want. Approving at 232263b. CI is green; the red entries are cancelled duplicate runs.
@iamwhatever, could you re-review? Your change request at 75319d8 was that, with an unchanged baseline and a pending sweep, every unattended acquire re-ran the full retire_kiro_identity_sessions sweep and drained the start permits. In dashboard/chat_turn/account_identity.py a waiter that finds a check in flight now joins it (in_flight / joined) instead of starting a second sweep, and a recorded pending-sweep result is reused for _PENDING_SWEEP_RETRY_SECS.
Non-blocking follow-up: every acquire now awaits the account check with no time limit. Please bound it with a timeout that falls back to today's behavior, so a stuck check cannot stall every session start.
After a `kiro-cli logout` or a Kiro account switch outside the dashboard, a running kiro-backed child keeps the previous account's credential and keeps answering. The check that retires such a child, chat_runner._retire_sessions_on_identity_change, ran in two places: before each dashboard chat turn and, since kirodotdev#18780, before each agent cron run. A task-runner step, a workflow agent, a channel turn, a heartbeat or Slack-thread auto-nudge cycle, a sub-agent completion and a channel /compact acquired without it, so on a host where only those run, a session left on the previous account kept being reused. The session manager now holds the check (identity_check_before_acquire), installed by both dashboard start paths after the identity baseline is seeded, and get_or_create, open_task_session and try_acquire await it before they allocate, claim or take an idle session's lease, so a new acquire path cannot leave it out. try_acquire is how every channel's /compact, and the model switch on Telegram, Discord and Webex, take a session; it checks before the lease because a sweep only flags a session someone holds, and it refuses a session the check flagged instead of taking it. It does not evict that session: the sweep also flags an idle parent it spared for its running sub-agents, and the next real turn's claim retires it. It runs as the gate's unattended caller: an account reading that identifies nobody sweeps nothing unless it proves a sign-out, the rule kirodotdev#18780 gave crons. The dashboard chat turn keeps its own attended check, placed before the slot switch lock, and tells its claim so (identity_checked=True). The cron's explicit call is removed, since its acquire now checks itself. A refused try_acquire used to read as a running reply. is_retiring, the same exact-key lookup, tells a refused caller that the check flagged the session. Each channel's /compact then answers that the Kiro account changed and the next message restarts the conversation, instead of asking the user to wait for a reply that is not running. The model switch on Telegram, Discord and Webex answers that the pick applies to the next message when the check retired or flagged the session. A Telegram pick for a resumed dashboard session stores no preference and that session restarts on its own model, so it answers that the session was not changed. An acquire the same task makes inside an acquire (a won-race retry, a task session's fallback to a dedicated one) does not check again; a task started meanwhile checks its own. The check runs before the acquire takes a cold-start permit, because the sweep collects every permit. Only the final drain of a shutdown or restart skips it: an update pause can resume and leaves try_acquire open, so it still checks. A check that raises is logged and the acquire goes ahead. A warm workflow worker acquires once and holds its session's lease until its last task, so it never acquires again, and a sweep only flags that session. Before each reused task it now runs the check alone (run_identity_check, the same rules as before an acquire), and a session the check flagged takes the worker's hard reset, whose re-acquire starts it on the current account, instead of a new conversation on the previous account's process. A dashboard channel member acquires at spawn and holds its lease until it dies, the same shape. Before each inbox message it now runs the check, and a session the check flagged is replaced through _reset_busy_session, so the message runs on the current account; if no replacement can be started, the member posts one message and stops, as a stuck member already does.
bolichen97
left a comment
There was a problem hiding this comment.
Approving again at bf6b2e1. Against my approval at 232263b, the range-diff shows a rebase plus one change. A companion or background runtime that is still busy (has_active_or_initializing_sessions) no longer counts as being on an unknown account, so it does not force another sweep until it is idle, because the sweep cannot retire it before then. A worker that holds its lease runs the account check before a reuse, and a flagged session takes the hard reset. The specs say both. No regex is added, and all checks pass.
Problem / Motivation
Goal: After a Kiro account switch or
kiro-cli logout, every turn that starts or reuses a session through the session manager checks the signed-in account first, not only dashboard chat turns and agent cron runs.After an account switch or a logout outside the dashboard, a running kiro-backed child keeps the previous account's credential and keeps answering, with no auth error (#3390). The check that retires such a child,
_retire_sessions_on_identity_changeindashboard/chat_turn/account_identity.py, runs before each dashboard chat turn (#4159) and, since #18780, before each agent cron run. Every other acquire skips it: task-runner steps, workflow agents, channel thread turns and/compactcommands, hooks, the heartbeat task runner, Slack-thread auto-nudge cycles and sub-agent completion turns. On a host where only those run, a session started under the previous account keeps being reused until a dashboard chat turn or a cron run sweeps.Why it matters
Most of those paths run with nobody watching. A turn on a reused session acts as the account the user left, and nothing in its output shows it. Each new acquire path also has to remember the call, which is why #18780's approving review asked for the check to live in one place (#19651).
Not a goal
get_or_createoropen_task_session(runtime.create_session,get_bg_session); the next checked acquire's sweep or stamp check retires or displaces the runtimes they use.What changed (motivation → approach → change)
Every session start or reuse through the session manager runs the account check first, so a session left on the previous account is retired before reuse.
_turn_admitindashboard/chat_turn/turn_admission.pyruns the check, attendedidentity_checked=True_acquire_with_model_fallbackget_or_createchecks; the own call is gone/compact, and the model switch on Telegram, Discord and Webextry_acquiretook an idle session's lease, no checktry_acquirechecks first, then takes the leaseget_or_createandopen_task_sessioncheck, unattendedworkflows/agent_pool.py) and a dashboard channel member's later messages (channel.py, throughchannel_account_check.py)run_identity_checkbefore each task or message; a session the check flagged is restarted on the current account (the worker's hard reset, the member's_reset_busy_session)The session manager in
session.pyholds the check asidentity_check_before_acquire; the wrapper that runs it is insession_parts/claims.py, withopen_task_sessioninsession_parts/runtimes.py.install_acquire_identity_checkindashboard/chat_turn/account_identity.pysets it, and both start paths (dashboard/server.py,dashboard/server_runtime/api_entrypoint.py) call it after the identity baseline is seeded.get_or_create,open_task_sessionandtry_acquireawait it before they allocate, claim or lease a session, and before taking a cold-start permit, since the sweep collects every permit.try_acquirechecks before the lease, since a sweep only flags a held session; its lease decision insession_allocation.pyrefuses, but does not evict, a session the check flagged: the flag also marks a parent kept for its sub-agents.A refused
try_acquireused to read as a running reply;is_retiring, the same exact-key lookup, tells the caller the check flagged the session:/compactinslack/handler_runtime/commands.py,telegram/dispatch/commands.py,discord/transport_dispatch_commands.py,teams/transport_dispatch.py,webex/transport_dispatch.py,imessage/transport_dispatch.py,whatsapp/transport_dispatch.pyCOMPACT_ACCOUNT_CHANGED_TEXTfrommessaging/commands.py: the Kiro account changed and the next message restarts the conversation/compactinwecom/transport_dispatch.py,feishu/transport_dispatch.py,weixin/transport_dispatch.pyCOMPACT_ACCOUNT_CHANGED_REPLY_ZHtelegram/dispatch/pickers.py,discord/transport_dispatch_model_picker.py,webex/transport_dispatch_commands.pyThe installed check is the gate's unattended caller, so #18780's rule covers every acquire but the dashboard chat turn: an account reading that identifies nobody sweeps nothing unless it proves a sign-out. The dashboard turn keeps its attended check, before the slot switch lock decision.
An acquire nested in a task's own acquire (a won-race retry, a task session falling back to a dedicated one) does not check again; a task started meanwhile checks its own, because the marker (
_ACQUIRING_TASK) weakly holds the task. Only the final drain of a shutdown or restart skips the check; an update pause leavestry_acquireopen, so it checks. A check that raises is logged and the acquire goes ahead; a cancellation cancels it.Concurrent acquires share one check. Each run of a pending sweep (a channel member holding its lease keeps it pending) drains every cold-start permit and the warm pool, so an acquire arriving mid-check takes its result, as does one within a minute after a check that left the sweep pending (
_PENDING_SWEEP_RETRY_SECS). Either runs its own when the result is empty (a sign-out or an unidentifiable account), a read since returned another account, or, after its store read, a claimable Kiro process's stamp proves neither the live account nor another (for example empty, or differing only in a store or vault source one side lacks, or in a key the child receives;holds_kiro_process_of_unknown_accountinsession_lifecycle_parts/identity_retirement.py, bound insession_lifecycle.pyandsession.py). One within the minute also does so once the sweep is no longer pending.KiroPrerequisiteService(kiro_prerequisite_service.py, re-exported bykiro_prerequisite.py) numbers each fresh read, andidentity_read_other_than(kiro_prerequisite_identity_tracking.py) answers exactly from the latest run of identical reads. One that takes the result still runs the stamp check. After the minute an acquire retries the sweep, which retires a busy holdout once it goes idle.The docs (
session.md,slack-gateway.md,learn-cron-dashboard.md,config.md,configuration.md,workflows.md,persistent-agent-channels.md), thesession.idle_exempt_keyshelp inconfig/sections_session.pyand itsconfig-baseline.jsoncopy describe the new checks and answers. Theslack/gateway_runtime/cron_fire.pycomment names where the cron's check runs.Backwards compatibility
With no check installed (the CLI, tests), acquires run unchecked, as before.
Compatible: on an unchanged signed-in account each acquire adds one identity read off the event loop (the kiro-cli store, the
.envkey and the Crew vault) and the stamp check, as each dashboard chat turn already does. After a switch to an account the check can identify, or a proven sign-out, the next acquire anywhere sweeps, as the next dashboard chat turn or cron run already would. Where the account cannot be identified, an acquire other than a dashboard chat turn touches no session, as before. A dashboard chat turn still checks once. After an account change, a channel/compactfinds the stale session retired and answers that there is no session to compact, or finds it flagged and answers that the account changed and the next message restarts the conversation; a Telegram, Discord or Webex model switch answers that the pick applies to the next message. All of them used to act on that session under the previous account. A warm workflow worker adds the same read before each reused task; after a switch the check flags its session, and its next task starts a new process instead of a new conversation on the previous account's process. A dashboard channel member adds the same read before each inbox message; after a switch its next message runs on a new session on the current account, so its conversation restarts, and a member whose session cannot be restarted posts one message and stops, as a stuck member already does.try_acquirenow waits for the account check before it takes the lease. One caller relied on it not waiting: the landing of a deferred model pick after a channel turn (dashboard/session_control_parts/model_switch.py). After it takes the lease, that landing now checks that the slot still names the same session and that the session lock is still free. Otherwise it hands the lease back and leaves the pick for a later boundary.Removes nothing: the diff adds
identity_check_before_acquire, anidentity_checkedkeyword onget_or_create, the check intry_acquire,is_retiring,run_identity_checkand its calls from a warm workflow worker and a dashboard channel member, a channel member's restart-failed message and itsfailedstate, theCOMPACT_ACCOUNT_CHANGED_TEXTandCOMPACT_ACCOUNT_CHANGED_REPLY_ZHreplies,install_acquire_identity_checkand its two install calls, the read-onlyholds_kiro_process_of_unknown_accountquery, moves the cron's call into its acquire (its explicit call and the two imports inslack/gateway.pyandslack/gateway_runtime/cron_fire.pyare deleted, and every cron acquire still runs the check), and rewords one help string (with its copies inconfig-baseline.jsonandsrc/kiro_crew/docs/configuration.md) and passages in six specs (session.md,slack-gateway.md,config.md,learn-cron-dashboard.md,workflows.md,persistent-agent-channels.md); no capability, setting or public name is removed.Tests
test/test_acquire_identity_check.pypins the front door on a realSessionManager:get_or_createruns the check before it starts a session, and a claim of a live session runs it too;open_task_sessionruns it before it opens.try_acquireretires a session left on the previous account instead of taking it, refuses one the stamp check flagged after an unobserved account round trip and leaves it for the next turn to retire, and takes a healthy idle session after one check.is_retiringanswers for the exact keytry_acquirerefuses: True for a flagged session, False for an unflagged or absent one, and it does not fold a bare legacy Slack alias thathas_sessionfolds.identity_checked=Trueskips it. An acquire the same task makes inside an acquire checks once, and a task started inside an acquire checks its own and does not keep the acquiring task alive.try_acquireduring an update pause still runs it./compactthat takes a shared result still refuses a session stamped with an interim account, and an acquire whose shared check was followed by a read of another account runs its own. Intest/test_external_logout_detection_baseline.py,identity_read_other_thanignores any number of repeat reads of the live account and answers yes for a third account, the baseline account, or another account read before the latest run began._turn_admit's claim passesidentity_checked=True, and_turn_admitruns the attended check itself. Both dashboard start paths install the check after the baseline seed.Each channel's
/compactanswers a flagged session that is still registered with the account-changed reply, and acquires and releases nothing: one test each intest/test_slack_handler_coverage.py,test/test_telegram_account_check.py,test/test_discord_dispatcher.py,test/test_teams_dispatch_cov80.py,test/test_webex_dispatch.py,test/test_wecom_dispatch.py,test/test_feishu_dispatch.py,test/test_imessage_dispatch.py,test/test_whatsapp_dispatch.pyandtest/test_weixin_dispatch.py. A model switch on a session the check retired or flagged answers that the pick applies to the next message, or for Telegram's resumed session that it changed nothing: tests intest/test_telegram_account_check.py,test/test_discord_interactions.pyandtest/test_webex_dispatch_commands.py. The transport test fakes that modeltry_acquiregainedis_retiring. Intest/test_workflows_agent_pool.pyevery reuse of a worker runs the check, and a worker whose session the check flagged takes the hard reset, nevernew_conversation; the workflow test fakes gainedrun_identity_checkandis_retiring. Intest/test_channel_prompt_busy.pya listening member runs the check before every message, a member whose session the check flagged answers on a replacement and never on the flagged provider, and a member whose replacement cannot be started posts one message and stops; itsFakeSessionsgained the same two methods.test/test_cron_identity_gate.pydrives the real cron callback into a realSessionManagerwired the way the dashboard wires it, so its cases (an account change, an unchanged account, anagent_sequencestep, a kept-alive session, an account it cannot identify, a proven sign-out swept once, a pooled provider) run through the installed check.test/test_chat_runner_composition_contract.pylistsdashboard/chat_turn/account_identity.pyamong the files that start a task (create_task(): the shared check starts its own task there.test/test_slack_post_message_call_sites.pyallows 78 direct sends inslack/handler_runtime/commands.py, one more than main, for the Slack/compactaccount-changed reply, a fixed notice.test/test_channel_turn_model_pick.pytakes the session lock, and separately rebinds the slot, while the landing'stry_acquirewaits; in each case the landing hands back the original lease and switches no session. Each half of that check fails its test when removed.Each safeguard fails a test when removed: 82 of 82 mutations caught (the check, each method's use of it,
try_acquire's check, its place before the lease and its refusal of a flagged session,is_retiring's answer and its exact-key lookup, each of the ten/compactreplies for a flagged session, each model switch's answer for a retired or flagged session and Telegram's for a resumed one,identity_checked, the final-drain skip and the update-pause check, the nesting guard, its task key and its weak hold on the task, the logged failure, the cancellation, the unattended caller, the shared check, its fresh-read fallback, its refusal of an empty result, its stamp check, its check for another observed account and its own task, the minute between retries of a pending sweep, its record of the last check, its pending checks before and after the store read, its covers and stamp checks, its guard for a holder of unknown account on both sharing paths, that guard's second look after the store read, its refusal when the holder query is missing or raises, its refusal when the read record is missing, raises or has no read count, the query's exclusion of holders spawned under the live account and of proven mismatches, and each of the four holder kinds it reads, and its shared start, the read record's account comparison, its baseline reads, its run start and its run bound, the install, the dashboard claim's flag, each start path's install, the warm workflow worker's check before reuse, its hard reset for a flagged session,run_identity_check's check, the reused worker's new conversation on an unchanged account, a channel member's check before each message, its replacement of a flagged session, and its stop when that replacement fails). The two acquire test files, the 18 changed transport tests, the two new workflow-pool tests and the three new channel tests pass 20 runs at-n0and 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_cron_sequence_member_alias.py,test/test_external_logout_detection.pyandtest/test_external_logout_detection_baseline.py. Those node ids also pass in a shuffled order (seed 28032).Proof: not provable -- other: reverting every production hunk at once stops pytest at collection, because the tests import names only the fix adds (
install_acquire_identity_check,is_retiring,run_identity_check), so prove.py reads INCONCLUSIVE; the mutations above revert one safeguard at a time and each one fails a testManual verification
Not run end to end: it needs a Kiro account switch on a live gateway. The tests run real session managers and the real cron callback; only the account-store reading is faked in them.
Related Issues
Fixes #19651
Fixes #20387
Sibling sweep
Swept:
git grep -n -E '\.get_or_create\(|\.open_task_session\(|mark_lifecycle_lease\(' -- src(every acquire, and every lease held past one turn) andgit grep -n -E 'AcpRuntime\(|AcpClient\(|new_conversation\(|WorkerPool\(|get_bg_session|get_subagent_runtime' -- src(every Kiro process kept across tasks).Sibling: src/kiro_crew/session_parts/claims.py -- changed here
Sibling: src/kiro_crew/session_parts/runtimes.py -- changed here
Sibling: src/kiro_crew/workflows/agent_pool.py -- changed here
Sibling: src/kiro_crew/channel.py -- changed here
Sibling: src/kiro_crew/session_background.py -- not affected --
get_bg_sessionhands out the background companion runtime, which the identity sweep itself retires or displaces (_retire_kiro_bg_runtime), so it never waits for a later acquireSibling: src/kiro_crew/session_allocation_parts/companions.py -- not affected --
get_subagent_runtimehands out per-parent sub-agent runtimes, which the identity sweep itself retires or displaces (_retire_kiro_subagent_runtimes), so none waits for a later acquireSibling: src/kiro_crew/apps/builtins/code_review_sage/sage_lib/review_pool.py -- not affected -- not a session-manager session, so it has no acquire to check: a review batch spawns its own runtime under the account the store names then, and
end_batchkills it when the last overlapping run endsSibling: src/kiro_crew/knowledge/llm_pool.py -- not affected -- not a session-manager session, so it has no acquire to check: its pool keeps knowledge workers warm as their own
AcpClientprocesses, and each starts a fresh process after at most 20 calls, so after a switch a warm worker serves at most 20 more calls on the previous accountPattern harvest
Rule candidate: review-prompt
Pattern: a safety check that every call site must remember to run before a shared operation (here the Kiro account check before
get_or_create) belongs inside that operation, installed once, with an explicit opt-out only for a caller that runs its own stricter check.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)