Skip to content

fix(session-control): keep the delegation refusal a 403 and stop it leaking the binding path - #11603

Closed
iamwhatever wants to merge 1 commit into
mainfrom
fix/delegation-refusal-status
Closed

iamwhatever wants to merge 1 commit into
mainfrom
fix/delegation-refusal-status

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

main is red. Four tests in test/test_session_control.py fail on every PR, because a guard added on the shared session-creation path took over a refusal that already had an owner.

Refusing to let one member's work be launched into another member's private memory is the check involved. It answered the wrong way in three separate ways at once.

Why it matters

Every open PR inherits these four failures, so nobody can tell their own red from this one. That is how the second half of the same breakage went unnoticed for hours: main's own post-merge runs are all cancelled, so nothing was watching.

The three wrong answers are not cosmetic. One of them puts a private filesystem path into a message that goes back to the caller. One of them turns "I could not check" into an unhandled crash instead of a refusal — the single outcome a permission check must never produce.

What changed (motivation → approach → change)

The refusal goes back to being a 403 that says nothing about the host.

the caller hits before after
not allowed to use that store 400 agent_store_mismatch 403 memory_delegation_denied
binding file corrupt 400, message = the private path 403, fixed message, no path
binding file unreadable unhandled OSError → 500 403, fixed message

The guard lives in src/kiro_crew/dashboard/session_control.py and reads the caller's own binding off disk, so it can fail three ways, and the three mean different things. It was catching them as one and answering str(exc), which is how the path escaped. OSError was not in the catch at all, so an unreadable file crashed the request instead of refusing it.

Now the real refusal keeps its own authored sentence, which is safe to show and says what the caller can do about it. The two "cannot verify" cases share one fixed sentence that names nothing on disk. Both are 403, because the request is well formed and the caller simply may not do this — the older test file has said so all along.

Ordering is load-bearing and the code says so: the refusal type subclasses the broad one, so its arm has to come first or every refusal collapses into the generic message.

Three assertions in test/test_member_session_control.py asked for the old 400. They were the newer of two contradicting descriptions of the same behaviour, and this PR resolves the contradiction toward the authorization reading.

flowchart TB
  subgraph BEFORE["Before"]
    direction TB
    B1["guard cannot answer"] --> B2["one catch, str(exc)"]
    B2 --> B3["400 + private path"]
    B1 --> B4["OSError uncaught"]
    B4 --> B5["500 crash"]
  end
  subgraph AFTER["After"]
    direction TB
    A1["guard cannot answer"] --> A2["refusal vs cannot-verify"]
    A2 --> A3["403, path never shown"]
  end
  class B3,B5 removed
  class A3 added
  class B1,B2,B4,A1,A2 ctx
  classDef added fill:#DCFCE7,stroke:#16A34A
  classDef changed fill:#FEF3C7,stroke:#D97706
  classDef removed fill:#FEE2E2,stroke:#DC2626,stroke-dasharray: 4 3
  classDef ctx fill:#E0F2FE,stroke:#0284C7
  linkStyle 2 stroke:#DC2626,stroke-dasharray:4 3
  linkStyle 4 stroke:#DC2626,stroke-dasharray:4 3
  linkStyle 6 stroke:#16A34A,stroke-width:2px
Loading

🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged

A caller now learns it was refused, and learns nothing about the machine.

Tests

The four already-failing tests in test/test_session_control.py pass without being touched — they are the regression test, and they were written before the defect. In test/test_member_session_control.py the three contradicting assertions now expect the 403, and the corrupt-binding one additionally asserts the private path is absent from the message, which nothing pinned before.

Manual verification

N/A — unit coverage sufficient. Each of the three inputs is driven directly, one by the real guard end to end and two by raising the exact exception the guard raises.

Known incomplete

main carries a second, separate defect from the same commit, which this PR deliberately does not touch: _pin_private_agent_assignment binds a new session to a private store without checking that the creator had authority to confer it, re-granting what the authority check in create_session withheld. It fails test_global_caller_cannot_grant_a_child_private_authority and test_a_v1_child_writes_no_private_binding, both on main before this PR. That is a change to who holds private-memory authority and belongs in its own reviewed change, so those two stay red here.

Related Issues

no linked issue: found while driving an unrelated PR whose CI inherited these failures.

Pattern harvest

Rule candidate: review-prompt
Pattern: a new guard placed on a shared path silently takes over an existing refusal, changing that refusal's status code, message and error class for every pre-existing caller.

Checklist

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

…eaking the binding path

The member-dispatch delegation guard added in #11438 sits on the common create_session path, so it shadowed the established refusal for every caller: an authorization refusal downgraded from 403 memory_delegation_denied to 400 agent_store_mismatch, the raw exception text (the private binding path) reached the caller, and OSError was not caught at all, escaping as an unhandled 500 instead of refusing.
@iamwhatever
iamwhatever requested review from a team and hoang-phan98 September 17, 2026 21:05
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: Unbreak main: restore the delegation refusal to a 403 that names nothing on disk, and make an unreadable binding refuse instead of crashing.
Not a goal: the separate private-authority leak in _pin_private_agent_assignment (see Known incomplete), or any change to who may delegate.

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

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Owning spec still says the corrupt/unreadable binding maps to agent_store_mismatch 4xx; code now answers 403 memory_delegation_denied — the same-commit spec-update rule is missed.

Watch

  • docs/system-specs/modules/session-control.md:236-238 ("both map to the agent_store_mismatch 4xx") documents exactly the mapping this diff removes, while line 157 already says memory_delegation_denied 403 — the PR resolves the code toward line 157 but leaves the contradiction in the spec, so the next contributor who reads the spec (as AGENTS.md mandates) builds against the dead contract. Line 249's retraction-path agent_store_mismatch needs the same audit.
    Clears when: the spec's binding-failure rows are updated to memory_delegation_denied/403 in this PR.
  • The PR's stated harm — "every open PR inherits these four failures" — is only half removed: by its own "Known incomplete" section, test_global_caller_cannot_grant_a_child_private_authority and test_a_v1_child_writes_no_private_binding stay red on main, so PRs still cannot tell their own red from inherited red until the follow-up lands.
    Clears when: the _pin_private_agent_assignment authority fix merges (or the two tests are explicitly marked pending it).

The test rewrite is justified, not a trigger: the 403 pin in test_session_control.py predates the regression (#11018), and the 400 assertions were introduced by the same commit (#11438) that broke it — the PR resolves toward the older decision.

[DESIGN-REVIEWED] e053f72

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e053f72

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

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e053f72

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

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of e053f72ff523dd288381f00fd439a4eadfb9395f — 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 session-control.md:238 — it still documents the old agent_store_mismatch 4xx mapping this PR changes; AGENTS.md requires the spec updated in the same commit.

What this change ships

Inventory (5 items) — 5 justified

Intent: restore the memory-delegation refusal to the 403 memory_delegation_denied that pre-existing tests and the spec pin, without leaking the binding path — a FIX (unwedges red main).

  1. A refused delegation now answers 403 instead of 400 — justified
  2. The refusal's error code is memory_delegation_denied, not agent_store_mismatch — justified
  3. A corrupt binding file's refusal message no longer contains the private path — justified
  4. An unreadable binding file now gets the 403 refusal instead of a 500 crash — justified
  5. Three member-test assertions rewritten from the 400 pin to 403, plus a new no-path assertion — justified

Pin-rewrite evidence checked: the opposing, older pin (test/test_session_control.py:2282-2304, untouched by the diff) and spec line session-control.md:157 both stand on base; the description declares the reversal explicitly. Not product shape — restores behaviour a spec and test already pin (lens 9 exemption). The declared-incomplete sibling (_pin_private_agent_assignment, two still-red tests) is named in the description as deliberately deferred.

[FIRST-PRINCIPLES-REVIEWED] e053f72

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #11593.

Both PRs rewrite the same except arms in create_session, so they cannot both land. #11593 is the superset:

  • same refusal — memory_delegation_denied 403, fixed message, no path in the text;
  • also keys the protected read on the caller's canonical history key, so a slot key or transcript stem can no longer read back as unbound;
  • also fences the birth pin, by passing the authorized store into _pin_private_agent_assignment, which is what fixes the two TestMemberChildPrivateBinding reds this PR leaves red.

Verified locally on #11593's head: test/test_session_control.py test/test_member_session_control.py → 223 passed, 0 failed. All six failures on main are covered there.

Nothing here is lost; if any wording from this PR's comments is worth keeping, fold it into #11593.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 17, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Superseded by #11593, which landed the same fix and went further.

#11593 keeps one delegation refusal — the 403 memory_delegation_denied with a fixed message — which is what this PR did, and it also fences the birth-time private pin to the store the delegation gate actually cleared. That second half is the defect this PR deliberately left open under Known incomplete (_pin_private_agent_assignment re-granting authority the caller did not have), and #11593's framing of it is sharper than mine: the gate authorizes bindings.memory_store_name while the pin derives its store from the selected agent's config entry, so the two could name different stores.

Verified on main at 2627b04: test/test_session_control.py and test/test_member_session_control.py are 223 passed, 0 failed. All six tests that were red are green.

Closing unmerged — nothing here to salvage. Thanks @chenmingwei23.

@bolichen97
bolichen97 deleted the fix/delegation-refusal-status branch September 20, 2026 08:57
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.

1 participant