Skip to content

fix(agents): review the Parent a reset adopts, not the spec it replaces - #12202

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/reset-permissions-review-gate
Sep 20, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/reset-permissions-review-gate

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

A whole-Parent reset could hand a Crew member permissions nobody reviewed.

Reset throws the member's private copy away and rebuilds it from the Parent. The review gate that is supposed to stop unreviewed permissions read the member's own spec — the spec being thrown away — and never looked at the Parent it was resetting to. So a Parent carrying toolsSettings allowed* / trusted* / auto* grants, autoAllowReadonly, or a permissions block the derive does not produce went straight into the member without raising alternate_permissions_require_review.

Why it matters

A Parent can be project-scoped, which means a file inside a repository. The reset intent pins the Parent's descriptor, not a digest of its contents, so the file can change between the pin and the reset. A repository could therefore carry auto-approval grants into a member, and the member's agent would run tool calls without a permission card. Crew's deny floor and sensitive-path check never run for an auto-approved call, so the grant is the whole control.

What changed (motivation → approach → change)

Moving part Before Now
What the gate reads snap["spec"] — the member spec a reset discards base — the dict the new spec is built from
When the gate runs only when the request names allowedTools / autoApprove / tools, or the grant list changes that, or any reset

base is already the right answer in both directions: on a reset it is the Parent, and on an ordinary apply it is the member's current spec. The fields the gate reads — toolsSettings, autoAllowReadonly, permissions, allowedTools — are not ordinary fields, so on an ordinary apply base carries exactly what snap["spec"] carried. The member name base holds reaches the derive only as a log label, never as part of a rule, so a reset onto a correctly derived Parent still passes.

The second half is needed because a reset names no sections and changes no grant list, so the old condition skipped the gate on the exact path that adopts a whole foreign spec.

Dropping the condition and gating every apply was measured, not assumed: it rejects an ordinary prompt-only apply on a member whose spec holds a hand-edited permissions block, which is a refusal this defect does not need. All 477 tests in test/test_agent_capabilities.py pass either way, so the narrower form was kept on the evidence of a constructed case rather than a green suite.

Backwards compatibility

Breaking: a reset onto a Parent that carries alternate permission shortcuts or a hand-edited permissions block now returns alternate_permissions_require_review (HTTP 409) instead of writing those permissions into the member. Writer sweep on origin/main @ 7e8f2c459fe073048162dcfcc54c595b23a6ddc8: CapabilityService.reset is the only reset_parent=True caller; its only production caller is src/kiro_crew/dashboard/handlers/agent_capabilities.py:134, which already catches CapabilityError and answers with the code and its status; the only frontend caller is agentReset in website/src/api/client.ts, reached from AgentTemplateDetail.tsx, which already catches the failure and tells the owner the change did not land. Nothing else reaches the path, so no writer needs a change.

Tests

Four tests in test/test_agent_capabilities.py:

  • a reset onto a Parent whose toolsSettings carries an allowedCommands grant raises alternate_permissions_require_review, and the member spec on disk is untouched;
  • a reset onto a Parent whose permissions block the derive would not produce raises the same error, member spec untouched;
  • a reset onto a Parent with correctly derived permissions still succeeds, and the member's permissions equal the value derived from its own allowedTools;
  • an ordinary apply that names no approval section still succeeds on a member whose spec holds a divergent permissions block.

The first two fail on unpatched source with DID NOT RAISE. The last two hold both ways and guard against a refusal this fix must not introduce.

Manual verification

N/A — unit coverage sufficient: both the refusal and the clean-reset path run through CapabilityService.reset end to end against real files in the test's isolated config, sidecar and agent homes.

Related Issues

no linked issue: the defect was found by reading the code that shipped with the capability-inheritance work, and no tracking issue exists for it.

Pattern harvest

Rule candidate: review-prompt
Pattern: a validation gate passed the state a write REPLACES instead of the state the write ADOPTS

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

@iamwhatever
iamwhatever requested review from a team and Zedmor September 20, 2026 05:27
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: A whole-Parent reset must have its permission review gate inspect the Parent it adopts, so a Parent carrying toolsSettings allowed*/trusted*/auto* grants, autoAllowReadonly, or a hand-written permissions block cannot reach a member without alternate_permissions_require_review.
Not a goal: changing _align_permissions or _alternate_shortcuts semantics, pinning a content digest on the reset intent, gating ordinary non-reset applies more widely than today, or fixing the unrelated src/kiro_crew/sandbox.py import assertion on main.

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

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d516449

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

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of d516449321a36555eacc5dbf84c4652be02f490a — 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 no supported Parent legitimately carries toolsSettings trusted*/allowed* keys — the shipped pptx-maker app specs do — since every whole-Parent reset onto one now 409s.

What this change ships

Inventory (4 items) — 4 justified

Intent: FIX — stop a whole-Parent reset from writing unreviewed auto-approval permissions into a Crew member. Provenance is checkable: two added tests fail on base, and the harm sits on named boundaries (external content is untrusted; the agent cannot choose its own ceiling). Verified against the code: ORDINARY_FIELDS (agent_capabilities.py:613) excludes every gate-read field, so ordinary applies see the same subject as before; agent_id in kas_permissions.py reaches only log lines, so a correctly derived Parent passes under the member's name. Second _align_permissions caller (:420) already reads the adopted state — no unfixed sibling. No new surface, no deleted pin, no rider.

  1. Reset onto a Parent carrying toolsSettings auto-approval shortcuts now returns 409 instead of adopting them — justified
  2. Reset onto a Parent with a hand-edited permissions block now returns the same 409 — justified
  3. Reset onto a correctly derived Parent still succeeds, permissions re-derived from the member's own grants — justified
  4. Ordinary applies naming no approval section behave exactly as before — justified

[FIRST-PRINCIPLES-REVIEWED] d516449

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify agent-spec-fields.md's permissions row: it still names fork/publish as the only _align_permissions refusing path; reset now refuses too.

[DESIGN-REVIEWED] d516449

@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 20, 2026
@iamwhatever
iamwhatever force-pushed the fix/reset-permissions-review-gate branch from c36fad6 to d5b765d Compare September 20, 2026 06:11
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: this branch opened on 363c701ac1 because src/kiro_crew/sandbox.py raised AssertionError at import from 4ed7335d88 onward and kiro_crew.agent_capabilities imports it, so no newer commit could run the tests. main now imports at 7e8f2c459fe073048162dcfcc54c595b23a6ddc8, so the branch sits on the tip. The two reds on the previous head -- test/test_vector_memory.py::TestConflictResolution::test_replacing_a_real_value_still_retires_episodic_memory and test/test_source_corpus.py::TestNoGateEnumeratesTheCheckoutByWalking::test_no_gate_scans_the_checkout_from_the_filesystem -- both belong to files this diff never touches and both pass on the new base. CI re-running.

@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 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for d5b765d462f99f09a735c8bc49199892dfc5d298; 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 d5b765d462f99f09a735c8bc49199892dfc5d298: <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 d5b765d462f99f09a735c8bc49199892dfc5d298; 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 d5b765d462f99f09a735c8bc49199892dfc5d298: <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 20, 2026
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

I've verified the change thoroughly:

  • derived_agent_permissions → allowed_tools_to_permissions uses agent_id (the name) only in debug/info log lines, never in rule content. So the name difference between snap["spec"] and base (which sets name=target) is behavior-neutral for the permission comparison.
  • _align_permissions reads only toolsSettings, autoAllowReadonly, permissions, allowedTools, name. On the non-reset path base differs from snap["spec"] only in ORDINARY_FIELDS and name, none of which change the align outcome — the swap is behavior-preserving.
  • The reset_parent disjunct plus _align_permissions(base, …) is the intended fail-closed fix: a reset now reviews the parent it adopts, matching the two new "review" tests and the round-trip test.

No candidate existed to falsify, and I found no grounded defect in the changed lines.

No findings.

[OPUS-REVIEWED] d516449

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

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

A whole-Parent reset builds its new member spec from the Parent, but the
permission review gate inspected the member's own spec. A Parent carrying
`toolsSettings` `allowed*`/`trusted*`/`auto*` grants, `autoAllowReadonly`, or a
`permissions` block the derive does not produce therefore reached the member
without raising `alternate_permissions_require_review`. A project-scoped Parent
is a file in a repository, and the reset intent pins the descriptor rather than
a content digest, so a repository could carry permissions into a member.

The gate now reads the same `base` dict the projection is built from -- the
Parent on a reset, the member's current spec otherwise -- and it runs on every
reset, not only when the request names `allowedTools`/`autoApprove`/`tools` or
the grant list changes.
@iamwhatever
iamwhatever force-pushed the fix/reset-permissions-review-gate branch from d5b765d to d516449 Compare September 20, 2026 07:57
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved to 7a2a27de1e8e7b45a6363caecc985e5f8b6d4e22, and the previous head kept two reds that only a new commit can retrigger. Both were the same GitHub installation API rate limit, not this diff: the Analyze (*) CodeQL jobs failed with API rate limit exceeded for installation and their run cannot be retried, and Dependency License Gate ran at 06:11:47Z inside the same window, where actions/dependency-review-action renders a 403 as Dependency review is not supported on this repository -- the gate passed on #12191 at 06:05Z and on #12197 at 06:45Z, either side of it. CI re-running.

@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 20, 2026
@chenmingwei23
chenmingwei23 merged commit 9854a8b into main Sep 20, 2026
93 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/reset-permissions-review-gate branch September 20, 2026 08:24
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 20, 2026

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

Approved: fix-class, security fix in the fail-closed direction. The review gate read snap["spec"] — the member spec a reset DISCARDS — so a Parent carrying alternate permission grants went straight in unreviewed; it now reads base, which is the Parent on a reset and the member's current spec on an ordinary apply. Verified both halves in the diff: the _align_permissions(base, spec) swap and the added reset_parent or on the gate condition. The narrower condition was kept deliberately rather than gating every apply, which the body backs with a constructed case rather than a green suite. Breaking change disclosed with a writer sweep naming the only reset_parent=True caller and both existing error handlers. 2 files only.

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

A whole-Parent reset builds its new member spec from the Parent, but the
permission review gate inspected the member's own spec. A Parent carrying
`toolsSettings` `allowed*`/`trusted*`/`auto*` grants, `autoAllowReadonly`, or a
`permissions` block the derive does not produce therefore reached the member
without raising `alternate_permissions_require_review`. A project-scoped Parent
is a file in a repository, and the reset intent pins the descriptor rather than
a content digest, so a repository could carry permissions into a member.

The gate now reads the same `base` dict the projection is built from -- the
Parent on a reset, the member's current spec otherwise -- and it runs on every
reset, not only when the request names `allowedTools`/`autoApprove`/`tools` or
the grant list changes.

Co-authored-by: Joe Guo <zejiangg@amazon.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.

3 participants