Skip to content

fix(identity): name recovery paths, reset refused flag, drop dead wrappers (#17612) - #19939

Merged
bolichen97 merged 1 commit into
mainfrom
fix/17612-co-tenant-followups
Oct 15, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/17612-co-tenant-followups

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: clear the four advisory items from #17612 that are within this PR's reach.

Five items were listed in #17612. Four are addressed here (items 1, 2, 4, 5a, 5b). Item 3 (the ## Tests offset in the merged PR #17524 body) requires the original PR author (chenmingwei23) or a maintainer to edit, as this PR should not modify another contributor's text.

Why it matters

The wrong comment about how a cleared stub regains its identity leaves operators without an accurate mental model of the recovery paths, and makes the code harder to audit. The stale identity_refused flag is harmless today but becomes a defect if a third guard is ever added. The missing reader makes the security argument incomplete. The wrapper and re-export are dead code.

Not a goal

What changed

Item 1 — comment corrected. The session_token and not conn.stub_session_token and shared_pid branch in _apply_claim had a comment claiming "a claim carrying ITS token repairs it through the branch above." That is wrong: a cleared stub is tokenless by definition, so the branch above (conn.stub_session_token != session_token) can never match it. The two real recovery paths are (1) a tokenless claim, which keeps its PID-wide reach unconditionally, and (2) a tokened claim arriving after _pid_live_tenants drops below two because the co-tenant's connections have disconnected. Both are now named in the comment. The reason string is also fixed: "cleared until a claim carrying its own token names it" → "cleared until a tokenless claim retargets it or the co-tenant disconnects".

Item 2 — identity_refused reset on re-attribution. The flag was set when a connection was cleared and never cleared. It is harmless while a caller is present (the existing_key guard in the recaller already rejects it), but the flag outliving the condition that set it is the kind of state that becomes a defect. conn.identity_refused = False is now set when conn.caller = updated_caller is set in the retarget path.

Item 4 — _policy_session_key named as a reader of the env rung. mcp_shared._policy_session_key calls resolve_own_identity(), which reads the KIROCREW_SESSION_KEY rung guarded by #17524. The backwards-compatibility argument in that PR named the lenient resolver and audit callers but not this one. A docstring note is added: on a shared pid the rung resolves no key, identity.failed is set, None is returned, and _resolve_tool_policy raises into resolution_failed, which is in _UNRESOLVED_REFUSES_CALL — so tools/call is refused rather than proceeding under a co-tenant's exclusion set.

Item 5a — _host_pid_hosts_several_sessions removed. The wrapper's body was return host_pid_is_shared(host_pid). The one call site in _resolve_session_key_strict now calls host_pid_is_shared directly. The docstring reference is updated.

Item 5b — _pid_live_tenants re-export kept. The composition-contract test (test_every_owner_name_is_bound_on_the_facade_to_the_owners_object) requires every name defined in a daemon/*.py module to be bound on gatewayd.py; since _pid_live_tenants is still defined and used in daemon/identity.py, the facade re-export must stay. The second OR condition in the issue's clears-when is met: control.py reads it directly from daemon.identity, not through gatewayd.

Backwards compatibility

Compatible. No change to runtime behavior.

Items 5a and 5b drop two names from the public surface of these modules.

Reader sweep on origin/main at aaffa10318:

  • _host_pid_hosts_several_sessions: no external callers (only mcp_core._resolve_session_key_strict, now calls host_pid_is_shared directly).
  • _pid_live_tenants through gatewayd: re-export kept; the composition-contract test requires it (every daemon/*.py name must be on the facade). control.py reads it from daemon.identity directly.

Tests

One new test: test_a_cleared_stub_regains_identity_after_co_tenant_disconnects in test_mcp_gateway_stub_session_token.py.

It pins the second recovery path (item 1): a cleared tokenless stub is retargeted when the co-tenant disconnects and _pid_live_tenants drops below two. It also pins item 2: identity_refused is False after retargeting.

Determinism to be proven by CI (no local test runner on this host per worker policy).

Manual verification

Static gates only: isort, flake8, mypy — all clean.

Pattern harvest

Not generalizable: the wrong comment and the stale flag are one-offs in this file. The reader-list gap is a documentation discipline; the two subtractions are cleanup.

Intended? / Repro

Verified per item:

  • Item 1 (comment): on the fix/claim-per-session merge commit, a cleared stub has stub_session_token = None; the branch above checks conn.stub_session_token, so it can never match. The comment was wrong. The two real paths are confirmed by code inspection.
  • Item 2 (stale flag): grep -n identity_refused src/kiro_crew/mcp_gateway/daemon/control.py on main shows the flag is set but never cleared in the retarget path. No test verifies the flag is cleared after retargeting.
  • Item 3 (PR fix(mcp): stop answering MCP identity per process on a runtime hosting several sessions #17524 body offset): not addressed here — requires chenmingwei23 or a maintainer.
  • Item 4 (_policy_session_key): grep -n "resolve_own_identity" src/kiro_crew/mcp_shared.py on main confirms _policy_session_key calls it. Not named in fix(mcp): stop answering MCP identity per process on a runtime hosting several sessions #17524's backwards-compatibility section.
  • Item 5a (wrapper): grep -n "_host_pid_hosts_several_sessions" src/kiro_crew/mcp_core.py on main shows the function body is return host_pid_is_shared(host_pid).
  • Item 5b (re-export): grep -n "_pid_live_tenants" src/kiro_crew/mcp_gateway/gatewayd.py on main shows the re-export. Removal breaks test_every_owner_name_is_bound_on_the_facade_to_the_owners_object — the composition-contract test mandates every daemon module name be on the facade. Re-export kept.

Related Issues

Fixes #17612

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 13, 2026 20:54
@CrysisDeu
CrysisDeu requested a review from mbriones98 October 13, 2026 20:54
@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: checking Automated validation is still running labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

The wrong recovery-path claim this PR fixes in code still sits in the design note, and deleting the wrapper also deleted the only written rationale for the unsigned read.

Watch

  • docs/architecture/design-notes/mcp-gateway-claim-push.md:79 still says a cleared connection stays cleared "until a claim carrying its own token names it". The PR exists to correct the operators' picture of how a cleared stub recovers ("leaves operators without an accurate mental model"), but it only corrects the code comments, so the doc readers actually use still gives the wrong answer. AGENTS.md asks for the doc to be updated in the same commit.
    Clears when: the claim-push design note names the two recovery paths (a tokenless claim, or every co-tenant disconnecting), worded the same as the new comment and reason string.
  • The removed _host_pid_hosts_several_sessions docstring was the only place that explained why the shared-pid check uses the unsigned mapping read: "it only ever DENIES an identity… the MAC-verified read would make the guard silently inert wherever the SEL trust root is missing… Source 3 below still demands the MAC, because source 3 GRANTS a key." host_pid_is_shared's own docstring says nothing about MAC versus unsigned. Without that note, the next person to "harden" the check by switching it to the verified read would quietly turn off the co-tenant guard on hosts with no SEL key.
    Clears when: that deny-only / grant-needs-MAC paragraph is moved into the host_pid_is_shared docstring in mcp_caller.py.

[DESIGN-REVIEWED] a25a5b9

Description read

[DESCRIPTION-READ] 077d358b62a52b804339b30c0babe2e73855397eae2b3c58e75557ce4449b641

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

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

The identity_refused = False reset does nothing anyone can observe. The description calls the stale flag "harmless today", and its only other argument is a guard that might be added later.

Not justified as shipped

  • Item 2 — inherited: the description's whole case is "harmless today … becomes a defect if a third guard is ever added". That is a guard that might exist later, not a defect. I grepped \.caller = None under mcp_gateway/ and got exactly 1 hit, control.py:279. That line sets identity_refused = True straight after it. So a re-attributed connection can only lose its caller again on a path that sets the flag again, and the reset changes nothing anyone can reach. The new test only asserts this unobservable state.
    Subtraction: delete conn.identity_refused = False and its four-line comment at control.py:336-340, plus the two identity_refused assertions in test_a_cleared_stub_regains_identity_after_co_tenant_disconnects.
    Clears when: the reset is deleted, or the PR shows a path where a re-attributed connection's caller goes back to None without the flag being set again.

What this change ships

Inventory (5 items) — 4 justified

Intent: give whoever audits the cleared-stub identity path accurate comments and less dead code (FIX of the advisory items in #17612).

  1. The comment and the audit/log reason now name the two real ways a cleared stub gets its identity back — justified
  2. A claim that re-attributes a connection now resets its "refused" flag — rides along on a "harmless today" premise; it changes nothing reachable
  3. The _policy_session_key docstring now names it as a reader of the env rung that is skipped on a shared pid — justified
  4. The _host_pid_hosts_several_sessions wrapper is deleted; the strict resolver calls host_pid_is_shared directly — justified
  5. A new test pins recovery after the co-tenant disconnects — justified

[FIRST-PRINCIPLES-REVIEWED] a25a5b9

Description read

[DESCRIPTION-READ] 2b34948d5cebdd3ffc604ebf0b78af9590d35e2c281932a59c33a854251d14f0

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a25a5b9

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

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

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch from 4cc1297 to e6230b5 Compare October 13, 2026 21:03
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/mcp_gateway/daemon/identity.py:101 -- “naming this connection's own token” misdocuments recovery: _apply_claim restores a cleared tokenless connection after the co-tenant disconnects, without matching any connection token (recurring-defect-patterns) -> Fix: describe tokened recovery when the PID is no longer shared in both this comment and the matching comment at line 596.
[GPT-REVIEWED] a25a5b9

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

@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 13, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch 2 times, most recently from 8d3c659 to a64edeb Compare October 13, 2026 21:24
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/agent_capabilities.py (same-dir), src/kiro_crew/cli_doctor.py (same-dir), src/kiro_crew/kiro_prerequisite.py (same-dir), src/kiro_crew/mcp_tools/apps.py (import), src/kiro_crew/session.py (same-dir), src/kiro_crew/session_background.py (same-dir) since this head went green (aaffa10 -> 3791b79); CI re-running.

@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch 3 times, most recently from bf447b1 to 38c385d Compare October 13, 2026 22:29
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_mcp_gateway_stub_session_token.py (related scope) since this head went green (3791b79 -> af8a5db); CI re-running. Also fixing Opus/First Principles findings: control.py comment precision, identity.py docstring + recaller comment updated to name both recovery paths.

@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch 2 times, most recently from 8f9d77a to 11ea502 Compare October 13, 2026 23:07
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/cron.py (same-dir) since this head went green (af8a5db -> f0b5aea); CI re-running.

@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 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch from 11ea502 to b5b647e Compare October 14, 2026 00:24
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/ same-dir files (acp_backends, artifacts, dashboard_feed, etc.) since this head went green (f0b5aea -> 09efe8a); CI re-running.

@CrysisDeu
CrysisDeu enabled auto-merge (squash) October 14, 2026 00:24
@CrysisDeu
CrysisDeu disabled auto-merge October 14, 2026 00:26
@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: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 14, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/conftest.py (import) since this head went green (09efe8a -> f5adcd7); CI re-running. This is the third rebase; if main continues to move, a maintainer review is needed before merge.

@CrysisDeu
CrysisDeu force-pushed the fix/17612-co-tenant-followups branch from b5b647e to a25a5b9 Compare October 14, 2026 01:13
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 14, 2026
@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 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at a25a5b9. This changes caller identity and session-token attribution, so approval remains with a human maintainer. Please also answer the current-head Design and First Principles items. They cover the old recovery story still in the design note, the unsigned deny-only read rationale lost with the wrapper, and the reachable effect of the new identity_refused reset. A fix or evidence-backed rebuttal should address each item. This is not an approval of the identity changes. Tests were inspected, not run locally. — crew-pr-reviewer (r99)

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

Checks green and PR Readiness passed at a25a5b9; non-feature change.

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

Readiness sweep review: read the full diff (merge-base) and the PR thread. PR Readiness is success on this head, mergeable, no effective CHANGES_REQUESTED, no unresolved blocking thread. Comments and dead-code removal only; merged-tree tests 358 passed. No regression to normal use found.

@bolichen97
bolichen97 merged commit 8b7d59f into main Oct 15, 2026
147 of 150 checks passed
@bolichen97
bolichen97 deleted the fix/17612-co-tenant-followups branch October 15, 2026 18:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 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.

Advisory follow-ups from the co-tenant identity review (#17524): cleared-stub recovery path, stale identity_refused, two subtractions

4 participants