Skip to content

feat: key gateway stub identity by session, not by process - #10324

Merged
chenmingwei23 merged 1 commit into
mainfrom
feat/stub-session-token
Sep 13, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
feat/stub-session-token

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The MCP gateway's stub path is the only channel that gives kirocrew-core a per-call caller identity (_meta.kirocrew.caller, injected by gatewayd after stripping any client-forged block). Every input it had for building that identity is keyed on the PROCESS TREE, not the session:

  • the stub's own self-report — KIROCREW_SESSION_KEY, else a session_pid_<pid>.txt ancestor walk (mcp_gateway/stub.py, mcp_caller.py); injected stub entries carry env: {}, so the stub reads whatever the runtime's process tree gives it,
  • gatewayd's own resolution — SO_PEERCRED peer pid → host /proc walk,
  • claim-push on warm-pool rekey() — keyed on the runtime PID, and _apply_claim REPLACES the caller on every indexed connection of that PID.

A spawn_run subagent shares its parent's kiro-cli process by default (agent.session_sharing), so one runtime hosts N ACP sessions and all three sources answer with the PARENT's session key for a subagent's stub — and a parent rekey overwrites whatever a subagent had.

Why it matters

Today the strict identity gate REFUSES when no channel exists, so the failure is safe. Once stubs become the default channel it stops being safe and becomes "wrongly succeeds as the parent": a subagent could monitor_start a loop on the user's chat slot, work_report onto the parent conductor's item, or set_project another slot's working tree. This lands the discriminator before that default can flip.

What changed (motivation → approach → change)

The tree cannot name a session, so something else has to. Kiro Crew mints one unguessable token per ACP session and gatewayd keys claims by (pid, token).

  1. Token on the stub entry. claim.mint_stub_session_token() (256 bits, secrets) plus session_servers.attach_stub_session_token(), which puts it in the env array of that session's injected entries. AcpRuntime.create_session / load_session mint one per ACP session (parent slot, each subagent session, each warm worker at warm time) and record it on the session handle. AcpClient mints one per client process — it serves one session at a time — and its rekey() re-binds the same token rather than re-minting, since stub processes outlive a single chat. pooled_session_servers' signature is untouched; the token is attached after it, which is why callers that monkeypatch it are unaffected.
  2. Stub forwards it. build_register_payload reads KIROCREW_STUB_SESSION_TOKEN and sends stub_session_token as a sibling of poolable. It is not a PoolKey dimension — a per-connection dimension in the key would make every session's backend private and turn pooling into a no-op (pool module docstring).
  3. gatewayd keys claims by (pid, token). A bounded, claim-written-only token → caller table. _apply_claim records the binding (a claim precedes its own stubs, so "matched zero connections" is the normal ordering) and re-targets connections whose token matches plus connections carrying none; a claim with no token re-targets every connection under the PID exactly as before.
  4. A token no claim has named is refused, not resolved. A binding outranks both process-tree sources at register time, and where none exists the self-report, the peer walk and the stub-initiated recaller frame (whose key comes from the same walk) are all declined — the connection stays identity-less, the state every warm-pool stub already starts in. The refusal is deliberately unconditional rather than scoped to "a sibling session is already named": an empty binding table is the state a fresh daemon, a respawn and an evicted binding all share, and in each of those the tree answer is a different session's.
  5. Repair is the owning session's own claim, never a fallback: awaited before session/new where the owner is known, pushed at rekey() and after new_conversation re-launches a worker's stubs, and re-pushed at the start of every turn by the shared identity publisher (messaging/identity.py, the same boundary that already rewrites session_pid_<pid>.txt because that mapping lives outside the process and can be lost while the session is alive). The per-turn re-push is what re-binds a token whose daemon restarted under it.
  6. The token is a bearer name, so it is popped off the register frame before the prewarm recorder (which persists whole register payloads to disk) can see it, and it never reaches a log record, stats(), or the stub fallback journal.
  7. No default moves. mcp_gateway.enabled and stub_servers are untouched, and a runtime with no gateway socket mints nothing — no gatewayd to bind a token means the token would have no reader.

Tests

test/test_mcp_gateway_stub_session_token.py (41 tests), driving the real gatewayd._handle_connection loop through the harness test_mcp_gateway_claim.py and test_identity_topology.py already use:

  • The three topologies, parametrized: no-token (neither connection carries one — a tokenless claim re-targets both, as before), all-tokens (a claim for one reaches only that one), mixed (the tokened connection is selected and the tokenless one rides along).
  • The isolation test: two connections under ONE runtime PID with different tokens — a claim for A re-keys only A, B's caller is unchanged, a parent re-claim still does not move B, and a claim with no token re-targets both.
  • End to end, on ProcessTopology's real subagent tree with the gateway's session_pid_<host_pid>.txt naming the parent: after the parent's rekey the subagent's stub still forwards as the SUBAGENT, and require_strict_session_key — the gate monitor_start and every reflexive tool route through — answers with the subagent's key against that identity.
  • Fail-closed: an unclaimed token is refused even with an empty binding table; its own claim repairs it; a recaller cannot name it; and a daemon respawn with both sessions live leaves neither wearing the other's identity, with the per-turn re-claim restoring both.
  • Register precedence: the binding beats the stub's self-report and beats the /proc walk (with the host chain still indexed so later claims land).
  • Leak bar: the token is absent from log records, stats(), stub_fallback.jsonl, and both the in-memory and flushed prewarm payloads.
  • Crew side: the claim is awaited before session/new; two sessions on one runtime get different tokens; an unclaimed warm worker mints a token but pushes no claim; no stub entries means no token and no claim; rekey() and new_conversation claim by the handle's token; the turn boundary re-claims and leaves a provider without stubs alone; and a source pin that the subagent path hands down its own session key.
  • The shipped binary: a second real-kiro-cli probe (REAL_CLI-gated, beside the existing precedence pin) asserts the child receives the env pair AND that an element carrying env still overrides the agent spec's same-named entry.

Revert-verified: 21 mutations, each reverting one half of the change (claim ignores the token, register ignores the binding, either fail-closed rule dropped, unbounded table, the token left on the prewarmed frame, attach never attaches, the stub never forwards, the runtime mints nothing or claims nothing, the turn boundary or new_conversation never re-claims, the client re-claim names no token) — all 21 caught, tree restored green.

Zero-regression bar, all UNMODIFIED: test_mcp_gateway_claim.py, every test_mcp_gateway_stub_* / test_stub_* / test_gatewayd_*, test_mcp_gateway_backend_coverage.py, test_mcp_gateway_control_plane.py, test_mcp_gateway_prewarm*, test_identity_topology.py, test_acp_runtime.py, test_acp_session_provider.py, test_acp_harness_wire_parity.py (the byte-golden wire capture) and test_real_kiro_cli_prefers_session_injected_server on the installed kiro-cli. A full local backend run was diffed against a run of the same suite on this PR's base commit: identical failure sets (host-environment reds — atomic no-replace rename is unavailable, missing optional deps), no branch-only failure.

Manual verification

isort, flake8, mypy src/kiro_crew and the black gate clean on the CI-pinned versions; docs-lint.sh clean; the diff-scoped gates (brand, harness parity, comment history, subprocess encoding, changelog history, focus cue, sync-io, loop-bound locks, agent-sdk boundary, memory-store seam, feature map) run with their own base-ref exports.

test/smoke_gateway.sh was NOT run: it requires a live gateway on localhost:5476 and drives ~20 real model turns asking an agent to attempt AWS credential exfiltration. It exercises the shell/credential gates, not the MCP-gateway stub path this change touches. The equivalent end-to-end coverage here is test_mcp_gateway_pool_integ.py and test_stub_broker_reconnect.py, which spawn real stubs against a real daemon, plus the real-kiro-cli probe above.

Known gaps

  • A gatewayd respawn mid-turn leaves that turn's stub connections identity-less until the next turn's re-claim (now armed on both turn boundaries: the dispatch publisher and AcpSessionProvider.stream). Fail-closed (a strict tool refuses with its diagnosis) rather than acting as another session, and bounded to one turn. Closing it fully would mean the daemon's supervisor replaying claims for every live session at spawn — worth doing on its own, not inside this change.
  • A session created on a path that names no owner AND never runs a turn through the shared identity publisher (an internal worker pool) keeps a token nothing claims, so its stubs stay identity-less instead of resolving to whatever the runtime's tree said. That is the intended direction of the trade, and those callers pass their own mcpServers or never resolve a session key today.

Review round 2 — what changed and why

GPT 5.6 F1 (round 1): an unclaimed token fell back to the process tree after a gatewayd respawn. Correct, and the reason was that the refusal was made conditional on observing a named sibling — which fails open in exactly the states where the observation is missing (fresh daemon, respawn, evicted binding). The rule is now unconditional: a token present with no usable binding gets NO identity, and repair comes only from the owning session's own claim, which is re-pushed at every turn boundary by the shared identity publisher (plus after new_conversation). Test: test_a_daemon_respawn_leaves_no_session_wearing_anothers_identity.

GPT 5.6 F1 (round 2): the token rides an env pair, and /proc/<pid>/environ is same-uid readable, so a sibling process can present another session's token. Two parts:

  1. Hardened. A claim binds the token together with the runtime PID it named, and a register is now answered from that binding only when the same PID is in the connecting stub's own ancestry — the same membership claim-push already needs to reach a connection at all. So the token narrows within a runtime and the runtime tree bounds who may present the token: holding another session's token from outside its runtime buys nothing. Test: test_a_stolen_token_buys_nothing_outside_its_runtime. Revert-verified (a token binding is honoured outside its own runtime tree → caught).

  2. Residual, and pre-existing. Inside one runtime's tree the token remains a bearer value, and no transport change closes that: argv is as readable as environ, and a 0600 sidecar is readable by the same uid too — same-uid confinement is the sandbox's job (agent.sandbox, off by default). More importantly, a same-uid process needs no token to do this today: a register frame with a self-reported session_key and no token is believed verbatim (_caller_from_register → caller, no verification), on this branch and on main alike. So the token grants no capability that the register path does not already grant for free. Authenticating the register frame itself is the real fix and is a separate change with its own blast radius — it is not something to bolt onto this one.

First Principles CONCERNS — unfixed siblings of the named root cause. Of the three create_session sites that named no owner, session_allocation.py:640 genuinely needed it: it opens a per-step session on the task run's shared runtime with the owning key already in scope. Fixed, and pinned by a parametrized source test over every shared-runtime session site so a deleted keyword argument fails the suite. The other two (session_background.py _bg runtime, review_pool.py sage pool) have no Crew session key to name and resolve to nothing today either — they are not sessions a reflexive tool acts for.

SAST (Semgrep). Two findings, both about the shape of test/log code rather than a leak: a ContextVar token-based reset in a test that crosses an asyncio boundary (switched to value-based restore, which the rule asks for), and a logger format string containing the word "token" (reworded — the token itself was never an argument).

Detect changed surface / Coverage Gate (round 1). GitHub API rate limit inside the job (API rate limit exceeded for installation), not a code failure; green on the re-run.

Review round 3 — what changed and why

GPT 5.6 (gatewayd.py:2890): the token's second factor was checked against pids the registrant authors. Correct, and it voided the factor: indexed_pids folds in the stub's self-reported ancestor_pids, so the same actor that read a token out of /proc/<pid>/environ could also name that token's runtime in its own chain and satisfy both halves alone. The register now authenticates the binding against peer_host_pids only — the chain gatewayd walks from the kernel's SO_PEERCRED peer pid, which the registrant cannot write. The self-reported pids keep their one job, claim indexing, where they are harmless: a claim only ever narrows to connections carrying its own token or none. A connection whose ancestry the kernel did not attest loses the register-time shortcut, not its identity, because claim-push still reaches it through the index. Tests: test_a_self_reported_ancestry_cannot_authenticate_a_token (the spoof: stub claims the victim's runtime pids, kernel places it elsewhere) and test_a_stolen_token_buys_nothing_outside_its_runtime. Revert-verified as its own mutation (the token is authenticated against the stub's SELF-REPORTED ancestry → caught).

Opus 4.8 (session_provider.py:503): a cold-started session's per-turn re-claim carried an empty key, so no token could ever be re-bound. Also correct, and it silently disabled the round-2 repair path on the most common topology: rekey() is a warm-pool event, so a pool miss, pooling switched off, or a subagent's own session reaches it never — _session_key stayed "", reclaim() pushed a keyless claim, and _apply_claim rejects that as malformed before _bind_token runs. Every provider is now told which session it serves at CONSTRUCTION (session_key= / channel_id=, still overwritten by a later rekey()), at all three sites that build one: the cold-start parent slot, the subagent, and the task runner's per-step session. Test: test_a_cold_started_session_can_re_bind_after_a_respawn walks the whole chain — the keyless claim binds nothing, the seeded one re-binds and re-targets the live stub — plus a parametrized source pin over every construction site.

First Principles CONCERNS: the per-turn re-claim never reached subagent sessions. True, and it was the one session type the token exists to protect: all 8 publish_turn_identity call sites are dispatch surfaces, and a subagent's turns are driven by its manager. So the re-claim now also fires at AcpSessionProvider.stream — the boundary every session on a shared runtime crosses to take a turn, subagents included. A daemon respawn mid-run therefore costs a subagent one turn rather than the rest of the run. Test: test_a_subagents_own_turn_re_establishes_its_claim; revert-verified as its own mutation.

GPT 5.6 (session_servers.py:68): the fallback backend inherited the session's bearer name. Real and new: when the gateway is unavailable the stub EXECs the operator's own MCP server binary in its place, and fallback_exec copied the whole environment — so a third-party backend inherited a value it could later register with and be answered as this session. That entry is now popped from exec_env before the exec (and before the Windows spawn that stands in for it), while the server's own declared env is still restored, which is the parity that path exists for. The non-fallback path never had this: gatewayd spawns backends from its own environment. Test: test_the_fallback_backend_never_inherits_the_token; revert-verified as its own mutation.

Rebased onto origin/main (one import-line conflict in stub.py from #10331's decode_target_args, both sides kept). 41 tests, 21/21 mutations caught, isort/flake8/mypy/black gate/docs-lint and the diff-scoped gates clean.

Related Issues

N/A — no tracking issue.

Pattern harvest

Pattern: an identity keyed on a resource that is SHARED by construction (a process tree hosting N sessions) reads as correct wherever N is 1, and answers with a sibling's identity as soon as it is not. The generalizable check is not "is this source trustworthy" but "does this source's key have the same cardinality as the thing being named". A second, narrower one from review: a fail-closed rule made conditional on observing a conflict ("refuse only when a sibling is already named") fails OPEN in every state where the observation itself is missing — an empty table, a cold start, a restart — so the condition has to be the token's own unresolved state, not the presence of a neighbour. Rule candidate: review-prompt — when a change resolves "which session/tenant is calling", ask what the resolution is KEYED on, whether one key can serve two callers, and what the rule does when its own evidence store is empty.

@iamwhatever
iamwhatever requested review from a team and Zedmor September 12, 2026 07:33
@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 Sep 12, 2026
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Fixes an identity keyed on a shared resource at its root (per-session token, fail-closed, claim-repaired), moves no default, and stays byte-compatible for tokenless paths.

Suggestions

  • The per-turn re-claim now has two owners — publish_turn_identity's duck-typed reach-in (_reclaim_gateway_stubs) and AcpSessionProvider.stream(). Putting the re-claim in both providers' stream() (AcpClient included) would make the turn boundary the single owner, retire the getattr reach-in, and cover any AcpClient-backed session whose turns never cross a dispatch surface.

[DESIGN-REVIEWED] 046462e

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 046462e24df0564c4a832fe043609ec36135b129 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 046462e

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

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 046462e24df0564c4a832fe043609ec36135b129 — 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: PASS

Verify the one asserted-but-unpinned premise: an AcpClient never serves two sessions at once — its single re-bound token silently merges identities if that ever changes.

What this change ships

Inventory (10 items) — 10 justified

Intent: give each ACP session on a shared kiro-cli process its own gateway identity so a subagent's MCP calls can never resolve — or be re-pointed — as its parent. ADDITION (hardening a named boundary: the agent-identity gate), with the defect pinned by tests in this PR that fail on base.

  1. Each session's injected stub entries carry a secret per-session token in their env — justified
  2. A claim re-targets only its own session's stubs; a parent rekey no longer renames a subagent's — justified
  3. A stub whose token no claim named is refused identity instead of resolved from the process tree — justified
  4. Tokenless stubs (hand-written configs, older overlays) keep byte-identical PID-wide behavior — justified
  5. Sessions on shared runtimes declare their owner at creation (subagent runs, task steps, cold starts) — justified
  6. Every turn re-pushes the session's claim, bounding a gatewayd-restart outage to one turn — justified
  7. Token never reaches logs, stats, fallback journal, prewarm file, or a fallback-exec'd backend's env — justified
  8. gatewayd holds a bounded (512-entry) in-memory token→session table — justified
  9. New reclaim() on both provider shapes, reached by the shared identity publisher — justified
  10. mcp.md and the stub-decoupling note updated in the same commit — justified

Counts run: runtime.create_session has 6 production call sites — 3 fixed here, new_conversation repaired by its post-create reclaim(), warm.py:1627 passes an explicit empty array (skips injection), review_pool.py:468 builds its runtime with no gateway socket (mints nothing). runtime.load_session has 1 caller, covered. No unfixed sibling. The existing per-session env mechanism (KIROCREW_SESSION_KEY on member entries) is not a second spelling: it is peer-asserted and frozen at stub launch, while the token is Crew-bound and re-bindable across rekeys — the property the fix needs.

[FIRST-PRINCIPLES-REVIEWED] 046462e

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

Both candidates rest on the same premise: that create_session() on these shared runtimes now mints and attaches a stub session token that never gets claimed, leaving the session identity-less. That premise fails at the first guard in _own_stub_session:

if not entries or not self._mcp_gateway_socket:
    return entries, ""

The ReviewPool runtime (review_pool.py:468, AcpRuntime(agent=..., work_dir=..., sandbox_mode="auto")) and the background runtime (session_background.py:520, AcpRuntime(agent=..., sandbox_mode=..., acp_backend=..., expect_mcp_reports=False)) are both constructed without mcp_gateway_socket, which defaults to None (runtime.py:724,787-788) and is never reassigned. So _own_stub_session returns (entries, "") immediately — no token minted, no token attached, stub_token="" on the handle. No stub carries a token, gatewayd's elif stub_session_token: branch is never reached for these connections, and the wire shape is byte-identical to pre-PR. There is no identity-less regression because there were no injected gateway stubs on these runtimes in the first place. The candidates' own confidence lines flag exactly this unverified assumption.

Both drop under falsification (a) — no concrete input reaches the changed behavior.

No findings.

[OPUS-REVIEWED] 046462e

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

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

@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 67ce104 to 0a2f889 Compare September 12, 2026 08:22
@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 Sep 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 0a2f8891cad1994f3732d21147cb6d0e0f68d807; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

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

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 0a2f8891cad1994f3732d21147cb6d0e0f68d807; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 0a2f8891cad1994f3732d21147cb6d0e0f68d807: <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 Sep 12, 2026
@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 0a2f889 to 65cc139 Compare September 12, 2026 08:50
@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 Sep 12, 2026
@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 65cc139 to 38d7bd1 Compare September 12, 2026 09:44
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 12, 2026
@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 38d7bd1 to 9d0a460 Compare September 12, 2026 19:16
@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 Sep 12, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 12, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 3c7f514: The residual is a same-uid co-tenant of one runtime, which is already inside the trust boundary Opus verified and dropped, and it grants no new capability because a tokenless register on main is already believed with any self-asserted session_key — authenticating the register frame itself is a separate change, tracked as a follow-up.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 3c7f5140aac2d662169a728220eb19418d32bda8.

The residual is a same-uid co-tenant of one runtime, which is already inside the trust boundary Opus verified and dropped, and it grants no new capability because a tokenless register on main is already believed with any self-asserted session_key — authenticating the register frame itself is a separate change, tracked as a follow-up.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention labels Sep 13, 2026
@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 3c7f514 to 7a0e956 Compare September 13, 2026 19:49
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 13, 2026
Every identity channel a broker stub had was keyed on the process tree:
the stub's own KIROCREW_SESSION_KEY / session_pid_<pid>.txt walk,
gatewayd's SO_PEERCRED /proc walk, and claim-push, which re-targeted
every connection indexed under a runtime PID. One kiro-cli process hosts
N ACP sessions, so all three answered with the parent slot for a
spawn_run subagent's stub, and a parent re-claim overwrote whatever a
subagent had.

Mint one unguessable token per ACP session, carry it in the env of that
session's injected stub entries, and have the stub return it on its
register frame as a sibling of poolable -- never a PoolKey dimension,
which would make every session's backend private and turn pooling into a
no-op. gatewayd keys claims by (pid, token): a claim re-targets the
connections carrying its token plus any carrying none, and a claim with
no token keeps the PID-wide reach a hand-written config still needs.

A token no claim has named is refused rather than resolved, and a claim's
binding is honoured only for a connection the KERNEL places under the
runtime that claim named -- the peer-pid chain gatewayd walks itself,
never the stub's self-reported ancestor_pids, which the registrant
authors and could point at any runtime whose token it had read. The
refusal is unconditional because an empty binding table is the state a
fresh daemon, a respawn and an evicted binding all share.

Repair is the owning session's own claim: awaited before session/new
where the owner is known, pushed at rekey() and after new_conversation,
and re-pushed at the start of every turn by the shared identity
publisher. A claim carries a session key or gatewayd discards it, so
every provider is told which session it serves at CONSTRUCTION -- rekey()
is a warm-pool event and a cold start never reaches it.

The token is a bearer name for a session's identity, so it is stripped
from the register frame before the prewarm recorder can persist it, and
never reaches a log record, stats() or the stub fallback journal.

No default changes: mcp_gateway.enabled and stub_servers are untouched,
and a runtime with no gateway socket mints nothing.
@iamwhatever
iamwhatever force-pushed the feat/stub-session-token branch from 7a0e956 to 046462e Compare September 13, 2026 20:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention 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 Sep 13, 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