Skip to content

fix(members): confirm a member session inside the client start that made it - #21452

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/member-confirm-after-respawn
Oct 17, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/member-confirm-after-respawn

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A member session that is respawned right before a prompt is confirmed against its saved spec before that prompt is sent.

Follows up #16847. That PR confirms a member's saved spec in the provider (AcpProvider.stream, stream_command, compact) after ensure_ready. But AcpClient.stream_events (client_turn.py) and the command paths in client_turn_control.py call ensure_ready again before sending. If the child died between the provider's gate and that call, ensure_ready respawns it and creates a new session. The prompt then goes into that new session, which no one confirmed. A GPT review lane raised this on #16847 and it was upheld.

Why it matters

A member whose consumed spec does not match its saved intent (withheld array, unreadable intent, different spec) can get one prompt through after a respawn. That is the exact case the #16847 gate exists to refuse.

Not a goal

What changed (motivation → approach → change)

Symptom: a send after a respawn reaches an unconfirmed member session. Root cause: the confirmation ran in the provider, one layer above the call that can create a new session. Change: _initialize_session in src/kiro_crew/acp/client_start.py now calls confirm_member_projection on the else arm of its existing if self._is_kiro: test (step 4, after the session exists and the array is consumed). Every adapter session a start creates is confirmed before ensure_ready returns, so every caller is covered, including ones added later. The kiro path takes the same if it always did and gains no call, conditional or failure point (harness-parity H13).

Every send-after-respawn path was checked. All AcpClient sends go through ensure_ready first: send_message, send_message_stream and stream_events in client_turn.py, and command_result, send_command and stream_command in client_turn_control.py. _session_id is set only inside _initialize_session, which only ensure_ready's cold path calls. So no path reaches a new session without passing the new check.

Fail closed: a refusal is an AcpError, so ensure_ready's existing handler ends the child and resets state; it retries once on a fresh process (which re-reads the saved spec and is refused again, or confirmed if the spec was mid-write) and then raises. A cancel skips that handler, so the new arm tears the session down itself before re-raising, the same shape _classify_failed_start uses. Either way the next ensure_ready never takes the warm return into an unconfirmed session. confirm_member_projection is idempotent per session id, so the provider's existing call after ensure_ready costs nothing extra. Its docstring is updated to the new call site.

Backwards compatibility

Compatible: this only refuses member sessions whose spec already fails the #16847 check, now one step earlier. Non-member sessions, kiro-cli sessions and confirmed member sessions behave as before.

Removes nothing: the diff adds a check and a teardown on cancel; no key, path, function or record is removed.

Tests

test/test_member_projection_send_paths.py drives the real ensure_ready and _initialize_session with a fake transport (spawn, request/response, the confirmation and the teardown stubbed):

  • test_a_respawn_inside_the_client_confirms_before_it_returns: a DeepSeek member start confirms before ensure_ready returns.
  • test_a_refused_respawn_is_torn_down_not_left_warm: a refusal ends the child on both attempts, clears _session_id, and the next ensure_ready confirms again rather than taking the warm return.
  • test_a_cancel_during_confirmation_is_torn_down_not_left_warm: a cancel mid-confirm tears down and clears _session_id.
  • test_a_kiro_start_gains_no_confirmation_call: a kiro member start never calls the confirmation (H13).

test/test_session_capabilities.py::test_claude_saved_projection_requires_consumed_matching_spec now expects the refusal from _initialize_session itself.

Mutation check (each mutant run against the file): removing the confirm call fails 3 tests; making it unconditional fails the kiro test; dropping the cancel teardown fails the cancel test.

Manual verification

N/A — unit coverage sufficient: the change is one call on an existing branch of _initialize_session, and the tests drive the real start path with only the transport stubbed.

Related Issues

Refs #16847, #12451

Pattern harvest

Rule candidate: review-prompt
Pattern: a gate placed above a call that can re-create the state it gated (respawn, reconnect, re-init) does not cover sends made after that call; put the gate where the state is created.

Sensitive change review

  • What rule changed: adapter member sessions are confirmed against the saved spec inside the start that created them, not only in the provider.
  • Before -> after: a respawn inside stream_events sent unconfirmed; now every new adapter session is confirmed or torn down before any send.
  • Worst case if wrong: a member session wrongly refused after respawn, failing the turn with the existing capability error.
  • Evidence checked: read every ensure_ready caller and every _session_id write; mutation-checked the new tests.
  • No regression:
    • Tools still work: kiro-cli and non-member sessions skip the check; confirmed sessions are unchanged.
    • Backward compatible: only refuses sessions the feat(members): confirm saved member specs on Claude, Codex and DeepSeek #16847 gate already refuses.
    • Existing tests: every test file touching ensure_ready, _initialize_session or member confirmation passes locally, except 17 in test_acp_spawn_offload.py that fail identically on main locally.
  • How to undo: revert this single commit.

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

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 17, 2026 02:11
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 5b12b202ce5d64dda49c9ee4ba8319651f397068 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

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

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 5b12b202ce5d64dda49c9ee4ba8319651f397068 — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

With the gate now inside _initialize_session, the provider's two confirm_member_projection calls do nothing, but the diff keeps them and documents them as a second check.

Not justified as shipped

  • Item 3 — duplicate of src/kiro_crew/acp/client_start.py:1105: the new docstring says the session is confirmed "again by the provider after it returns (a no-op for a session already confirmed)". _session_id is only set in _initialize_session, and confirmation is cached per session id, so neither provider call can ever refuse anything. That leaves two spellings of one gate. _ready_confirmed_session still calls itself "The one gate every path that sends a prompt goes through", which is now false.
    Subtraction: delete await self._client.confirm_member_projection() at src/kiro_crew/providers/acp_turns.py:152 and src/kiro_crew/providers/acp_lifecycle.py:84. Shrink _ready_confirmed_session down to ensure_ready, or inline it.
    Clears when: both provider calls are deleted, or the PR names a session the provider call refuses that the start-time call does not.

What this change ships

Inventory (4 items) — 3 justified

Intent: make sure a member session that respawns just before a prompt is checked against its saved spec before anything is sent. FIX.

  1. Adapter member sessions are confirmed inside the start that creates them, so every ensure_ready caller is covered — justified
  2. A cancel during confirmation tears the session down, so the next start cannot reuse an unconfirmed session — justified
  3. The provider still confirms after ensure_ready, now documented as a no-op — duplicate of client_start.py confirm arm
  4. A test now expects the refusal from _initialize_session itself — justified

[FIRST-PRINCIPLES-REVIEWED] 5b12b20

Description read

[DESCRIPTION-READ] bf48c834209398cb040e83ca9e1ae27d24620372c63b77df0a195293063dc41b

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 5b12b202ce5d64dda49c9ee4ba8319651f397068 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check one thing before merge: a deterministic spec refusal now costs a second spawn and is recorded as startup outcome "error", not as a capability refusal.

Suggestions

  • AcpToolGateUnroutable fails fast because a fresh process re-reads the same configuration. A capability_runtime_unverified refusal is just as deterministic. Fail fast on it the same way, or write down in the comment that the one retry is there on purpose to cover a spec that was mid-write.

[DESIGN-REVIEWED] 5b12b20

Description read

[DESCRIPTION-READ] f7750993ed8c829710623635eb3093752fa0e00a6a95ad1cbf835c50e50619db

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

Advisory only: one finding, nothing blocks the merge.

FINDING — src/kiro_crew/acp/client_start.py:1105 — A member whose saved spec can't be confirmed fails the same way on every attempt. Its refusal from await self.confirm_member_projection() is a plain AcpError, so ensure_ready's generic except (AcpTimeoutError, AcpError, OSError) arm logs "ACP init failed … retrying with fresh process" and spawns, creates and tears down a second child before refusing again (the test pins ["spawn", "confirm", "teardown"] * 2). The AcpToolGateUnroutable and sandbox arms exist to stop exactly this kind of wasted retry. → Fix: raise a dedicated non-retryable AcpError subclass from _confirm_member_projection and handle it before the generic arm, the way AcpToolGateUnroutable is handled (_cleanup_failed_live_spawn, _reset_state, re-raise). That handler goes in the untouched part of ensure_ready.

[OPUS-REVIEWED] 5b12b20

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

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

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 5b12b20

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 5b12b202ce5d64dda49c9ee4ba8319651f397068: <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 17, 2026
…ade it

Follows up #16847. stream_events runs ensure_ready again after the
provider's send gate, and a child that died in between is respawned there,
so the prompt went into a session nobody had confirmed. The confirmation
now runs in _initialize_session, on the else arm of its existing kiro
test, so every adapter session a start creates is confirmed before any
caller can send, and the kiro path gains no call (harness-parity H13). A
refusal goes through ensure_ready's error handler, which ends the child; a
cancel is torn down in place, so the next ensure_ready never takes the
warm return into an unconfirmed session.

Co-authored-by: Claude <noreply@anthropic.com>
@iamwhatever
iamwhatever force-pushed the fix/member-confirm-after-respawn branch from cfdfc7e to 5b12b20 Compare October 17, 2026 02:50
@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 17, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Disposition for the First Principles CONCERNS on 5b12b20 (advisory, no push).

Item 3 (provider calls kept): kept on purpose. Here is a session the provider call refuses and the start-time call does not.

_initialize_session sets _session_id from session/new (or session/load) before the new confirm arm in step 4. Several awaits sit between the two: _persist_advertised_models_if_changed, _reseed_after_capture, _pin_claude_starting_mode, _discard_pi_mcp_handoff, and the asyncio.to_thread(require_unchanged_derived_spec, ...) call. A cancel in that window skips the confirm arm. ensure_ready does not catch CancelledError, so the child stays live with _session_id set. The next ensure_ready takes the warm return into that session without confirming it. _confirmed_capability_session was never set for it, so the provider's confirm_member_projection in _ready_confirmed_session (acp_turns.py) and in start (acp_lifecycle.py) is what judges it before the next send.

So the two checks cover different windows:

Session Start-time arm Provider call
Created by a respawn inside stream_events / command paths confirms not reached (the hole this PR closes)
Start cancelled after session/new, before step 4 skipped confirms
Normal start confirms no-op (cached)

Deleting the provider calls would reopen the second row. Closing that row inside the start would mean tearing down on a cancel at every await after session/new. That is the wider "a cancelled start leaves a half-built warm session" class, which also affects the other startup checks, and it is outside this PR's goal.

On the _ready_confirmed_session docstring calling itself "the one gate": that wording now undersells the start-time arm. I'm leaving it as is to avoid a full CI rerun for a docstring. If a blocking finding forces another push, I'll fix it then.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 17, 2026
@chenmingwei23
chenmingwei23 merged commit 6c953b3 into main Oct 17, 2026
103 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/member-confirm-after-respawn branch October 17, 2026 05:36
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 17, 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.

2 participants