Repository navigation
fix(agent): re-govern crew-bound shared templates when the ceiling tightens - #18811
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS One unreadable or hard-linked file anywhere in the agents directory holds the ceiling memo, even when no crew binds it. Only an operator's fix on disk clears it. Watch
[DESIGN-REVIEWED] d8aeff6 Description read[DESCRIPTION-READ] 9afd3e831b6b5b7dc411a1131ea286bb08d6ab7cc377ff52c67ea3f70ca834a5 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 |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The new strict spec listing re-implements a raising agents-dir walk that Not justified as shipped
What this change shipsInventory (8 items) — 7 justifiedIntent: a tightened governance ceiling stops a crew-bound shared template from auto-approving tools the ceiling now denies (#9598). This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] d8aeff6 Description read[DESCRIPTION-READ] 481531a435a52b3ddb70da3b82a64d434ccd8985d18efe3a3c1c5d5b728dc540 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
2576155 to
dd557b1
Compare
423538f to
cf51b02
Compare
|
When the governance ceiling tightens, this PR re-filters a crew-bound shared template's allowedTools and autoApprove so it stops auto-approving tools the ceiling now denies. The root-cause analysis looks right: publish clears fork lineage, so the fork-refresh governance pass never visited these specs. The new _govern_bound_shared_specs pass reuses the same governance passes under the spec lock. HOLD because this is permission and tool-approval governance code (allowedTools/autoApprove, the conductor-spec hold and the reproject_for_ceiling_change memo), which needs a maintainer's sign-off under the brief. Both whole-design lanes report CONCERNS on cf51b02 and neither has a disposition. Design notes that _specs_for sets the retry hold on any OSError from any file in the agents directory. So one permanently unreadable, unrelated file (for example root-owned) would keep _conductor_spec_held set and rebuild on every poll. First Principles notes _specs_for is a third name-to-spec resolver beside agent_spec_path and spec_by_declared_name, with different stem and ambiguity rules. Before this lands, please narrow the hold to OSErrors on files that actually match the bound name and reuse an existing resolver, or answer both items. Checks are green and base is main. — crew-pr-reviewer |
iamwhatever
left a comment
There was a problem hiding this comment.
This PR re-filters allowedTools/autoApprove on crew-bound shared templates when the governance ceiling tightens. The root cause is right: publish clears fork lineage, so the fork-refresh pass never visited these specs. _govern_bound_shared_specs reuses the same two passes under the spec lock and writes only when something was removed. I checked the deny direction and did not find a path that keeps a denied grant in a JSON spec. The new retry hold has a regression. At src/kiro_crew/agent_materialization/fork_refresh.py:456, _specs_for sets unreadable = True on an OSError from ANY file in the agents directory, even when that file has nothing to do with the bound name. That sets _conductor_spec_held, and agent.py:3809 then skips its generation memo, so every distribution poll and hourly wake runs rebuild_agent_config_reporting. That rebuild rewrites the spec files kiro-cli watches, which is exactly what the memo's docstring says must not happen. One permanently unreadable unrelated file (for example a root-owned spec left by sudo kiro-cli) is enough to keep this going for the life of the process. Suggested fix: hold only for a transient error on a file whose stem matches the bound name, and skip-and-warn on PermissionError. You could instead resolve through agent_spec_path as First Principles suggests. Add a test showing that a permanently unreadable unrelated file does not keep the hold set. Both CONCERNS items on cf51b02 are still unanswered. — crew-pr-reviewer (deep re-check)
cf51b02 to
ae39bb7
Compare
fbdc288 to
bed0b2e
Compare
bed0b2e to
05ac025
Compare
05ac025 to
2e1bf3d
Compare
2e1bf3d to
52f123f
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
This PR re-filters allowedTools/autoApprove on crew-bound shared templates when the governance ceiling tightens. The root cause is right: publish clears fork lineage, so the fork refresh never visited these files. Head 91cf263 fixes the PermissionError half of my change request: a denied read is warned and skipped, and test_a_spec_this_user_may_not_read_never_holds proves it for an unrelated file. The same regression is still reachable another way, though. In src/kiro_crew/agent_materialization/fork_refresh.py, _scan_agent_specs puts every file in the agents directory into retry when the fenced reader refuses it (_refusal_holds returns True for any regular file, so any second hard link counts) or when it hits any other OSError. _govern_bound_shared_specs then sets held = True whether or not that file claims a bound name. A hard-linked notes.json that no crew binds therefore keeps _conductor_spec_held set until a person removes the link. Until then, every distribution poll and profile-watch tick skips the generation memo (agent.py _reproject_holding_the_lock and reproject_for_profile_change) and reruns rebuild_agent_config_reporting. The only signal is a log WARNING, and prime_ceiling_projection's boot warning blames "a conductor spec", which is the wrong cause. Design Review raises exactly this on 91cf263, and its CONCERNS and First Principles' CONCERNS (unbound templates started through spawn are still unfiltered) have no disposition on this head. Suggested fix, which stays fail-closed: keep the memo held but skip the rebuild while nothing has changed, keyed on the generation plus a fingerprint of the held paths (path, st_ino, st_nlink, st_mtime_ns). Alternatively, hold a refused regular file only when its stem is a bound name or a bounded head read shows it declares one. Add a test where an unrelated hard-linked file runs several passes without triggering a rebuild, fix the boot warning's wording, and in the description name the unbound-template spawn path as out of scope. — crew-pr-reviewer (deep re-check)
A crew-bound shared template left unfiltered for a reason a retry can clear holds the ceiling memo until a pass filters it, so the next poll or maintenance wake retries it. A read this user is denied holds like any other read failure: kiro-cli cannot load that file now, but loads whatever grants it carries once its permissions are restored, and nothing moves the ceiling then. The agents directory is read once per pass, however many crews are bound. A hold that rests only on what the pass could not read (a hard link, an I/O error, a failed listing, a config file its load could not read whole) cannot clear until one of them changes or reads, so the pass records each file with its inode, link count and mtime, the config fingerprint, and the answer generation. The ceiling hook and the maintenance wake skip the rebuild while that answer is current and every recorded file is unchanged and still reads as held; the memo stays pending. A conductor installer's hold is retried as before, and the boot, pending and retry warnings name which kind of spec is held.
|
Thanks for the deep re-check. Every point is addressed on d8aeff6 (rebased on current main, still two commits). All checks are green. 1. An unrelated hard-linked file holds and rebuilds on every poll. I took your first suggestion, which stays fail-closed. The hold still stands, because an unread file may be the one that declares a bound name. What changed is that the rebuild is skipped while nothing the hold rests on has changed. When a pass holds only on what it could not read, it records the answer generation, each file's
The memo stays pending throughout. The re-read is needed because a cleared sharing violation or restored permissions change none of the four stat fields. A conductor installer's hold, a write that raised and a rebuild that raised are retried as before. I rejected the second suggestion (hold only a bound stem, or a file a head read shows declaring a bound name): the head read opens an inode the fence refuses, and an I/O error would still churn. 2. The boot warning blames a conductor spec. The boot warning, the pending warning and the maintenance-retry warning now say whether a crew-bound shared template or a conductor spec is held ( 3. The lane findings.
|
iamwhatever
left a comment
There was a problem hiding this comment.
When the governance ceiling tightens, this re-filters allowedTools/autoApprove on every spec a crew in config.json is bound to. The root cause is fixed: publish clears fork lineage, so the fork refresh never visited these files. Head d8aeff6 answers my change request from 91cf263. The hold still stands, so it stays fail-closed, but _held_rebuild_would_repeat and shared_template_hold_unchanged skip the rebuild while the generation, each held file's (inode, nlink, mtime) and its fenced re-read are unchanged. test_an_unrelated_hard_linked_file_holds_without_a_rebuild_per_poll proves one rebuild across four polls and a wake, and the boot, pending and retry warnings now name the real cause through _hold_cause. I tried to break it in four ways. Editing a held file through its other hard link changes mtime and triggers a rebuild. A ceiling change mismatches the generation and triggers a rebuild. A new claimant added under an unchanged generation behaves exactly as on main, where the memo also returns early. A denied read now holds instead of being skipped, which closes the restore-permissions bypass GPT found. I grepped for other readers of _projected_ceiling_generation and _conductor_spec_held: only the gateway maintenance retry reads them, so a held memo delays nothing else. That answers Design's stray-file concern. The unbound-template spawn path is now named out of scope in the description. Checks are green and the base is main. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: When the governance ceiling tightens, a shared agent template that a crew is bound to stops auto-approving the tools the ceiling now denies, as Kiro Crew's own specs and crew forks already do.
kiro-cli honours a spec file's
allowedToolsandautoApprovebefore Kiro Crew's PreToolUse gate. A ceiling move re-derives Kiro Crew's specs and re-filters forks, but a template made on the Agent templates tab, edited on the detail page, or published is filtered only when written.Why it matters
A tightened ceiling should bind the next session. For a crew bound to a shared template it did not.
Not a goal
spawn: it keeps the grants it was saved with. The spawn path is out of scope here, andgovernance.mdsays so.What changed (motivation → approach → change)
_refresh_forked_templates_lockedends with_govern_bound_shared_specs, which runs the fork refresh's two passes (_apply_governance_passes) over every spec a crew inconfig.jsonbinds, by stem or declared name, all claimants on a collision. It skips only the file another writer rewrites (_files_with_their_own_writer), and rewrites a file only when a pass removed something.fork_refresh._shared_template_held. The rebuild folds it into its conductor hold, so the ceiling memo stays pending. Any readOSErrorholds, a denied read included: kiro-cli cannot load that file now, but loads its grants once permissions are restored, with no ceiling move to retry. So do a failed listing (iter_agent_spec_files_strict) and a refused regular file (a second hard link)._shared_template_hold_record)._reproject_holding_the_lockandretry_held_conductor_specsskip the rebuild whileshared_template_hold_unchangedfinds that answer current (and the last rebuild's,_rebuild_answer_generation), every file unchanged and still held, and a fresh config load still incomplete. The probe reads through the same fence, quietly; the memo stays pending. A new answer, an edited file, a removed link or a read that now succeeds rebuilds on the next tick. A conductor installer's hold (_conductor_installers_held), a raised write and a raised rebuild are retried as before. The boot, pending and retry warnings now name a shared template or a conductor spec.Options considered:
spawnpath; that is the follow-up._PROFILE_WATCH_RETRY_S; Design, First Principles). It rewriteskirocrew.jsonand the owned specs every interval for as long as an unrelated hard link stays, which nothing bounds. After a transient failure clears, it keeps the denied grant live for up to an interval. The probe rebuilds on the next poll, and only when a retry can land._conductor_spec_held; this head adds one predicate where the retry sites rebuild. A verdict returned from the rebuild cannot carry the deferred boot pass's hold, which lands after the rebuild returned.published_frommarker, docs only, a fixed retry budget.Backwards compatibility
Compatible: only grants the current ceiling denies are removed, only on crew-bound specs; nothing is written on an ungoverned host or when nothing is denied.
Removes user data, one way: a denied
allowedToolsentry or governedautoApprovelist is dropped, not parked, so a later loosening does not restore it. Every writer of these lists already works this way. Reader paths are relative to thekiro_crewpackage.Reader: dashboard/handlers/agent_templates.py:api_agent_templates -- crew page -- lists the file minus denied entries; test_a_bound_shared_template_is_re_filtered_after_the_ceiling_tightens
Reader: dashboard/agent_admin/agent_detail.py:api_agent_detail -- crew page -- shows the remaining grants; a re-add is filtered by the same ceiling on save
Reader: dashboard/handlers/agent_panel.py:api_agent_panel_publish -- crew page -- copies the filtered file
Reader: acp/client.py:AcpClient._spawn -- chat -- kiro-cli loads the filtered spec; a removed tool still runs through the PreToolUse gate
Tests
New on this head:
test_an_unrelated_hard_linked_file_holds_without_a_rebuild_per_poll(test_conductor_allowed_tools_survive.py): the real rebuild and hook with an unbound hard-linkednotes.json. Four polls and a maintenance wake run one rebuild, the memo stays pending, and the poll after the link goes rebuilds and lands.test_a_malformed_config_overlay_holds_without_a_rebuild_per_polldoes the same with aconfig.local.jsonthat does not parse. Both fail on 91cf263 (... was rebuilt again).test_a_bound_template_made_unreadable_is_filtered_once_readable_again(mode 000, then restored) andtest_a_spec_this_user_may_not_read_holds_until_it_readsfail on 3a41f42 (False is True).test_agent_refactor_fork_refresh.py:..._holds_and_the_probe_finds_it_unchanged(quiet probe; a new answer or removed link ends it),test_a_read_failure_that_clears_with_nothing_changed_on_disk_is_retried,test_a_file_held_unread_that_is_edited_is_retried,test_a_hold_no_file_marks_records_nothing_to_probe,test_an_unreadable_config_holds_until_a_load_reads_it_whole,test_a_conductor_installer_hold_is_rebuilt_even_beside_an_unchanged_template_hold,..._still_rebuilds_when_the_answer_moved_mid_rebuild,test_the_boot_warning_names_a_shared_template_hold.Earlier rounds: about forty tests pin the filter, the exemption, each hold cause, the strict listing and the config flags.
Locally: 164 related test files pass (6
test_agent_template_skills.pyfailures also fail on clean main here); boot smoke, mypy and linters clean.Manual verification
N/A — unit coverage sufficient: real files, real rebuild and hook.
Related Issues
Fixes #9598
Pattern harvest
Rule candidate: review-prompt
Pattern: a fail-closed retry that rebuilds every tick while nothing can change.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.