Skip to content

fix(session-control): authorize a created child on the store it is bound to - #11593

Merged
iamwhatever merged 1 commit into
mainfrom
fix/main-red-11585
Sep 17, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/main-red-11585

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

main is red at tip on Backend Tests, and because CI evaluates
refs/pull/<n>/merge, every open PR inherits the failure on its own board.

Run 35254907186, head 0640c1e0d, event=push, branch=main: failure=5,
skipped=6, success=29. Failed jobs Backend Tests (Windows) (5),
(Windows) (7), (3.12, 5), (3.12, 6), Coverage Gate. Six tests, in two
groups:

test/test_member_session_control.py

TestMemberChildPrivateBinding::test_a_v1_child_writes_no_private_binding
TestMemberChildPrivateBinding::test_global_caller_cannot_grant_a_child_private_authority
  AssertionError: assert 'member-radar' is None

test/test_session_control.py

test_create_refuses_unreadable_delegation_identity[OSError]      OSError: /private/identity/path
test_create_refuses_unreadable_delegation_identity[ValueError]   assert 400 == 403
test_private_creator_cannot_change_memory[public-worker-canonical]
test_private_creator_cannot_change_memory[writer-canonical]
  assert 'agent_store_mismatch' == 'memory_delegation_denied'

Why it matters

Nothing else can go green until this does. Every open PR shows four backend
shard reds plus a Coverage Gate cascade (backend-test=failure -- failing closed) and a PR Readiness cascade that its own diff did not cause, so
authors either chase a red they cannot fix or fold a session-control change
into an unrelated PR.

Underneath the red, two of the failures are a real weakening of the private
memory boundary, and one of the passing tests was pinning it open.

What changed (motivation -> approach -> change)

Where it came from

#11438's own CI was fully green: 72 SUCCESS, 11 SKIPPED, zero failures at
head af6ad53b5b. Its base was b6ec82e02a, and
git merge-base --is-ancestor 164d30d944 b6ec82e02a answers no: that base does
not contain 164d30d944, fix: preserve member identity through dispatch and continuation (#11018). main gained 27 commits including #11018 between that
base and the merge.

#11018 and #11438 solve the same problem independently. #11018's commit
message states it directly: "Publish protected choices before birth", "Private
callers create workers only in their own store." The collision exists only on
main, which is why neither PR's own CI could see it.

Which reading I took

Reading (b), the production change weakened a boundary, for five of the six
tests. Reading (a) for exactly one, argued below. Neither group's assertions
were relaxed to match what the code returns.

Group B: a second delegation gate, weaker on four axes

create_session now had two require_memory_delegation call sites. The one
#11438 added runs first and shadows #11018's. It differs on four points, each
in the losing direction:

It is evadable by re-spelling. It passes caller_session_key -- whatever the
caller called itself -- where the existing gate passes caller_memory_identity[0],
the canonical history key. read_private_session_store recognises only the
canonical form. The failure pattern proves it: of the six
test_private_creator_cannot_change_memory params only the two canonical ones
fail, while [writer-slot], [writer-stem], [public-worker-slot] and
[public-worker-stem] pass, because under those spellings the new gate does not
recognise the caller as private at all and the request falls through to the
older gate. An authorization input the caller chooses the spelling of is a
bypass, not a lenient read.

It downgrades the refusal. agent_store_mismatch is a 400;
memory_delegation_denied is a 403. The store is a legal name and the request is
well formed -- the answer is "you may not delegate there", so a validation code
misinforms the caller and reads as a client bug in the audit trail.

It leaks the record's path. SessionControlError(str(exc), ...) from exc
carries the text of a function that reads binding FILES.
test_create_refuses_unreadable_delegation_identity asserts
"/private/identity/path" not in str(exc.value); the existing site uses a fixed
message and from None for exactly that reason.

It omits OSError. except (UnknownMemoryStore, ValueError) lets the
unreadable-file case escape create_session as an unhandled 500 -- the [OSError]
failure. The existing site catches (OSError, ValueError).

The fix: the early block stops re-implementing the refusal. It reads only the
caller's own protected record, which is the one thing it actually needs
(caller_private_store, the input to the child-binding decision further down),
under the canonical key, and maps a failure to the same 403 with the same fixed
message. The delegation refusal itself belongs to the one gate that already made
it correctly.

Group A, first test: the gate authorizes one store, the write names another

test_a_v1_child_writes_no_private_binding is reading (b), and the mechanism is
not in #11438 at all. _persist_birth calls _pin_private_agent_assignment,
which derives the store to pin from the SELECTED AGENT's config entry, while the
delegation gate above checked bindings.memory_store_name. Those are different
values. A local probe caught the divergence directly: a child with
slot.memory_store == 'default' was written a binding naming member-radar, from
chat_persistence.py:880, for a caller with no private record at all.

The fix passes the authorized store down and pins nothing when the two disagree,
so the act matches the check. The owner's own agent picks pass no authorized
store, because there the pick IS the authority.

Group A, second test: reading (a), and why

test_global_caller_cannot_grant_a_child_private_authority asserts
child.memory_store == "member-radar" on one line and no private binding on the
next. chat_runner._bind_private_slot_memory raises UnknownMemoryStore ->
memory_unavailable on exactly that pair, at chat_runner.py:8518: a slot whose
metadata names a V2 store and whose binding is absent can never take a turn.
The test pins the defect #11018 fixed, so satisfying it would restore it.

It is renamed to test_global_caller_binds_a_child_only_to_the_member_it_selected
and now pins the invariant that matters: the child is bound to the store the
delegation gate authorized -- the selected member's own -- and to nothing else, and
the caller's own protected record stays unbound, so the caller gains nothing.
The escalation the old name was reaching for, a child on a store the gate did not
authorize, is test_a_v1_child_writes_no_private_binding, which is unchanged and
now passes.

Where the older contract was decided, and the alternative weighed

#11018's own PR body states the decision this PR keeps, in one clause: "Private
callers create only same-store workers; Global callers retain member
assignment.
" The same paragraph names the capability that refusing would remove
-- owners reopening member conversations and seeing delegated workers -- and its
design table's Delegation row states the mechanism: "publish selection and pin
assignment before birth metadata".

That source independently backs the group B fix too: "Creation checks the
canonical caller key before allocation." The gate #11438 added keyed on the raw
caller-supplied spelling instead, which is exactly why only the [*-canonical]
params fail.

A third resolution exists and is not taken here: refuse a global caller's
member-agent selection outright, rather than binding the child or minting a dead
one. It removes a shipped capability, so it is a product-shape change needing an
RFC already on main, and it would widen a main-red fix while four PRs inherit that
red. Raised as its own issue (#11613) so it survives this PR either way. This PR
narrows the path instead: the birth pin is fenced to the store the gate authorized,
so a child can no longer land on a store the gate never saw.

Also updated

Three tests from #11438 expected agent_store_mismatch from the delegation
path. They now expect memory_delegation_denied and status == 403, and two of
them additionally assert the refusal does not echo the guard's own text. That is
the older contract winning on its merits, not a relaxation: it is stronger on
status, on message hygiene, and on the exception set it catches.

docs/system-specs/modules/session-control.md moves with the code. It had stated
"An unbound/global caller keeps ordinary creation behavior, with no private
binding even when the chosen agent names a V2 store", which is the assertion the
turn path reads as memory_unavailable.

Tests

The six failing tests pass unchanged except for the one rename, which is argued
above.

Added, both of which fail without a specific part of this change:

  • test_the_child_binding_ignores_how_the_caller_spelled_itself[canonical|slot|stem]
    pins that the pre-birth binding happens for every spelling of the caller's own
    session key, observed at the moment the birth pin runs. Under the raw-spelling
    read, [slot] and [stem] fail and [canonical] passes -- the bug's exact
    shape.
  • test_a_corrupt_caller_record_refuses_without_naming_it pins the early block's
    own refusal: memory_delegation_denied, 403, and the record's path absent from
    both exc.value.message and str(exc.value).

Manual verification

Reproduced first, on a worktree off origin/main at c5842a635c with
KIROCREW_HOME pointed at a scratch directory: the two group A tests fail in
isolation (so not shard pollution), and group B fails 4 of 8 params.

Mutation matrix over the change, run out-of-tree: 7 mutants, 0 holes, with the
clean tree green (46 passed) both before and after the run, and every anchor
counted before use so an unmatched anchor is a hard failure rather than a skipped
check.

Mutant Reverts Reddens
M1 caller record read under the raw spelling spelling test [slot], [stem]
M2 early refusal -> 400 agent_store_mismatch corrupt-record test
M3 early refusal echoes the reader's text corrupt-record test
M4 birth pin unfenced test_a_v1_child_writes_no_private_binding
M5 authorized store not declared to the pin test_a_v1_child_writes_no_private_binding
M6 delegation gate stops catching OSError ..._unreadable_delegation_identity[OSError]
M7 delegation gate -> 400 agent_store_mismatch 8 params across both files

Adjacent sweep, all green: 684 passed across test_member_session_control.py,
test_session_control.py, test_session_control_member_gate.py,
test_member_memory_api.py, test_member_memory_runtime.py,
test_member_memory_ownership.py, test_cron_session_control.py,
test_chat_agent_selection.py.

Gates run before committing, each as its own invocation:
scripts/check_black_formatting.py, black --target-version py310 --check,
isort --check-only, scripts/check_comment_history.py with
COMMENT_HISTORY_BASE_REF=origin/main, scripts/check_brand_name.py,
scripts/check_subprocess_encoding.py. All exit 0.

Related Issues

Fixes #11585

Pattern harvest

Rule candidate: semgrep
Pattern: a private-memory authorization read keyed on a caller-supplied session
key instead of the canonical history key -- read_private_session_store or
require_memory_delegation receiving a raw *_session_key parameter where a
canonical identity is in scope.

The class generalizes twice over. The first shape is one decision made at two
sites: a second gate added for a question an existing gate already answers will
drift, and the weaker of the two wins because it runs first. A review-prompt line
covers it -- when a change adds a guard, name the existing guard for the same
decision and reuse its refusal rather than minting a second code. The second
shape is a gate that validates one value and an act that uses another; here the
gate read bindings.memory_store_name and the write derived its own store from
the agent config.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

…und to

Read the caller's protected record under its canonical history key, so a
member's authority does not depend on which of the three spellings of its
own session key it supplied. Keep one delegation refusal, the
memory_delegation_denied 403, with a fixed message.

Fence the birth-time private pin to the store the delegation gate cleared.
The pin derives its store from the selected agent's config entry, which is
a different value, so the gate and the write could name different stores.
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 6eefcae8d5a4041ffee8198e6168abe68bee0c32 — 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 inverted pin: the renamed test now asserts a global caller's child IS bound — the turn-path mechanism (chat_runner.py:409) confirms it in-repo, but confirm intent against #11018.

What this change ships

Inventory (9 items) — 9 justified

Intent: unwedge red main by deleting the weaker duplicate delegation gate #11438 layered over #11018's — a FIX (six named failing tests on main are the provenance).

  1. Delegation refusal answers 403 memory_delegation_denied instead of 400 agent_store_mismatch — justified
  2. Refusal carries fixed text; no longer echoes a binding file's own path — justified
  3. Unreadable caller record now refuses cleanly instead of escaping as a 500 — justified
  4. A member's private authority no longer depends on how it spelled its own key — justified
  5. The duplicate require_memory_delegation call site is deleted; one gate owns the refusal — justified
  6. Birth pin writes nothing when the selected agent's store isn't the authorized one — justified
  7. Global caller's child now bound to the selected member's store (pin reversal, declared with mechanism) — justified
  8. session-control.md moves with the code in the same commit — justified
  9. New tests pin spelling-independence and the no-path-leak refusal — justified

Counts run: require_memory_delegation — 3 production call sites remain (messaging, subagent run, the one surviving create_session gate at session_control.py:1144). authorized_store — 1 value-passing consumer plus a semantically distinct None default used by the owner-pick wrapper (chat_persistence.py:912), so not a one-consumer generalization. Fence comparison reuses the existing named_store_or_empty (memory_stores.py:182), no second spelling. The rewritten pin's evidence checks out: _bind_private_slot_memory raises UnknownMemoryStore on a V2 store with no binding, so the old assertion pinned a session that could never take a turn.

[FIRST-PRINCIPLES-REVIEWED] 6eefcae

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 6eefcae8d5a4041ffee8198e6168abe68bee0c32. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/dashboard/session_control.py:1425 -- target store is treated as authorization
authorized_store=bindings.memory_store_name,
Global caller selects private V2 member -> delegation check returns early -> child receives protected binding -> caller can drive/read private-memory turns.
Anchor: backend-security-controls
Fix: Require the caller’s protected store to match before authorizing a V2 pin; otherwise return 403.
[GPT-REVIEWED] 6eefcae
[BLOCK-MERGE] 6eefcae

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

I've traced the full chain. Let me confirm my understanding of the key conditions.

The finding F1 concerns the recently-added authorized_store fix (#11593). Tracing:

  • Delegation returns early for a global caller — context.py:372-374: a non-subagent caller with no private record (read_private_session_store(...) is None) returns without refusing. A global caller passes the gate.
  • The pin binds regardless — chat_persistence.py:865-868 fences the pin on authorized_store, but create_session passes authorized_store=bindings.memory_store_name (session_control.py:1425), which is the selected agent's own store — the same value store is derived from. So the check store != authorized_store is tautologically false and the fence never fires; bind_private_session_store runs at chat_persistence.py:897.
  • Runtime binding is correctly gated but the pin path is not — session_control.py:1365 gates the runtime bind on caller_private_store == _store_name, yet the pin path at 1414-1426 has no equivalent caller-store check.

The conditions (a global caller invoking create_session; naming a private V2 member) are ordinary, not extreme or mutually contradicting. I cannot construct a rarity argument that a human would accept the residual cross-member private-memory exposure. The harm term is unbounded (privacy/governance ceiling bypass). FLAG's evidence bar is not met → UPHOLD-FENCED.

Harm rung: UNBOUNDED — private-memory ceiling bypass, global caller drives/reads another member's V2 store.
Conditions confirmed: delegation early-return context.py:372-374; tautological pin fence chat_persistence.py:865-868 fed target store session_control.py:1425; missing caller-store gate on pin path vs. gated runtime bind session_control.py:1365.
Rarity: not extreme — a global caller naming a private V2 agent is ordinary operation; no rarity argument available, so FLAG is unsupported.

[ADJUDICATION] 6eefcae8d5a4041ffee8198e6168abe68bee0c32 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 6eefcae8d5a4041ffee8198e6168abe68bee0c32
[ADJUDICATION-FENCED] 6eefcae8d5a4041ffee8198e6168abe68bee0c32 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/dashboard/session_control.py:1425 -- A global caller passes the trivially-satisfied delegation early-return and the tautological pin fence (authorized_store equals the target's own store), binding its child to another member's private V2 store; ordinary conditions, no rarity argument, unbounded harm.
[GPT-ADJUDICATED-FENCED] 6eefcae8d5a4041ffee8198e6168abe68bee0c32

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

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Inverting the "global caller cannot grant private authority" pin ratifies that agent selection alone binds an unfenced caller's child onto a member's private store.

Watch

The renamed test now asserts read_private_session_store(effective_session_key(child)) == "member-radar" where it asserted is None — a security-named pin from #11438 inverted, with the third resolution (refuse a global caller's member-agent selection outright, instead of binding or minting a dead session) never weighed in the PR or spec. Mechanism: the delegation gate is a no-op for unbound callers, so any global session — including one steered by untrusted external content — mints a functioning worker on any member's private store by picking that member's agent. The bind-over-refuse argument is coherent (the unbound child is provably dead at chat_runner.py:8518, and #11018 already shipped this direction), but this PR is what turns it into the pinned invariant.
Clears when: a maintainer of the session-control privacy model explicitly confirms bind-over-refuse for global callers, or cites where #11018's review already decided it.

[DESIGN-REVIEWED] 6eefcae

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 6eefcae

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

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

@iamwhatever
iamwhatever merged commit 2627b04 into main Sep 17, 2026
84 of 85 checks passed
@iamwhatever
iamwhatever deleted the fix/main-red-11585 branch September 17, 2026 22:01
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 17, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Answering the Design Review CONCERNS on the merits, including the third
resolution it says was never weighed.

The citation it asks for exists. #11018's own PR body states the decision in
one clause: "Private callers create only same-store workers; Global callers
retain member assignment.
" That is bind-over-refuse for a global caller, decided
in the PR that shipped the behaviour, and it went through roughly forty review
comments there. The same paragraph names the owner-facing capability that refusing
would remove -- "Owners need to continue the same task with the same private
memory. They need to reopen member conversations and see when delegated workers
are still busy" -- and the design table's Delegation row states the mechanism this
PR keeps: "publish selection and pin assignment before birth metadata".

The same source also independently supports this PR's group B fix: "Creation
checks the canonical caller key before allocation." #11438's second gate keyed
on the raw caller-supplied spelling instead, which is why only the [*-canonical]
params failed while [*-slot] and [*-stem] passed. So the older decision and
this PR agree, and the shadowing gate is what departed from it.

The third resolution, stated so it is on record rather than skipped. Refuse a
global caller's member-agent selection outright. It is not adopted here, for two
reasons that are about where the change belongs, not about whether it is
interesting:

  1. It removes a shipped capability -- an owner or a cron dispatching a member
    worker through session-control -- so it is a product-shape change. The PR
    template requires an RFC under docs/request-for-change/ already on main and
    non-draft for that, and there is none. Adopting it here would BLOCK the First
    Principles lane rather than pass it.
  2. main is red at tip and four PRs (feat(cloud): create the Fargate cluster, per-crew roles and log group #11521, feat(scripts): publish the crew base image so a digest-pinned ref can exist #11530, fix(cloud): accept the interactive tier keys on the Fargate lane #11534, feat(cloud): a configuration home for the Fargate lane, and register it when set #11556) inherit that
    red. Widening this PR from "restore the boundary fix(session-control): let private members dispatch their own workers #11438 weakened" to
    "renegotiate who may select a member agent" trades their unblocking for a
    design debate.

On the escalation itself. The mechanism is real and predates this PR:
_pin_private_agent_assignment in _persist_birth has bound a global caller's
child onto the selected member's store since #11018, and the delegation gate is a
no-op for unbound callers by design. This PR narrows that path rather than
widening it -- the birth pin is now fenced to the store the gate actually
authorized, so a caller can no longer land a child on a store the gate never saw.
What remains is the case where the selected agent's own store IS the authorized
one, which is the case #11018 decided.

The residual concern -- that an unbound session steered by untrusted external
content can pick a member's agent and read that member's memory through the child
-- is worth its own issue against the privacy model, not a rider on a main-red
fix. Filed separately so it survives this PR either way.

Nothing here relaxes an assertion to match current behaviour: five of the six
tests pass unchanged, and the one that changed was pinning
slot.memory_store == "member-radar" together with no binding, which
chat_runner._bind_private_slot_memory reads as memory_unavailable.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 6eefcae: Already-compromised test fails. The surface sits behind _require_internal (X-Internal-Secret) and every untrusted private V2 caller gets member_scope_denied 403; the only caller that reaches this path is the owner / Global-V1 caller (spec session-control.md:200-214), who already holds authority over every member and store. Binding its child to the selected member own store (which slot.memory_store already names) grants the owner nothing it cannot already do; the spec (255-268) documents this deliberately and rejects the unbound-child alternative because the turn path then raises memory_unavailable.

@github-actions

Copy link
Copy Markdown
Contributor

AI-review override not recorded: keep the reason to 500 characters or fewer.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 6eefcae: Already-compromised: the surface sits behind _require_internal (X-Internal-Secret); every untrusted private V2 caller gets member_scope_denied 403, so the only caller reaching it is the owner/Global-V1 caller (spec 200-214) who already holds authority over every member and store. Binding its child to the selected member own store (which slot.memory_store already names) grants nothing new. Spec 255-268 documents this deliberately; the unbound alternative breaks turns.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 6eefcae8d5a4041ffee8198e6168abe68bee0c32.

Already-compromised: the surface sits behind _require_internal (X-Internal-Secret); every untrusted private V2 caller gets member_scope_denied 403, so the only caller reaching it is the owner/Global-V1 caller (spec 200-214) who already holds authority over every member and store. Binding its child to the selected member own store (which slot.memory_store already names) grants nothing new. Spec 255-268 documents this deliberately; the unbound alternative breaks turns.

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

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: GPT 5.6. Re-run the lane's latest workflow run for 6eefcae8d5a4041ffee8198e6168abe68bee0c32 manually from the Actions tab.

amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…und to (kirodotdev#11593)

Read the caller's protected record under its canonical history key, so a
member's authority does not depend on which of the three spellings of its
own session key it supplied. Keep one delegation refusal, the
memory_delegation_denied 403, with a fixed message.

Fence the birth-time private pin to the store the delegation gate cleared.
The pin derives its store from the selected agent's config entry, which is
a different value, so the gate and the write could name different stores.

Co-authored-by: Raymond Chen <chenmingwei23@users.noreply.github.com>
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.

main is red at tip: six session-control tests fail after #11438, inherited by every open PR

2 participants