Skip to content

fix(cards): stop listing template grants a new bot does not get - #41716

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
keyejia:fix/card-no-template-grants
Dec 1, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
keyejia:fix/card-no-template-grants

Conversation

@keyejia

@keyejia keyejia commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: the Create a bot and Import cards show only what the new bot will really run without asking, and ask for the widening acknowledgement only when the press really widens something.

Both cards read the default bot template's bare @<server> grants (template_auto_approved_servers in src/kiro_crew/dashboard/change_cards_readers.py). The Create card lists them as "Runs without asking", and the Import card lists them as "Your bots use these without asking". Either way the press is marked as a widening change and the owner must tick the acknowledgement.

The press does not grant them. It writes the new bot its own file with "allowedTools": [] and "mcpServers": {} (write_mate_config in src/kiro_crew/mate_config.py), and no template's servers reach it.

Why it matters

The owner is asked to accept grants that never happen. A card that claims a widening on every create teaches people to tick the box without reading it, which weakens the acknowledgement for the cards that really do widen something.

Not a goal

  • Changing what a new bot is granted.
  • Changing how cards that really widen access are shown.
  • Removing the frontend rendering of the old rows (cards saved by an earlier build still carry them; see Backwards compatibility).

What changed (motivation → approach → change)

  • Symptom: the Create and Import cards list template grants and ask for a widening acknowledgement.
  • Cause: the shared state read for crewmate.create and crewmate.import still read the template's allowedTools, from a time when a new bot was bound to the template. Today the press writes the bot its own minimal file.
  • Change (cards):
    • _sync_read_state no longer reads the template. Its creating-kind snapshot is {"exists": ...}, so a new card has no grant row and no widening risk.
    • template_auto_approved_servers and _server_reach were used only by that read, so they are removed, along with their re-exports from kiro_crew.dashboard.change_cards and its facade inventory entry.
    • build_preview for both kinds still renders inherited_auto_approve / inherited_reach when a stored snapshot carries them, so a card saved by an earlier build rebuilds to the plan it stored.
    • comparable_state drops those two keys for both creating kinds. Without that, pressing a card saved by an earlier build compared its old before with today's read and answered 409 changed_since_preview although nothing had changed.
  • Change (create route), so that "no template grants" stays true:
    • Before, POST /api/agents published the bot bound to its template, then adopted the bot's own file best-effort (_eager_copy_mate_config → adopt_own_file). If that adopt failed (a write failure, or a user-level agent of that name appearing in between), the bot kept running on the template with the template's grants, which the card would no longer show.
    • Now the route writes the bot's own file (write_mate_config) BEFORE publishing, and publishes the binding already pointing at it (kiro_agent = <name>), as the owned-config RFC's create flow describes (docs/request-for-change/rfc-mate-owned-agent-config.md §5.4: write the file, then the binding with kiro_agent = <id>). A write that fails refuses the create with 409 bot_config_unwritable, inside the block that already retires the new memory and workspace on any failure, so nothing is published.
    • The name clash is refused the same way. The route already refused a user-level agent of the new key before anything is written (template_name_in_use). Right before the own-file write it now checks user_agent_named(name) again, and a clash that appeared in between also answers 409 template_name_in_use with nothing published. Such an agent would otherwise win over the bot's own file.
    • Writing the file before publishing opens one race: another create of the same name (the CLI publishes, then writes its file) wins, the owner edits that file, and this create's write would replace it before persist_member_config answers agent_exists. The pre-publish write (write_mate_config(name, unbound=True)) therefore re-reads config.json under the owner lock every Bot-file write already holds, and refuses a name already bound there with 409 agent_exists, leaving that file as it is. It reads config.json and config.local.json through read_config_for_update, which fails closed: a file that cannot be parsed, or an agents section that is not an object, may bind the Bot, so the write is refused and the file kept, with the refusal memory provisioning gives that roster (UnknownMemoryStore, 409 member_memory_unavailable). Every other create writes its file after publishing and waits on that lock, so a file with another Bot's additions always has its binding on disk by then.
    • A create that fails after the name check puts the Bot's file back as it was, whichever step failed. Before the write, capture_mate_config reads under the owner lock the file's bytes (or that there is none), its owners.json entry (or none) and whether the dispatch snapshot names it. On any failure, restore_mate_config reconciles all three to that capture under the same lock, rewriting only what differs, so a step that never ran changes nothing. It does nothing when config.json binds the name by then (another create won it), cannot be read, or another instance owns the file. A deleted Bot's retained file (deleting keeps it) therefore survives a failed re-create, and a new Bot's file, owner entry and snapshot name (retract_mate_agent) go.
    • _eager_copy_mate_config still runs afterwards and answers already_owned, so its "kept source pointer" fallback cannot leave a created bot on the template. The mate-tools grant sees the bot on its own file, as before.
    • This is the fail-closed option: a Bot is never published on its template, so a card with no grant row stays true. Disclosure was not kept because a write failure cannot be predicted when the card is shown.

Backwards compatibility

Compatible: a new card simply has no grant row, and a card saved by an earlier build still rebuilds and now applies. A create that succeeds ends in the same state as before (bound to its own file; the eager adopt used to repoint it a moment later). The one new refusal is a create whose own file cannot be written, which used to succeed with the bot left on its template.

Reader: src/kiro_crew/change_card_catalog_plans.py:build_preview (crewmate.create) -- crew page, chat, app -- still reads inherited_auto_approve from the stored snapshot, so a saved card rebuilds unchanged (test_crewmate_create_shows_inherited_auto_approvals_and_asks_to_widen)
Reader: src/kiro_crew/change_card_catalog_plans.py:_import_preview (crewmate.import) -- crew page, app -- still reads inherited_auto_approve and inherited_reach from the stored snapshot (test_the_card_lists_every_part_and_creates_in_normal_with_no_grant)
Reader: src/kiro_crew/dashboard/change_cards_records.py:rebuild_record -- crew page -- rebuilds a saved card from its saved before, which still carries the keys, so the derived rows still match
Reader: src/kiro_crew/dashboard/handlers/change_cards.py:_run_card_step conflict check -- crew page, chat, app -- compares through comparable_state, which now ignores the two old keys (test_a_card_saved_with_template_grants_still_applies)
Reader: website/src/cards/CardChanges.tsx:FIELD_LABELS / approval hint -- crew page -- renders template_auto_approve and import_approval rows only when a card has them; a new card has none
Reader: website/src/cards/ChangeCard.tsx:template_auto_approve row lookup -- crew page -- finds no row on a new card and falls through as for any card without one
Reader: src/kiro_crew/dashboard/change_cards.py:template_auto_approved_servers, _server_reach -- release -- removed from the facade; git grep on main finds no other caller in src, apps, skills or packages
Reader: src/kiro_crew/member_mate_tools.py:_grant -- crew page, chat -- reads the published binding; it now names the bot's own file from the start, the state it already required (binding.kiro_agent == member)

Tests

  • test_a_template_grant_the_new_bot_never_gets_is_not_shown_or_acknowledged[crewmate.create|crewmate.import]: with a default template that grants @slack-mcp and @builder-mcp, the state read is {"exists": False}, and the preview has no auto_approve, template_auto_approve or import_approval row and is not a widening risk.
  • test_a_card_saved_with_template_grants_still_applies[crewmate.create|crewmate.import]: a card stored with inherited_auto_approve / inherited_reach in before (and a widening risk) is pressed against today's {"exists": False} read, and the create runs (200) instead of 409 changed_since_preview.
  • test_an_own_file_that_cannot_be_written_refuses_the_create: when write_mate_config raises MateConfigError, POST /api/agents answers 409 bot_config_unwritable and persists nothing.
  • test_a_name_clash_that_appears_after_the_first_check_refuses_the_create: user_agent_named is false at the first check and true at the write. The create answers 409 template_name_in_use, writes no own file and persists nothing.
  • test_a_bot_published_after_the_first_check_keeps_its_file: config.json already binds the name and its own file holds the owner's edit. The create answers 409 agent_exists, persists nothing and leaves the file byte-identical.
  • test_a_create_that_lost_the_race_leaves_the_winners_file (test_mate_owned_config.py): write_mate_config(name, unbound=True) writes when the name is unbound, and raises MemberAlreadyExists without touching an edited file once config.json binds it.
  • test_a_roster_that_cannot_be_read_refuses_the_write[*]: with a truncated config.json, or one whose agents is a list, the write raises UnknownMemoryStore ("configuration is unreadable") and the owner's edited file is kept. test_private_creation_refuses_degraded_config_but_allows_absent_memory again answers 409 member_memory_unavailable for those rosters.
  • test_a_create_that_fails_at_any_step_leaves_the_bot_file_as_it_was[step-seed] (14 cases): a failure is injected at each step (the Bot file write, the owners.json write, the snapshot publish, provision_member_workspace, and a cancel of the request while the write is in flight), each with the key's file absent, a deleted Bot's customised file with its owner entry, and the file without one. The file's bytes, the owner entry and the snapshot name end exactly as they were. (The owner write runs only when the entry is missing, so that step has no case with it seeded.) Against f70befe404's source, the 5 owner-write and snapshot-publish cases fail; prove.py --base f70befe404 reports PROVEN.
  • test_builtin_kirocrew_is_a_legal_choice, test_unknown_template_warns_and_still_creates: now expect the persisted binding to name the bot's own file.
  • test_import_shares_the_create_state_read_and_partial_line: the import and create kinds share one state read.
  • Removed test_template_auto_approved_servers_reads_bare_grants_only and test_an_inherited_server_row_says_what_the_server_reaches with the helpers they tested.

Proof: PROVEN test/test_api_agents_create_template.py::TestExplicitTemplateStillWorks::test_builtin_kirocrew_is_a_legal_choice, test/test_api_agents_create_template.py::TestExplicitTemplateStillWorks::test_an_own_file_that_cannot_be_written_refuses_the_create, test/test_api_agents_create_template.py::TestExplicitTemplateStillWorks::test_a_name_clash_that_appears_after_the_first_check_refuses_the_create, test/test_api_agents_create_template.py::TestExplicitTemplateStillWorks::test_a_bot_published_after_the_first_check_keeps_its_file, test/test_api_agents_create_template.py::TestExplicitTemplateStillWorks::test_a_create_that_fails_at_any_step_leaves_the_bot_file_as_it_was[file-none] (head 4924f43)

prove.py names at most 5 tests. test_a_card_saved_with_template_grants_still_applies[*] also fails with main's src/ (checked in a separate worktree: both cases answer 409 changed_since_preview).

Gate proof: tree 556d0f81fb2a; ran 26; skipped none

Related backend tests (scripts/local-gate.py --base upstream/main): 139,777 passed, 38 failed. Every one of the 38 also fails on upstream/main (a00219d) on this host, run the same way: missing boto3 and SageMaker credentials, the KAS bundle and engine pins, identity and xdist helpers. None touches this diff. Facade, mirror and member-memory suites (test_facade_mirror_guards, test_facade_mirror, test_facade_bindings, test_facade_shared_checks, test_member_memory_creation_capability, test_member_memory_publication, test_mate_worker_kit): 599 passed. test_wait_discipline_ratchet.py and test_flake_pattern_ratchet.py pass in full: the cancellation test waits with async_wait_until(started.is_set) and async_wait_until(handlers[0].done), so it has no fixed sleep and parks no pool thread, and its worker asserts the result of its one Event.wait. The frontend related set was not run on this host (no vitest installed); CI runs it. The diff touches no file under website/.

Manual verification

See Real-machine verification.

Real-machine verification

Cards (head 5e6ac8e8a8, before the create-route change)

Machine: Linux 5.10 x86_64 (Amazon Linux 2), 2026-11-24 01:31 UTC, run by a person from a script. Before: main at 724c07dfff. After: 5e6ac8e8a8.

For each commit, in a temporary worktree with its own HOME, KIROCREW_HOME and KIRO_HOME:

  1. Start a gateway from that worktree's code: KIROCREW_PROFILE=standalone KIROCREW_HOME=<data home> KIRO_HOME=<data home>/kiro KIROCREW_PORT=<free port> PYTHONPATH=<worktree>/src kirocrew gateway --no-crons --no-tunnel. ss -ltn shows it listening on loopback only.
  2. Sign in with kirocrew token --port <port>.
  3. Add a bare @rmv-demo grant to the default bot template, <data home>/kiro/agents/kirocrew.json, keeping what the gateway wrote.
  4. POST /api/members/import with one minimal .crewmate file (manifest, empty agent.json, rules, goal, no crons), and print the card's risk and rows.
  5. Cancel the card (POST /api/cards/<id>/cancel, HTTP 200 both times), so no bot is created. Afterwards the agents dir holds only the gateway's own specs.
  6. Cleanup: stop the gateway by the PID the script started and remove the worktree.
Before (main 724c07d) After (5e6ac8e)
Import reply HTTP 200, crewmate.import card HTTP 200, crewmate.import card
risk widen normal
Grant row template_auto_approve / "Your Bots use these without asking" / [{"name": "rmv-demo"}] none
Approval row import_approval / "Approval" / normal approval_mode / "Approval" / normal
Other rows (name, sender, description, rules, goal) present identical

The approval row's key is expected to change. _import_preview uses import_approval only when an inherited-grant row follows it, and approval_mode otherwise. That is main's own behaviour for an import with no inherited grants (test_the_card_lists_every_part_and_creates_in_normal_with_no_grant, bare case). The label ("Approval") and the value the create sends (normal) are the same. Only the hint changes: the import-specific hint written for the grant row is replaced by the standard hint for normal.

Real-machine verification (review round)

Create route, POST /api/agents. Machine: Linux 5.10 x86_64 (Amazon Linux 2), 2026-11-25 03:17 UTC, run by a person from a script. Before: main at 8ce0c6ca2a. After: this head, 0798c7ee73.

For each commit, in a temporary worktree with its own HOME, KIROCREW_HOME and KIRO_HOME (KIROCREW_PROFILE=standalone), a gateway runs from that worktree's code on a free port, listening on loopback only. Each case sends POST /api/agents {"name": "<case>", "kiro_agent": "kirocrew"}, then prints the reply, the saved binding and whether the bot's own file <KIRO_HOME>/mates/agents/<name>.json exists:

  1. ok: a normal create (rmv-ok), then DELETE /api/agents/rmv-ok.
  2. ro: <KIRO_HOME>/mates/agents is chmod 555 (dr-xr-xr-x), so the own file cannot be written (rmv-ro).
  3. clash: a user-level agent <KIRO_HOME>/agents/rmv-clash.json already has the bot's name (rmv-clash).

Cleanup: the script stops the gateway by the PID it started and removes the worktree. It reported both clean.

Case Before (main 8ce0c6c) After (0798c7e)
ok HTTP 200; binding kiro_agent='rmv-ok'; own file exists HTTP 200; binding kiro_agent='rmv-ok'; own file exists
ro HTTP 200; binding kiro_agent='kirocrew' (left on the template); own file missing; log Bot rmv-ro: Bot config copy failed; kept source pointer HTTP 409 bot_config_unwritable (could not write Bot config for 'rmv-ro' at …/mates/agents/rmv-ro.json: [Errno 13] Permission denied); no bot published; own file missing
clash HTTP 409 template_name_in_use; no bot published HTTP 409 template_name_in_use; no bot published
Log lines naming the own-file copy one (the ro case) none

On main, a create whose own file cannot be written still publishes the bot, bound to the template, so it runs the template's grants. On this head that create is refused and nothing is published.

The run predates the bound-name refusal and the clean-up of a create that fails after the write (both above). The refusal applies only to a name config.json already binds or a roster that cannot be read, and the clean-up only after a successful write followed by a failure; none of the three cases reaches either (in ro the write itself fails), so their replies and files are unchanged. Both are covered by the tests above.

Related Issues

Closes #41634

Sibling sweep

Swept: git grep -n -e "allowedTools" -e "kiro_agents_dir" -- src/kiro_crew/dashboard/change_cards_readers.py src/kiro_crew/change_card_catalog_plans.py
Sibling: src/kiro_crew/dashboard/change_cards_readers.py -- not affected -- no other card state read takes grants from a template spec; crewmate.update reads the bot's own config.
Swept: git grep -n "adopt_own_file" -- src
Sibling: src/kiro_crew/cli_commands_agent.py:333 -- not affected -- kirocrew agent create raises no card, and on a failed adopt it already prints that the bot keeps running as its template, so nothing is under-disclosed there.

Pattern harvest

Not generalizable: one state read kept describing an older bot-creation model after creation moved to a minimal own file, and the create route kept a best-effort step whose failure brought that older model back. Both are fixed at their single site here.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • 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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 24, 2026
@keyejia
keyejia marked this pull request as ready for review November 24, 2026 01:16
@keyejia
keyejia requested review from a team and KiroCrewCaptain as code owners November 24, 2026 01:16
@keyejia
keyejia requested a review from dodgeblaster November 24, 2026 01:16
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 4924f4347a8ad1c0de76e2b929be8b2788c670b3 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 4924f4347a8ad1c0de76e2b929be8b2788c670b3 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the card no longer claims template grants, and the create route now writes the Bot's own file before publishing it, so the card stays true. Only the patch's own files read the removed helpers.

Notes

  • Other create paths (the CLI, for one) still publish first and adopt the file afterwards. A failed adopt there still leaves a Bot running on its template. That is outside this card's press, but worth a follow-up so every creator shares one write-then-publish step.

[DESIGN-REVIEWED] 4924f43

Description read

[DESCRIPTION-READ] 837aaa46a5b0cf71b73407b65f9f62b145eb308a95cd61c666cd28c0bd019508

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 Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 4924f4347a8ad1c0de76e2b929be8b2788c670b3 via the fork AI-review pipeline — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The card fix works because the route now publishes each new Bot already bound to its own file, which is the create order in rfc-mate-owned-agent-config §5.4 (status implemented on base).

What this change ships

Inventory (8 items) — 8 justified

Intent: the owner sees only grants a new Bot really gets, and is asked to acknowledge a widening only when one happens. This is a FIX.

  1. The Create and Import cards no longer list the template's auto-approved servers or ask for the widening acknowledgement — justified
  2. A card saved by an earlier build still applies instead of answering 409 changed_since_preview (comparable_state drops the two old keys) — justified
  3. A card saved by an earlier build still shows its stored grant rows when rebuilt — justified
  4. POST /api/agents writes the Bot's own file before publishing, and the binding names that file from the start, never the template — justified
  5. A create whose own file cannot be written is now refused with 409 bot_config_unwritable — justified
  6. A user-level agent of the same name that appears after the first check is refused with 409 template_name_in_use — justified
  7. A create that loses the race to another create of the same name, or finds config.json unreadable, is refused and leaves the existing file untouched (write_mate_config(unbound=True)) — justified
  8. A create that fails puts back the Bot's file, its owner entry and its snapshot entry (capture_mate_config, restore_mate_config, retract_mate_agent); template_auto_approved_servers and _server_reach are deleted — justified

[FIRST-PRINCIPLES-REVIEWED] 4924f43

Description read

[DESCRIPTION-READ] f849b17a44dde2c50eaad118ac3d6996936c84779161b758dbb5969c361edb8c

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 Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 4924f4347a8ad1c0de76e2b929be8b2788c670b3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4924f43

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 4924f4347a8ad1c0de76e2b929be8b2788c670b3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4924f43

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

Review bot check on head 5e6ac8e8a8. I read both GPT 6.1 findings against the code on this head. Both hold, so I am asking for changes. The goal itself is right: on the success path the press writes the Bot its own minimal file, and the card should not claim template grants there.

  1. Saved Create and Import cards can no longer Apply (F2, upheld). Every Create or Import card saved by an earlier build has before = {"exists": ..., "inherited_auto_approve": [...]} (main always wrote the key, even as []; Import also wrote inherited_reach). This head reads {"exists": ...}. At Apply, handlers/change_cards.py compares comparable_state(kind, current) with comparable_state(kind, rec["before"]), and comparable_state (change_cards_readers.py:416) drops nothing for these two kinds. So every such card returns 409 changed_since_preview until it is previewed again (cards live 24 h, CARD_TTL_SECONDS). That contradicts the Backwards compatibility section, which says a saved card still works.
    Fix: in comparable_state, for catalog.CREWMATE_CREATING_KINDS, drop inherited_auto_approve and inherited_reach before comparing (keep exists). Add a test that applies a card whose stored before carries inherited_auto_approve and expects it to pass the check.

  2. The fallback path still runs the template, and the card no longer says so (F1, security-class, fenced). adopt_own_file (mate_config.py) raises MateConfigError when a user-level agent already has the Bot's name, and when write_mate_config fails. _eager_copy_mate_config (dashboard/agent_admin/crew_records.py) catches that and leaves kiro_agent on the template ("kept source pointer"). member_chat_agent (mate_worker.py) then runs that template, with its bare @server grants. Before this PR the card listed those grants and asked for the widening acknowledgement. Now it shows none, so on that path the card understates what the Bot runs without asking. The PR's premise ("the press does not grant them") holds only when the copy succeeds.
    Fix, either of these:

    • (preferred) make the create fail closed: when adopt_own_file raises, refuse the create (or roll the binding back) instead of keeping the template pointer. A Bot then never runs on the template, and the card stays true with no grant row; or
    • keep disclosing on the path you can predict: if user_agent_named(<new key>) is true at read time, return the template's grants as before, and make the write-failure path refuse the create.
      Please add a test for the name-clash case.

Because finding 2 is security-class, the GPT lane keeps its block until a new head clears it, so this needs a code change, not an override. I'll re-review the next head.

AI-assisted, sent by Bolin Review bot

@keyejia
keyejia force-pushed the fix/card-no-template-grants branch 2 times, most recently from fb5d218 to 7054791 Compare November 24, 2026 21:25
@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 Nov 24, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Re-reviewed 7054791 against 5e6ac8e (git range-diff). Both points from my change request are fixed in code, and I approved the held fork runs.

  1. Saved cards (F2): fixed. comparable_state now drops inherited_auto_approve and inherited_reach for CREWMATE_CREATING_KINDS, so a card saved by an earlier build passes the Apply check. test_change_card_crewmate_import.py covers it.
  2. Fallback ran the template (F1, security-class): fixed at the root. _api_kirocrew_agents_create now writes the Bot's own file before it publishes, and publishes the binding on that file. A user-level agent with the same name refuses the create with 409 template_name_in_use, and a failed write refuses it with 409 bot_config_unwritable, with nothing published. No path is left where a created Bot runs its template, so the card is now right to say it has no template grants.

One thing left before I approve (real-machine-verify, Reviewing): the "Create route (this head)" subsection is still marked Pending. Please add the three POST /api/agents runs you list (normal create, read-only own-file folder, user-level name clash), Before on main and After on 7054791. I'll approve once they are in and CI is green.

AI-assisted, sent by Bolin Review bot

@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 Nov 24, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Re-reviewed 7054791. Both findings from my last review are fixed:

  • F2: comparable_state drops inherited_auto_approve and inherited_reach for both creating kinds, and test_a_card_saved_with_template_grants_still_applies presses a card saved with them against today's read (it fails on main's src/).
  • F1: POST /api/agents now writes the Bot's own file before it publishes, binds kiro_agent to it from the start, and refuses with 409 template_name_in_use / bot_config_unwritable on a late name clash or a failed write. A Bot can no longer be published running its template, so the card stays true with no grant row. The late-clash and unwritable-file tests cover both refusals.

I approved the held workflow runs on this head. One ask before I approve (real-machine-verify, Reviewing: this head changes what the create route runs): the "Create route (this head)" section is still pending. Please add the three runs it lists on a real gateway at 7054791: a normal create, a create with the own-file folder read-only, and a create whose name a user-level agent already has.

AI-assisted, sent by Bolin Review bot

@keyejia
keyejia force-pushed the fix/card-no-template-grants branch 2 times, most recently from 0798c7e to 11572af Compare November 25, 2026 03:47
@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 Nov 25, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Re-reviewed 11572af. The concurrent-create guard reads right (write_mate_config(name, unbound=True) refuses, under the owner lock, a name config.json already binds). One red to fix before I approve, and it is this head's own:

Backend Tests (3.12, 6) fails test/test_facade_mirror_guards.py::test_no_test_patches_a_shared_name_on_an_owner_directly. Two of the new tests patch config_path on one owner module instead of through the facade:

  • test/test_api_agents_create_template.py:329 monkeypatch.setattr(loader_locations, "config_path", ...)
  • test/test_mate_owned_config.py:307 (same name)

config_path is bound by more than one member of the kiro_crew.config.loader mirror family, so the guard requires the facade patch, whose undo restores every holder. The fix is to patch it the way the existing helpers do, e.g. monkeypatch.setattr("kiro_crew.config.loader.config_path", lambda: config) (see test/_hot_reload_helpers.py:161). The Coverage Gate red follows from the same shard.

Once that's green I'll approve with auto merge.

AI-assisted, sent by Bolin Review bot

@keyejia
keyejia force-pushed the fix/card-no-template-grants branch from 11572af to 1410dec Compare November 25, 2026 05:44
@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 Nov 25, 2026
@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 Nov 30, 2026
@keyejia
keyejia force-pushed the fix/card-no-template-grants branch 2 times, most recently from f70befe to 71d1125 Compare November 30, 2026 21:34
@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 Dec 1, 2026
The Create a bot and Import cards read the default bot template's bare
@server grants through template_auto_approved_servers and listed them as
"Runs without asking" / "Your bots use these without asking", marking the
press as a widening change that asks for an acknowledgement. But the press
writes the new bot its own file with empty additions (write_mate_config),
and no template's servers reach it. So the row named grants the bot never
gets, and the acknowledgement asked about a widening that does not happen.

The state read for both cards no longer reads the template, so a new card
has no such row and no widening risk. template_auto_approved_servers and
_server_reach, used only by that read, are removed. The plan builders still
render a stored snapshot that carries inherited grants, so a card saved by
an earlier build rebuilds to the plan it stored and keeps its history and
Undo, and comparable_state drops the two old keys for both creating kinds,
so pressing such a card no longer answers 409 changed_since_preview.

The card can say "no template grants" only if a created bot can never be
left on its template. The create route used to publish the binding on the
template and adopt the bot's own file afterwards, best-effort; a failed
adopt left the bot running the template's grants. The route now writes the
bot's own file before publishing and publishes the binding on it, as the
owned-config RFC describes. A write that fails refuses the create (409
bot_config_unwritable) with nothing published, and so does a user-level
agent of the bot's name that appears after the first name check (409
template_name_in_use), since it would win over the bot's own file.

Writing the file first means a create that loses the name race to another
(the CLI publishes, then writes) could replace the winner's file, owner
edits included. The pre-publish write now re-reads config.json under the
same owner lock every Bot-file write takes, and refuses a name already
bound there (409 agent_exists), leaving that file as it is. It reads
config.json and config.local.json through read_config_for_update, so a
file that cannot be read refuses the write too: it may bind the Bot. That
refusal is the one memory provisioning gives the same roster (409
member_memory_unavailable).

A create that fails after the name check puts the Bot's file back as it
was. capture_mate_config reads, under the owner lock and before the
write, the file's bytes (or that there is none), its owners.json entry
and whether the dispatch snapshot names it; on any failure,
restore_mate_config reconciles all three to that, rewriting only what
differs, unless config.json binds the name by then. So a deleted Bot's
retained file survives a failed re-create, a new Bot's file goes, and it
holds whichever step failed: the file write, the owner entry, the
snapshot publish, provisioning, or a shutdown cancelling the request.

Closes kirodotdev#41634
@bolichen97

Copy link
Copy Markdown
Contributor

@kellenji The one red on this head is not from your change. Backend Tests shard 7 fails test/test_autonudge_shutdown_terminal_reprobe.py::test_MUTATION_a_failed_holds_settlement_write_keeps_memory_store_and_restart_agreed, twice (the first run and my rerun). That test was fixed on main by #45124 (1bcc9e0, 11-30 22:42Z), but this run tests merge commit c4e0992f2b, which GitHub built at 21:34Z, before the fix. A rerun reuses that same merge, so it cannot pick the fix up.

Please rebase onto current main (the branch is 96 commits behind) and push. The new head gets a fresh merge with the fix. I'll release its fork CI and re-review the head, and once it's green I'll approve and clear my old change request.

AI-assisted, sent by Bolin Review bot

@keyejia
keyejia force-pushed the fix/card-no-template-grants branch from 71d1125 to 4924f43 Compare December 1, 2026 04:52
@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 Dec 1, 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.

Re-reviewed head 4924f4347a, rebased onto current main (4 behind) as asked. The fresh merge includes the #45124 fix for the autonudge test that was red on the old merge, and the change itself (template grants a new bot does not get are no longer listed, with the async_wait_until rerun) is the one I reviewed. Approving, which replaces my earlier change request.

AI-assisted, sent by Bolin Review bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create and import cards list template grants a new bot does not get

2 participants